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

Commit

Permalink
printing data frames with validation function information (#115)
Browse files Browse the repository at this point in the history
* first test functions for validate_mesh_structure_pairs

* storing atlases and successful/failed validation functions in a data frame

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* restoring test_validation.py to the original merged version. Chages are implemented on another branch

* validate_atlases.py: going back to the version on main, appending only the name of the successful and failed functions (not the function object) to lists in validate_atlases function

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* populating dictionaries in for loop, writing JSON files

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* saving JSON files to ~/.brainglobe/atlases/validation

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* printing where to find the result files

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update bg_atlasgen/validate_atlases.py

Co-authored-by: Alessandro Felder <[email protected]>

* Update bg_atlasgen/validate_atlases.py

removing unused variables

Co-authored-by: Alessandro Felder <[email protected]>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* saving only one JSON file with all the information

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* uncommenting test functions

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Alessandro Felder <[email protected]>
  • Loading branch information
3 people authored Feb 12, 2024
1 parent ae19fad commit 03392f3
Showing 1 changed file with 33 additions and 18 deletions.
51 changes: 33 additions & 18 deletions bg_atlasgen/validate_atlases.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Script to validate atlases"""

import json
import os
from pathlib import Path

Expand Down Expand Up @@ -151,18 +152,20 @@ def validate_atlas(atlas_name, version, validation_functions):
if not updated:
update_atlas(atlas_name)

# list to store the errors of the failed validations
failed_validations = {atlas_name: []}
successful_validations = {atlas_name: []}
validation_results = {atlas_name: []}

for i, validation_function in enumerate(validation_functions):
for i, validation_function in enumerate(all_validation_functions):
try:
validation_function(BrainGlobeAtlas(atlas_name))
successful_validations[atlas_name].append(validation_function)
validation_results[atlas_name].append(
(validation_function.__name__, None, str("Pass"))
)
except AssertionError as error:
failed_validations[atlas_name].append((validation_function, error))
validation_results[atlas_name].append(
(validation_function.__name__, str(error), str("Fail"))
)

return successful_validations, failed_validations
return validation_results


if __name__ == "__main__":
Expand All @@ -178,17 +181,29 @@ def validate_atlas(atlas_name, version, validation_functions):

valid_atlases = []
invalid_atlases = []
validation_results = {}

for atlas_name, version in get_all_atlases_lastversions().items():
successful_validations, failed_validations = validate_atlas(
temp_validation_results = 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 ###")
print(valid_atlases)
print("### Invalid atlases ###")
print(invalid_atlases)
validation_results.update(temp_validation_results)

print("Validation has been completed")
print("Find validation_results.json in ~/.brainglobe/atlases/validation/")

# Get the directory path
output_dir_path = str(get_brainglobe_dir() / "atlases/validation")

# Create the directory if it doesn't exist
if not os.path.exists(output_dir_path):
os.makedirs(output_dir_path)

# Open a file for writing (will overwrite any files from previous runs!)
with open(
str(
get_brainglobe_dir() / "atlases/validation/validation_results.json"
),
"w",
) as file:
json.dump(validation_results, file)

0 comments on commit 03392f3

Please sign in to comment.