Skip to content
Snippets Groups Projects
Commit 42f1c413 authored by Paul McCarthy's avatar Paul McCarthy
Browse files

Fix various python 2/3 incompatibilities. Also simplified

featdesign.loadDesignMat function
parent fa56d9cc
No related branches found
No related tags found
No related merge requests found
...@@ -40,6 +40,8 @@ load an atlas image, which will be one of the following atlas-specific ...@@ -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 xml.etree.ElementTree as et
import os.path as op import os.path as op
import glob import glob
...@@ -521,11 +523,11 @@ class AtlasDescription(object): ...@@ -521,11 +523,11 @@ class AtlasDescription(object):
return self.atlasID != other.atlasID return self.atlasID != other.atlasID
def __cmp__(self, other): def __lt__(self, other):
"""Compares this ``AtlasDescription`` with another by their ``name`` """Compares this ``AtlasDescription`` with another by their ``name``
attribute. attribute.
""" """
return cmp(self.name.lower(), other.name.lower()) return self.name.lower() < other.name.lower()
class Atlas(fslimage.Image): class Atlas(fslimage.Image):
...@@ -559,8 +561,10 @@ class Atlas(fslimage.Image): ...@@ -559,8 +561,10 @@ class Atlas(fslimage.Image):
res = resolution res = resolution
reses = np.concatenate(atlasDesc.pixdims) reses = np.concatenate(atlasDesc.pixdims)
if resolution is None: imageIdx = np.argmin(reses) / 3 if resolution is None: imageIdx = np.argmin(reses)
else: imageIdx = np.argmin(np.abs(reses - res)) / 3 else: imageIdx = np.argmin(np.abs(reses - res))
imageIdx = imageIdx // 3
if isLabel: imageFile = atlasDesc.summaryImages[imageIdx] if isLabel: imageFile = atlasDesc.summaryImages[imageIdx]
else: imageFile = atlasDesc.images[ imageIdx] else: imageFile = atlasDesc.images[ imageIdx]
......
...@@ -540,7 +540,7 @@ def getFirstLevelEVs(featDir, settings, designMat): ...@@ -540,7 +540,7 @@ def getFirstLevelEVs(featDir, settings, designMat):
# above, about the voxelwise # above, about the voxelwise
# confound EV locations, holds # confound EV locations, holds
startIdx = len(evs) + 1 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 ' raise FSFError('Unsupported voxelwise confound ordering '
'({} -> {})'.format(startIdx, voxConfLocs)) '({} -> {})'.format(startIdx, voxConfLocs))
...@@ -640,26 +640,11 @@ def loadDesignMat(designmat): ...@@ -640,26 +640,11 @@ def loadDesignMat(designmat):
:arg designmat: Path to the ``design.mat`` file. :arg designmat: Path to the ``design.mat`` file.
""" """
matrix = None
log.debug('Loading FEAT design matrix from {}'.format(designmat)) log.debug('Loading FEAT design matrix from {}'.format(designmat))
with open(designmat, 'rt') as f: matrix = np.loadtxt(designmat, comments='/', ndmin=2)
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)
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 ' raise FSFError('{} does not appear to be a '
'valid design.mat file'.format(designmat)) 'valid design.mat file'.format(designmat))
......
...@@ -470,8 +470,8 @@ class Nifti(notifier.Notifier): ...@@ -470,8 +470,8 @@ class Nifti(notifier.Notifier):
elif qform_code != constants.NIFTI_XFORM_UNKNOWN: code = qform_code elif qform_code != constants.NIFTI_XFORM_UNKNOWN: code = qform_code
# Invalid values # Invalid values
if code > 4: code = constants.NIFTI_XFORM_UNKNOWN if code not in range(5):
elif code < 0: code = constants.NIFTI_XFORM_UNKNOWN code = constants.NIFTI_XFORM_UNKNOWN
return int(code) return int(code)
...@@ -836,7 +836,7 @@ class Image(Nifti): ...@@ -836,7 +836,7 @@ class Image(Nifti):
self.__nibImage = None self.__nibImage = None
self.__imageWrapper = None self.__imageWrapper = None
if self.__fileobj is not None: if getattr(self, '__fileobj', None) is not None:
self.__fileobj.close() self.__fileobj.close()
......
...@@ -415,7 +415,7 @@ class ImageWrapper(notifier.Notifier): ...@@ -415,7 +415,7 @@ class ImageWrapper(notifier.Notifier):
""" """
shape = self.__image.shape shape = self.__image.shape
slices = zip([0] * len(shape), shape) slices = [[0, s] for s in shape]
return sliceCovered(slices, self.__coverage) return sliceCovered(slices, self.__coverage)
......
...@@ -221,7 +221,6 @@ def loadVTKPolydataFile(infile): ...@@ -221,7 +221,6 @@ def loadVTKPolydataFile(infile):
for i in range(nVertices): for i in range(nVertices):
vertLine = lines[i + 5] vertLine = lines[i + 5]
vertices[i, :] = map(float, vertLine.split())
vertices[i, :] = [float(w) for w in vertLine.split()] vertices[i, :] = [float(w) for w in vertLine.split()]
indexOffset = 0 indexOffset = 0
...@@ -232,7 +231,6 @@ def loadVTKPolydataFile(infile): ...@@ -232,7 +231,6 @@ def loadVTKPolydataFile(infile):
start = indexOffset start = indexOffset
end = indexOffset + polygonLengths[i] end = indexOffset + polygonLengths[i]
indices[start:end] = map(int, polyLine[1:])
indices[start:end] = [int(w) for w in polyLine[1:]] indices[start:end] = [int(w) for w in polyLine[1:]]
indexOffset += polygonLengths[i] indexOffset += polygonLengths[i]
......
...@@ -290,8 +290,11 @@ def _wxIdleLoop(ev): ...@@ -290,8 +290,11 @@ def _wxIdleLoop(ev):
except queue.Empty: except queue.Empty:
# Make sure that we get called periodically, # Make sure that we get called periodically,
# if EVT_IDLE decides to stop firing. # if EVT_IDLE decides to stop firing. If
_idleTimer.Start(_idleCallRate, wx.TIMER_ONE_SHOT) # _idleTimer is None, then idleReset has
# probably been called.
if _idleTimer is not None:
_idleTimer.Start(_idleCallRate, wx.TIMER_ONE_SHOT)
return return
now = time.time() now = time.time()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment