Skip to content
Open
Changes from all commits
Commits
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
37 changes: 37 additions & 0 deletions pypreprocess/nipype_preproc_spm_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@
import inspect
import numpy as np
import nibabel
import nipype
from distutils.version import LooseVersion
from .slice_timing import get_slice_indices
from .conf_parser import _generate_preproc_pipeline
import matplotlib
matplotlib.use('Agg')
from sklearn.externals.joblib import Parallel, delayed, Memory as JoblibMemory
from nilearn._utils.compat import _basestring
import nipype.interfaces.spm as spm
from nipype.interfaces import base
from nipype.caching import Memory as NipypeMemory
from .configure_spm import _configure_spm, _get_version_spm
from .io_utils import (
Expand All @@ -46,6 +49,27 @@
TISSUES = None


# This patch is needed as a work around for issue as reported in
# pypreprocess #288
# Complete discussion is happened in Nipype issue tracker
# https://github.com/nipy/nipype/issues/2406

if LooseVersion(nipype.__version__) > LooseVersion("0.13.0"):
# The functionality in this patch only works for recent nipype
# versions > 0.13.0. Less than 0.13.0 will recieve an
# AttributeError: 'module' object has no attribute 'ImageFileSPM'
class PatchedRealignInputSpec(spm.Realign.input_spec):
in_files = base.InputMultiPath(
base.InputMultiPath(spm.base.ImageFileSPM(exists=True)),
field='data',
mandatory=True,
copyfile=True,
desc='list of filenames to realign')

class PatchedRealign(spm.Realign):
input_spec = PatchedRealignInputSpec


def _configure_backends(spm_dir=None, matlab_exec=None, spm_mcr=None,
critical=True):
""" Configure SPM backend.
Expand Down Expand Up @@ -303,6 +327,19 @@ def _do_subject_realign(subject_data, reslice=False, register_to_mean=False,
if not hasattr(subject_data, 'nipype_results'):
subject_data.nipype_results = {}

# This work around is needed for issue as reported in
# pypreprocess #288
# Complete discussion is happened in Nipype issue tracker
# https://github.com/nipy/nipype/issues/2406
if LooseVersion(nipype.__version__) > LooseVersion("0.13.0"):
# We check for more recent versions of nipype and fall back to
# input specifications to older versions. For newer versions,
# input specifications are changed.
# XXX: This needs to be checked and removed after a nipype
# release 1.0.1
patched = PatchedRealign()
spm.Realign.input_spec = patched.input_spec

# create node
if caching:
cache_dir = os.path.join(subject_data.scratch, 'cache_dir')
Expand Down