Skip to content

Commit

Permalink
atlas utils testing
Browse files Browse the repository at this point in the history
  • Loading branch information
adamltyson committed Aug 26, 2020
1 parent f0c0e33 commit 393c99a
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 4 deletions.
27 changes: 23 additions & 4 deletions brainreg_segment/atlas/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,33 @@


def lateralise_atlas_image(
atlas, hemispheres, left_hemisphere_value=1, right_hemisphere_value=2
masked_atlas_annotations,
hemispheres,
left_hemisphere_value=1,
right_hemisphere_value=2,
):
atlas_left = atlas[hemispheres == left_hemisphere_value]
atlas_right = atlas[hemispheres == right_hemisphere_value]
return atlas_left, atlas_right
"""
:param masked_atlas_annotations: Masked image of atlas annotations
:param hemispheres: Hemispheres image
:param left_hemisphere_value: Value encoded in hemispheres image
:param right_hemisphere_value: Value encoded in hemispheres image
:return: Tuple (left, right) of numpy arrays of values within
each hemisphere
"""
annotation_left = masked_atlas_annotations[
hemispheres == left_hemisphere_value
]
annotation_right = masked_atlas_annotations[
hemispheres == right_hemisphere_value
]
return annotation_left, annotation_right


def get_available_atlases():
"""
Get the available brainglobe atlases
:return: Dict of available atlases (["name":version])
"""
available_atlases = utils.conf_from_url(
descriptors.remote_url_base.format("last_versions.conf")
)
Expand Down
35 changes: 35 additions & 0 deletions tests/tests/test_unit/test_atlas/test_atlas_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import numpy as np
from brainreg_segment.atlas import utils as atlas_utils

from bg_atlasapi import BrainGlobeAtlas

atlas_name = "allen_mouse_50um"


def test_get_available_atlases():
atlases = atlas_utils.get_available_atlases()

# arbitrary selection of atlases
assert float(atlases["allen_mouse_10um"]) >= 0.3
assert float(atlases["allen_mouse_25um"]) >= 0.3
assert float(atlases["allen_mouse_50um"]) >= 0.3
assert float(atlases["mpin_zfish_1um"]) >= 0.4


def test_lateralise_atlas_image():
atlas = BrainGlobeAtlas(atlas_name)

mask = np.random.random(atlas.annotation.shape) > 0.7
masked_annotations = mask * atlas.annotation
annotations_left, annotations_right = atlas_utils.lateralise_atlas_image(
masked_annotations,
atlas.hemispheres,
left_hemisphere_value=atlas.left_hemisphere_value,
right_hemisphere_value=atlas.right_hemisphere_value,
)

# not the best way to test this is functioning properly
total_vals_in = np.prod(mask.shape)
total_vals_out = len(annotations_left) + len(annotations_right)

assert total_vals_in == total_vals_out

0 comments on commit 393c99a

Please sign in to comment.