Skip to content

Commit

Permalink
Add tests: check region-volume intersection, centroid containednedness
Browse files Browse the repository at this point in the history
  • Loading branch information
AhmetNSimsek committed Nov 10, 2023
1 parent 50e4db3 commit 7356b80
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 3 deletions.
31 changes: 28 additions & 3 deletions e2e/features/test_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,32 @@ def test_get_instances(Cls: siibra.features.Feature):
assert isinstance(instances, list)


ids = [
selected_queries = [
(siibra.get_region('julich 2.9', 'hoc1 left'), siibra.features.dataset.EbrainsDataFeature),
(siibra.get_region('julich 3', 'hoc1 left'), siibra.features.tabular.BigBrainIntensityProfile),
(siibra.get_region('julich 2.9', 'hoc1'), siibra.features.tabular.CellDensityProfile),
(siibra.get_region('julich 2.9', 'hoc1'), siibra.features.tabular.ReceptorDensityProfile),
(siibra.parcellations['julich 2.9'], siibra.features.connectivity.StreamlineCounts),
(siibra.parcellations['julich 3'], siibra.features.connectivity.FunctionalConnectivity),
(siibra.parcellations['julich 3'], siibra.features.connectivity.AnatomoFunctionalConnectivity),
(siibra.get_region('julich 2.9', 'CA2 (Hippocampus) right'), siibra.features.image.PLIVolumeOfInterest)
]


@pytest.mark.parametrize("query", selected_queries)
def test_feature_query_and_get_instance_by_id(query):
fts = siibra.features.get(query[0], query[1])
assert len(fts) > 0
for feature in fts:
if isinstance(feature, siibra.features.feature.CompoundFeature):
feat = siibra.features.Feature._get_instance_by_id(feature.id)
assert feat.id == feature.id
for element in feature:
feat = siibra.features.Feature._get_instance_by_id(element.id)
assert feat.id == element.id


selected_ids = [
"lq0::EbrainsDataFeature::p:minds/core/parcellationatlas/v1.0.0/94c1125b-b87e-45e4-901c-00daee7f2579-290::r:Area hOc1 (V1, 17, CalcS) left::https://nexus.humanbrainproject.org/v0/data/minds/core/dataset/v1.0.0/3ff328fa-f48f-474b-bd81-b5ee7ca230b6",
"cf0::BigBrainIntensityProfile::p:minds/core/parcellationatlas/v1.0.0/94c1125b-b87e-45e4-901c-00daee7f2579-290::r:Area hOc1 (V1, 17, CalcS) left::nodsid::6ba1f5c180a63705d84c25db9ff7efa7", # CompoundFeature of 1579 BigBrainIntensityProfile features grouped by (Modified silver staining modality) anchored at Area hOc1 (V1, 17, CalcS) left with Set of 1579 points in the Bounding box from (-63.69,-59.94,-29.09) mm to (0.91,77.90,54.03)mm in BigBrain microscopic template (histology) space
"lq0::BigBrainIntensityProfile::p:minds/core/parcellationatlas/v1.0.0/94c1125b-b87e-45e4-901c-00daee7f2579-290::r:Area hOc1 (V1, 17, CalcS) left::a48879314d93d15c74e6512e9af9c91d", # BigBrainIntensityProfile (Modified silver staining) anchored at Area hOc1 (V1, 17, CalcS) left with Point in BigBrain microscopic template (histology) [0.4248340129852295,50.589298248291016,-14.839699745178223]
Expand All @@ -27,7 +52,7 @@ def test_get_instances(Cls: siibra.features.Feature):
]


@pytest.mark.parametrize("fid", ids)
@pytest.mark.parametrize("fid", selected_ids)
def test_get_instance(fid):
feat = siibra.features.Feature._get_instance_by_id(fid)
assert feat.id == fid
Expand All @@ -36,7 +61,7 @@ def test_get_instance(fid):
# this tests whether or not calling a live query caused proxy feature to be
# added to subclasses. (It should not: causes memory leak and also increases
# query time linearly)
@pytest.mark.parametrize("fid", ids)
@pytest.mark.parametrize("fid", selected_ids)
def test_subclass_count(fid):
len_before = len(siibra.features.Feature.SUBCLASSES[siibra.features.Feature])
_ = siibra.features.Feature._get_instance_by_id(fid)
Expand Down
34 changes: 34 additions & 0 deletions e2e/volumes/test_volume.py
Original file line number Diff line number Diff line change
@@ -1 +1,35 @@
import siibra
from siibra.volumes import Volume
from siibra.core.region import Region
import numpy as np
import pytest
# TODO write a test for the volume-region and volume-volume intersection


selected_regions = [
(siibra.get_region('julich 2.9', 'CA2 (Hippocampus) right'), 'mni152'),
(siibra.get_region('julich 2.9', 'CA2 (Hippocampus) left'), 'colin27'),
(siibra.get_region('julich 2.9', 'hoc1 left'), 'bigbrain'),
(siibra.get_region('julich 3', 'sts'), 'mni152'),
(siibra.get_region('Von Economo Koskinas', 'TC: Area supratemporalis granulosa right'), 'mni152')
]


@pytest.mark.parametrize("region, space", selected_regions)
def test_region_intersection_with_its_own_volume(region, space):
assert isinstance(region, Region)
volume = region.get_regional_map(space)
intersection = region.intersection(volume)
assert isinstance(intersection, Volume)
assert np.all(
np.equal(intersection.fetch().dataobj, volume.fetch().dataobj)
), "Intersection of a regional map with its region object should be the same volume."


@pytest.mark.parametrize("region, space", selected_regions)
def test_region_intersection_with_its_centroid(region, space):
assert isinstance(region, Region)
centroids = region.compute_centroids(space)
assert centroids in region
intersection = region.intersection(centroids)
assert intersection == centroids

0 comments on commit 7356b80

Please sign in to comment.