From d3e39f3fd82a45d738d637071f6ff1243a6abd7f Mon Sep 17 00:00:00 2001
From: Paul McCarthy <pauldmccarthy@gmail.com>
Date: Fri, 13 Oct 2017 14:25:21 +0100
Subject: [PATCH] Small tweaks to atlases bits

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

diff --git a/fsl/data/atlases.py b/fsl/data/atlases.py
index 51d2f507e..7920c9627 100644
--- a/fsl/data/atlases.py
+++ b/fsl/data/atlases.py
@@ -565,6 +565,9 @@ class AtlasDescription(object):
         for i, label in enumerate(self.labels):
             label.x, label.y, label.z = coords[i]
 
+        # Make sure the labels are sorted by index
+        self.labels = list(sorted(self.labels))
+
 
     def find(self, index=None, value=None):
         """Find an :class:`.AtlasLabel` either by ``index``, or by ``value``.
@@ -579,7 +582,7 @@ class AtlasDescription(object):
             raise ValueError('Only one of index or value may be specified')
 
         if index is not None: return self.labels[         index]
-        else:                 return self.__labelsByValue[value]
+        else:                 return self.__labelsByValue[int(value)]
 
 
     def __eq__(self, other):
@@ -881,7 +884,6 @@ class ProbabilisticAtlas(Atlas):
            loc[2] >= self.shape[2]:
             return []
 
-
         props = self[loc[0], loc[1], loc[2], :]
 
         # We only return labels for this atlas -
@@ -917,6 +919,9 @@ class ProbabilisticAtlas(Atlas):
         weights   = mask[boolmask]
         weightsum = weights.sum()
 
+        if weightsum == 0:
+            return [0.0] * len(self.desc.labels)
+
         for label in self.desc.labels:
 
             vals  = self[..., label.index]
-- 
GitLab