Skip to content

Commit 953282e

Browse files
committed
Raise when get_map gets a invalid space argument
1 parent 8161f73 commit 953282e

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

siibra/core/parcellation.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
# except Exception as e:
3232
# pass
3333

34+
class ConflictingArgumentException(ValueError):
35+
pass
36+
3437

3538
class ParcellationVersion:
3639
def __init__(
@@ -166,8 +169,9 @@ def get_map(self, space=None, maptype: Union[str, MapType] = MapType.LABELLED, s
166169
A ParcellationMap representing the volumetric map or
167170
a SparseMap representing the list of statistical maps.
168171
"""
169-
if not isinstance(maptype, MapType):
172+
if isinstance(maptype, str):
170173
maptype = MapType[maptype.upper()]
174+
assert isinstance(maptype, MapType), f"`maptype` have to be a MapType or str, not {type(maptype)}"
171175

172176
candidates = [
173177
m for m in parcellationmap.Map.registry()
@@ -177,15 +181,18 @@ def get_map(self, space=None, maptype: Union[str, MapType] = MapType.LABELLED, s
177181
and m.parcellation.matches(self)
178182
]
179183
if len(candidates) == 0:
180-
logger.error(f"No {maptype} map in {space} available for {str(self)}")
181-
return None
184+
raise ConflictingArgumentException(
185+
f"No {maptype} map with space specification '{space}' available for {str(self)}"
186+
)
182187
if len(candidates) > 1:
183188
spec_candidates = [
184-
c for c in candidates if all(w.lower() in c.name.lower() for w in spec.split())
189+
c for c in candidates
190+
if all(w.lower() in c.name.lower() for w in spec.split())
185191
]
186192
if len(spec_candidates) == 0:
187-
logger.warning(f"'{spec}' does not match any options from {[c.name for c in candidates]}.")
188-
return None
193+
raise ConflictingArgumentException(
194+
f"'{spec}' does not match any options from {[c.name for c in candidates]}."
195+
)
189196
if len(spec_candidates) > 1:
190197
logger.warning(
191198
f"Multiple maps are available in this specification of space, parcellation, and map type.\n"

test/core/test_parcellation.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import unittest
2-
from siibra.core.parcellation import Parcellation, ParcellationVersion, MapType
2+
from siibra.core.parcellation import (
3+
Parcellation, ParcellationVersion, MapType, ConflictingArgumentException
4+
)
35
from siibra.core.region import Region
4-
from siibra.commons import Species, MapIndex
6+
from siibra.commons import Species
57
from uuid import uuid4
68
from parameterized import parameterized
79
from unittest.mock import patch, MagicMock
@@ -21,6 +23,7 @@
2123
region_child2 = Region("bar")
2224
region_parent = Region("parent foo bar", children=[region_child1, region_child2])
2325

26+
2427
class DummySpace:
2528
def matches(self):
2629
raise NotImplementedError
@@ -218,7 +221,6 @@ def test_find_regions(self, parents_only):
218221
p.find.assert_called_once_with(regionspec="fooz")
219222
self.assertEqual(result, [parc3] if parents_only else [parc1, parc2, parc3])
220223

221-
222224
@parameterized.expand([
223225
# partial matches work
224226
("foo bar", False, False, region_parent),
@@ -232,7 +234,6 @@ def test_find_regions(self, parents_only):
232234
def test_get_region(self, regionspec, find_topmost, allow_tuple, result):
233235
self.parc.children = [region_parent]
234236
self.assertIs(self.parc.get_region(regionspec, find_topmost, allow_tuple), result)
235-
236237

237238

238239
# all_parcs = [p for p in parcellations]
@@ -271,5 +272,4 @@ def test_get_region(self, regionspec, find_topmost, allow_tuple, result):
271272

272273
# parc.get_map(space, map_type)
273274

274-
275275
parc_has_ebrains_doi = [("human", "julich brain 2.9")]

0 commit comments

Comments
 (0)