Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
34dd5ea
enh: appropriate xor for threshold and white matter parameters
satra Aug 12, 2013
d3616d2
enh: adding initial version of resting workflow
satra Aug 12, 2013
27eea36
enh: completed upto compcorr correction
satra Aug 12, 2013
41f48e4
updated changes
Aug 13, 2013
b7633e0
Merge pull request #23 from cdla/enh/restingwf
satra Aug 13, 2013
731308b
fix: parameters, node types
satra Aug 13, 2013
39793ef
changes filter1 form fsl.FilterRegressor to fsl.GLM
Aug 14, 2013
ccd1d48
enh: use voxel dimension were erosion and smoothing, pep8 cleanup
satra Aug 14, 2013
8393f3b
changes filter1 form fsl.FilterRegressor to fsl.GLM
Aug 14, 2013
dca8707
added dewarp and datasink format
Aug 14, 2013
682fdca
Merge branch 'enh/restingwf' of https://github.com/cdla/nipype into e…
Aug 14, 2013
3720a93
Merge pull request #24 from cdla/enh/restingwf
satra Aug 15, 2013
687b962
fix: glm fixes and pep8 cleanup
satra Aug 15, 2013
db6f5cf
fix: force demean and ensure sigma calculation returns float
satra Aug 15, 2013
c30a4a0
fix: cleaned up datasink organization
satra Aug 15, 2013
c30e92e
enh: some parcellation time series
satra Aug 19, 2013
d4330e3
Merge branch 'fix/mapnode' into enh/restingwf
satra Aug 20, 2013
7caa670
fix: cleaned prov encoding to store dictionaries and lists as prov json
satra Aug 21, 2013
aa31885
enh: added new options to apply volume transform
satra Aug 21, 2013
dbfbb3c
fix: changed warning to logging
satra Aug 21, 2013
8a4a800
api: changed smoothing sigmas to accept float in antsRegistration
satra Aug 21, 2013
5e35791
enh: updated antsApplyTransforms to accept input image type
satra Aug 21, 2013
9e043c6
enh: updated to use ants for structural registration to OASIS templat…
satra Aug 21, 2013
1c13c4f
enh: updated datasink
satra Aug 21, 2013
4730b20
enh: save mni timeseries
satra Aug 21, 2013
4e7958e
tst: fixed ants doctests to indicate smoothing sigmas
satra Aug 21, 2013
176574e
fix: some datasink changes
satra Aug 21, 2013
6fc3977
doc: improved documentation and fixed PEP8
satra Aug 21, 2013
be783ea
minor changes
Aug 21, 2013
07b5082
Merge branch 'enh/restingwf' of git://github.com/satra/nipype into en…
Aug 21, 2013
4148d4d
tst: trying to test travis error with pipeline
satra Aug 21, 2013
542af3a
enh: added registration output and reference image
satra Aug 21, 2013
d8bc0d9
Merge branch 'enh/restingwf' of git://github.com/satra/nipype into en…
Aug 22, 2013
25ab601
enh: added argument parsing
satra Aug 22, 2013
1398866
fix: remove only json hash files
satra Aug 22, 2013
fe036bd
enh: writing out a single combined timeseries file
satra Aug 23, 2013
ee3aa67
fix: cleaned up substitutions and added multiple fsaverage targets
satra Aug 26, 2013
cd78002
Merge branch 'enh/restingwf' of git://github.com/satra/nipype into en…
Aug 26, 2013
15c7f64
Merge branch 'enh/restingwf' of git://github.com/satra/nipype into en…
Aug 26, 2013
19f8088
added field map parse args to satra's most recent version
Aug 27, 2013
cc0d20a
minor changes
Aug 27, 2013
5f76bed
readded engine.py ... my bad
Aug 27, 2013
d41d48e
minor changes
Aug 27, 2013
3d530de
fixed tab spacing issue
Aug 28, 2013
57a421b
fixed more tabbing issues
Aug 28, 2013
76c7dd9
tabbing issues
Aug 28, 2013
d9b4b16
revenge of the tab issues
Aug 28, 2013
6b03107
tab issues
Aug 28, 2013
c16ad6c
tab issues
Aug 28, 2013
8fc6abe
tab...
Aug 28, 2013
68a433f
tab
Aug 28, 2013
f11e0c6
tab
Aug 28, 2013
3a50048
tab
Aug 28, 2013
25754ac
tab issue
Aug 28, 2013
839f879
repositioned int() and float() functions
Aug 29, 2013
9598fa2
Merge pull request #25 from cdla/enh/restingwf
satra Sep 2, 2013
ad53ba9
fix: write timeseries appropriately
satra Sep 2, 2013
fa1a1f8
sty: pep8 fixes
satra Sep 2, 2013
90a55ac
Merge branch 'master' into enh/restingwf
satra Sep 7, 2013
24c204d
Merge branch 'master' into enh/restingwf
satra Sep 8, 2013
21ec38b
fix: updated ants example to use new parameters from ants
satra Sep 8, 2013
e3f0470
fix: resolved conlfict
satra Sep 8, 2013
7b501ed
enh: replaced erosion with slicethickness and added epimask support f…
satra Sep 8, 2013
3d21ad1
enh: compressing more into functions
satra Sep 9, 2013
cc2dd07
fix: add imports to the functions
satra Sep 9, 2013
0801376
fix: use ceiling of slice thickness for erosion purposes
satra Sep 9, 2013
f4c5282
fix: moved imports for dicominfo outside of the function
satra Sep 9, 2013
c2031ca
api: always run datasink and let copyfiles decide if things need to b…
satra Sep 9, 2013
90608b0
enh: added SpaceTimeRealign from nipy 0.4.dev
satra Sep 9, 2013
f51b951
enh: replace realignment routine with newer Nipype interface for Nipy…
satra Sep 9, 2013
951de05
Merge branch 'master' into enh/restingwf
satra Sep 9, 2013
7b18731
fix: replaced plugin_args with proper arguments
satra Sep 10, 2013
489f656
fix: set slice_times as seconds outside workflow generating function
satra Sep 10, 2013
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
760 changes: 760 additions & 0 deletions examples/rsfmri_preprocessing.py

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions nipype/interfaces/freesurfer/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,9 @@ def __init__(self, **kwargs):
class BinarizeInputSpec(FSTraitedSpec):
in_file = File(exists=True, argstr='--i %s', mandatory=True,
copyfile=False, desc='input volume')
min = traits.Float(argstr='--min %f',
min = traits.Float(argstr='--min %f', xor=['wm_ven_csf'],
desc='min thresh')
max = traits.Float(argstr='--max %f',
max = traits.Float(argstr='--max %f', xor=['wm_ven_csf'],
desc='max thresh')
rmin = traits.Float(argstr='--rmin %f',
desc='compute min based on rmin*globalmean')
Expand All @@ -356,7 +356,7 @@ class BinarizeInputSpec(FSTraitedSpec):
desc='set match vals to 2 and 41 (aseg for cerebral WM)')
ventricles = traits.Bool(argstr='--ventricles',
desc='set match vals those for aseg ventricles+choroid (not 4th)')
wm_ven_csf = traits.Bool(argstr='--wm+vcsf',
wm_ven_csf = traits.Bool(argstr='--wm+vcsf', xor=['min', 'max'],
desc='WM and ventricular CSF, including choroid (not 4th)')
binary_file = File(argstr='--o %s', genfile=True,
desc='binary output volume')
Expand Down Expand Up @@ -430,7 +430,7 @@ def _list_outputs(self):
outfile = fname_presuffix(self.inputs.in_file,
newpath=os.getcwd(),
suffix='_thresh')
outputs['binary_file'] = outfile
outputs['binary_file'] = os.path.abspath(outfile)
value = self.inputs.count_file
if isdefined(value):
if isinstance(value, bool):
Expand Down
5 changes: 2 additions & 3 deletions nipype/interfaces/fsl/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1804,7 +1804,6 @@ def _list_outputs(self):
return outputs

def _gen_filename(self, name):
if name in ('out_file'):
return fname_presuffix(self.inputs.in_file,
suffix='_glm.txt', use_ext=False)
if name in ['out_file']:
return self._gen_fname(self.inputs.in_file, suffix='_glm')
return None
4 changes: 3 additions & 1 deletion nipype/interfaces/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class DataSink(IOBase):
input_spec = DataSinkInputSpec
output_spec = DataSinkOutputSpec

def __init__(self, infields=None, **kwargs):
def __init__(self, infields=None, force_run=True, **kwargs):
"""
Parameters
----------
Expand All @@ -232,6 +232,8 @@ def __init__(self, infields=None, **kwargs):
self.inputs._outputs[key] = Undefined
undefined_traits[key] = Undefined
self.inputs.trait_set(trait_change_notify=False, **undefined_traits)
if force_run:
self._always_run = True

def _get_dst(self, src):
## If path is directory with trailing os.path.sep,
Expand Down
2 changes: 1 addition & 1 deletion nipype/interfaces/nipy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .model import FitGLM, EstimateContrast
from .preprocess import ComputeMask, FmriRealign4d
from .preprocess import ComputeMask, FmriRealign4d, SpaceTimeRealigner
from .utils import Similarity
130 changes: 129 additions & 1 deletion nipype/interfaces/nipy/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
from nipy.labs.mask import compute_mask
from nipy.algorithms.registration import FmriRealign4d as FR4d
from nipy import save_image, load_image
from nipy.algorithms.registration import SpaceTimeRealign
from nipy.algorithms.registration.groupwise_registration import SpaceRealign

from ..base import (TraitedSpec, BaseInterface, traits,
BaseInterfaceInputSpec, isdefined, File,
Expand Down Expand Up @@ -82,7 +84,7 @@ class FmriRealign4dInputSpec(BaseInterfaceInputSpec):
desc="File to realign")
tr = traits.Float(desc="TR in seconds",
mandatory=True)
slice_order = traits.List(traits.Int(), maxver=0.3,
slice_order = traits.List(traits.Int(),
desc=('0 based slice order. This would be equivalent to entering'
'np.argsort(spm_slice_order) for this field. This effects'
'interleaved acquisition. This field will be deprecated in'
Expand Down Expand Up @@ -117,6 +119,7 @@ class FmriRealign4dOutputSpec(TraitedSpec):
desc="Motion parameter files")


@np.deprecate_with_doc('Please use SpaceTimeRealign instead')
class FmriRealign4d(BaseInterface):
"""Simultaneous motion and slice timing correction algorithm

Expand Down Expand Up @@ -196,6 +199,131 @@ def _list_outputs(self):
return outputs


class SpaceTimeRealignerInputSpec(BaseInterfaceInputSpec):

in_file = InputMultiPath(exists=True,
mandatory=True,
desc="File to realign")
tr = traits.Float(desc="TR in seconds", requires=['slice_times'])
slice_times = traits.Either(traits.List(traits.Float()),
traits.Enum('asc_alt_2', 'asc_alt_2_1',
'asc_alt_half', 'asc_alt_siemens',
'ascending', 'desc_alt_2',
'desc_alt_half', 'descending'),
desc=('Actual slice acquisition times.'))
slice_info = traits.Either(traits.Int,
traits.List(min_len=2, max_len=2),
desc=('Single integer or length 2 sequence '
'If int, the axis in `images` that is the '
'slice axis. In a 4D image, this will '
'often be axis = 2. If a 2 sequence, then'
' elements are ``(slice_axis, '
'slice_direction)``, where ``slice_axis`` '
'is the slice axis in the image as above, '
'and ``slice_direction`` is 1 if the '
'slices were acquired slice 0 first, slice'
' -1 last, or -1 if acquired slice -1 '
'first, slice 0 last. If `slice_info` is '
'an int, assume '
'``slice_direction`` == 1.'),
requires=['slice_times'],
)


class SpaceTimeRealignerOutputSpec(TraitedSpec):
out_file = OutputMultiPath(File(exists=True),
desc="Realigned files")
par_file = OutputMultiPath(File(exists=True),
desc=("Motion parameter files. Angles are not "
"euler angles"))


class SpaceTimeRealigner(BaseInterface):
"""Simultaneous motion and slice timing correction algorithm

If slice_times is not specified, this algorithm performs spatial motion
correction

This interface wraps nipy's SpaceTimeRealign algorithm [1]_ or simply the
SpatialRealign algorithm when timing info is not provided.

Examples
--------
>>> from nipype.interfaces.nipy import SpaceTimeRealigner
>>> #Run spatial realignment only
>>> realigner = SpaceTimeRealigner()
>>> realigner.inputs.in_file = ['functional.nii']
>>> res = realigner.run() # doctest: +SKIP

>>> realigner = SpaceTimeRealigner()
>>> realigner.inputs.in_file = ['functional.nii']
>>> realigner.inputs.tr = 2
>>> realigner.inputs.slice_times = range(0, 3, 67)
>>> realigner.inputs.slice_info = 2
>>> res = realigner.run() # doctest: +SKIP


References
----------
.. [1] Roche A. A four-dimensional registration algorithm with \
application to joint correction of motion and slice timing \
in fMRI. IEEE Trans Med Imaging. 2011 Aug;30(8):1546-54. DOI_.

.. _DOI: http://dx.doi.org/10.1109/TMI.2011.2131152

"""

input_spec = SpaceTimeRealignerInputSpec
output_spec = SpaceTimeRealignerOutputSpec
keywords = ['slice timing', 'motion correction']

def _run_interface(self, runtime):

all_ims = [load_image(fname) for fname in self.inputs.in_file]

if not isdefined(self.inputs.slice_times):
R = SpaceRealign(all_ims)
else:
R = SpaceTimeRealign(all_ims,
tr=self.inputs.tr,
slice_times=self.inputs.slice_times,
slice_info=self.inputs.slice_info,
)

R.estimate(refscan=None)

corr_run = R.resample()
self._out_file_path = []
self._par_file_path = []

for j, corr in enumerate(corr_run):
self._out_file_path.append(os.path.abspath('corr_%s.nii.gz' %
(split_filename(self.inputs.in_file[j])[1])))
save_image(corr, self._out_file_path[j])

self._par_file_path.append(os.path.abspath('%s.par' %
(os.path.split(self.inputs.in_file[j])[1])))
mfile = open(self._par_file_path[j], 'w')
motion = R._transforms[j]
# nipy does not encode euler angles. return in original form of
# translation followed by rotation vector see:
# http://en.wikipedia.org/wiki/Rodrigues'_rotation_formula
for i, mo in enumerate(motion):
params = ['%.10f' % item for item in np.hstack((mo.translation,
mo.rotation))]
string = ' '.join(params) + '\n'
mfile.write(string)
mfile.close()

return runtime

def _list_outputs(self):
outputs = self._outputs().get()
outputs['out_file'] = self._out_file_path
outputs['par_file'] = self._par_file_path
return outputs


class TrimInputSpec(BaseInterfaceInputSpec):
in_file = File(
exists=True, mandatory=True,
Expand Down
1 change: 1 addition & 0 deletions nipype/pipeline/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -1211,6 +1211,7 @@ def hash_exists(self, updatehash=False):
outdir = self.output_dir()
hashfiles = glob(os.path.join(outdir, '_0x*.json'))
if len(hashfiles) > 1:
logger.info(hashfiles)
logger.info('Removing multiple hashfiles and forcing node to rerun')
for hashfile in hashfiles:
os.unlink(hashfile)
Expand Down
8 changes: 7 additions & 1 deletion nipype/pipeline/plugins/multiproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,14 @@ def _get_result(self, taskid):

def _submit_job(self, node, updatehash=False):
self._taskid += 1
try:
if node.inputs.terminal_output == 'stream':
node.inputs.terminal_output = 'file'
except:
pass
self._taskresult[self._taskid] = self.pool.apply_async(run_node,
(node, updatehash,))
(node,
updatehash,))
return self._taskid

def _report_crash(self, node, result=None):
Expand Down