Skip to content

Commit

Permalink
Enh: allow digesting bounding boxes of volumes from preconfiguration
Browse files Browse the repository at this point in the history
  • Loading branch information
AhmetNSimsek committed Apr 9, 2024
1 parent 269aaf9 commit 5845cbc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
8 changes: 5 additions & 3 deletions siibra/configuration/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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":
Expand Down
13 changes: 1 addition & 12 deletions siibra/features/image/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

from ...volumes import volume as _volume
from ...volumes.providers import provider
from ...locations import boundingbox

from typing import List

Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions siibra/volumes/volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 5845cbc

Please sign in to comment.