diff --git a/fsl/data/atlases.py b/fsl/data/atlases.py index e2b89d06b095adba3772d4dd72bac8c9a06b8543..d43a09d954a636414f67faed284318e1048e20cc 100644 --- a/fsl/data/atlases.py +++ b/fsl/data/atlases.py @@ -595,12 +595,25 @@ class AtlasDescription(object): labels, and a 3D ``LabelAtlas`` may have more values than labels. """ - if (index is None and value is None) or \ - (index is not None and value is not None): - raise ValueError('Only one of index or value may be specified') + if ((index is not None) + (value is not None) + (name is not None)) != 1: + raise ValueError('Only one of index, value, or name may be specified') + if index is not None: return self.labels[ index] + elif value is not None: return self.__labelsByValue[int(value)] + else: + matches = [l for l in self.labels if l.name == name] + if len(matches) == 0: + # look for partial matches only if there are no full matches + matches = [l for l in self.labels if l.name[:len(name)] == name] + if len(matches) == 0: + raise IndexError('No match for {} found in labels {}'.format( + name, tuple(l.name for l in self.labels) + )) + elif len(matches) > 1: + raise IndexError('Multiple matches for {} found in labels {}'.format( + name, tuple(l.name for l in self.labels) + )) + return matches[0] - if index is not None: return self.labels[ index] - else: return self.__labelsByValue[int(value)] def __eq__(self, other): diff --git a/fsl/utils/filetree/trees/ProbtrackX.tree b/fsl/utils/filetree/trees/ProbtrackX.tree index 38db04c26930365b9046b8171ba28bfbd116ff39..06daa454663e653654814de6b36e8cb6f1214672 100644 --- a/fsl/utils/filetree/trees/ProbtrackX.tree +++ b/fsl/utils/filetree/trees/ProbtrackX.tree @@ -1,4 +1,4 @@ -basename=fdt +basename=fdt_paths probtrackx.log (log_cmd) {basename}.log (log_settings) diff --git a/tests/test_atlases.py b/tests/test_atlases.py index a30cb0919f6a7577043e3d0cf4def81a1add5803..8f4136b5dfb6dbaaa46a1e6061275c3c549a6f02 100644 --- a/tests/test_atlases.py +++ b/tests/test_atlases.py @@ -254,16 +254,31 @@ def test_find(): assert atlas .find(value=label.value) == label assert atlas .find(index=label.index) == label + assert atlas .find(name=label.name) == label assert atlas.desc.find(value=label.value) == label assert atlas.desc.find(index=label.index) == label + assert atlas.desc.find(name=label.name) == label + + if atlas is not lblatlas: + # lblatlas has a lot of very similar label names + assert atlas .find(name=label.name[:-2]) == label + assert atlas.desc.find(name=label.name[:-2]) == label with pytest.raises(ValueError): atlas.find() with pytest.raises(ValueError): atlas.find(index=1, value=1) + with pytest.raises(ValueError): + atlas.find(index=1, name=1) + with pytest.raises(ValueError): + atlas.find(value=1, name=1) with pytest.raises(IndexError): atlas.find(index=len(labels)) + with pytest.raises(IndexError): + atlas.find(name='InvalidROI') + with pytest.raises(IndexError): + atlas.find(name='') maxval = max([l.value for l in labels]) with pytest.raises(KeyError):