diff --git a/fsl/data/atlases.py b/fsl/data/atlases.py index db1925fa46e88b69ffe596070cdf765291bc0e18..9f6b9fe8df68f665233dadd9fac579521f8ea80f 100644 --- a/fsl/data/atlases.py +++ b/fsl/data/atlases.py @@ -40,6 +40,8 @@ load an atlas image, which will be one of the following atlas-specific """ +from __future__ import division + import xml.etree.ElementTree as et import os.path as op import glob @@ -521,11 +523,11 @@ class AtlasDescription(object): return self.atlasID != other.atlasID - def __cmp__(self, other): + def __lt__(self, other): """Compares this ``AtlasDescription`` with another by their ``name`` attribute. """ - return cmp(self.name.lower(), other.name.lower()) + return self.name.lower() < other.name.lower() class Atlas(fslimage.Image): @@ -559,8 +561,10 @@ class Atlas(fslimage.Image): res = resolution reses = np.concatenate(atlasDesc.pixdims) - if resolution is None: imageIdx = np.argmin(reses) / 3 - else: imageIdx = np.argmin(np.abs(reses - res)) / 3 + if resolution is None: imageIdx = np.argmin(reses) + else: imageIdx = np.argmin(np.abs(reses - res)) + + imageIdx = imageIdx // 3 if isLabel: imageFile = atlasDesc.summaryImages[imageIdx] else: imageFile = atlasDesc.images[ imageIdx] diff --git a/fsl/data/featdesign.py b/fsl/data/featdesign.py index ee5843064b0d2c9bccc93dd4322be98f5f51f2a4..ed8d905994e98a1c6a240230cab56307f6a6b5b8 100644 --- a/fsl/data/featdesign.py +++ b/fsl/data/featdesign.py @@ -540,7 +540,7 @@ def getFirstLevelEVs(featDir, settings, designMat): # above, about the voxelwise # confound EV locations, holds startIdx = len(evs) + 1 - if voxConfLocs != range(startIdx, startIdx + len(voxConfFiles)): + if voxConfLocs != list(range(startIdx, startIdx + len(voxConfFiles))): raise FSFError('Unsupported voxelwise confound ordering ' '({} -> {})'.format(startIdx, voxConfLocs)) @@ -640,26 +640,11 @@ def loadDesignMat(designmat): :arg designmat: Path to the ``design.mat`` file. """ - matrix = None - log.debug('Loading FEAT design matrix from {}'.format(designmat)) - with open(designmat, 'rt') as f: - - while True: - line = f.readline() - - # readline returns an empty string at EOF - if line == '': - break - - # Matrix data starts after "/Matrix" - if line.strip() == '/Matrix': - break - - matrix = np.loadtxt(f, ndmin=2) + matrix = np.loadtxt(designmat, comments='/', ndmin=2) - if matrix is None or matrix.size == 0: + if matrix is None or matrix.size == 0 or len(matrix.shape) != 2: raise FSFError('{} does not appear to be a ' 'valid design.mat file'.format(designmat)) diff --git a/fsl/data/image.py b/fsl/data/image.py index 1b93982be91d51ba32da528a555d9030faddb9b1..f44c3bec5539e84f24a8ee9285fd713499b687aa 100644 --- a/fsl/data/image.py +++ b/fsl/data/image.py @@ -470,8 +470,8 @@ class Nifti(notifier.Notifier): elif qform_code != constants.NIFTI_XFORM_UNKNOWN: code = qform_code # Invalid values - if code > 4: code = constants.NIFTI_XFORM_UNKNOWN - elif code < 0: code = constants.NIFTI_XFORM_UNKNOWN + if code not in range(5): + code = constants.NIFTI_XFORM_UNKNOWN return int(code) @@ -836,7 +836,7 @@ class Image(Nifti): self.__nibImage = None self.__imageWrapper = None - if self.__fileobj is not None: + if getattr(self, '__fileobj', None) is not None: self.__fileobj.close() diff --git a/fsl/data/imagewrapper.py b/fsl/data/imagewrapper.py index 810624daaccd695c857f0b1f90ccd989e7207b55..81658f594817ad90b3f4f9c7fd7fecbd9949e0a2 100644 --- a/fsl/data/imagewrapper.py +++ b/fsl/data/imagewrapper.py @@ -415,7 +415,7 @@ class ImageWrapper(notifier.Notifier): """ shape = self.__image.shape - slices = zip([0] * len(shape), shape) + slices = [[0, s] for s in shape] return sliceCovered(slices, self.__coverage) diff --git a/fsl/data/mesh.py b/fsl/data/mesh.py index e34ebf2a7b3bedaee0ef80c629c5b23a794fa577..2a9c47df7bdacc938cbcef57bf459b05529f8db1 100644 --- a/fsl/data/mesh.py +++ b/fsl/data/mesh.py @@ -221,7 +221,6 @@ def loadVTKPolydataFile(infile): for i in range(nVertices): vertLine = lines[i + 5] - vertices[i, :] = map(float, vertLine.split()) vertices[i, :] = [float(w) for w in vertLine.split()] indexOffset = 0 @@ -232,7 +231,6 @@ def loadVTKPolydataFile(infile): start = indexOffset end = indexOffset + polygonLengths[i] - indices[start:end] = map(int, polyLine[1:]) indices[start:end] = [int(w) for w in polyLine[1:]] indexOffset += polygonLengths[i] diff --git a/fsl/utils/async.py b/fsl/utils/async.py index 938a83c384746540cf77bce76dd089e64591d4aa..a8e8efa0e41a39336b4acecb6ab7709c1c14ac04 100644 --- a/fsl/utils/async.py +++ b/fsl/utils/async.py @@ -290,8 +290,11 @@ def _wxIdleLoop(ev): except queue.Empty: # Make sure that we get called periodically, - # if EVT_IDLE decides to stop firing. - _idleTimer.Start(_idleCallRate, wx.TIMER_ONE_SHOT) + # if EVT_IDLE decides to stop firing. If + # _idleTimer is None, then idleReset has + # probably been called. + if _idleTimer is not None: + _idleTimer.Start(_idleCallRate, wx.TIMER_ONE_SHOT) return now = time.time()