Skip to content

Commit 88b08c0

Browse files
committed
Merge remote-tracking branch 'origin/pr/903'
Conflicts: CHANGES
2 parents 89e55ac + 541b6aa commit 88b08c0

File tree

15 files changed

+1956
-50
lines changed

15 files changed

+1956
-50
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Next Release
2020
are found in nipype.algorithms.metrics instead of misc
2121
* ENH: New interface in algorithms.metrics: ErrorMap (a voxel-wise diff map).
2222
* ENH: New FreeSurfer workflow: create_skullstripped_recon_flow()
23+
* ENH: Deep revision of workflows for correction of dMRI artifacts. New dmri_preprocessing
24+
example.
2325
* ENH: New data grabbing interface that works over SSH connections, SSHDataGrabber
2426
* ENH: New color mode for write_graph
2527
* ENH: You can now force MapNodes to be run serially

examples/dmri_preprocessing.py

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
# coding: utf-8
2+
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
3+
# vi: set ft=python sts=4 ts=4 sw=4 et:
4+
5+
"""
6+
===================
7+
dMRI: Preprocessing
8+
===================
9+
10+
Introduction
11+
============
12+
13+
This script, dmri_preprocessing.py, demonstrates how to prepare dMRI data
14+
for tractography and connectivity analysis with nipype.
15+
16+
We perform this analysis using the FSL course data, which can be acquired from
17+
here: http://www.fmrib.ox.ac.uk/fslcourse/fsl_course_data2.tar.gz
18+
19+
Can be executed in command line using ``python dmri_preprocessing.py``
20+
21+
22+
Import necessary modules from nipype.
23+
"""
24+
25+
import os # system functions
26+
import nipype.interfaces.io as nio # Data i/o
27+
import nipype.interfaces.utility as niu # utility
28+
import nipype.algorithms.misc as misc
29+
30+
import nipype.pipeline.engine as pe # pypeline engine
31+
32+
from nipype.interfaces import fsl
33+
from nipype.interfaces import ants
34+
35+
36+
"""
37+
Load specific nipype's workflows for preprocessing of dMRI data:
38+
:class:`nipype.workflows.dmri.preprocess.epi.all_peb_pipeline`,
39+
as data include a *b0* volume with reverse encoding direction
40+
(*P>>>A*, or *y*), in contrast with the general acquisition encoding
41+
that is *A>>>P* or *-y* (in RAS systems).
42+
"""
43+
44+
from nipype.workflows.dmri.fsl.artifacts import all_fsl_pipeline, remove_bias
45+
46+
"""
47+
Map field names into individual subject runs
48+
"""
49+
50+
info = dict(dwi=[['subject_id', 'dwidata']],
51+
bvecs=[['subject_id', 'bvecs']],
52+
bvals=[['subject_id', 'bvals']],
53+
dwi_rev=[['subject_id', 'nodif_PA']])
54+
55+
infosource = pe.Node(interface=niu.IdentityInterface(fields=['subject_id']),
56+
name="infosource")
57+
58+
# Set the subject 1 identifier in subject_list,
59+
# we choose the preproc dataset as it contains uncorrected files.
60+
subject_list = ['subj1_preproc']
61+
62+
63+
"""Here we set up iteration over all the subjects. The following line
64+
is a particular example of the flexibility of the system. The
65+
``datasource`` attribute ``iterables`` tells the pipeline engine that
66+
it should repeat the analysis on each of the items in the
67+
``subject_list``. In the current example, the entire first level
68+
preprocessing and estimation will be repeated for each subject
69+
contained in subject_list.
70+
"""
71+
72+
infosource.iterables = ('subject_id', subject_list)
73+
74+
75+
"""
76+
Now we create a :class:`nipype.interfaces.io.DataGrabber` object and
77+
fill in the information from above about the layout of our data. The
78+
:class:`~nipype.pipeline.engine.Node` module wraps the interface object
79+
and provides additional housekeeping and pipeline specific
80+
functionality.
81+
"""
82+
83+
datasource = pe.Node(nio.DataGrabber(infields=['subject_id'],
84+
outfields=info.keys()), name='datasource')
85+
86+
datasource.inputs.template = "%s/%s"
87+
88+
# This needs to point to the fdt folder you can find after extracting
89+
# http://www.fmrib.ox.ac.uk/fslcourse/fsl_course_data2.tar.gz
90+
datasource.inputs.base_directory = os.path.abspath('fdt1')
91+
datasource.inputs.field_template = dict(dwi='%s/%s.nii.gz',
92+
dwi_rev='%s/%s.nii.gz')
93+
datasource.inputs.template_args = info
94+
datasource.inputs.sort_filelist = True
95+
96+
97+
"""
98+
An inputnode is used to pass the data obtained by the data grabber to the
99+
actual processing functions
100+
"""
101+
102+
inputnode = pe.Node(niu.IdentityInterface(fields=["dwi", "bvecs", "bvals",
103+
"dwi_rev"]), name="inputnode")
104+
105+
106+
"""
107+
108+
Setup for dMRI preprocessing
109+
============================
110+
111+
In this section we initialize the appropriate workflow for preprocessing of
112+
diffusion images.
113+
114+
Artifacts correction
115+
--------------------
116+
117+
We will use the combination of ``topup`` and ``eddy`` as suggested by FSL.
118+
119+
In order to configure the susceptibility distortion correction (SDC), we first
120+
write the specific parameters of our echo-planar imaging (EPI) images.
121+
122+
Particularly, we look into the ``acqparams.txt`` file of the selected subject
123+
to gather the encoding direction, acceleration factor (in parallel sequences
124+
it is > 1), and readout time or echospacing.
125+
126+
"""
127+
128+
epi_AP = {'echospacing': 66.5e-3, 'enc_dir': 'y-'}
129+
epi_PA = {'echospacing': 66.5e-3, 'enc_dir': 'y'}
130+
prep = all_fsl_pipeline(epi_params=epi_AP, altepi_params=epi_PA)
131+
132+
133+
"""
134+
135+
Bias field correction
136+
---------------------
137+
138+
Finally, we set up a node to correct for a single multiplicative bias field
139+
from computed on the *b0* image, as suggested in [Jeurissen2014]_.
140+
141+
"""
142+
143+
bias = remove_bias()
144+
145+
146+
"""
147+
Connect nodes in workflow
148+
=========================
149+
150+
We create a higher level workflow to connect the nodes. Please excuse the
151+
author for writing the arguments of the ``connect`` function in a not-standard
152+
style with readability aims.
153+
"""
154+
155+
wf = pe.Workflow(name="dMRI_Preprocessing")
156+
wf.base_dir = os.path.abspath('preprocessing_dmri_tutorial')
157+
wf.connect([
158+
(infosource, datasource, [('subject_id', 'subject_id')])
159+
,(datasource, prep, [('dwi', 'inputnode.in_file'),
160+
('dwi_rev', 'inputnode.alt_file'),
161+
('bvals', 'inputnode.in_bval'),
162+
('bvecs', 'inputnode.in_bvec')])
163+
,(prep, bias, [('outputnode.out_file', 'inputnode.in_file'),
164+
('outputnode.out_mask', 'inputnode.in_mask')])
165+
,(datasource, bias, [('bvals', 'inputnode.in_bval')])
166+
])
167+
168+
169+
"""
170+
Run the workflow as command line executable
171+
"""
172+
173+
if __name__ == '__main__':
174+
wf.run()
175+
wf.write_graph()

