From d6d481b696785cfab33875e316d6073bd8a744d2 Mon Sep 17 00:00:00 2001 From: Viktor Plattner Date: Mon, 29 Jan 2024 16:47:44 +0000 Subject: [PATCH 01/19] first test functions for validate_mesh_structure_pairs --- tests/test_unit/test_validation.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/test_unit/test_validation.py b/tests/test_unit/test_validation.py index 5fcf9f0..cb24d91 100644 --- a/tests/test_unit/test_validation.py +++ b/tests/test_unit/test_validation.py @@ -9,6 +9,7 @@ _assert_close, validate_atlas_files, validate_mesh_matches_image_extents, + validate_mesh_structure_pairs, ) @@ -69,3 +70,24 @@ def test_assert_close_negative(): AssertionError, match="differ by more than 10 times pixel size" ): _assert_close(99.5, 30, 2) + +def test_validate_mesh_structure_pairs_no_obj(atlas): + """ + Tests if validate_mesh_structure_pairs function raises an error, + when there is at least one structure in the atlas that doesn't have + a corresponding obj file. + + True for: allen_mouse_100um (structure 545 doesn't have an obj file) + False for: admba_3d_e11_5_mouse_16um (it has all pairs) + + """ + with pytest.raises( + AssertionError, match="Structures with ID \[.*\] are in the atlas, but don't have a corresponding mesh file" + ): + validate_mesh_structure_pairs(atlas) + +def test_validate_mesh_structure_pairs_not_in_atlas(atlas): + with pytest.raises( + AssertionError, match="Structures with IDs \[.*\] have a mesh file, but are not accessible through the atlas" + ): + validate_mesh_structure_pairs(atlas) \ No newline at end of file From 512cd639c3b072181e7474808224fc5917ec2d4a Mon Sep 17 00:00:00 2001 From: Viktor Plattner Date: Wed, 31 Jan 2024 12:25:46 +0000 Subject: [PATCH 02/19] storing atlases and successful/failed validation functions in a data frame --- bg_atlasgen/validate_atlases.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/bg_atlasgen/validate_atlases.py b/bg_atlasgen/validate_atlases.py index 503883f..f592101 100644 --- a/bg_atlasgen/validate_atlases.py +++ b/bg_atlasgen/validate_atlases.py @@ -5,6 +5,7 @@ from pathlib import Path import numpy as np +import pandas as pd from bg_atlasapi import BrainGlobeAtlas from bg_atlasapi.config import get_brainglobe_dir from bg_atlasapi.list_atlases import ( @@ -179,17 +180,42 @@ def validate_atlas(atlas_name, version, validation_functions): valid_atlases = [] invalid_atlases = [] + df_successful = pd.DataFrame() + df_failed = pd.DataFrame() + for atlas_name, version in get_all_atlases_lastversions().items(): 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) + for k, v in successful_validations.items(): + new_row = pd.DataFrame({'Atlas': [k], 'Function': [v]}) + df_successful = pd.concat([df_successful, new_row], ignore_index=True) + # df_successful["Function"] = df_successful["Function"].apply(lambda x: x[0].__name__ if x else pd.NA) + + for k, v in failed_validations.items(): + new_row = pd.DataFrame({'Atlas': [k], 'Function': [v]}) + df_failed = pd.concat([df_failed, new_row], ignore_index=True) + # df_failed["Function"] = df_failed["Function"].apply(lambda x: x[0].__name__ if x else pd.NA) + + print("Summary") print("### Valid atlases ###") print(valid_atlases) print("### Invalid atlases ###") print(invalid_atlases) + + # df_successful = pd.DataFrame(data=successful_validations.items(), columns=["Atlas", "Function"]) + # df_successful["Function"] = df_successful["Function"].apply(lambda x: x[0].__name__ if x else pd.NA) + # + # df_failed = pd.DataFrame(failed_validations.items(), columns=["Atlas", "Function"]) + # df_failed["Function"] = df_failed["Function"].apply(lambda x: x[0].__name__ if x else pd.NA) + + + print(df_successful) + print(df_failed) From 3aaf90a5a6d2c43bee62d008ae69b862aea077cd Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 31 Jan 2024 12:41:41 +0000 Subject: [PATCH 03/19] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- bg_atlasgen/validate_atlases.py | 10 +++++----- tests/test_unit/test_validation.py | 10 +++++++--- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/bg_atlasgen/validate_atlases.py b/bg_atlasgen/validate_atlases.py index f592101..94f6f9e 100644 --- a/bg_atlasgen/validate_atlases.py +++ b/bg_atlasgen/validate_atlases.py @@ -194,16 +194,17 @@ def validate_atlas(atlas_name, version, validation_functions): invalid_atlases.append(item) for k, v in successful_validations.items(): - new_row = pd.DataFrame({'Atlas': [k], 'Function': [v]}) - df_successful = pd.concat([df_successful, new_row], ignore_index=True) + new_row = pd.DataFrame({"Atlas": [k], "Function": [v]}) + df_successful = pd.concat( + [df_successful, new_row], ignore_index=True + ) # df_successful["Function"] = df_successful["Function"].apply(lambda x: x[0].__name__ if x else pd.NA) for k, v in failed_validations.items(): - new_row = pd.DataFrame({'Atlas': [k], 'Function': [v]}) + new_row = pd.DataFrame({"Atlas": [k], "Function": [v]}) df_failed = pd.concat([df_failed, new_row], ignore_index=True) # df_failed["Function"] = df_failed["Function"].apply(lambda x: x[0].__name__ if x else pd.NA) - print("Summary") print("### Valid atlases ###") print(valid_atlases) @@ -216,6 +217,5 @@ def validate_atlas(atlas_name, version, validation_functions): # df_failed = pd.DataFrame(failed_validations.items(), columns=["Atlas", "Function"]) # df_failed["Function"] = df_failed["Function"].apply(lambda x: x[0].__name__ if x else pd.NA) - print(df_successful) print(df_failed) diff --git a/tests/test_unit/test_validation.py b/tests/test_unit/test_validation.py index cb24d91..57bc401 100644 --- a/tests/test_unit/test_validation.py +++ b/tests/test_unit/test_validation.py @@ -71,6 +71,7 @@ def test_assert_close_negative(): ): _assert_close(99.5, 30, 2) + def test_validate_mesh_structure_pairs_no_obj(atlas): """ Tests if validate_mesh_structure_pairs function raises an error, @@ -82,12 +83,15 @@ def test_validate_mesh_structure_pairs_no_obj(atlas): """ with pytest.raises( - AssertionError, match="Structures with ID \[.*\] are in the atlas, but don't have a corresponding mesh file" + AssertionError, + match="Structures with ID \[.*\] are in the atlas, but don't have a corresponding mesh file", ): validate_mesh_structure_pairs(atlas) + def test_validate_mesh_structure_pairs_not_in_atlas(atlas): with pytest.raises( - AssertionError, match="Structures with IDs \[.*\] have a mesh file, but are not accessible through the atlas" + AssertionError, + match="Structures with IDs \[.*\] have a mesh file, but are not accessible through the atlas", ): - validate_mesh_structure_pairs(atlas) \ No newline at end of file + validate_mesh_structure_pairs(atlas) From 4e29467c594fc320aba9989f570fd4eafa610f73 Mon Sep 17 00:00:00 2001 From: Viktor Plattner Date: Wed, 31 Jan 2024 12:46:33 +0000 Subject: [PATCH 04/19] restoring test_validation.py to the original merged version. Chages are implemented on another branch --- tests/test_unit/test_validation.py | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/tests/test_unit/test_validation.py b/tests/test_unit/test_validation.py index cb24d91..5fcf9f0 100644 --- a/tests/test_unit/test_validation.py +++ b/tests/test_unit/test_validation.py @@ -9,7 +9,6 @@ _assert_close, validate_atlas_files, validate_mesh_matches_image_extents, - validate_mesh_structure_pairs, ) @@ -70,24 +69,3 @@ def test_assert_close_negative(): AssertionError, match="differ by more than 10 times pixel size" ): _assert_close(99.5, 30, 2) - -def test_validate_mesh_structure_pairs_no_obj(atlas): - """ - Tests if validate_mesh_structure_pairs function raises an error, - when there is at least one structure in the atlas that doesn't have - a corresponding obj file. - - True for: allen_mouse_100um (structure 545 doesn't have an obj file) - False for: admba_3d_e11_5_mouse_16um (it has all pairs) - - """ - with pytest.raises( - AssertionError, match="Structures with ID \[.*\] are in the atlas, but don't have a corresponding mesh file" - ): - validate_mesh_structure_pairs(atlas) - -def test_validate_mesh_structure_pairs_not_in_atlas(atlas): - with pytest.raises( - AssertionError, match="Structures with IDs \[.*\] have a mesh file, but are not accessible through the atlas" - ): - validate_mesh_structure_pairs(atlas) \ No newline at end of file From f6b0dc07f7dcd9ada6ce4a2bef46b6f050d5a73b Mon Sep 17 00:00:00 2001 From: Viktor Plattner Date: Thu, 1 Feb 2024 16:25:58 +0000 Subject: [PATCH 05/19] 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 --- bg_atlasgen/validate_atlases.py | 32 +++----------------------------- 1 file changed, 3 insertions(+), 29 deletions(-) diff --git a/bg_atlasgen/validate_atlases.py b/bg_atlasgen/validate_atlases.py index 94f6f9e..9315cb8 100644 --- a/bg_atlasgen/validate_atlases.py +++ b/bg_atlasgen/validate_atlases.py @@ -5,7 +5,6 @@ from pathlib import Path import numpy as np -import pandas as pd from bg_atlasapi import BrainGlobeAtlas from bg_atlasapi.config import get_brainglobe_dir from bg_atlasapi.list_atlases import ( @@ -153,16 +152,16 @@ def validate_atlas(atlas_name, version, validation_functions): if not updated: update_atlas(atlas_name) - # list to store the errors of the failed validations + # dictionary of lists to store the errors of the failed validations failed_validations = {atlas_name: []} successful_validations = {atlas_name: []} for i, validation_function in enumerate(validation_functions): try: validation_function(BrainGlobeAtlas(atlas_name)) - successful_validations[atlas_name].append(validation_function) + successful_validations[atlas_name].append(validation_function.__name__) except AssertionError as error: - failed_validations[atlas_name].append((validation_function, error)) + failed_validations[atlas_name].append((validation_function.__name__, str(error))) return successful_validations, failed_validations @@ -180,42 +179,17 @@ def validate_atlas(atlas_name, version, validation_functions): valid_atlases = [] invalid_atlases = [] - df_successful = pd.DataFrame() - df_failed = pd.DataFrame() - for atlas_name, version in get_all_atlases_lastversions().items(): 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) - for k, v in successful_validations.items(): - new_row = pd.DataFrame({"Atlas": [k], "Function": [v]}) - df_successful = pd.concat( - [df_successful, new_row], ignore_index=True - ) - # df_successful["Function"] = df_successful["Function"].apply(lambda x: x[0].__name__ if x else pd.NA) - - for k, v in failed_validations.items(): - new_row = pd.DataFrame({"Atlas": [k], "Function": [v]}) - df_failed = pd.concat([df_failed, new_row], ignore_index=True) - # df_failed["Function"] = df_failed["Function"].apply(lambda x: x[0].__name__ if x else pd.NA) - print("Summary") print("### Valid atlases ###") print(valid_atlases) print("### Invalid atlases ###") print(invalid_atlases) - - # df_successful = pd.DataFrame(data=successful_validations.items(), columns=["Atlas", "Function"]) - # df_successful["Function"] = df_successful["Function"].apply(lambda x: x[0].__name__ if x else pd.NA) - # - # df_failed = pd.DataFrame(failed_validations.items(), columns=["Atlas", "Function"]) - # df_failed["Function"] = df_failed["Function"].apply(lambda x: x[0].__name__ if x else pd.NA) - - print(df_successful) - print(df_failed) From fd8a6a8a2fdc8dac8b0207554e079b7ba2bc40e2 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 1 Feb 2024 16:26:12 +0000 Subject: [PATCH 06/19] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- bg_atlasgen/validate_atlases.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bg_atlasgen/validate_atlases.py b/bg_atlasgen/validate_atlases.py index 9315cb8..b038fba 100644 --- a/bg_atlasgen/validate_atlases.py +++ b/bg_atlasgen/validate_atlases.py @@ -159,9 +159,13 @@ def validate_atlas(atlas_name, version, validation_functions): for i, validation_function in enumerate(validation_functions): try: validation_function(BrainGlobeAtlas(atlas_name)) - successful_validations[atlas_name].append(validation_function.__name__) + successful_validations[atlas_name].append( + validation_function.__name__ + ) except AssertionError as error: - failed_validations[atlas_name].append((validation_function.__name__, str(error))) + failed_validations[atlas_name].append( + (validation_function.__name__, str(error)) + ) return successful_validations, failed_validations From a0ba87b1ba89e434679855d37e09d95f68f78f39 Mon Sep 17 00:00:00 2001 From: Viktor Plattner Date: Thu, 1 Feb 2024 17:14:21 +0000 Subject: [PATCH 07/19] populating dictionaries in for loop, writing JSON files --- bg_atlasgen/validate_atlases.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/bg_atlasgen/validate_atlases.py b/bg_atlasgen/validate_atlases.py index 9315cb8..aab1b9e 100644 --- a/bg_atlasgen/validate_atlases.py +++ b/bg_atlasgen/validate_atlases.py @@ -2,6 +2,7 @@ import os +import json from pathlib import Path import numpy as np @@ -179,10 +180,17 @@ def validate_atlas(atlas_name, version, validation_functions): valid_atlases = [] invalid_atlases = [] + successful_validations = {} + failed_validations = {} + for atlas_name, version in get_all_atlases_lastversions().items(): - successful_validations, failed_validations = validate_atlas( + temp_successful_validations, temp_failed_validations = validate_atlas( atlas_name, version, all_validation_functions ) + + successful_validations.update(temp_successful_validations) + failed_validations.update(temp_failed_validations) + for item in successful_validations: valid_atlases.append(item) for item in failed_validations: @@ -193,3 +201,12 @@ def validate_atlas(atlas_name, version, validation_functions): print(valid_atlases) print("### Invalid atlases ###") print(invalid_atlases) + + # Open a file for writing + with open('failed_validations.json', 'w') as file: + # Write the dictionary to the file in JSON format + json.dump(failed_validations, file) + + with open('successful_validations.json', 'w') as file: + # Write the dictionary to the file in JSON format + json.dump(successful_validations, file) \ No newline at end of file From 0bd3163cbda5a24d59d4858a5bc4bd58c7d67ddc Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 1 Feb 2024 17:16:53 +0000 Subject: [PATCH 08/19] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- bg_atlasgen/validate_atlases.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bg_atlasgen/validate_atlases.py b/bg_atlasgen/validate_atlases.py index 61fd0b9..0786e60 100644 --- a/bg_atlasgen/validate_atlases.py +++ b/bg_atlasgen/validate_atlases.py @@ -1,8 +1,8 @@ """Script to validate atlases""" -import os import json +import os from pathlib import Path import numpy as np @@ -207,10 +207,10 @@ def validate_atlas(atlas_name, version, validation_functions): print(invalid_atlases) # Open a file for writing - with open('failed_validations.json', 'w') as file: + with open("failed_validations.json", "w") as file: # Write the dictionary to the file in JSON format json.dump(failed_validations, file) - with open('successful_validations.json', 'w') as file: + with open("successful_validations.json", "w") as file: # Write the dictionary to the file in JSON format - json.dump(successful_validations, file) \ No newline at end of file + json.dump(successful_validations, file) From a980f673d3d403f266bceded5b8ef5c843232bcb Mon Sep 17 00:00:00 2001 From: Viktor Plattner Date: Fri, 2 Feb 2024 14:12:01 +0000 Subject: [PATCH 09/19] saving JSON files to ~/.brainglobe/atlases/validation --- bg_atlasgen/validate_atlases.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/bg_atlasgen/validate_atlases.py b/bg_atlasgen/validate_atlases.py index 0786e60..2294c7c 100644 --- a/bg_atlasgen/validate_atlases.py +++ b/bg_atlasgen/validate_atlases.py @@ -206,11 +206,18 @@ def validate_atlas(atlas_name, version, validation_functions): print("### Invalid atlases ###") print(invalid_atlases) + # 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 - with open("failed_validations.json", "w") as file: + with open(str(get_brainglobe_dir() / "atlases/validation/failed_validations.json"), "w") as file: # Write the dictionary to the file in JSON format json.dump(failed_validations, file) - with open("successful_validations.json", "w") as file: + with open(str(get_brainglobe_dir() / "atlases/validation/successful_validations.json"), "w") as file: # Write the dictionary to the file in JSON format json.dump(successful_validations, file) From eec486a21f353ad186ff830f8581ddca7aad44c6 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 2 Feb 2024 14:12:41 +0000 Subject: [PATCH 10/19] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- bg_atlasgen/validate_atlases.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/bg_atlasgen/validate_atlases.py b/bg_atlasgen/validate_atlases.py index 2294c7c..e3cc542 100644 --- a/bg_atlasgen/validate_atlases.py +++ b/bg_atlasgen/validate_atlases.py @@ -214,10 +214,21 @@ def validate_atlas(atlas_name, version, validation_functions): os.makedirs(output_dir_path) # Open a file for writing - with open(str(get_brainglobe_dir() / "atlases/validation/failed_validations.json"), "w") as file: + with open( + str( + get_brainglobe_dir() / "atlases/validation/failed_validations.json" + ), + "w", + ) as file: # Write the dictionary to the file in JSON format json.dump(failed_validations, file) - with open(str(get_brainglobe_dir() / "atlases/validation/successful_validations.json"), "w") as file: + with open( + str( + get_brainglobe_dir() + / "atlases/validation/successful_validations.json" + ), + "w", + ) as file: # Write the dictionary to the file in JSON format json.dump(successful_validations, file) From 398dcccc7f55cea21919ba2ba3b4adc9d53639d2 Mon Sep 17 00:00:00 2001 From: Viktor Plattner Date: Fri, 2 Feb 2024 14:26:07 +0000 Subject: [PATCH 11/19] printing where to find the result files --- bg_atlasgen/validate_atlases.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/bg_atlasgen/validate_atlases.py b/bg_atlasgen/validate_atlases.py index e3cc542..f65c3a9 100644 --- a/bg_atlasgen/validate_atlases.py +++ b/bg_atlasgen/validate_atlases.py @@ -200,11 +200,8 @@ def validate_atlas(atlas_name, version, validation_functions): for item in failed_validations: invalid_atlases.append(item) - print("Summary") - print("### Valid atlases ###") - print(valid_atlases) - print("### Invalid atlases ###") - print(invalid_atlases) + print("Validation has been completed") + print("Find successful_validations.json and failed_validations.json in ~/.brainglobe/atlases/validation/") # Get the directory path output_dir_path = str(get_brainglobe_dir() / "atlases/validation") From 56686e15a8f81dc0b6a00a1a546c1f2f9c3a46db Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 2 Feb 2024 14:31:00 +0000 Subject: [PATCH 12/19] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- bg_atlasgen/validate_atlases.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bg_atlasgen/validate_atlases.py b/bg_atlasgen/validate_atlases.py index f65c3a9..4f26279 100644 --- a/bg_atlasgen/validate_atlases.py +++ b/bg_atlasgen/validate_atlases.py @@ -201,7 +201,9 @@ def validate_atlas(atlas_name, version, validation_functions): invalid_atlases.append(item) print("Validation has been completed") - print("Find successful_validations.json and failed_validations.json in ~/.brainglobe/atlases/validation/") + print( + "Find successful_validations.json and failed_validations.json in ~/.brainglobe/atlases/validation/" + ) # Get the directory path output_dir_path = str(get_brainglobe_dir() / "atlases/validation") From 576d8d204a1d6d61e435da4f77ac047c0ce55b53 Mon Sep 17 00:00:00 2001 From: viktorpm <50667179+viktorpm@users.noreply.github.com> Date: Mon, 5 Feb 2024 14:27:41 +0000 Subject: [PATCH 13/19] Update bg_atlasgen/validate_atlases.py Co-authored-by: Alessandro Felder --- bg_atlasgen/validate_atlases.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bg_atlasgen/validate_atlases.py b/bg_atlasgen/validate_atlases.py index 4f26279..9b1453a 100644 --- a/bg_atlasgen/validate_atlases.py +++ b/bg_atlasgen/validate_atlases.py @@ -212,7 +212,7 @@ def validate_atlas(atlas_name, version, validation_functions): if not os.path.exists(output_dir_path): os.makedirs(output_dir_path) - # Open a file for writing + # Open a file for writing (will overwrite any files from previous runs!) with open( str( get_brainglobe_dir() / "atlases/validation/failed_validations.json" From d7a7d3b59b889df5a5f91e0e92e41c627bd3c18a Mon Sep 17 00:00:00 2001 From: viktorpm <50667179+viktorpm@users.noreply.github.com> Date: Mon, 5 Feb 2024 14:46:45 +0000 Subject: [PATCH 14/19] Update bg_atlasgen/validate_atlases.py removing unused variables Co-authored-by: Alessandro Felder --- bg_atlasgen/validate_atlases.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/bg_atlasgen/validate_atlases.py b/bg_atlasgen/validate_atlases.py index 9b1453a..b22b8b8 100644 --- a/bg_atlasgen/validate_atlases.py +++ b/bg_atlasgen/validate_atlases.py @@ -195,10 +195,6 @@ def validate_atlas(atlas_name, version, validation_functions): successful_validations.update(temp_successful_validations) failed_validations.update(temp_failed_validations) - for item in successful_validations: - valid_atlases.append(item) - for item in failed_validations: - invalid_atlases.append(item) print("Validation has been completed") print( From defaa294ff9c6999da1625a5cbd9a098fa384832 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 5 Feb 2024 14:47:23 +0000 Subject: [PATCH 15/19] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- bg_atlasgen/validate_atlases.py | 1 - 1 file changed, 1 deletion(-) diff --git a/bg_atlasgen/validate_atlases.py b/bg_atlasgen/validate_atlases.py index b22b8b8..8af2db7 100644 --- a/bg_atlasgen/validate_atlases.py +++ b/bg_atlasgen/validate_atlases.py @@ -195,7 +195,6 @@ def validate_atlas(atlas_name, version, validation_functions): successful_validations.update(temp_successful_validations) failed_validations.update(temp_failed_validations) - print("Validation has been completed") print( "Find successful_validations.json and failed_validations.json in ~/.brainglobe/atlases/validation/" From 8773286d1c44c398c15353a2628da334c5b85b57 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 6 Feb 2024 13:23:43 +0000 Subject: [PATCH 16/19] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- bg_atlasgen/validate_atlases.py | 1 - 1 file changed, 1 deletion(-) diff --git a/bg_atlasgen/validate_atlases.py b/bg_atlasgen/validate_atlases.py index 6a2db52..7cee1db 100644 --- a/bg_atlasgen/validate_atlases.py +++ b/bg_atlasgen/validate_atlases.py @@ -1,7 +1,6 @@ """Script to validate atlases""" import json - import os from pathlib import Path From da4cc8f61aa905e153b66819eb0deae516e25745 Mon Sep 17 00:00:00 2001 From: Viktor Plattner Date: Fri, 9 Feb 2024 16:45:16 +0000 Subject: [PATCH 17/19] saving only one JSON file with all the information --- bg_atlasgen/validate_atlases.py | 51 +++++++++++---------------------- 1 file changed, 17 insertions(+), 34 deletions(-) diff --git a/bg_atlasgen/validate_atlases.py b/bg_atlasgen/validate_atlases.py index 7cee1db..b287bf7 100644 --- a/bg_atlasgen/validate_atlases.py +++ b/bg_atlasgen/validate_atlases.py @@ -152,51 +152,45 @@ def validate_atlas(atlas_name, version, validation_functions): if not updated: update_atlas(atlas_name) - # dictionary of lists 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.__name__ + validation_results[atlas_name].append( + (validation_function.__name__, None, str("Pass")) ) except AssertionError as error: - failed_validations[atlas_name].append( - (validation_function.__name__, str(error)) + validation_results[atlas_name].append( + (validation_function.__name__, str(error), str("Fail")) ) - return successful_validations, failed_validations + return validation_results 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, + # validate_atlas_files, + # validate_mesh_matches_image_extents, + # open_for_visual_check, + # validate_checksum, check_additional_references, validate_mesh_structure_pairs, ] valid_atlases = [] invalid_atlases = [] - successful_validations = {} - failed_validations = {} + validation_results = {} for atlas_name, version in get_all_atlases_lastversions().items(): - temp_successful_validations, temp_failed_validations = validate_atlas( - atlas_name, version, all_validation_functions - ) + temp_validation_results = validate_atlas(atlas_name, version, all_validation_functions) + validation_results.update(temp_validation_results) - successful_validations.update(temp_successful_validations) - failed_validations.update(temp_failed_validations) print("Validation has been completed") print( - "Find successful_validations.json and failed_validations.json in ~/.brainglobe/atlases/validation/" + "Find validation_results.json in ~/.brainglobe/atlases/validation/" ) # Get the directory path @@ -209,19 +203,8 @@ def validate_atlas(atlas_name, version, validation_functions): # Open a file for writing (will overwrite any files from previous runs!) with open( str( - get_brainglobe_dir() / "atlases/validation/failed_validations.json" - ), - "w", - ) as file: - # Write the dictionary to the file in JSON format - json.dump(failed_validations, file) - - with open( - str( - get_brainglobe_dir() - / "atlases/validation/successful_validations.json" + get_brainglobe_dir() / "atlases/validation/validation_results.json" ), "w", ) as file: - # Write the dictionary to the file in JSON format - json.dump(successful_validations, file) + json.dump(validation_results, file) \ No newline at end of file From 6c00f6d3699ab002c1f0e066d87456b791196ff8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 9 Feb 2024 16:45:30 +0000 Subject: [PATCH 18/19] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- bg_atlasgen/validate_atlases.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/bg_atlasgen/validate_atlases.py b/bg_atlasgen/validate_atlases.py index b287bf7..d28ae33 100644 --- a/bg_atlasgen/validate_atlases.py +++ b/bg_atlasgen/validate_atlases.py @@ -184,14 +184,13 @@ def validate_atlas(atlas_name, version, validation_functions): validation_results = {} for atlas_name, version in get_all_atlases_lastversions().items(): - temp_validation_results = validate_atlas(atlas_name, version, all_validation_functions) + temp_validation_results = validate_atlas( + atlas_name, version, all_validation_functions + ) validation_results.update(temp_validation_results) - print("Validation has been completed") - print( - "Find validation_results.json in ~/.brainglobe/atlases/validation/" - ) + print("Find validation_results.json in ~/.brainglobe/atlases/validation/") # Get the directory path output_dir_path = str(get_brainglobe_dir() / "atlases/validation") @@ -207,4 +206,4 @@ def validate_atlas(atlas_name, version, validation_functions): ), "w", ) as file: - json.dump(validation_results, file) \ No newline at end of file + json.dump(validation_results, file) From 58722fd68c7c31fa29343eb5c68bcf7cfc3f5d70 Mon Sep 17 00:00:00 2001 From: Viktor Plattner Date: Fri, 9 Feb 2024 17:38:50 +0000 Subject: [PATCH 19/19] uncommenting test functions --- bg_atlasgen/validate_atlases.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bg_atlasgen/validate_atlases.py b/bg_atlasgen/validate_atlases.py index b287bf7..ce8cbf6 100644 --- a/bg_atlasgen/validate_atlases.py +++ b/bg_atlasgen/validate_atlases.py @@ -171,10 +171,10 @@ def validate_atlas(atlas_name, version, validation_functions): 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, + validate_atlas_files, + validate_mesh_matches_image_extents, + open_for_visual_check, + validate_checksum, check_additional_references, validate_mesh_structure_pairs, ]