Skip to content
Snippets Groups Projects
Commit cf99f6ab authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
Browse files

Atlas mask query methods raise a custom error type if mask is bad

parent e94616ed
No related branches found
No related tags found
No related merge requests found
...@@ -605,6 +605,14 @@ class Atlas(fslimage.Image): ...@@ -605,6 +605,14 @@ class Atlas(fslimage.Image):
self.desc = atlasDesc self.desc = atlasDesc
class MaskError(Exception):
"""Exception raised by the :meth:`LabelAtlas.maskLabel` and
:meth:`ProbabilisticAtlas.maskProportions` when a mask is provided which
does not match the atlas space.
"""
pass
class LabelAtlas(Atlas): class LabelAtlas(Atlas):
"""A 3D atlas which contains integer labels for each region. """A 3D atlas which contains integer labels for each region.
...@@ -714,7 +722,8 @@ class LabelAtlas(Atlas): ...@@ -714,7 +722,8 @@ class LabelAtlas(Atlas):
mask, xform = mask.resample(self.shape[:3], dtype=np.float32, order=0) mask, xform = mask.resample(self.shape[:3], dtype=np.float32, order=0)
if not fslimage.Image(mask, xform=xform).sameSpace(self): if not fslimage.Image(mask, xform=xform).sameSpace(self):
raise ValueError('Mask is not in the same space as atlas') raise MaskError('Mask is not in the same space as atlas')
# Extract the labels that are in # Extract the labels that are in
...@@ -858,7 +867,7 @@ class ProbabilisticAtlas(Atlas): ...@@ -858,7 +867,7 @@ class ProbabilisticAtlas(Atlas):
mask, xform = mask.resample(self.shape[:3], dtype=np.float32, order=0) mask, xform = mask.resample(self.shape[:3], dtype=np.float32, order=0)
if not fslimage.Image(mask, xform=xform).sameSpace(self): if not fslimage.Image(mask, xform=xform).sameSpace(self):
raise ValueError('Mask is not in the same space as atlas') raise MaskError('Mask is not in the same space as atlas')
boolmask = mask > 0 boolmask = mask > 0
weights = mask[boolmask] weights = mask[boolmask]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment