diff --git a/fsl/data/featanalysis.py b/fsl/data/featanalysis.py index a35d81b54eabf8db23fabde9aeed175fa56ccf56..39e40c9122c163d68adbfe0d308bd9146ef37306 100644 --- a/fsl/data/featanalysis.py +++ b/fsl/data/featanalysis.py @@ -64,7 +64,7 @@ def isFEATImage(path): try: path = fslimage.addExt(path, mustExist=True) - except: + except fslimage.PathError: return False dirname = op.dirname( path) @@ -115,7 +115,7 @@ def hasStats(featdir): try: getZStatFile(featdir, 0) return True - except: + except fslimage.PathError: return False diff --git a/fsl/data/featdesign.py b/fsl/data/featdesign.py index ed8d905994e98a1c6a240230cab56307f6a6b5b8..26c10595b9a207d91bfe341c1f70f4d8eb8aa65e 100644 --- a/fsl/data/featdesign.py +++ b/fsl/data/featdesign.py @@ -326,7 +326,8 @@ class VoxelwiseEV(NormalEV): if op.exists(filename): self.filename = filename else: - log.warning('Voxelwise EV file does not exist: '.format(filename)) + log.warning('Voxelwise EV file does not ' + 'exist: {}'.format(filename)) self.filename = None @@ -406,8 +407,8 @@ class VoxelwiseConfoundEV(EV): if op.exists(filename): self.filename = filename else: - log.warning('Voxelwise confound EV file ' - 'does not exist: '.format(filename)) + log.warning('Voxelwise confound EV file does ' + 'not exist: {}'.format(filename)) self.filename = None @@ -547,7 +548,7 @@ def getFirstLevelEVs(featDir, settings, designMat): # Create the voxelwise confound EVs. # We make a name for the EV from the # file name. - for i, (f, l) in enumerate(zip(voxConfFiles, voxConfLocs)): + for i, f in enumerate(voxConfFiles): title = op.basename(fslimage.removeExt(f)) evs.append(VoxelwiseConfoundEV(len(evs), i, title, f)) diff --git a/fsl/data/image.py b/fsl/data/image.py index 0ec4fb1033e67d8a8f4185dbc081299676412e9d..b1c93c0873ab37fd2e620e0d391b65f276d86df3 100644 --- a/fsl/data/image.py +++ b/fsl/data/image.py @@ -222,6 +222,8 @@ class Nifti(notifier.Notifier): # qform = header.get('qform_code', -1) # sform = header.get('sform_code', -1) # + # TODO Change this in fslpy 2.0.0 + # if isinstance(header, nib.nifti1.Nifti1Header): intent = header['intent_code'] qform = header['qform_code'] @@ -309,8 +311,8 @@ class Nifti(notifier.Notifier): val = self.header[key] - try: val = bytes(val).partition(b'\0')[0] - except: val = bytes(val) + try: val = bytes(val).partition(b'\0')[0] + except Exception: val = bytes(val) val = val.decode('ascii') @@ -611,12 +613,12 @@ class Nifti(notifier.Notifier): :class:`Nifti` instance) has the same dimensions and is in the same space as this image. """ - return np.all(np.isclose(self .__shape[:3], - other.__shape[:3])) and \ - np.all(np.isclose(self .__pixdim[:3], - other.__pixdim[:3])) and \ - np.all(np.isclose(self .__voxToWorldMat, - other.__voxToWorldMat)) + return np.all(np.isclose(self .shape[:3], + other.shape[:3])) and \ + np.all(np.isclose(self .pixdim[:3], + other.pixdim[:3])) and \ + np.all(np.isclose(self .voxToWorldMat, + other.voxToWorldMat)) def getOrientation(self, axis, xform): @@ -1426,7 +1428,7 @@ def read_segments(fileobj, segments, n_bytes): # actual file is available via the fobj attribute lock = getattr(fileobj.fobj, '_arrayproxy_lock') - except: + except AttributeError: return fileslice.orig_read_segments(fileobj, segments, n_bytes) if len(segments) == 0: diff --git a/fsl/data/imagewrapper.py b/fsl/data/imagewrapper.py index ab8362985b2ac73705e82d73da415c999ba8ccf0..22883780cc896248346e76afac34ab983b88382a 100644 --- a/fsl/data/imagewrapper.py +++ b/fsl/data/imagewrapper.py @@ -231,7 +231,7 @@ class ImageWrapper(notifier.Notifier): self.__image = None if self.__taskThread is not None: self.__taskThread.stop() - self.__taskThraed = None + self.__taskThread = None def getTaskThread(self): @@ -459,7 +459,7 @@ class ImageWrapper(notifier.Notifier): # the min/max per volume/expansion, and # iteratively update the stored per-volume # coverage and data range. - for i, exp in enumerate(expansions): + for exp in expansions: data = self.__getData(exp, isTuple=True) data = data.squeeze(squeezeDims) @@ -750,7 +750,7 @@ def naninfrange(data): # finite values in the array try: return data[finite].min(), data[finite].max() - except: + except Exception: return np.nan, np.nan @@ -1097,7 +1097,7 @@ def calcExpansion(slices, coverage): # 'padding' dimensions of size 1. def finishExpansion(exp, vol): exp.append((vol, vol + 1)) - for i in range(padDims): + for _ in range(padDims): exp.append((0, 1)) return exp diff --git a/fsl/data/melodicanalysis.py b/fsl/data/melodicanalysis.py index d0074f27f2637e9e882b8e3c2fbf33d14b9ee8cc..e13dd1e9906448fe90a72a249d82d690facc8031 100644 --- a/fsl/data/melodicanalysis.py +++ b/fsl/data/melodicanalysis.py @@ -49,7 +49,7 @@ def isMelodicImage(path): try: path = fslimage.addExt(path, mustExist=True) - except: + except fslimage.PathError: return False dirname = op.dirname( path) diff --git a/fsl/data/mesh.py b/fsl/data/mesh.py index c3c701232406c37d3bdd0ddff8e54cd63d3fab28..d052ccb399df3afd1a7fad3c2ead762eac6e3663 100644 --- a/fsl/data/mesh.py +++ b/fsl/data/mesh.py @@ -380,7 +380,7 @@ def findReferenceImage(modelfile): dirname = op.dirname(modelfile) prefixes = [getFIRSTPrefix(modelfile)] - except: + except ValueError: return None if prefixes[0].endswith('_first'): @@ -389,7 +389,7 @@ def findReferenceImage(modelfile): for p in prefixes: try: return fslimage.addExt(op.join(dirname, p), mustExist=True) - except: + except fslimage.PathError: continue return None diff --git a/fsl/utils/async.py b/fsl/utils/async.py index 373e49e64ce5270ca2f8a5013cc898f18cd7720a..4ff8dec1568defff31edc67dda1c76f8e88dcf55 100644 --- a/fsl/utils/async.py +++ b/fsl/utils/async.py @@ -87,8 +87,8 @@ import functools import threading import collections -try: import queue -except: import Queue as queue +try: import queue +except ImportError: import Queue as queue log = logging.getLogger(__name__) @@ -142,7 +142,7 @@ def run(task, onFinish=None, onError=None, name=None): except Exception as e: - log.warn('Task "{}" crashed'.format(name), exc_info=True) + log.warning('Task "{}" crashed'.format(name), exc_info=True) callback(onError, e) # If WX, run on a thread @@ -759,7 +759,7 @@ class TaskThread(threading.Thread): # Any other error typically indicates # that this is a daemon thread, and # the TaskThread object has been GC'd - except: + except Exception: break finally: diff --git a/fsl/utils/platform.py b/fsl/utils/platform.py index 972790abd7b1621bf2010f670bc56e6bb8bd2436..32e9d296a84219ef6d3700e721b8a83e87f57718 100644 --- a/fsl/utils/platform.py +++ b/fsl/utils/platform.py @@ -146,6 +146,7 @@ class Platform(notifier.Notifier): self.__glRenderer = None self.__glIsSoftware = None self.__fslVersion = None + self.__fsldir = None self.fsldir = os.environ.get('FSLDIR', None) # Determine if a display is available. We do @@ -239,18 +240,16 @@ class Platform(notifier.Notifier): pi = [t.lower() for t in wx.PlatformInfo] - for tag in pi: - - if any(['cocoa' in p for p in pi]): platform = WX_MAC_COCOA - elif any(['carbon' in p for p in pi]): platform = WX_MAC_CARBON - elif any(['gtk' in p for p in pi]): platform = WX_GTK - else: platform = WX_UNKNOWN + if any(['cocoa' in p for p in pi]): plat = WX_MAC_COCOA + elif any(['carbon' in p for p in pi]): plat = WX_MAC_CARBON + elif any(['gtk' in p for p in pi]): plat = WX_GTK + else: plat = WX_UNKNOWN - if platform is WX_UNKNOWN: - log.warning('Could not determine wx platform from ' - 'information: {}'.format(pi)) + if platform is WX_UNKNOWN: + log.warning('Could not determine wx platform from ' + 'information: {}'.format(pi)) - return platform + return plat @property diff --git a/fsl/utils/settings.py b/fsl/utils/settings.py index 491198adb5f86729e93e9b7d80859b6e8047f35a..675ad29c4880f466e7c113f9f7100ad4be4883d7 100644 --- a/fsl/utils/settings.py +++ b/fsl/utils/settings.py @@ -341,7 +341,7 @@ class Settings(object): if not op.exists(cfgdir): try: os.makedirs(cfgdir) - except: + except OSError: log.warning( 'Unable to create {} configuration ' 'directory: {}'.format(cid, cfgdir), @@ -372,7 +372,7 @@ class Settings(object): try: with open(configFile, 'rb') as f: return pickle.load(f) - except: + except (IOError, pickle.UnpicklingError): log.debug('Unable to load stored {} configuration file ' '{}'.format(self.__configID, configFile), exc_info=True) @@ -391,7 +391,7 @@ class Settings(object): try: with open(configFile, 'wb') as f: pickle.dump(config, f) - except: + except (IOError, pickle.PicklingError): log.warning('Unable to save {} configuration file ' '{}'.format(self.__configID, configFile), exc_info=True) diff --git a/fsl/utils/weakfuncref.py b/fsl/utils/weakfuncref.py index 71350145ec3e8a54d1e94a63e9d0e54be90c34c5..937481c014c00b71bda39e7c2985bf78ecbb084d 100644 --- a/fsl/utils/weakfuncref.py +++ b/fsl/utils/weakfuncref.py @@ -148,9 +148,9 @@ class WeakFunctionRef(object): obj = self.obj() # Return the bound method object - try: return getattr(obj, self.funcName) + try: return getattr(obj, self.funcName) # If the function is a bound private method, # its name on the instance will have been # mangled, so we need to search for it - except: return self.__findPrivateMethod() + except AttributeError: return self.__findPrivateMethod()