Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
tidying up duplications
Browse files Browse the repository at this point in the history
  • Loading branch information
viktorpm committed Jan 16, 2024
1 parent f7fa093 commit af84ec3
Showing 1 changed file with 27 additions and 37 deletions.
64 changes: 27 additions & 37 deletions bg_atlasgen/validate_atlases.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,42 +102,16 @@ def check_additional_references():
pass


def validate_atlas(atlas_name, version):
def validate_atlas(atlas_name, version, all_validation_functions):
"""Validates the latest version of a given atlas"""

print(atlas_name, version)
atlas = BrainGlobeAtlas(atlas_name)
BrainGlobeAtlas(atlas_name)
updated = get_atlases_lastversions()[atlas_name]["updated"]
if not updated:
update_atlas(atlas_name)
atlas_path = Path(get_brainglobe_dir()) / f"{atlas_name}_v{version}"
assert validate_atlas_files(
atlas_path
), f"Atlas file {atlas_path} validation failed"
assert validate_mesh_matches_image_extents(
atlas
), "Atlas object validation failed"


# list to store the validation functions
all_validation_functions = [
validate_atlas_files,
validate_mesh_matches_image_extents,
open_for_visual_check,
validate_checksum,
check_additional_references,
validate_atlas,
]

# list to store atlas specific parameters for all validation function
all_validation_function_parameters = []

# list to store the errors of the failed validations
failed_validations = []
successful_validations = []


for atlas_name, version in get_all_atlases_lastversions().items():
Path(get_brainglobe_dir()) / f"{atlas_name}_v{version}"

validation_function_parameters = [
# validate_atlas_files(atlas_path: Path)
(Path(get_brainglobe_dir() / f"{atlas_name}_v{version}"),),
Expand All @@ -152,7 +126,10 @@ def validate_atlas(atlas_name, version):
# validate_atlas(atlas_name, version)
(atlas_name, version),
]
# all_validation_function_parameters.append(validation_function_parameters)

# list to store the errors of the failed validations
failed_validations = []
successful_validations = []

for i, validation_function in enumerate(all_validation_functions):
try:
Expand All @@ -161,17 +138,30 @@ def validate_atlas(atlas_name, version):
except AssertionError as error:
failed_validations.append((atlas_name, validation_function, error))

return successful_validations, failed_validations


if __name__ == "__main__":
# list to store the validation functions
all_validation_functions = [
validate_atlas_files,
validate_mesh_matches_image_extents,
open_for_visual_check,
validate_checksum,
check_additional_references,
validate_atlas,
]

valid_atlases = []
invalid_atlases = []
for atlas_name, version in get_all_atlases_lastversions().items():
try:
validate_atlas(atlas_name, version)
valid_atlases.append(atlas_name)
except AssertionError as e:
invalid_atlases.append((atlas_name, e))
continue
successful_validations, failed_validations = validate_atlas(
atlas_name, version, all_validation_functions
)
for item in successful_validations:
valid_atlases.append(item)
for item in failed_validations:
invalid_atlases.append(item)

print("Summary")
print("### Valid atlases ###")
Expand Down

0 comments on commit af84ec3

Please sign in to comment.