Skip to content

Commit 24352d7

Browse files
committed
FIX: spm.Realign compatible with recent versions of nipype
1 parent 3d5bd7c commit 24352d7

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

pypreprocess/nipype_preproc_spm_utils.py

+37
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,16 @@
1313
import inspect
1414
import numpy as np
1515
import nibabel
16+
import nipype
17+
from distutils.version import LooseVersion
1618
from .slice_timing import get_slice_indices
1719
from .conf_parser import _generate_preproc_pipeline
1820
import matplotlib
1921
matplotlib.use('Agg')
2022
from sklearn.externals.joblib import Parallel, delayed, Memory as JoblibMemory
2123
from nilearn._utils.compat import _basestring
2224
import nipype.interfaces.spm as spm
25+
from nipype.interfaces import base
2326
from nipype.caching import Memory as NipypeMemory
2427
from .configure_spm import _configure_spm, _get_version_spm
2528
from .io_utils import (
@@ -46,6 +49,27 @@
4649
TISSUES = None
4750

4851

52+
# This patch is needed as a work around for issue as reported in
53+
# pypreprocess #288
54+
# Complete discussion is happened in Nipype issue tracker
55+
# https://github.com/nipy/nipype/issues/2406
56+
57+
if LooseVersion(nipype.__version__) > LooseVersion("0.13.0"):
58+
# The functionality in this patch only works for recent nipype
59+
# versions > 0.13.0. Less than 0.13.0 will recieve an
60+
# AttributeError: 'module' object has no attribute 'ImageFileSPM'
61+
class PatchedRealignInputSpec(spm.Realign.input_spec):
62+
in_files = base.InputMultiPath(
63+
base.InputMultiPath(spm.base.ImageFileSPM(exists=True)),
64+
field='data',
65+
mandatory=True,
66+
copyfile=True,
67+
desc='list of filenames to realign')
68+
69+
class PatchedRealign(spm.Realign):
70+
input_spec = PatchedRealignInputSpec
71+
72+
4973
def _configure_backends(spm_dir=None, matlab_exec=None, spm_mcr=None,
5074
critical=True):
5175
""" Configure SPM backend.
@@ -303,6 +327,19 @@ def _do_subject_realign(subject_data, reslice=False, register_to_mean=False,
303327
if not hasattr(subject_data, 'nipype_results'):
304328
subject_data.nipype_results = {}
305329

330+
# This work around is needed for issue as reported in
331+
# pypreprocess #288
332+
# Complete discussion is happened in Nipype issue tracker
333+
# https://github.com/nipy/nipype/issues/2406
334+
if LooseVersion(nipype.__version__) > LooseVersion("0.13.0"):
335+
# We check for more recent versions of nipype and fall back to
336+
# input specifications to older versions. For newer versions,
337+
# input specifications are changed.
338+
# XXX: This needs to be checked and removed after a nipype
339+
# release 1.0.1
340+
patched = PatchedRealign()
341+
spm.Realign.input_spec = patched.input_spec
342+
306343
# create node
307344
if caching:
308345
cache_dir = os.path.join(subject_data.scratch, 'cache_dir')

0 commit comments

Comments
 (0)