Skip to content

Commit 05d74ec

Browse files
committed
more NUMPY_MMAP fixes
1 parent 671fc03 commit 05d74ec

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

nipype/algorithms/modelgen.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import numpy as np
2929
from scipy.special import gammaln
3030

31+
from ..utils import NUMPY_MMAP
3132
from ..interfaces.base import (BaseInterface, TraitedSpec, InputMultiPath,
3233
traits, File, Bunch, BaseInterfaceInputSpec,
3334
isdefined)
@@ -354,7 +355,7 @@ def _generate_standard_design(self, infolist,
354355
for i, out in enumerate(outliers):
355356
numscans = 0
356357
for f in filename_to_list(sessinfo[i]['scans']):
357-
shape = load(f).shape
358+
shape = load(f, mmap=NUMPY_MMAP).shape
358359
if len(shape) == 3 or shape[3] == 1:
359360
iflogger.warning(("You are using 3D instead of 4D "
360361
"files. Are you sure this was "
@@ -457,7 +458,7 @@ def _concatenate_info(self, infolist):
457458
if isinstance(f, list):
458459
numscans = len(f)
459460
elif isinstance(f, (str, bytes)):
460-
img = load(f)
461+
img = load(f, mmap=NUMPY_MMAP)
461462
numscans = img.shape[3]
462463
else:
463464
raise Exception('Functional input not specified correctly')
@@ -781,7 +782,7 @@ def _generate_clustered_design(self, infolist):
781782
infoout[i].onsets = None
782783
infoout[i].durations = None
783784
if info.conditions:
784-
img = load(self.inputs.functional_runs[i])
785+
img = load(self.inputs.functional_runs[i], mmap=NUMPY_MMAP)
785786
nscans = img.shape[3]
786787
reg, regnames = self._cond_to_regress(info, nscans)
787788
if hasattr(infoout[i], 'regressors') and infoout[i].regressors:

nipype/workflows/fmri/fsl/preprocess.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,21 @@ def pickfirst(files):
2828
def pickmiddle(files):
2929
from nibabel import load
3030
import numpy as np
31+
from nipype.utils import NUMPY_MMAP
3132
middlevol = []
3233
for f in files:
33-
middlevol.append(int(np.ceil(load(f).shape[3] / 2)))
34+
middlevol.append(int(np.ceil(load(f, mmap=NUMPY_MMAP).shape[3] / 2)))
3435
return middlevol
3536

3637

3738
def pickvol(filenames, fileidx, which):
3839
from nibabel import load
3940
import numpy as np
41+
from nipype.utils import NUMPY_MMAP
4042
if which.lower() == 'first':
4143
idx = 0
4244
elif which.lower() == 'middle':
43-
idx = int(np.ceil(load(filenames[fileidx]).shape[3] / 2))
45+
idx = int(np.ceil(load(filenames[fileidx], mmap=NUMPY_MMAP).shape[3] / 2))
4446
elif which.lower() == 'last':
4547
idx = load(filenames[fileidx]).shape[3] - 1
4648
else:

nipype/workflows/rsfmri/fsl/resting.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ def select_volume(filename, which):
1414
"""
1515
from nibabel import load
1616
import numpy as np
17+
from nipype.utils import NUMPY_MMAP
18+
1719
if which.lower() == 'first':
1820
idx = 0
1921
elif which.lower() == 'middle':
20-
idx = int(np.ceil(load(filename).shape[3] / 2))
22+
idx = int(np.ceil(load(filename, mmap=NUMPY_MMAP).shape[3] / 2))
2123
else:
2224
raise Exception('unknown value for volume selection : %s' % which)
2325
return idx

0 commit comments

Comments
 (0)