Skip to content

Commit

Permalink
Check BoundingBox._space_spec w Volume._space_spec to prevent rec…
Browse files Browse the repository at this point in the history
…ursion
  • Loading branch information
AhmetNSimsek committed Apr 10, 2024
1 parent 5845cbc commit 5e2efa0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
6 changes: 3 additions & 3 deletions siibra/configuration/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def build_volume(cls, 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."
assert result._boundingbox._space_spec == result._space_spec, "BoundingBox of a volume cannot be in a different space than the volume's space."

return result

Expand Down Expand Up @@ -358,9 +358,9 @@ def build_boundingbox(cls, spec):
bboxspec = spec.get("boundingbox", None)
if bboxspec is None:
return None
space_id = bboxspec.get("space").get("@id")
space_spec = bboxspec.get("space")
coords = [tuple(c) for c in bboxspec.get("coordinates")]
return boundingbox.BoundingBox(coords[0], coords[1], space=space_id)
return boundingbox.BoundingBox(coords[0], coords[1], space=space_spec)

@classmethod
@build_type("siibra/feature/fingerprint/receptor/v0.1")
Expand Down
14 changes: 11 additions & 3 deletions siibra/locations/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
import numpy as np
from abc import abstractmethod

from typing import TYPE_CHECKING, Union, Dict
if TYPE_CHECKING:
from siibra.core.space import Space


class Location(BrainStructure):
"""
Expand All @@ -42,15 +46,19 @@ class Location(BrainStructure):
_MASK_MEMO = {} # cache region masks for Location._assign_region()
_ASSIGNMENT_CACHE = {} # caches assignment results, see Region.assign()

def __init__(self, space):
self._space_spec = space
def __init__(self, spacespec: Union[str, Dict[str, str], "Space"]):
self._space_spec = spacespec
self._space_cached = None

@property
def space(self):
if self._space_cached is None:
from ..core.space import Space
self._space_cached = Space.get_instance(self._space_spec)
if isinstance(self._space_spec, dict):
spec = self._space_spec.get("@id") or self._space_spec.get("name")
self._space_cached = Space.get_instance(spec)
else:
self._space_cached = Space.get_instance(self._space_spec)
return self._space_cached

@abstractmethod
Expand Down
2 changes: 1 addition & 1 deletion test/core/test_parcellation.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def test_get_region(self, regionspec, find_topmost, allow_tuple, result):


@pytest.mark.parametrize('space_id,parc_id,map_type', [
('waxholm', 'v4', 'labelled')
('waxholm', 'waxholm v4', 'labelled')
])
def test_should_be_able_to_fetch_map(space_id, parc_id, map_type):

Expand Down

0 comments on commit 5e2efa0

Please sign in to comment.