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

Commit

Permalink
Structure validation (#110)
Browse files Browse the repository at this point in the history
* draft validation functions

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

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

* run on all atlases, don't crash on assertion error

* fixing atlas path

* Clearer output printing

* tidy up validation script, remove weird test_git

* add dev install, make test structure, initial tests

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

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

* add tests and return for _assert_close()

* add test for validate mesh matches annotation

* fix linting

* update version for actions

* drop py3.8 in tox, run pytest in tox

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

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

* fix copy-paste error in pytest command

* drop py3.8 from gh action workflow file too

* Adding docstrings to validation script

* wip: draft structure validation function

* Making path tests stricter, breaking up long strings, adding diff_tolerance argument to _assert_close function

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

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

* restructuring validate_mesh_matches_image_extents function, adding comments

* testing expected files and  meshes directory separately

* looping through validation functions and parameters to catch individual errors

* removing hard coded path, generalising to all atlases

* adding successful_validations list

* tidying up duplications

* fix recursive bug

* checkout finished validate_atlases.py from validation branch

* adding validate_mesh_structure_pairs function

* Update bg_atlasgen/validate_atlases.py

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

* adding assertion to validate_mesh_structure_pairs function

* checking IDs via bg_atlasapi, checking if IDs have mesh files and accesible through the atlas

* Update bg_atlasgen/validate_atlases.py

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

* passing atlas_name to validate_mesh_structure_pairs function

* addressing Niko's final comments, cleaning code

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

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

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Alessandro Felder <[email protected]>
Co-authored-by: alessandrofelder <[email protected]>
  • Loading branch information
4 people authored Jan 23, 2024
1 parent 93e95ab commit a4acdb4
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions bg_atlasgen/validate_atlases.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Script to validate atlases"""


import os
from pathlib import Path

import numpy as np
Expand Down Expand Up @@ -104,6 +105,36 @@ def check_additional_references():
pass


def validate_mesh_structure_pairs(atlas_name: str, atlas_path: Path):
# json_path = Path(atlas_path / "structures.json")
atlas = BrainGlobeAtlas(atlas_name)

obj_path = Path(atlas_path / "meshes")

ids_from_bg_atlas_api = list(atlas.structures.keys())
ids_from_mesh_files = [
int(Path(file).stem)
for file in os.listdir(obj_path)
if file.endswith(".obj")
]

in_mesh_not_bg = []
for id in ids_from_mesh_files:
if id not in ids_from_bg_atlas_api:
in_mesh_not_bg.append(id)

in_bg_not_mesh = []
for id in ids_from_bg_atlas_api:
if id not in ids_from_mesh_files:
in_bg_not_mesh.append(id)

if len(in_mesh_not_bg) or len(in_bg_not_mesh):
raise AssertionError(
f"Structures with ID {in_bg_not_mesh} are in the atlas, but don't have a corresponding mesh file; "
f"Structures with IDs {in_mesh_not_bg} have a mesh file, but are not accessible through the atlas."
)


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

Expand All @@ -124,6 +155,11 @@ def validate_atlas(atlas_name, version, all_validation_functions):
(),
# check_additional_references()
(),
# validate_mesh_structure_pairs(atlas_name: str, atlas_path: Path):
(
atlas_name,
Path(get_brainglobe_dir() / f"{atlas_name}_v{version}"),
),
]

# list to store the errors of the failed validations
Expand All @@ -148,6 +184,7 @@ def validate_atlas(atlas_name, version, all_validation_functions):
open_for_visual_check,
validate_checksum,
check_additional_references,
validate_mesh_structure_pairs,
]

valid_atlases = []
Expand Down

0 comments on commit a4acdb4

Please sign in to comment.