Skip to content

Do not open nifti files with mmap if numpy < 1.12.0 #1796

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 31 commits into from
Feb 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
7cbe9df
Do not open nifti files with mmap if numpy < 1.12.0
oesteban Feb 2, 2017
0db15b5
fix leftover typo
oesteban Feb 3, 2017
b67868f
use anaconda in travis cc #1788
oesteban Feb 3, 2017
b5899cd
simplify conda installation
oesteban Feb 3, 2017
332d46d
remove adding conda-forge channel
oesteban Feb 3, 2017
85ca6e5
readd conda update
oesteban Feb 3, 2017
c411e23
remove requirement version in nibabel
oesteban Feb 3, 2017
0d5d6dd
revise conda installation
oesteban Feb 3, 2017
70a7cb2
fix travis file
oesteban Feb 4, 2017
452a284
add icu to conda (#1798), append conda-forge instead of prepend
oesteban Feb 4, 2017
4291ffc
install boto3 in python 3
oesteban Feb 4, 2017
bdf62ab
Merge remote-tracking branch 'upstream/master' into fix/1795
oesteban Feb 10, 2017
a34c0fd
fix travis.xml
oesteban Feb 10, 2017
11fd619
fix travis (second round)
oesteban Feb 10, 2017
2ec16f8
fix conda-forge channel, split anaconda download
oesteban Feb 10, 2017
5b46772
remove breaklines
oesteban Feb 10, 2017
1308921
do not try to install conda after a travis_retry
oesteban Feb 10, 2017
2abe8f5
do not use travis python
oesteban Feb 10, 2017
25e65b9
roll back to miniconda, use some hints from https://conda.io/docs/tra…
oesteban Feb 10, 2017
5d60cef
fix error in travis.yml
oesteban Feb 10, 2017
1c956b0
remove if switch
oesteban Feb 10, 2017
13b3cc6
fix miniconda link
oesteban Feb 10, 2017
d37d440
Merge remote-tracking branch 'upstream/master' into fix/1795
oesteban Feb 11, 2017
ebaaebd
Merge branch 'fix/1795' of github.com:oesteban/nipype into fix/1795
oesteban Feb 11, 2017
3d1e644
fix command to update conda to a certain version
oesteban Feb 11, 2017
f3ebcc5
reenable version pinning for nibabel in requirements.txt
oesteban Feb 11, 2017
3820f9f
replace all nibabel imports and the nibabel.load to have the NUMPY_MMAP
oesteban Feb 15, 2017
671fc03
add NUMPY_MMAP import
oesteban Feb 15, 2017
05d74ec
more NUMPY_MMAP fixes
oesteban Feb 15, 2017
875ed0b
the last nibabel.load without NUMPY_MMAP
oesteban Feb 15, 2017
20e10f9
fix import NUMPY_MMAP location in examples
oesteban Feb 15, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
cache:
- apt
apt: true

language: python
python:
- 2.7
Expand All @@ -10,11 +11,7 @@ env:
- INSTALL_DEB_DEPENDECIES=false NIPYPE_EXTRAS="doc,tests,fmri,profiler"
- INSTALL_DEB_DEPENDECIES=true NIPYPE_EXTRAS="doc,tests,fmri,profiler,duecredit"
before_install:
- function bef_inst {
wget http://repo.continuum.io/miniconda/Miniconda${TRAVIS_PYTHON_VERSION:0:1}-latest-Linux-x86_64.sh
-O /home/travis/.cache/miniconda.sh &&
bash /home/travis/.cache/miniconda.sh -b -p /home/travis/miniconda &&
export PATH=/home/travis/miniconda/bin:$PATH &&
- function apt_inst {
if $INSTALL_DEB_DEPENDECIES; then sudo rm -rf /dev/shm; fi &&
if $INSTALL_DEB_DEPENDECIES; then sudo ln -s /run/shm /dev/shm; fi &&
bash <(wget -q -O- http://neuro.debian.net/_files/neurodebian-travis.sh) &&
Expand All @@ -26,18 +23,24 @@ before_install:
source /etc/fsl/fsl.sh;
source /etc/afni/afni.sh;
export FSLOUTPUTTYPE=NIFTI_GZ; fi }
- travis_retry bef_inst
install:
# Add install of vtk and mayavi to test mesh (disabled): conda install -y vtk mayavi &&
- function inst {
- function conda_inst {
export CONDA_HOME=$HOME/conda &&
wget https://repo.continuum.io/miniconda/Miniconda${TRAVIS_PYTHON_VERSION:0:1}-latest-Linux-x86_64.sh
-O /home/travis/.cache/conda.sh &&
bash /home/travis/.cache/conda.sh -b -p ${CONDA_HOME} &&
export PATH=${CONDA_HOME}/bin:$PATH &&
hash -r &&
conda config --set always_yes yes --set changeps1 no &&
conda update -q conda &&
conda install python=${TRAVIS_PYTHON_VERSION} &&
conda config --add channels conda-forge &&
conda update --yes conda &&
conda update --all -y python=$TRAVIS_PYTHON_VERSION &&
conda install -y nipype icu &&
rm -r /home/travis/miniconda/lib/python${TRAVIS_PYTHON_VERSION}/site-packages/nipype* &&
pip install -r requirements.txt &&
pip install -e .[$NIPYPE_EXTRAS]; }
- travis_retry inst
rm -r ${CONDA_HOME}/lib/python${TRAVIS_PYTHON_VERSION}/site-packages/nipype*; }
# Add install of vtk and mayavi to test mesh (disabled): conda install -y vtk mayavi
- travis_retry apt_inst
- travis_retry conda_inst
install:
- travis_retry pip install -e .[$NIPYPE_EXTRAS]
script:
- py.test --doctest-modules nipype
deploy:
Expand Down
11 changes: 7 additions & 4 deletions examples/dmri_camino_dti.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
Import necessary modules from nipype.
"""

import os # system functions
import nipype.interfaces.io as nio # Data i/o
import nipype.interfaces.utility as util # utility
import nipype.pipeline.engine as pe # pypeline engine
import nipype.interfaces.camino as camino
import nipype.interfaces.fsl as fsl
import nipype.interfaces.camino2trackvis as cam2trk
import nipype.algorithms.misc as misc
import os # system functions

"""
We use the following functions to scrape the voxel and data dimensions of the input images. This allows the
Expand All @@ -36,27 +36,30 @@

def get_vox_dims(volume):
import nibabel as nb
from nipype.utils import NUMPY_MMAP
if isinstance(volume, list):
volume = volume[0]
nii = nb.load(volume)
nii = nb.load(volume, mmap=NUMPY_MMAP)
hdr = nii.header
voxdims = hdr.get_zooms()
return [float(voxdims[0]), float(voxdims[1]), float(voxdims[2])]


def get_data_dims(volume):
import nibabel as nb
from nipype.utils import NUMPY_MMAP
if isinstance(volume, list):
volume = volume[0]
nii = nb.load(volume)
nii = nb.load(volume, mmap=NUMPY_MMAP)
hdr = nii.header
datadims = hdr.get_data_shape()
return [int(datadims[0]), int(datadims[1]), int(datadims[2])]


def get_affine(volume):
import nibabel as nb
nii = nb.load(volume)
from nipype.utils import NUMPY_MMAP
nii = nb.load(volume, mmap=NUMPY_MMAP)
return nii.affine

subject_list = ['subj1']
Expand Down
17 changes: 10 additions & 7 deletions examples/dmri_connectivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
First, we import the necessary modules from nipype.
"""

import inspect

import os.path as op # system functions
import cmp # connectome mapper
import nipype.interfaces.io as nio # Data i/o
import nipype.interfaces.utility as util # utility
import nipype.pipeline.engine as pe # pypeline engine
Expand All @@ -56,10 +60,6 @@
import nipype.interfaces.freesurfer as fs # freesurfer
import nipype.interfaces.cmtk as cmtk
import nipype.algorithms.misc as misc
import inspect

import os.path as op # system functions
import cmp # connectome mapper

"""
We define the following functions to scrape the voxel and data dimensions of the input images. This allows the
Expand All @@ -74,27 +74,30 @@

def get_vox_dims(volume):
import nibabel as nb
from nipype.utils import NUMPY_MMAP
if isinstance(volume, list):
volume = volume[0]
nii = nb.load(volume)
nii = nb.load(volume, mmap=NUMPY_MMAP)
hdr = nii.header
voxdims = hdr.get_zooms()
return [float(voxdims[0]), float(voxdims[1]), float(voxdims[2])]


def get_data_dims(volume):
import nibabel as nb
from nipype.utils import NUMPY_MMAP
if isinstance(volume, list):
volume = volume[0]
nii = nb.load(volume)
nii = nb.load(volume, mmap=NUMPY_MMAP)
hdr = nii.header
datadims = hdr.get_data_shape()
return [int(datadims[0]), int(datadims[1]), int(datadims[2])]


def get_affine(volume):
import nibabel as nb
nii = nb.load(volume)
from nipype.utils import NUMPY_MMAP
nii = nb.load(volume, mmap=NUMPY_MMAP)
return nii.affine


Expand Down
4 changes: 3 additions & 1 deletion examples/fmri_ants_openfmri.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
from nipype.workflows.fmri.fsl import (create_featreg_preproc,
create_modelfit_workflow,
create_fixed_effects_flow)
from nipype.utils import NUMPY_MMAP


config.enable_provenance()
version = 0
Expand Down Expand Up @@ -68,7 +70,7 @@ def median(in_files):
"""
average = None
for idx, filename in enumerate(filename_to_list(in_files)):
img = nb.load(filename)
img = nb.load(filename, mmap=NUMPY_MMAP)
data = np.median(img.get_data(), axis=3)
if average is None:
average = data
Expand Down
3 changes: 2 additions & 1 deletion examples/fmri_fsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,11 @@ def pickfirst(files):

def getmiddlevolume(func):
from nibabel import load
from nipype.utils import NUMPY_MMAP
funcfile = func
if isinstance(func, list):
funcfile = func[0]
_, _, _, timepoints = load(funcfile).shape
_, _, _, timepoints = load(funcfile, mmap=NUMPY_MMAP).shape
return int(timepoints / 2) - 1

preproc.connect(inputnode, ('func', getmiddlevolume), extract_ref, 't_min')
Expand Down
4 changes: 3 additions & 1 deletion examples/fmri_spm_auditory.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import nipype.algorithms.modelgen as model # model specification
import os # system functions


"""

Preliminaries
Expand Down Expand Up @@ -120,9 +121,10 @@

def get_vox_dims(volume):
import nibabel as nb
from nipype.utils import NUMPY_MMAP
if isinstance(volume, list):
volume = volume[0]
nii = nb.load(volume)
nii = nb.load(volume, mmap=NUMPY_MMAP)
hdr = nii.header
voxdims = hdr.get_zooms()
return [float(voxdims[0]), float(voxdims[1]), float(voxdims[2])]
Expand Down
5 changes: 3 additions & 2 deletions examples/fmri_spm_face.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
from __future__ import division
from builtins import range

import os # system functions
import nipype.interfaces.io as nio # Data i/o
import nipype.interfaces.spm as spm # spm
import nipype.interfaces.matlab as mlab # how to run matlab
import nipype.interfaces.utility as util # utility
import nipype.pipeline.engine as pe # pypeline engine
import nipype.algorithms.modelgen as model # model specification
import os # system functions

"""

Expand Down Expand Up @@ -114,9 +114,10 @@

def get_vox_dims(volume):
import nibabel as nb
from nipype.utils import NUMPY_MMAP
if isinstance(volume, list):
volume = volume[0]
nii = nb.load(volume)
nii = nb.load(volume, mmap=NUMPY_MMAP)
hdr = nii.header
voxdims = hdr.get_zooms()
return [float(voxdims[0]), float(voxdims[1]), float(voxdims[2])]
Expand Down
22 changes: 14 additions & 8 deletions examples/rsfmri_vol_surface_preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
import scipy as sp
import nibabel as nb


imports = ['import os',
'import nibabel as nb',
'import numpy as np',
Expand Down Expand Up @@ -117,9 +118,10 @@ def median(in_files):
"""
import numpy as np
import nibabel as nb
from nipype.utils import NUMPY_MMAP
average = None
for idx, filename in enumerate(filename_to_list(in_files)):
img = nb.load(filename)
img = nb.load(filename, mmap=NUMPY_MMAP)
data = np.median(img.get_data(), axis=3)
if average is None:
average = data
Expand All @@ -145,11 +147,12 @@ def bandpass_filter(files, lowpass_freq, highpass_freq, fs):
from nipype.utils.filemanip import split_filename, list_to_filename
import numpy as np
import nibabel as nb
from nipype.utils import NUMPY_MMAP
out_files = []
for filename in filename_to_list(files):
path, name, ext = split_filename(filename)
out_file = os.path.join(os.getcwd(), name + '_bp' + ext)
img = nb.load(filename)
img = nb.load(filename, mmap=NUMPY_MMAP)
timepoints = img.shape[-1]
F = np.zeros((timepoints))
lowidx = int(timepoints / 2) + 1
Expand Down Expand Up @@ -260,11 +263,12 @@ def extract_noise_components(realigned_file, mask_file, num_components=5,
from scipy.linalg.decomp_svd import svd
import numpy as np
import nibabel as nb
from nipype.utils import NUMPY_MMAP
import os
imgseries = nb.load(realigned_file)
imgseries = nb.load(realigned_file, mmap=NUMPY_MMAP)
components = None
for filename in filename_to_list(mask_file):
mask = nb.load(filename).get_data()
mask = nb.load(filename, mmap=NUMPY_MMAP).get_data()
if len(np.nonzero(mask > 0)[0]) == 0:
continue
voxel_timecourses = imgseries.get_data()[mask > 0]
Expand Down Expand Up @@ -329,10 +333,11 @@ def extract_subrois(timeseries_file, label_file, indices):
"""
from nipype.utils.filemanip import split_filename
import nibabel as nb
from nipype.utils import NUMPY_MMAP
import os
img = nb.load(timeseries_file)
img = nb.load(timeseries_file, mmap=NUMPY_MMAP)
data = img.get_data()
roiimg = nb.load(label_file)
roiimg = nb.load(label_file, mmap=NUMPY_MMAP)
rois = roiimg.get_data()
prefix = split_filename(timeseries_file)[1]
out_ts_file = os.path.join(os.getcwd(), '%s_subcortical_ts.txt' % prefix)
Expand All @@ -352,8 +357,9 @@ def combine_hemi(left, right):
"""
import os
import numpy as np
lh_data = nb.load(left).get_data()
rh_data = nb.load(right).get_data()
from nipype.utils import NUMPY_MMAP
lh_data = nb.load(left, mmap=NUMPY_MMAP).get_data()
rh_data = nb.load(right, mmap=NUMPY_MMAP).get_data()

indices = np.vstack((1000000 + np.arange(0, lh_data.shape[0])[:, None],
2000000 + np.arange(0, rh_data.shape[0])[:, None]))
Expand Down
13 changes: 7 additions & 6 deletions examples/rsfmri_vol_surface_preprocessing_nipy.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import numpy as np
import scipy as sp
import nibabel as nb
from nipype.utils import NUMPY_MMAP

imports = ['import os',
'import nibabel as nb',
Expand Down Expand Up @@ -116,7 +117,7 @@ def median(in_files):
"""
average = None
for idx, filename in enumerate(filename_to_list(in_files)):
img = nb.load(filename)
img = nb.load(filename, mmap=NUMPY_MMAP)
data = np.median(img.get_data(), axis=3)
if average is None:
average = data
Expand All @@ -143,7 +144,7 @@ def bandpass_filter(files, lowpass_freq, highpass_freq, fs):
for filename in filename_to_list(files):
path, name, ext = split_filename(filename)
out_file = os.path.join(os.getcwd(), name + '_bp' + ext)
img = nb.load(filename)
img = nb.load(filename, mmap=NUMPY_MMAP)
timepoints = img.shape[-1]
F = np.zeros((timepoints))
lowidx = int(timepoints / 2) + 1
Expand Down Expand Up @@ -268,9 +269,9 @@ def extract_subrois(timeseries_file, label_file, indices):
The first four columns are: freesurfer index, i, j, k positions in the
label file
"""
img = nb.load(timeseries_file)
img = nb.load(timeseries_file, mmap=NUMPY_MMAP)
data = img.get_data()
roiimg = nb.load(label_file)
roiimg = nb.load(label_file, mmap=NUMPY_MMAP)
rois = roiimg.get_data()
prefix = split_filename(timeseries_file)[1]
out_ts_file = os.path.join(os.getcwd(), '%s_subcortical_ts.txt' % prefix)
Expand All @@ -288,8 +289,8 @@ def extract_subrois(timeseries_file, label_file, indices):
def combine_hemi(left, right):
"""Combine left and right hemisphere time series into a single text file
"""
lh_data = nb.load(left).get_data()
rh_data = nb.load(right).get_data()
lh_data = nb.load(left, mmap=NUMPY_MMAP).get_data()
rh_data = nb.load(right, mmap=NUMPY_MMAP).get_data()

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