Skip to content

Commit f63dcd2

Browse files
authored
Merge pull request #200 from FZJ-INM1-BDA/bugfix_multipleCentorids
WIP fix when multiple centroids are available
2 parents 927e39e + 00f9f65 commit f63dcd2

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

siibra/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from .commons import logger, QUIET, VERBOSE
1717

1818
# __version__ is parsed by setup.py
19-
__version__ = "0.3a22"
19+
__version__ = "0.3a23"
2020
logger.info(f"Version: {__version__}")
2121
logger.warning("This is a development release. Use at your own risk.")
2222
logger.info(

siibra/core/region.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,9 @@ def vol_to_id_dict(vol: VolumeSrc):
971971
if detail:
972972
try:
973973
centroids = self.centroids(space)
974-
assert len(centroids) == 1, f"expect a single centroid as return for centroid(space) call, but got {len(centroids)} results."
974+
assert len(centroids) > 0, f"Region.to_model detailed flag set, expect a single centroid as return for centroid(space) call, but got none."
975+
if len(centroids) != 1:
976+
logger.warn(f"Region.to_model detailed flag set. Can only handle one and only one centroid, but got {len(centroids)}. Using the first one, if available, or return None")
975977
pev.has_annotation.best_view_point = BestViewPoint(
976978
coordinate_space={
977979
"@id": space.model_id
@@ -983,6 +985,9 @@ def vol_to_id_dict(vol: VolumeSrc):
983985
}
984986
) for pt in centroids[0]]
985987
)
988+
except AssertionError as e:
989+
# no centroids found. Log warning, but do not raise.
990+
logger.warn(e)
986991
except NotImplementedError:
987992
# Region masks for surface spaces are not yet supported. for surface-based spaces
988993
pass

test/core/test_region.py

+14
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,20 @@ def test_region_to_model(region: Region):
140140
# import re
141141
# assert re.match(r"^[\w/\-.:]+$", model.id), f"model_id should only contain [\w/\-.:]+, but is instead {model.id}"
142142

143+
144+
detailed_region_in_space = [
145+
("minds/core/parcellationatlas/v1.0.0/ebb923ba-b4d5-4b82-8088-fa9215c2e1fe-v4", "stria medullaris thalami", "minds/core/referencespace/v1.0.0/d5717c4a-0fa1-46e6-918c-b8003069ade8")
146+
]
147+
@pytest.mark.parametrize('parc_id,region_id,space_id', detailed_region_in_space)
148+
def test_detailed_region_in_space(parc_id,region_id,space_id):
149+
p = siibra.parcellations[parc_id]
150+
assert p is not None
151+
r = p.decode_region(region_id)
152+
assert r is not None
153+
s = siibra.spaces[space_id]
154+
assert s is not None
155+
r.to_model(detail=True, space=s)
156+
143157
detailed_region=[
144158
("julich 2.9", "hoc1 left", "mni152", False, True),
145159
("julich 2.9", "hoc1 right", "mni152", False, True),

0 commit comments

Comments
 (0)