Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extend region model, catch cases where mapIndex is None #167

Merged
merged 2 commits into from
Mar 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 15 additions & 3 deletions siibra/core/region.py
Original file line number Diff line number Diff line change
Expand Up @@ -877,9 +877,21 @@ def vol_to_id_dict(vol: VolumeSrc):
for parcvol in parc_volumes
if parcvol.volume_type == "neuroglancer/precomputed"
and parcvol.space is space]
map_idx = self.index.map
if map_idx is not None:
pev.has_annotation.visualized_in = vol_to_id_dict(ng_parc_volumes[map_idx])

# self.index.label can sometimes be None. e.g. "basal forebrain"
# in such a case, do not populate visualized in
if self.index.label is not None:

# self.index.map can sometimes be None, but label is defined
if self.index.map is None:

# In rare instances, e.g. julich brain 2.9, "Ch 123 (Basal Forebrain)"
# self.index.map is undefined (expect a single volume?)
# but there exist multiple volumes (in the example, one for left/ one for right hemisphere)
if len(ng_parc_volumes) == 1:
pev.has_annotation.visualized_in = vol_to_id_dict(ng_parc_volumes[0])
else:
pev.has_annotation.visualized_in = vol_to_id_dict(ng_parc_volumes[self.index.map])
except IndexError:
pass

Expand Down
15 changes: 15 additions & 0 deletions test/core/test_region.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import unittest
from unittest.mock import MagicMock
import pytest
import re

from siibra import parcellations, spaces, retrieval
from siibra.core.region import Region
Expand Down Expand Up @@ -161,5 +162,19 @@ def test_detail_region(parc_spec,region_spec,space_spec,expect_raise):
assert model.has_annotation is not None
assert model.has_annotation.best_view_point is not None

has_inspired_by = [
("julich 2.9", "hoc1 left", "mni152"),
("long bundle", "Left short cingulate fibres", "mni152")
]

@pytest.mark.parametrize('parc_spec, region_spec, space_spec', has_inspired_by)
def test_has_inspired_by(parc_spec, region_spec, space_spec):
p = siibra.parcellations[parc_spec]
r = p.decode_region(region_spec)
model = r.to_model(space=siibra.spaces[space_spec])
assert model.has_annotation.visualized_in is not None, f"expecting has_annotation.visualized_in is defined"
assert re.match(r"^precomputed:\/\/", model.has_annotation.visualized_in["@id"]), f"expecting has_annotation.visualized_in starts with precomputed://"


if __name__ == "__main__":
unittest.main()