From 03392f34408f11c14f72c9d5c4fedf93aa9f1ddf Mon Sep 17 00:00:00 2001 From: viktorpm <50667179+viktorpm@users.noreply.github.com> Date: Mon, 12 Feb 2024 10:13:36 +0000 Subject: [PATCH] printing data frames with validation function information (#115) * 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 * Update bg_atlasgen/validate_atlases.py removing unused variables Co-authored-by: Alessandro Felder * [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 --- bg_atlasgen/validate_atlases.py | 51 +++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/bg_atlasgen/validate_atlases.py b/bg_atlasgen/validate_atlases.py index d993c5c..56b7618 100644 --- a/bg_atlasgen/validate_atlases.py +++ b/bg_atlasgen/validate_atlases.py @@ -1,5 +1,6 @@ """Script to validate atlases""" +import json import os from pathlib import Path @@ -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__": @@ -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)