From de6dcde65053b74931b4f2c57059a2ea407d1c49 Mon Sep 17 00:00:00 2001
From: Paul McCarthy <pauld.mccarthy@gmail.com>
Date: Mon, 10 Apr 2017 18:19:58 +0100
Subject: [PATCH] Fix to fsl.data.mesh.findReferenceImage

---
 fsl/data/mesh.py | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/fsl/data/mesh.py b/fsl/data/mesh.py
index edd16c3d7..ce7094e58 100644
--- a/fsl/data/mesh.py
+++ b/fsl/data/mesh.py
@@ -243,7 +243,7 @@ def loadVTKPolydataFile(infile):
 def getFIRSTPrefix(modelfile):
     """If the given ``vtk`` file was generated by `FIRST
     <https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/FIRST>`_, this function
-    will return the file prefix. Otherwise an ``Exception`` will be
+    will return the file prefix. Otherwise a ``ValueError`` will be
     raised.
     """
 
@@ -268,8 +268,18 @@ def findReferenceImage(modelfile):
 
     try:
 
-        prefix = getFIRSTPrefix(modelfile)
-        return fslimage.addExt(prefix, mustExist=True)
-
+        dirname  = op.dirname(modelfile)
+        prefixes = [getFIRSTPrefix(modelfile)]
     except:
         return None
+
+    if prefixes[0].endswith('_first'):
+        prefixes.append(prefixes[0][:-6])
+
+    for p in prefixes:
+        try:
+            return fslimage.addExt(op.join(dirname, p), mustExist=True)
+        except:
+            continue
+
+    return None
-- 
GitLab