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

printing data frames with validation function information #115

Merged
merged 23 commits into from
Feb 12, 2024
Merged
Changes from 5 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d6d481b
first test functions for validate_mesh_structure_pairs
viktorpm Jan 29, 2024
512cd63
storing atlases and successful/failed validation functions in a data …
viktorpm Jan 31, 2024
3aaf90a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 31, 2024
4e29467
restoring test_validation.py to the original merged version. Chages a…
viktorpm Jan 31, 2024
84de0d1
restoring test_validation.py to the original merged version. Chages a…
viktorpm Jan 31, 2024
f6b0dc0
validate_atlases.py: going back to the version on main, appending onl…
viktorpm Feb 1, 2024
fd8a6a8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 1, 2024
a0ba87b
populating dictionaries in for loop, writing JSON files
viktorpm Feb 1, 2024
6d9707b
Merge branch 'cosmetics' of github.com:brainglobe/bg-atlasgen into co…
viktorpm Feb 1, 2024
0bd3163
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 1, 2024
a980f67
saving JSON files to ~/.brainglobe/atlases/validation
viktorpm Feb 2, 2024
eec486a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 2, 2024
398dccc
printing where to find the result files
viktorpm Feb 2, 2024
56686e1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 2, 2024
576d8d2
Update bg_atlasgen/validate_atlases.py
viktorpm Feb 5, 2024
d7a7d3b
Update bg_atlasgen/validate_atlases.py
viktorpm Feb 5, 2024
defaa29
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 5, 2024
16dee78
Merge branch 'main' into cosmetics
viktorpm Feb 6, 2024
8773286
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 6, 2024
da4cc8f
saving only one JSON file with all the information
viktorpm Feb 9, 2024
6c00f6d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 9, 2024
58722fd
uncommenting test functions
viktorpm Feb 9, 2024
dea87e4
Merge branch 'cosmetics' of github.com:brainglobe/bg-atlasgen into co…
viktorpm Feb 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions bg_atlasgen/validate_atlases.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from pathlib import Path

import numpy as np
import pandas as pd

Check warning on line 8 in bg_atlasgen/validate_atlases.py

View check run for this annotation

Codecov / codecov/patch

bg_atlasgen/validate_atlases.py#L8

Added line #L8 was not covered by tests
from bg_atlasapi import BrainGlobeAtlas
from bg_atlasapi.config import get_brainglobe_dir
from bg_atlasapi.list_atlases import (
Expand All @@ -15,10 +16,10 @@
from bg_atlasapi.update_atlases import update_atlas


def validate_atlas_files(atlas: BrainGlobeAtlas):

Check warning on line 19 in bg_atlasgen/validate_atlases.py

View check run for this annotation

Codecov / codecov/patch

bg_atlasgen/validate_atlases.py#L19

Added line #L19 was not covered by tests
"""Checks if basic files exist in the atlas folder"""

atlas_path = (

Check warning on line 22 in bg_atlasgen/validate_atlases.py

View check run for this annotation

Codecov / codecov/patch

bg_atlasgen/validate_atlases.py#L22

Added line #L22 was not covered by tests
Path(get_brainglobe_dir())
/ f"{atlas.atlas_name}_v{get_local_atlas_version(atlas.atlas_name)}"
)
Expand Down Expand Up @@ -95,26 +96,26 @@
return True


def open_for_visual_check(atlas: BrainGlobeAtlas):

Check warning on line 99 in bg_atlasgen/validate_atlases.py

View check run for this annotation

Codecov / codecov/patch

bg_atlasgen/validate_atlases.py#L99

Added line #L99 was not covered by tests
# implement visual checks later
pass


def validate_checksum(atlas: BrainGlobeAtlas):

Check warning on line 104 in bg_atlasgen/validate_atlases.py

View check run for this annotation

Codecov / codecov/patch

bg_atlasgen/validate_atlases.py#L104

Added line #L104 was not covered by tests
# implement later
pass


def check_additional_references(atlas: BrainGlobeAtlas):

Check warning on line 109 in bg_atlasgen/validate_atlases.py

View check run for this annotation

Codecov / codecov/patch

bg_atlasgen/validate_atlases.py#L109

Added line #L109 was not covered by tests
# check additional references are different, but have same dimensions
pass


def validate_mesh_structure_pairs(atlas: BrainGlobeAtlas):

Check warning on line 114 in bg_atlasgen/validate_atlases.py

View check run for this annotation

Codecov / codecov/patch

bg_atlasgen/validate_atlases.py#L114

Added line #L114 was not covered by tests
"""Ensure mesh files (.obj) exist for each expected structure in the atlas."""
ids_from_bg_atlas_api = list(atlas.structures.keys())

Check warning on line 116 in bg_atlasgen/validate_atlases.py

View check run for this annotation

Codecov / codecov/patch

bg_atlasgen/validate_atlases.py#L116

Added line #L116 was not covered by tests

atlas_path = (

Check warning on line 118 in bg_atlasgen/validate_atlases.py

View check run for this annotation

Codecov / codecov/patch

bg_atlasgen/validate_atlases.py#L118

Added line #L118 was not covered by tests
Path(get_brainglobe_dir())
/ f"{atlas.atlas_name}_v{get_local_atlas_version(atlas.atlas_name)}"
)
Expand Down Expand Up @@ -143,7 +144,7 @@
)