nipype/algorithms/tests/test_normalize_tpms.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*-
1+
# coding: utf-8
32
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
43
# vi: set ft=python sts=4 ts=4 sw=4 et:
5-
#
6-
# @Author: oesteban - [email protected]
7-
# @Date: 2014-05-28 17:57:20
8-
# @Last Modified by: oesteban
9-
# @Last Modified time: 2014-05-29 13:43:09
104

115
import os
126
from shutil import rmtree

nipype/interfaces/elastix/__init__.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*-
1+
# coding: utf-8
32
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
43
# vi: set ft=python sts=4 ts=4 sw=4 et:
5-
#
6-
# @Author: oesteban - [email protected]
7-
# @Date: 2014-06-02 12:06:07
8-
# @Last Modified by: oesteban
9-
# @Last Modified time: 2014-06-17 10:59:20
4+
105
"""Top-level namespace for elastix."""
116

127
from registration import Registration, ApplyWarp, AnalyzeWarp, PointsWarp

nipype/interfaces/elastix/base.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*-
1+
# coding: utf-8
32
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
43
# vi: set ft=python sts=4 ts=4 sw=4 et:
5-
#
6-
# @Author: oesteban - [email protected]
7-
# @Date: 2014-06-03 13:42:46
8-
# @Last Modified by: oesteban
9-
# @Last Modified time: 2014-06-17 10:17:43
4+
105
"""The :py:mod:`nipype.interfaces.elastix` provides the interface to
116
the elastix registration software.
127

nipype/interfaces/elastix/registration.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*-
1+
# coding: utf-8
32
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
43
# vi: set ft=python sts=4 ts=4 sw=4 et:
5-
#
6-
# @Author: oesteban - [email protected]
7-
# @Date: 2014-06-02 12:06:50
8-
# @Last Modified by: oesteban
9-
# @Last Modified time: 2014-09-01 21:03:57
4+
105
"""
116
Interfaces to perform image registrations and to apply the resulting
127
displacement maps to images and points.

