From 6009879c80b2d866cad21bbbbc76d8183d6b982d Mon Sep 17 00:00:00 2001
From: Paul McCarthy <pauldmccarthy@gmail.com>
Date: Fri, 6 Jul 2018 16:52:24 +0100
Subject: [PATCH] RF: Do not try to load files of unsupported type

---
 fsl/wrappers/wrapperutils.py | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/fsl/wrappers/wrapperutils.py b/fsl/wrappers/wrapperutils.py
index e63baf3e3..d9a8951b8 100644
--- a/fsl/wrappers/wrapperutils.py
+++ b/fsl/wrappers/wrapperutils.py
@@ -624,12 +624,15 @@ class _FileOrThing(object):
                             log.debug('Loading prefixed output %s [%s]: %s',
                                       prefPat, prefName, filename)
 
-                            fval             = self.__load(filename)
-                            basename         = self.__removeExt(basename)
-                            basename         = basename.replace(prefPat,
-                                                                prefName)
-                            result[basename] = fval
-                            break
+                            # if the load function returns
+                            # None, this file is probably
+                            # not of the correct type.
+                            fval = self.__load(filename)
+                            if fval is not None:
+                                basename = self.__removeExt(basename)
+                                basename = basename.replace(prefPat, prefName)
+                                result[basename] = fval
+                                break
 
                     # if file did not match any pattern,
                     # move it into the real prefix, where
@@ -807,6 +810,10 @@ def fileOrImage(*args, **kwargs):
         return op.join(workdir, '{}.nii.gz'.format(name))
 
     def load(path):
+
+        if not fslimage.looksLikeImage(path):
+            return None
+
         # create an independent in-memory
         # copy of the image file
         img = nib.load(path)
@@ -863,7 +870,9 @@ def fileOrArray(*args, **kwargs):
     def prepOut(workdir, name, val):
         return op.join(workdir, '{}.txt'.format(name))
 
-    load = np.loadtxt
+    def load(path):
+        try:              return np.loadtxt(path)
+        except Exception: return None
 
     def decorator(func):
         fot = _FileOrThing(func,
-- 
GitLab