|
13 | 13 | import inspect
|
14 | 14 | import numpy as np
|
15 | 15 | import nibabel
|
| 16 | +import nipype |
| 17 | +from distutils.version import LooseVersion |
16 | 18 | from .slice_timing import get_slice_indices
|
17 | 19 | from .conf_parser import _generate_preproc_pipeline
|
18 | 20 | import matplotlib
|
19 | 21 | matplotlib.use('Agg')
|
20 | 22 | from sklearn.externals.joblib import Parallel, delayed, Memory as JoblibMemory
|
21 | 23 | from nilearn._utils.compat import _basestring
|
22 | 24 | import nipype.interfaces.spm as spm
|
| 25 | +from nipype.interfaces import base |
23 | 26 | from nipype.caching import Memory as NipypeMemory
|
24 | 27 | from .configure_spm import _configure_spm, _get_version_spm
|
25 | 28 | from .io_utils import (
|
|
46 | 49 | TISSUES = None
|
47 | 50 |
|
48 | 51 |
|
| 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 | + |
49 | 73 | def _configure_backends(spm_dir=None, matlab_exec=None, spm_mcr=None,
|
50 | 74 | critical=True):
|
51 | 75 | """ Configure SPM backend.
|
@@ -303,6 +327,19 @@ def _do_subject_realign(subject_data, reslice=False, register_to_mean=False,
|
303 | 327 | if not hasattr(subject_data, 'nipype_results'):
|
304 | 328 | subject_data.nipype_results = {}
|
305 | 329 |
|
| 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 | + |
306 | 343 | # create node
|
307 | 344 | if caching:
|
308 | 345 | cache_dir = os.path.join(subject_data.scratch, 'cache_dir')
|
|
0 commit comments