From cf99f6ab0ad403d17ebcd9a314b45d0fe53830e7 Mon Sep 17 00:00:00 2001
From: Paul McCarthy <pauldmccarthy@gmail.com>
Date: Thu, 12 Oct 2017 16:04:37 +0100
Subject: [PATCH] Atlas mask query methods raise a custom error type if mask is
 bad

---
 fsl/data/atlases.py | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/fsl/data/atlases.py b/fsl/data/atlases.py
index 22ddbb7e7..9c6fbec45 100644
--- a/fsl/data/atlases.py
+++ b/fsl/data/atlases.py
@@ -605,6 +605,14 @@ class Atlas(fslimage.Image):
         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):
     """A 3D atlas which contains integer labels for each region.
 
@@ -714,7 +722,8 @@ class LabelAtlas(Atlas):
         mask, xform = mask.resample(self.shape[:3], dtype=np.float32, order=0)
 
         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
@@ -858,7 +867,7 @@ class ProbabilisticAtlas(Atlas):
         mask, xform = mask.resample(self.shape[:3], dtype=np.float32, order=0)
 
         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
         weights   = mask[boolmask]
-- 
GitLab