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

Raise when get_map gets a invalid space argument #460

Closed
wants to merge 1 commit into from
Closed
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
19 changes: 13 additions & 6 deletions siibra/core/parcellation.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
# except Exception as e:
# pass

class ConflictingArgumentException(ValueError):
pass


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

candidates = [
m for m in parcellationmap.Map.registry()
Expand All @@ -177,15 +181,18 @@ def get_map(self, space=None, maptype: Union[str, MapType] = MapType.LABELLED, s
and m.parcellation.matches(self)
]
if len(candidates) == 0:
logger.error(f"No {maptype} map in {space} available for {str(self)}")
return None
raise ConflictingArgumentException(
f"No {maptype} map with space specification '{space}' available for {str(self)}"
)
if len(candidates) > 1:
spec_candidates = [
c for c in candidates if all(w.lower() in c.name.lower() for w in spec.split())
c for c in candidates
if all(w.lower() in c.name.lower() for w in spec.split())
]
if len(spec_candidates) == 0:
logger.warning(f"'{spec}' does not match any options from {[c.name for c in candidates]}.")
return None
raise ConflictingArgumentException(
f"'{spec}' does not match any options from {[c.name for c in candidates]}."
)
if len(spec_candidates) > 1:
logger.warning(
f"Multiple maps are available in this specification of space, parcellation, and map type.\n"
Expand Down
10 changes: 5 additions & 5 deletions test/core/test_parcellation.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import unittest
from siibra.core.parcellation import Parcellation, ParcellationVersion, MapType
from siibra.core.parcellation import (
Parcellation, ParcellationVersion, MapType, ConflictingArgumentException
)
from siibra.core.region import Region
from siibra.commons import Species, MapIndex
from siibra.commons import Species
from uuid import uuid4
from parameterized import parameterized
from unittest.mock import patch, MagicMock
Expand All @@ -21,6 +23,7 @@
region_child2 = Region("bar")
region_parent = Region("parent foo bar", children=[region_child1, region_child2])


class DummySpace:
def matches(self):
raise NotImplementedError
Expand Down Expand Up @@ -218,7 +221,6 @@ def test_find_regions(self, parents_only):
p.find.assert_called_once_with(regionspec="fooz")
self.assertEqual(result, [parc3] if parents_only else [parc1, parc2, parc3])


@parameterized.expand([
# partial matches work
("foo bar", False, False, region_parent),
Expand All @@ -232,7 +234,6 @@ def test_find_regions(self, parents_only):
def test_get_region(self, regionspec, find_topmost, allow_tuple, result):
self.parc.children = [region_parent]
self.assertIs(self.parc.get_region(regionspec, find_topmost, allow_tuple), result)



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

# parc.get_map(space, map_type)


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