diff --git a/siibra/core/parcellation.py b/siibra/core/parcellation.py index 788427db7..1b2e15d02 100644 --- a/siibra/core/parcellation.py +++ b/siibra/core/parcellation.py @@ -137,7 +137,12 @@ def matches(self, spec): return True return super().matches(spec) - def get_map(self, space=None, maptype: Union[str, MapType] = MapType.LABELLED, spec: str = ""): + def get_map( + self, + space=None, + maptype: Union[str, MapType] = MapType.LABELLED, + spec: str = "" + ): """ Get the maps for the parcellation in the requested template space. @@ -169,15 +174,17 @@ def get_map(self, space=None, maptype: Union[str, MapType] = MapType.LABELLED, s if not isinstance(maptype, MapType): maptype = MapType[maptype.upper()] + space_inst = parcellationmap._space.Space.registry()[space] + candidates = [ m for m in parcellationmap.Map.registry() - if m.space.matches(space) + if m.space.matches(space_inst) and m.maptype == maptype and m.parcellation and m.parcellation.matches(self) ] if len(candidates) == 0: - logger.error(f"No {maptype} map in {space} available for {str(self)}") + logger.error(f"No {maptype} map in '{space}' available for {str(self)}") return None if len(candidates) > 1: spec_candidates = [ diff --git a/siibra/volumes/parcellationmap.py b/siibra/volumes/parcellationmap.py index 4feb8bf65..159a0b928 100644 --- a/siibra/volumes/parcellationmap.py +++ b/siibra/volumes/parcellationmap.py @@ -28,7 +28,7 @@ Species, CompareMapsResult ) -from ..core import concept, space, parcellation, region as _region +from ..core import concept, space as _space, parcellation, region as _region from ..locations import point, pointset from ..retrieval import requests @@ -45,22 +45,26 @@ from ..core.region import Region -class ExcessiveArgumentException(ValueError): pass +class ExcessiveArgumentException(ValueError): + pass -class InsufficientArgumentException(ValueError): pass +class InsufficientArgumentException(ValueError): + pass -class ConflictingArgumentException(ValueError): pass +class ConflictingArgumentException(ValueError): + pass -class NonUniqueIndexError(RuntimeError): pass +class NonUniqueIndexError(RuntimeError): + pass @dataclass class Assignment: input_structure: int - centroid: Union[Tuple[np.ndarray], point.Point] + centroid: Union[Tuple[np.ndarray], point.Point] volume: int fragment: str map_value: np.ndarray @@ -286,8 +290,8 @@ def get_region(self, label: int = None, volume: int = 0, index: MapIndex = None) def space(self): for key in ["@id", "name"]: if key in self._space_spec: - return space.Space.get_instance(self._space_spec[key]) - return space.Space(None, "Unspecified space", species=Species.UNSPECIFIED_SPECIES) + return _space.Space.get_instance(self._space_spec[key]) + return _space.Space(None, "Unspecified space", species=Species.UNSPECIFIED_SPECIES) @property def parcellation(self): @@ -794,7 +798,7 @@ def _assign( minsize_voxel=1, lower_threshold=0.0, **kwargs - ) -> List[Union[Assignment,AssignImageResult]]: + ) -> List[Union[Assignment, AssignImageResult]]: """ For internal use only. Returns a dataclass, which provides better static type checking. """ @@ -805,7 +809,7 @@ def _assign( return self._assign_points(item, lower_threshold) if isinstance(item, Nifti1Image): return self._assign_image(item, minsize_voxel, lower_threshold, **kwargs) - + raise RuntimeError( f"Items of type {item.__class__.__name__} cannot be used for region assignment." ) @@ -1078,7 +1082,7 @@ def progress(it, N: int = None, desc: str = "", min_elements=5): seqlen = N or len(it) return iter(it) if seqlen < min_elements \ else siibra_tqdm(it, desc=desc, total=N) - + iter_func = iterate_connected_components if split_components \ else lambda img: [(1, img)] diff --git a/test/volumes/test_parcellationmap.py b/test/volumes/test_parcellationmap.py index a699a60f6..6d46a053b 100644 --- a/test/volumes/test_parcellationmap.py +++ b/test/volumes/test_parcellationmap.py @@ -1,6 +1,6 @@ import unittest from unittest.mock import patch, MagicMock -from siibra.volumes.parcellationmap import Map, space, parcellation, MapType, MapIndex, ExcessiveArgumentException, InsufficientArgumentException, ConflictingArgumentException, NonUniqueIndexError +from siibra.volumes.parcellationmap import Map, _space, parcellation, MapType, MapIndex, ExcessiveArgumentException, InsufficientArgumentException, ConflictingArgumentException, NonUniqueIndexError from siibra.commons import Species from siibra.core.region import Region from uuid import uuid4 @@ -95,8 +95,8 @@ def test_space(self, set_space_spec, called_arg, called_get_instance, return_spa self.map = TestMap.get_instance(space_spec=set_space_spec) - with patch.object(space.Space, 'get_instance') as mock_get_instance: - return_space = space.Space(None, "Returned Space", species=Species.HOMO_SAPIENS) if return_space_flag else None + with patch.object(_space.Space, 'get_instance') as mock_get_instance: + return_space = _space.Space(None, "Returned Space", species=Species.HOMO_SAPIENS) if return_space_flag else None mock_get_instance.return_value = return_space actual_returned_space = self.map.space