Skip to content

Commit

Permalink
Update how regions are compared to locations
Browse files Browse the repository at this point in the history
  • Loading branch information
AhmetNSimsek committed Oct 11, 2024
1 parent f2ba788 commit f27e5ef
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion e2e/features/image/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
(siibra.features.get(siibra.get_template("big brain"), "CellBodyStainedVolumeOfInterest"), 2),
(siibra.features.get(siibra.get_template("mni152"), "image", restrict_space=True), 4),
(siibra.features.get(siibra.get_template("mni152"), "image", restrict_space=False), 13),
(siibra.features.get(siibra.get_region('julich 3', 'hoc1 left'), "CellbodyStainedSection"), 47),
(siibra.features.get(siibra.get_region('julich 3.0.3', 'hoc1 left'), "CellbodyStainedSection"), 47),
(siibra.features.get(siibra.get_region('julich 2.9', 'hoc1 left'), "CellbodyStainedSection"), 41)
]
features = [f for fts, _ in results for f in fts]
Expand Down
27 changes: 19 additions & 8 deletions siibra/core/region.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,17 +642,28 @@ def assign(self, other: structure.BrainStructure) -> AnatomicalAssignment:
self._ASSIGNMENT_CACHE[self, other] = regionmap.assign(other)
return self._ASSIGNMENT_CACHE[self, other]

try:
regionbbox_otherspace = self.get_boundingbox(other.space, restrict_space=False)
if regionbbox_otherspace is not None:
self._ASSIGNMENT_CACHE[self, other] = regionbbox_otherspace.assign(other)
return self._ASSIGNMENT_CACHE[self, other]
except Exception as e:
logger.debug(e)

assignment_result = None
for space in self.supported_spaces:
for targetspace in self.supported_spaces:
try:
other_warped = other.warp(space)
regionmap = self.get_regional_map(space)
other_warped = other.warp(targetspace)
regionmap = self.get_regional_map(targetspace)
assignment_result = regionmap.assign(other_warped)
except SpaceWarpingFailedError:
try:
regionbbox_warped = self.get_boundingbox(
space, restrict_space=True
).warp(other.space)
regionbbox_targetspace = self.get_boundingbox(
targetspace, restrict_space=True
)
if regionbbox_targetspace is None:
continue
regionbbox_warped = regionbbox_targetspace.warp(other.space)
except SpaceWarpingFailedError:
continue
assignment_result = regionbbox_warped.assign(other)
Expand Down Expand Up @@ -694,7 +705,7 @@ def get_boundingbox(
space: _space.Space,
maptype: MapType = MapType.LABELLED,
threshold_statistical=None,
restrict_space=False,
restrict_space=True,
**fetch_kwargs
):
"""Compute the bounding box of this region in the given space.
Expand Down Expand Up @@ -740,7 +751,7 @@ def get_boundingbox(
bbox_warped = bbox.warp(spaceobj)
except SpaceWarpingFailedError:
continue
logger.warning(
logger.debug(
f"No bounding box for {self.name} defined in {spaceobj.name}, "
f"warped the bounding box from {other_space.name} instead."
)
Expand Down

0 comments on commit f27e5ef

Please sign in to comment.