Skip to content

Commit

Permalink
Merge pull request #373 from FZJ-INM1-BDA/addTestForUnmatchedMapRegions
Browse files Browse the repository at this point in the history
Test configured maps to get regions from parcellations
  • Loading branch information
AhmetNSimsek authored Aug 22, 2023
2 parents 4057d1a + a493401 commit 2a2ef1d
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 63 deletions.
4 changes: 3 additions & 1 deletion e2e/features/connectivity/test_connectivity.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import siibra
import pytest
from typing import List

import sys
from siibra.features.connectivity.regional_connectivity import RegionalConnectivity
from e2e.util import check_duplicate

pytestmark = pytest.mark.skipif(sys.platform == "win32", reason="Fails due to memory limitation issues on Windows on Github actions. (Passes on local machines.)")

features = [
f
for Cls in siibra.features.feature.Feature.SUBCLASSES[RegionalConnectivity]
Expand Down
60 changes: 60 additions & 0 deletions e2e/volumes/test_mapshape.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import pytest
import siibra
from itertools import product


# checks labelled/statistical returns volume size matches template
# see https://github.com/FZJ-INM1-BDA/siibra-python/issues/302
MNI152_ID = "minds/core/referencespace/v1.0.0/dafcffc5-4826-4bf1-8ff6-46b8a31ff8e2"
COLIN_ID = "minds/core/referencespace/v1.0.0/7f39f7be-445b-47c0-9791-e971c0b6d992"

JBA_29_ID = (
"minds/core/parcellationatlas/v1.0.0/94c1125b-b87e-45e4-901c-00daee7f2579-290"
)
JBA_30_ID = (
"minds/core/parcellationatlas/v1.0.0/94c1125b-b87e-45e4-901c-00daee7f2579-300"
)

HOC1_RIGHT = "Area hOc1 (V1, 17, CalcS) - right hemisphere"
FP1_RIGHT = "Area Fp1 (FPole) - right hemisphere"

STATISTIC_ENDPOINT = "statistical"
LABELLED_ENDPOINT = "labelled"

map_shape_args = product(
((MNI152_ID, (193, 229, 193)),),
(JBA_29_ID,),
(STATISTIC_ENDPOINT, LABELLED_ENDPOINT),
(HOC1_RIGHT, FP1_RIGHT, None),
)


@pytest.mark.parametrize("space_shape,parc_id,map_endpoint,region_name", map_shape_args)
def test_map_shape(space_shape, parc_id, map_endpoint, region_name):
if region_name is None and map_endpoint == STATISTIC_ENDPOINT:
assert True
return
space_id, expected_shape = space_shape

volume_data = None
if region_name is not None:
region = siibra.get_region(parc_id, region_name)
volume_data = region.fetch_regional_map(space_id, map_endpoint)
else:
labelled_map = siibra.get_map(parc_id, space_id, map_endpoint)
assert labelled_map is not None
volume_data = labelled_map.fetch()

assert volume_data
assert (
volume_data.get_fdata().shape == expected_shape
), f"{volume_data.get_fdata().shape}, {expected_shape}, {region_name}, {map_endpoint}, {space_id}"


def test_template_resampling():
mp = siibra.maps.COLIN27_JBA29_LABELLED
mp_img = mp.fetch()
template = mp.space.get_template().fetch()
assert mp_img.shape != template.shape
resamp_template = mp.get_resampled_template()
assert mp_img.shape == resamp_template.shape
76 changes: 15 additions & 61 deletions e2e/volumes/test_parcellationmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,64 +88,18 @@ def test_merged_fragment_shape(siibramap: Map, format):
assert vol_l.dataobj.shape == vol_r.dataobj.shape == vol_b.dataobj.shape


def test_sparsemap_cache_uniqueness():
mp157 = siibra.get_map("julich 3.0", "colin 27", "statistical", spec="157")
mp175 = siibra.get_map("julich 3.0", "colin 27", "statistical", spec="175")
assert mp157.sparse_index.probs[0] != mp175.sparse_index.probs[0]


# checks labelled/statistical returns volume size matches template
# see https://github.com/FZJ-INM1-BDA/siibra-python/issues/302
MNI152_ID = "minds/core/referencespace/v1.0.0/dafcffc5-4826-4bf1-8ff6-46b8a31ff8e2"
COLIN_ID = "minds/core/referencespace/v1.0.0/7f39f7be-445b-47c0-9791-e971c0b6d992"

JBA_29_ID = (
"minds/core/parcellationatlas/v1.0.0/94c1125b-b87e-45e4-901c-00daee7f2579-290"
)
JBA_30_ID = (
"minds/core/parcellationatlas/v1.0.0/94c1125b-b87e-45e4-901c-00daee7f2579-300"
)

HOC1_RIGHT = "Area hOc1 (V1, 17, CalcS) - right hemisphere"
FP1_RIGHT = "Area Fp1 (FPole) - right hemisphere"

STATISTIC_ENDPOINT = "statistical"
LABELLED_ENDPOINT = "labelled"

map_shape_args = product(
((MNI152_ID, (193, 229, 193)),),
(JBA_29_ID,),
(STATISTIC_ENDPOINT, LABELLED_ENDPOINT),
(HOC1_RIGHT, FP1_RIGHT, None),
)


@pytest.mark.parametrize("space_shape,parc_id,map_endpoint,region_name", map_shape_args)
def test_map_shape(space_shape, parc_id, map_endpoint, region_name):
if region_name is None and map_endpoint == STATISTIC_ENDPOINT:
assert True
return
space_id, expected_shape = space_shape

volume_data = None
if region_name is not None:
region = siibra.get_region(parc_id, region_name)
volume_data = region.fetch_regional_map(space_id, map_endpoint)
else:
labelled_map = siibra.get_map(parc_id, space_id, map_endpoint)
assert labelled_map is not None
volume_data = labelled_map.fetch()

assert volume_data
assert (
volume_data.get_fdata().shape == expected_shape
), f"{volume_data.get_fdata().shape}, {expected_shape}, {region_name}, {map_endpoint}, {space_id}"


def test_template_resampling():
mp = siibra.maps.COLIN27_JBA29_LABELLED
mp_img = mp.fetch()
template = mp.space.get_template().fetch()
assert mp_img.shape != template.shape
resamp_template = mp.get_resampled_template()
assert mp_img.shape == resamp_template.shape
def test_region_1to1ness_in_parcellation():
failed = []
for m in Map.registry():
parc = m.parcellation
for region_name in m.regions:
try:
_ = parc.get_region(region_name)
except Exception:
failed.append(
{
"region name": region_name,
"map": m.name
}
)
assert len(failed) == 0, print("The regions in maps that can't be gotten in respective parcellations\n", failed)
7 changes: 7 additions & 0 deletions e2e/volumes/test_sparsemap_cache_uniqueness.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import siibra


def test_sparsemap_cache_uniqueness():
mp157 = siibra.get_map("julich 3.0", "colin 27", "statistical", spec="157")
mp175 = siibra.get_map("julich 3.0", "colin 27", "statistical", spec="175")
assert mp157.sparse_index.probs[0] != mp175.sparse_index.probs[0]
2 changes: 1 addition & 1 deletion siibra/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.4a61
0.4a62

0 comments on commit 2a2ef1d

Please sign in to comment.