nipype/interfaces/elastix/utils.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*-
1+
# coding: utf-8
32
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
43
# vi: set ft=python sts=4 ts=4 sw=4 et:
5-
#
6-
# @Author: oesteban - [email protected]
7-
# @Date: 2014-06-17 10:17:07
8-
# @Last Modified by: oesteban
9-
# @Last Modified time: 2014-09-01 21:05:33
4+
105
"""
116
Generic interfaces to manipulate registration parameters files, including
127
transform files (to configure warpings)

nipype/workflows/data/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# coding: utf-8
2+
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
3+
# vi: set ft=python sts=4 ts=4 sw=4 et:
4+
import os.path as op
5+
6+
7+
def get_flirt_schedule(name):
8+
if name == 'ecc':
9+
return op.abspath(op.join(op.dirname(__file__),
10+
'ecc.sch'))
11+
elif name == 'hmc':
12+
return op.abspath(op.join(op.dirname(__file__),
13+
'hmc.sch'))
14+
else:
15+
raise RuntimeError('Requested file does not exist.')

nipype/workflows/data/ecc.sch

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# 4mm scale
2+
setscale 4
3+
setoption smoothing 6
4+
setoption paramsubset 1 0 0 0 0 0 0 1 1 1 1 1 1
5+
clear U
6+
clear UA
7+
clear UB
8+
clear US
9+
clear UP
10+
# try the identity transform as a starting point at this resolution
11+
clear UQ
12+
setrow UQ 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1
13+
optimise 7 UQ 0.0 0.0 0.0 0.0 0.0 0.0 0.0 rel 4
14+
sort U
15+
copy U UA
16+
# select best 4 optimised solutions and try perturbations of these
17+
clear U
18+
copy UA:1-4 U
19+
optimise 7 UA:1-4 1.0 0.0 0.0 0.0 0.0 0.0 0.0 rel 4
20+
optimise 7 UA:1-4 -1.0 0.0 0.0 0.0 0.0 0.0 0.0 abs 4
21+
optimise 7 UA:1-4 0.0 1.0 0.0 0.0 0.0 0.0 0.0 abs 4
22+
optimise 7 UA:1-4 0.0 -1.0 0.0 0.0 0.0 0.0 0.0 abs 4
23+
optimise 7 UA:1-4 0.0 0.0 1.0 0.0 0.0 0.0 0.0 abs 4
24+
optimise 7 UA:1-4 0.0 0.0 -1.0 0.0 0.0 0.0 0.0 abs 4
25+
optimise 7 UA:1-4 0.0 0.0 0.0 0.0 0.0 0.0 0.1 abs 4
26+
optimise 7 UA:1-4 0.0 0.0 0.0 0.0 0.0 0.0 -0.1 abs 4
27+
optimise 7 UA:1-4 0.0 0.0 0.0 0.0 0.0 0.0 0.2 abs 4
28+
optimise 7 UA:1-4 0.0 0.0 0.0 0.0 0.0 0.0 -0.2 abs 4
29+
sort U
30+
copy U UB
31+
# 2mm scale
32+
setscale 2
33+
setoption smoothing 4
34+
setoption paramsubset 1 0 0 0 0 0 0 1 1 1 1 1 1
35+
clear U
36+
clear UC
37+
clear UD
38+
clear UE
39+
clear UF
40+
# remeasure costs at this scale
41+
measurecost 7 UB 0 0 0 0 0 0 rel
42+
sort U
43+
copy U UC
44+
clear U
45+
optimise 7 UC:1-3 0.0 0.0 0.0 0.0 0.0 0.0 0.0 abs 2
46+
copy U UD
47+
sort U
48+
copy U UF
49+
# also try the identity transform as a starting point at this resolution
50+
sort U
51+
clear U UG
52+
clear U
53+
setrow UG 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1
54+
optimise 7 UG 0.0 0.0 0.0 0.0 0.0 0.0 0.0 abs 2
55+
sort U
56+
copy U UG
57+
# 1mm scale
58+
setscale 1
59+
setoption smoothing 2
60+
setoption boundguess 1
61+
setoption paramsubset 1 0 0 0 0 0 0 1 1 1 1 1 1
62+
clear U
63+
#also try the identity transform as a starting point at this resolution
64+
setrow UK 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1
65+
optimise 12 UK:1-2 0.0 0.0 0.0 0.0 0.0 0.0 0.0 abs 1
66+
sort U
67+

0 commit comments

Comments
 (0)