diff --git a/siibra/configuration/factory.py b/siibra/configuration/factory.py index 185ed49c3..bb751959c 100644 --- a/siibra/configuration/factory.py +++ b/siibra/configuration/factory.py @@ -274,7 +274,10 @@ def build_volume(cls, spec): name=spec.get("name", ""), variant=spec.get("variant"), datasets=cls.extract_datasets(spec), + bbox=cls.build_boundingbox(spec) ) + if result._boundingbox is not None: + assert result._boundingbox.space == result.space, "BoundingBox of a volume cannot be in a different space than the volume's space." return result @@ -355,7 +358,7 @@ def build_boundingbox(cls, spec): bboxspec = spec.get("boundingbox", None) if bboxspec is None: return None - space_id = spec.get("space").get("@id") + space_id = bboxspec.get("space").get("@id") coords = [tuple(c) for c in bboxspec.get("coordinates")] return boundingbox.BoundingBox(coords[0], coords[1], space=space_id) @@ -408,8 +411,7 @@ def build_section(cls, spec): "region": spec.get('region', None), "space_spec": vol._space_spec, "providers": vol._providers.values(), - "datasets": cls.extract_datasets(spec), - "boundingbox": cls.build_boundingbox(spec) + "datasets": cls.extract_datasets(spec) } modality = spec.get('modality', "") if modality == "cell body staining": diff --git a/siibra/features/image/image.py b/siibra/features/image/image.py index 22cf7f17f..6d989b0d8 100644 --- a/siibra/features/image/image.py +++ b/siibra/features/image/image.py @@ -21,7 +21,6 @@ from ...volumes import volume as _volume from ...volumes.providers import provider -from ...locations import boundingbox from typing import List @@ -63,8 +62,7 @@ def __init__( space_spec: dict, providers: List[provider.VolumeProvider], region: str = None, - datasets: List = [], - boundingbox: "boundingbox.BoundingBox" = None + datasets: List = [] ): feature.Feature.__init__( self, @@ -85,15 +83,6 @@ def __init__( self._anchor_cached = ImageAnchor(self, region=region) self._description_cached = None self._name_cached = name - self._boundingbox = boundingbox - - def get_boundingbox( - self, clip: bool = True, background: float = 0.0, **fetch_kwargs - ) -> "boundingbox.BoundingBox": - if self._boundingbox is None: - return super().get_boundingbox(clip, background, **fetch_kwargs) - else: - return self._boundingbox def _to_zip(self, fh: ZipFile): super()._to_zip(fh) diff --git a/siibra/volumes/volume.py b/siibra/volumes/volume.py index 2f48b0411..5b1bc6fdb 100644 --- a/siibra/volumes/volume.py +++ b/siibra/volumes/volume.py @@ -75,12 +75,14 @@ def __init__( name: str = "", variant: str = None, datasets: List['TypeDataset'] = [], + bbox: "boundingbox.BoundingBox" = None ): self._name = name self._space_spec = space_spec self.variant = variant self._providers: Dict[str, _provider.VolumeProvider] = {} self.datasets = datasets + self._boundingbox = bbox for provider in providers: srctype = provider.srctype assert srctype not in self._providers @@ -140,6 +142,9 @@ def get_boundingbox(self, clip: bool = True, background: float = 0.0, **fetch_kw RuntimeError If the volume provider does not have a bounding box calculator. """ + if self._boundingbox is not None and len(fetch_kwargs) == 0: + return self._boundingbox + fmt = fetch_kwargs.get("format") if (fmt is not None) and (fmt not in self.formats): raise ValueError(