def validate_atlas(atlas_name, version, validation_functions):

Check warning on line 147 in bg_atlasgen/validate_atlases.py

View check run for this annotation

Codecov / codecov/patch

bg_atlasgen/validate_atlases.py#L147

Added line #L147 was not covered by tests
"""Validates the latest version of a given atlas"""

print(atlas_name, version)
Expand All @@ -153,15 +154,15 @@
update_atlas(atlas_name)

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

Check warning on line 158 in bg_atlasgen/validate_atlases.py

View check run for this annotation

Codecov / codecov/patch

bg_atlasgen/validate_atlases.py#L157-L158

Added lines #L157 - L158 were not covered by tests

for i, validation_function in enumerate(validation_functions):

Check warning on line 160 in bg_atlasgen/validate_atlases.py

View check run for this annotation

Codecov / codecov/patch

bg_atlasgen/validate_atlases.py#L160

Added line #L160 was not covered by tests
try:
validation_function(BrainGlobeAtlas(atlas_name))
successful_validations[atlas_name].append(validation_function)

Check warning on line 163 in bg_atlasgen/validate_atlases.py

View check run for this annotation

Codecov / codecov/patch

bg_atlasgen/validate_atlases.py#L162-L163

Added lines #L162 - L163 were not covered by tests
except AssertionError as error:
failed_validations[atlas_name].append((validation_function, error))

Check warning on line 165 in bg_atlasgen/validate_atlases.py

View check run for this annotation

Codecov / codecov/patch

bg_atlasgen/validate_atlases.py#L165

Added line #L165 was not covered by tests

return successful_validations, failed_validations

Expand All @@ -179,17 +180,42 @@

valid_atlases = []
invalid_atlases = []
df_successful = pd.DataFrame()
df_failed = pd.DataFrame()

Check warning on line 184 in bg_atlasgen/validate_atlases.py

View check run for this annotation

Codecov / codecov/patch

bg_atlasgen/validate_atlases.py#L183-L184

Added lines #L183 - L184 were not covered by tests

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(

Check warning on line 198 in bg_atlasgen/validate_atlases.py

View check run for this annotation

Codecov / codecov/patch

bg_atlasgen/validate_atlases.py#L196-L198

Added lines #L196 - L198 were not covered by tests
[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)

Check warning on line 205 in bg_atlasgen/validate_atlases.py

View check run for this annotation

Codecov / codecov/patch

bg_atlasgen/validate_atlases.py#L203-L205

Added lines #L203 - L205 were not covered by tests
# 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)

Check warning on line 221 in bg_atlasgen/validate_atlases.py

View check run for this annotation

Codecov / codecov/patch

bg_atlasgen/validate_atlases.py#L220-L221

Added lines #L220 - L221 were not covered by tests
Loading