Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrating atlas validation in wrapup.py #445

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

viktorpm
Copy link
Contributor

@viktorpm viktorpm commented Jan 20, 2025

Description

This PR integrates our atlas validation functions in the wrapup section of atlas packaging.

What is this PR

  • Bug fix
  • Addition of a new feature
  • Other

Why is this PR needed?

Currently, we run the validation functions on finalised atlases. We want to integrate this step with atlas generation to see if an atlas is valid or not immediately.

References

?

How has this PR been tested?

Locally on

  • whs_sd_rat.py
  • princeton_mouse.py
  • admba_3d_dev_mouse.py
  • axolotl_atlas.py
  • cavefish_atlas.py
  • humanatlas.py

Is this a breaking change?

No

Does this PR require an update to the documentation?

Possibly

Checklist:

  • The code has been tested locally
  • Tests have been added to cover all new functionality (unit & integration)
  • The documentation has been updated to reflect any changes
  • The code has been formatted with pre-commit

@viktorpm
Copy link
Contributor Author

Example output for whs_sd_rat.py:

No mesh file exists for: {'name': 'spiral ganglion', 'acronym': 'SpG', 'id': 162, 'structure_id_path': [10000, 1049, 162], 'rgb_triplet': (185, 255, 233)}, ignoring it
In the end, 1 structures with mesh are kept
Finalising atlas
Running atlas validation on whs_sd_rat_39um_v1.2
passed validate_atlas_files
passed catch_missing_structures
passed catch_missing_mesh_files
failed validate_mesh_matches_image_extents: ('Mesh coordinate 955.5 and annotation coordinate 0.0', 'differ by more than 10 times pixel size 39.0')
passed open_for_visual_check
passed validate_checksum
passed validate_image_dimensions
passed validate_additional_references
Saving compressed atlas data at: /home/plattnerv/brainglobe_workingdir/whs_sd_rat/whs_sd_rat_39um_v1.2.tar.gz

Process finished with exit code 0

Catches known error.

@viktorpm viktorpm marked this pull request as ready for review January 20, 2025 17:43
Copy link
Member

@alessandrofelder alessandrofelder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lovely.

Two small comments for simplification :)

brainglobe_atlasapi/atlas_generation/wrapup.py Outdated Show resolved Hide resolved
brainglobe_atlasapi/atlas_generation/wrapup.py Outdated Show resolved Hide resolved
Copy link
Member

@alessandrofelder alessandrofelder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @viktorpm

Sorry - I wasn't clear enough in my description of the changes I suggested, which (if I am right??) would significantly simplify the code even further. (Let's chat if you have questions!).

@@ -174,18 +196,28 @@ def catch_missing_mesh_files(atlas: BrainGlobeAtlas):
)


def catch_missing_structures(atlas: BrainGlobeAtlas):
def catch_missing_structures(
atlas: BrainGlobeAtlas, custom_atlas_path: Path = None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
atlas: BrainGlobeAtlas, custom_atlas_path: Path = None
atlas: BrainGlobeAtlas

Comment on lines +213 to 221
if custom_atlas_path is None:
atlas_path = (
Path(get_brainglobe_dir()) / f"{atlas.atlas_name}_v"
f"{get_local_atlas_version(atlas.atlas_name)}"
)
else:
atlas_path = custom_atlas_path

obj_path = Path(atlas_path / "meshes")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if custom_atlas_path is None:
atlas_path = (
Path(get_brainglobe_dir()) / f"{atlas.atlas_name}_v"
f"{get_local_atlas_version(atlas.atlas_name)}"
)
else:
atlas_path = custom_atlas_path
obj_path = Path(atlas_path / "meshes")
obj_path = Path(atlas.root_dir/ "meshes")

This is what I had in mind (and for other functions for which this PRs adds a custom_atlas_path parameter.

Comment on lines +260 to +275
(validate_atlas_files, atlas_to_validate, atlas_to_validate.root_dir),
(
catch_missing_structures,
atlas_to_validate,
atlas_to_validate.root_dir,
),
(
catch_missing_mesh_files,
atlas_to_validate,
atlas_to_validate.root_dir,
),
(validate_mesh_matches_image_extents, atlas_to_validate),
(open_for_visual_check, atlas_to_validate),
(validate_checksum, atlas_to_validate),
(validate_image_dimensions, atlas_to_validate),
(validate_additional_references, atlas_to_validate),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do the changes I suggested, this can just be a list of functions (without atlas_to_validate or atlas_to_validate.root_dir!) and we can just call func(atlas_to_validate) below

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants