Skip to content

Commit 2125c0b

Browse files
authored
Merge pull request #3121 from steve19922/stop-using-numpy_mmap-constant
[REF] removed all uses of numpy_mmap
2 parents 76d8e88 + e4b18c6 commit 2125c0b

24 files changed

+49
-81
lines changed

examples/dmri_camino_dti.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -35,30 +35,27 @@
3535

3636
def get_vox_dims(volume):
3737
import nibabel as nb
38-
from nipype.utils import NUMPY_MMAP
3938
if isinstance(volume, list):
4039
volume = volume[0]
41-
nii = nb.load(volume, mmap=NUMPY_MMAP)
40+
nii = nb.load(volume)
4241
hdr = nii.header
4342
voxdims = hdr.get_zooms()
4443
return [float(voxdims[0]), float(voxdims[1]), float(voxdims[2])]
4544

4645

4746
def get_data_dims(volume):
4847
import nibabel as nb
49-
from nipype.utils import NUMPY_MMAP
5048
if isinstance(volume, list):
5149
volume = volume[0]
52-
nii = nb.load(volume, mmap=NUMPY_MMAP)
50+
nii = nb.load(volume)
5351
hdr = nii.header
5452
datadims = hdr.get_data_shape()
5553
return [int(datadims[0]), int(datadims[1]), int(datadims[2])]
5654

5755

5856
def get_affine(volume):
5957
import nibabel as nb
60-
from nipype.utils import NUMPY_MMAP
61-
nii = nb.load(volume, mmap=NUMPY_MMAP)
58+
nii = nb.load(volume)
6259
return nii.affine
6360

6461

examples/dmri_connectivity.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -73,30 +73,27 @@
7373

7474
def get_vox_dims(volume):
7575
import nibabel as nb
76-
from nipype.utils import NUMPY_MMAP
7776
if isinstance(volume, list):
7877
volume = volume[0]
79-
nii = nb.load(volume, mmap=NUMPY_MMAP)
78+
nii = nb.load(volume)
8079
hdr = nii.header
8180
voxdims = hdr.get_zooms()
8281
return [float(voxdims[0]), float(voxdims[1]), float(voxdims[2])]
8382

8483

8584
def get_data_dims(volume):
8685
import nibabel as nb
87-
from nipype.utils import NUMPY_MMAP
8886
if isinstance(volume, list):
8987
volume = volume[0]
90-
nii = nb.load(volume, mmap=NUMPY_MMAP)
88+
nii = nb.load(volume)
9189
hdr = nii.header
9290
datadims = hdr.get_data_shape()
9391
return [int(datadims[0]), int(datadims[1]), int(datadims[2])]
9492

9593

9694
def get_affine(volume):
9795
import nibabel as nb
98-
from nipype.utils import NUMPY_MMAP
99-
nii = nb.load(volume, mmap=NUMPY_MMAP)
96+
nii = nb.load(volume)
10097
return nii.affine
10198

10299

examples/fmri_ants_openfmri.py

-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
from nipype.workflows.fmri.fsl import (create_featreg_preproc,
4242
create_modelfit_workflow,
4343
create_fixed_effects_flow)
44-
from nipype.utils import NUMPY_MMAP
4544

4645
config.enable_provenance()
4746
version = 0

examples/fmri_fsl.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,10 @@ def pickfirst(files):
101101

102102
def getmiddlevolume(func):
103103
from nibabel import load
104-
from nipype.utils import NUMPY_MMAP
105104
funcfile = func
106105
if isinstance(func, list):
107106
funcfile = func[0]
108-
_, _, _, timepoints = load(funcfile, mmap=NUMPY_MMAP).shape
107+
_, _, _, timepoints = load(funcfile).shape
109108
return int(timepoints / 2) - 1
110109

111110

examples/fmri_spm_auditory.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,9 @@
107107

108108
def get_vox_dims(volume):
109109
import nibabel as nb
110-
from nipype.utils import NUMPY_MMAP
111110
if isinstance(volume, list):
112111
volume = volume[0]
113-
nii = nb.load(volume, mmap=NUMPY_MMAP)
112+
nii = nb.load(volume)
114113
hdr = nii.header
115114
voxdims = hdr.get_zooms()
116115
return [float(voxdims[0]), float(voxdims[1]), float(voxdims[2])]

examples/fmri_spm_face.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,9 @@
101101

102102
def get_vox_dims(volume):
103103
import nibabel as nb
104-
from nipype.utils import NUMPY_MMAP
105104
if isinstance(volume, list):
106105
volume = volume[0]
107-
nii = nb.load(volume, mmap=NUMPY_MMAP)
106+
nii = nb.load(volume)
108107
hdr = nii.header
109108
voxdims = hdr.get_zooms()
110109
return [float(voxdims[0]), float(voxdims[1]), float(voxdims[2])]

examples/rsfmri_vol_surface_preprocessing.py

+8-13
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,9 @@ def median(in_files):
117117
"""
118118
import numpy as np
119119
import nibabel as nb
120-
from nipype.utils import NUMPY_MMAP
121120
average = None
122121
for idx, filename in enumerate(filename_to_list(in_files)):
123-
img = nb.load(filename, mmap=NUMPY_MMAP)
122+
img = nb.load(filename)
124123
data = np.median(img.get_data(), axis=3)
125124
if average is None:
126125
average = data
@@ -146,12 +145,11 @@ def bandpass_filter(files, lowpass_freq, highpass_freq, fs):
146145
from nipype.utils.filemanip import split_filename, list_to_filename
147146
import numpy as np
148147
import nibabel as nb
149-
from nipype.utils import NUMPY_MMAP
150148
out_files = []
151149
for filename in filename_to_list(files):
152150
path, name, ext = split_filename(filename)
153151
out_file = os.path.join(os.getcwd(), name + '_bp' + ext)
154-
img = nb.load(filename, mmap=NUMPY_MMAP)
152+
img = nb.load(filename)
155153
timepoints = img.shape[-1]
156154
F = np.zeros((timepoints))
157155
lowidx = int(timepoints / 2) + 1
@@ -264,12 +262,11 @@ def extract_noise_components(realigned_file,
264262
from scipy.linalg.decomp_svd import svd
265263
import numpy as np
266264
import nibabel as nb
267-
from nipype.utils import NUMPY_MMAP
268265
import os
269-
imgseries = nb.load(realigned_file, mmap=NUMPY_MMAP)
266+
imgseries = nb.load(realigned_file)
270267
components = None
271268
for filename in filename_to_list(mask_file):
272-
mask = nb.load(filename, mmap=NUMPY_MMAP).get_data()
269+
mask = nb.load(filename).get_data()
273270
if len(np.nonzero(mask > 0)[0]) == 0:
274271
continue
275272
voxel_timecourses = imgseries.get_data()[mask > 0]
@@ -334,11 +331,10 @@ def extract_subrois(timeseries_file, label_file, indices):
334331
"""
335332
from nipype.utils.filemanip import split_filename
336333
import nibabel as nb
337-
from nipype.utils import NUMPY_MMAP
338334
import os
339-
img = nb.load(timeseries_file, mmap=NUMPY_MMAP)
335+
img = nb.load(timeseries_file)
340336
data = img.get_data()
341-
roiimg = nb.load(label_file, mmap=NUMPY_MMAP)
337+
roiimg = nb.load(label_file)
342338
rois = roiimg.get_data()
343339
prefix = split_filename(timeseries_file)[1]
344340
out_ts_file = os.path.join(os.getcwd(), '%s_subcortical_ts.txt' % prefix)
@@ -359,9 +355,8 @@ def combine_hemi(left, right):
359355
"""
360356
import os
361357
import numpy as np
362-
from nipype.utils import NUMPY_MMAP
363-
lh_data = nb.load(left, mmap=NUMPY_MMAP).get_data()
364-
rh_data = nb.load(right, mmap=NUMPY_MMAP).get_data()
358+
lh_data = nb.load(left).get_data()
359+
rh_data = nb.load(right).get_data()
365360

366361
indices = np.vstack((1000000 + np.arange(0, lh_data.shape[0])[:, None],
367362
2000000 + np.arange(0, rh_data.shape[0])[:, None]))

examples/rsfmri_vol_surface_preprocessing_nipy.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@
7676
import numpy as np
7777
import scipy as sp
7878
import nibabel as nb
79-
from nipype.utils.config import NUMPY_MMAP
8079

8180
"""
8281
A list of modules and functions to import inside of nodes
@@ -129,7 +128,7 @@ def median(in_files):
129128
"""
130129
average = None
131130
for idx, filename in enumerate(filename_to_list(in_files)):
132-
img = nb.load(filename, mmap=NUMPY_MMAP)
131+
img = nb.load(filename)
133132
data = np.median(img.get_data(), axis=3)
134133
if average is None:
135134
average = data
@@ -156,7 +155,7 @@ def bandpass_filter(files, lowpass_freq, highpass_freq, fs):
156155
for filename in filename_to_list(files):
157156
path, name, ext = split_filename(filename)
158157
out_file = os.path.join(os.getcwd(), name + '_bp' + ext)
159-
img = nb.load(filename, mmap=NUMPY_MMAP)
158+
img = nb.load(filename)
160159
timepoints = img.shape[-1]
161160
F = np.zeros((timepoints))
162161
lowidx = int(timepoints / 2) + 1
@@ -282,9 +281,9 @@ def extract_subrois(timeseries_file, label_file, indices):
282281
The first four columns are: freesurfer index, i, j, k positions in the
283282
label file
284283
"""
285-
img = nb.load(timeseries_file, mmap=NUMPY_MMAP)
284+
img = nb.load(timeseries_file)
286285
data = img.get_data()
287-
roiimg = nb.load(label_file, mmap=NUMPY_MMAP)
286+
roiimg = nb.load(label_file)
288287
rois = roiimg.get_data()
289288
prefix = split_filename(timeseries_file)[1]
290289
out_ts_file = os.path.join(os.getcwd(), '%s_subcortical_ts.txt' % prefix)
@@ -303,8 +302,8 @@ def extract_subrois(timeseries_file, label_file, indices):
303302
def combine_hemi(left, right):
304303
"""Combine left and right hemisphere time series into a single text file
305304
"""
306-
lh_data = nb.load(left, mmap=NUMPY_MMAP).get_data()
307-
rh_data = nb.load(right, mmap=NUMPY_MMAP).get_data()
305+
lh_data = nb.load(left).get_data()
306+
rh_data = nb.load(right).get_data()
308307

309308
indices = np.vstack((1000000 + np.arange(0, lh_data.shape[0])[:, None],
310309
2000000 + np.arange(0, rh_data.shape[0])[:, None]))

nipype/algorithms/confounds.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
OutputMultiPath,
2727
SimpleInterface,
2828
)
29-
from ..utils import NUMPY_MMAP
3029
from ..utils.misc import normalize_mc_params
3130

3231
IFLOGGER = logging.getLogger("nipype.interface")
@@ -599,7 +598,7 @@ def _run_interface(self, runtime):
599598
else 0
600599
)
601600

602-
imgseries = nb.load(self.inputs.realigned_file, mmap=NUMPY_MMAP)
601+
imgseries = nb.load(self.inputs.realigned_file)
603602

604603
if len(imgseries.shape) != 4:
605604
raise ValueError(
@@ -917,7 +916,7 @@ class TSNR(BaseInterface):
917916
output_spec = TSNROutputSpec
918917

919918
def _run_interface(self, runtime):
920-
img = nb.load(self.inputs.in_file[0], mmap=NUMPY_MMAP)
919+
img = nb.load(self.inputs.in_file[0])
921920
header = img.header.copy()
922921
vollist = [nb.load(filename) for filename in self.inputs.in_file]
923922
data = np.concatenate(
@@ -1263,7 +1262,7 @@ def combine_mask_files(mask_files, mask_method=None, mask_index=None):
12631262
)
12641263
)
12651264
if mask_index < len(mask_files):
1266-
mask = nb.load(mask_files[mask_index], mmap=NUMPY_MMAP)
1265+
mask = nb.load(mask_files[mask_index])
12671266
return [mask]
12681267
raise ValueError(
12691268
("mask_index {0} must be less than number of mask " "files {1}").format(
@@ -1273,7 +1272,7 @@ def combine_mask_files(mask_files, mask_method=None, mask_index=None):
12731272
masks = []
12741273
if mask_method == "none":
12751274
for filename in mask_files:
1276-
masks.append(nb.load(filename, mmap=NUMPY_MMAP))
1275+
masks.append(nb.load(filename))
12771276
return masks
12781277

12791278
if mask_method == "union":

nipype/algorithms/icc.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
traits,
1212
File,
1313
)
14-
from ..utils import NUMPY_MMAP
1514

1615

1716
class ICCInputSpec(BaseInterfaceInputSpec):
@@ -46,7 +45,7 @@ def _run_interface(self, runtime):
4645

4746
session_datas = [
4847
[
49-
nb.load(fname, mmap=NUMPY_MMAP).get_fdata()[maskdata].reshape(-1, 1)
48+
nb.load(fname).get_fdata()[maskdata].reshape(-1, 1)
5049
for fname in sessions
5150
]
5251
for sessions in self.inputs.subjects_sessions

nipype/algorithms/misc.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
Undefined,
2929
)
3030
from ..utils.filemanip import fname_presuffix, split_filename, ensure_list
31-
from ..utils import NUMPY_MMAP
3231

3332
from . import confounds
3433

@@ -210,7 +209,7 @@ def _gen_output_filename(self, name):
210209

211210
def _run_interface(self, runtime):
212211
for fname in self.inputs.volumes:
213-
img = nb.load(fname, mmap=NUMPY_MMAP)
212+
img = nb.load(fname)
214213

215214
affine = img.affine
216215
affine = np.dot(self.inputs.transformation_matrix, affine)
@@ -1320,7 +1319,7 @@ def split_rois(in_file, mask=None, roishape=None):
13201319
if roishape is None:
13211320
roishape = (10, 10, 1)
13221321

1323-
im = nb.load(in_file, mmap=NUMPY_MMAP)
1322+
im = nb.load(in_file)
13241323
imshape = im.shape
13251324
dshape = imshape[:3]
13261325
nvols = imshape[-1]
@@ -1411,7 +1410,7 @@ def merge_rois(in_files, in_idxs, in_ref, dtype=None, out_file=None):
14111410
except:
14121411
pass
14131412

1414-
ref = nb.load(in_ref, mmap=NUMPY_MMAP)
1413+
ref = nb.load(in_ref)
14151414
aff = ref.affine
14161415
hdr = ref.header.copy()
14171416
rsh = ref.shape
@@ -1469,7 +1468,7 @@ def merge_rois(in_files, in_idxs, in_ref, dtype=None, out_file=None):
14691468
data[idata] = cdata[0:nels]
14701469
nb.Nifti1Image(data.reshape(rsh[:3]), aff, hdr).to_filename(fname)
14711470

1472-
imgs = [nb.load(im, mmap=NUMPY_MMAP) for im in nii]
1471+
imgs = [nb.load(im) for im in nii]
14731472
allim = nb.concat_images(imgs)
14741473
allim.to_filename(out_file)
14751474

nipype/algorithms/modelgen.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from nibabel import load
1818
import numpy as np
1919

20-
from ..utils import NUMPY_MMAP
2120
from ..interfaces.base import (
2221
BaseInterface,
2322
TraitedSpec,
@@ -474,7 +473,7 @@ def _generate_standard_design(
474473
for i, out in enumerate(outliers):
475474
numscans = 0
476475
for f in ensure_list(sessinfo[i]["scans"]):
477-
shape = load(f, mmap=NUMPY_MMAP).shape
476+
shape = load(f).shape
478477
if len(shape) == 3 or shape[3] == 1:
479478
iflogger.warning(
480479
"You are using 3D instead of 4D "
@@ -604,7 +603,7 @@ def _concatenate_info(self, infolist):
604603
if isinstance(f, list):
605604
numscans = len(f)
606605
elif isinstance(f, (str, bytes)):
607-
img = load(f, mmap=NUMPY_MMAP)
606+
img = load(f)
608607
numscans = img.shape[3]
609608
else:
610609
raise Exception("Functional input not specified correctly")
@@ -984,7 +983,7 @@ def _generate_clustered_design(self, infolist):
984983
infoout[i].onsets = None
985984
infoout[i].durations = None
986985
if info.conditions:
987-
img = load(self.inputs.functional_runs[i], mmap=NUMPY_MMAP)
986+
img = load(self.inputs.functional_runs[i])
988987
nscans = img.shape[3]
989988
reg, regnames = self._cond_to_regress(info, nscans)
990989
if hasattr(infoout[i], "regressors") and infoout[i].regressors:

nipype/algorithms/rapidart.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from nibabel import load, funcs, Nifti1Image
1919
import numpy as np
2020

21-
from ..utils import NUMPY_MMAP
2221
from ..interfaces.base import (
2322
BaseInterface,
2423
traits,
@@ -485,12 +484,12 @@ def _detect_outliers_core(self, imgfile, motionfile, runidx, cwd=None):
485484

486485
# read in functional image
487486
if isinstance(imgfile, (str, bytes)):
488-
nim = load(imgfile, mmap=NUMPY_MMAP)
487+
nim = load(imgfile)
489488
elif isinstance(imgfile, list):
490489
if len(imgfile) == 1:
491-
nim = load(imgfile[0], mmap=NUMPY_MMAP)
490+
nim = load(imgfile[0])
492491
else:
493-
images = [load(f, mmap=NUMPY_MMAP) for f in imgfile]
492+
images = [load(f) for f in imgfile]
494493
nim = funcs.concat_images(images)
495494

496495
# compute global intensity signal

0 commit comments

Comments
 (0)