Skip to content

Commit 2fa95f0

Browse files
committed
added schedules for FLIRT
1 parent b76c0e5 commit 2fa95f0

File tree

5 files changed

+207
-38
lines changed

5 files changed

+207
-38
lines changed

nipype/workflows/data/__init__.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
# @Author: oesteban
4+
# @Date: 2014-09-05 11:23:48
5+
# @Last Modified by: oesteban
6+
# @Last Modified time: 2014-09-05 11:33:27
7+
import os.path as op
8+
9+
10+
def get_flirt_schedule(name):
11+
if name == 'ecc':
12+
return op.abspath(op.join(op.dirname(__file__),
13+
'ecc.sch'))
14+
elif name == 'hmc':
15+
return op.abspath(op.join(op.dirname(__file__),
16+
'hmc.sch'))
17+
else:
18+
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+

nipype/workflows/data/hmc.sch

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

nipype/workflows/dmri/preprocess/epi.py

Lines changed: 47 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -19,38 +19,41 @@ def all_fmb_pipeline(name='hmc_sdc_ecc',
1919
acc_factor=3,
2020
enc_dir='y-')):
2121
"""
22-
Builds a pipeline including three artifact corrections: head-motion correction (HMC),
23-
susceptibility-derived distortion correction (SDC), and Eddy currents-derived distortion
24-
correction (ECC).
22+
Builds a pipeline including three artifact corrections: head-motion
23+
correction (HMC), susceptibility-derived distortion correction (SDC),
24+
and Eddy currents-derived distortion correction (ECC).
2525
2626
The displacement fields from each kind of distortions are combined. Thus,
2727
only one interpolation occurs between input data and result.
2828
29-
.. warning:: this workflow rotates the gradients table (*b*-vectors) [Leemans09]_.
29+
.. warning:: this workflow rotates the gradients table (*b*-vectors)
30+
[Leemans09]_.
3031
3132
3233
"""
33-
inputnode = pe.Node(niu.IdentityInterface(fields=['in_file', 'in_bvec', 'in_bval',
34-
'bmap_pha', 'bmap_mag']), name='inputnode')
35-
36-
outputnode = pe.Node(niu.IdentityInterface(fields=['out_file', 'out_mask', 'out_bvec']),
37-
name='outputnode')
38-
34+
inputnode = pe.Node(niu.IdentityInterface(fields=['in_file', 'in_bvec',
35+
'in_bval', 'bmap_pha', 'bmap_mag']), name='inputnode')
3936

37+
outputnode = pe.Node(niu.IdentityInterface(fields=['out_file', 'out_mask',
38+
'out_bvec']), name='outputnode')
4039
avg_b0_0 = pe.Node(niu.Function(input_names=['in_dwi', 'in_bval'],
41-
output_names=['out_file'], function=b0_average), name='b0_avg_pre')
40+
output_names=['out_file'], function=b0_average),
41+
name='b0_avg_pre')
4242
avg_b0_1 = pe.Node(niu.Function(input_names=['in_dwi', 'in_bval'],
43-
output_names=['out_file'], function=b0_average), name='b0_avg_post')
44-
bet_dwi0 = pe.Node(fsl.BET(frac=0.3, mask=True, robust=True), name='bet_dwi_pre')
45-
bet_dwi1 = pe.Node(fsl.BET(frac=0.3, mask=True, robust=True), name='bet_dwi_post')
43+
output_names=['out_file'], function=b0_average),
44+
name='b0_avg_post')
45+
bet_dwi0 = pe.Node(fsl.BET(frac=0.3, mask=True, robust=True),
46+
name='bet_dwi_pre')
47+
bet_dwi1 = pe.Node(fsl.BET(frac=0.3, mask=True, robust=True),
48+
name='bet_dwi_post')
4649

4750
hmc = hmc_pipeline()
4851
sdc = sdc_fmb(fugue_params=fugue_params, bmap_params=bmap_params,
4952
epi_params=epi_params)
5053
ecc = ecc_pipeline()
5154
unwarp = apply_all_corrections()
5255

53-
wf = pe.Workflow('dMRI_Artifacts')
56+
wf = pe.Workflow(name=name)
5457
wf.connect([
5558
(inputnode, hmc, [('in_file', 'inputnode.in_file'),
5659
('in_bvec', 'inputnode.in_bvec'),
@@ -64,6 +67,7 @@ def all_fmb_pipeline(name='hmc_sdc_ecc',
6467
,(inputnode, sdc, [('in_bval', 'inputnode.in_bval'),
6568
('bmap_pha', 'inputnode.bmap_pha'),
6669
('bmap_mag', 'inputnode.bmap_mag')])
70+
,(hmc, ecc, [('outputnode.out_xfms', 'inputnode.in_xfms')])
6771
,(inputnode, ecc, [('in_file', 'inputnode.in_file'),
6872
('in_bval', 'inputnode.in_bval')])
6973
,(bet_dwi0, ecc, [('mask_file', 'inputnode.in_mask')])
@@ -93,34 +97,39 @@ def all_peb_pipeline(name='hmc_sdc_ecc',
9397
enc_dir='y',
9498
epi_factor=1)):
9599
"""
96-
Builds a pipeline including three artifact corrections: head-motion correction (HMC),
97-
susceptibility-derived distortion correction (SDC), and Eddy currents-derived distortion
98-
correction (ECC).
100+
Builds a pipeline including three artifact corrections: head-motion
101+
correction (HMC), susceptibility-derived distortion correction (SDC),
102+
and Eddy currents-derived distortion correction (ECC).
99103
100-
.. warning:: this workflow rotates the gradients table (*b*-vectors) [Leemans09]_.
104+
.. warning:: this workflow rotates the gradients table (*b*-vectors)
105+
[Leemans09]_.
101106
102107
103108
"""
104-
inputnode = pe.Node(niu.IdentityInterface(fields=['in_file', 'in_bvec', 'in_bval',
105-
'alt_file']), name='inputnode')
109+
inputnode = pe.Node(niu.IdentityInterface(fields=['in_file', 'in_bvec',
110+
'in_bval', 'alt_file']), name='inputnode')
106111

107112
outputnode = pe.Node(niu.IdentityInterface(fields=['out_file', 'out_mask',
108113
'out_bvec']), name='outputnode')
109114

110115
avg_b0_0 = pe.Node(niu.Function(input_names=['in_dwi', 'in_bval'],
111-
output_names=['out_file'], function=b0_average), name='b0_avg_pre')
116+
output_names=['out_file'], function=b0_average),
117+
name='b0_avg_pre')
112118
avg_b0_1 = pe.Node(niu.Function(input_names=['in_dwi', 'in_bval'],
113-
output_names=['out_file'], function=b0_average), name='b0_avg_post')
114-
bet_dwi0 = pe.Node(fsl.BET(frac=0.3, mask=True, robust=True), name='bet_dwi_pre')
115-
bet_dwi1 = pe.Node(fsl.BET(frac=0.3, mask=True, robust=True), name='bet_dwi_post')
119+
output_names=['out_file'], function=b0_average),
120+
name='b0_avg_post')
121+
bet_dwi0 = pe.Node(fsl.BET(frac=0.3, mask=True, robust=True),
122+
name='bet_dwi_pre')
123+
bet_dwi1 = pe.Node(fsl.BET(frac=0.3, mask=True, robust=True),
124+
name='bet_dwi_post')
116125

117126
hmc = hmc_pipeline()
118127
sdc = sdc_peb(epi_params=epi_params, altepi_params=altepi_params)
119128
ecc = ecc_pipeline()
120129

121130
unwarp = apply_all_corrections()
122131

123-
wf = pe.Workflow('dMRI_Artifacts')
132+
wf = pe.Workflow(name=name)
124133
wf.connect([
125134
(inputnode, hmc, [('in_file', 'inputnode.in_file'),
126135
('in_bvec', 'inputnode.in_bvec'),
@@ -136,6 +145,7 @@ def all_peb_pipeline(name='hmc_sdc_ecc',
136145
,(inputnode, ecc, [('in_file', 'inputnode.in_file'),
137146
('in_bval', 'inputnode.in_bval')])
138147
,(bet_dwi0, ecc, [('mask_file', 'inputnode.in_mask')])
148+
,(hmc, ecc, [('outputnode.out_xfms', 'inputnode.in_xfms')])
139149
,(ecc, avg_b0_1, [('outputnode.out_file', 'in_dwi')])
140150
,(inputnode, avg_b0_1, [('in_bval', 'in_bval')])
141151
,(avg_b0_1, bet_dwi1, [('out_file', 'in_file')])
@@ -173,8 +183,8 @@ def all_fsl_pipeline(name='fsl_all_correct',
173183
174184
"""
175185

176-
inputnode = pe.Node(niu.IdentityInterface(fields=['in_file', 'in_bvec', 'in_bval',
177-
'alt_file']), name='inputnode')
186+
inputnode = pe.Node(niu.IdentityInterface(fields=['in_file', 'in_bvec',
187+
'in_bval', 'alt_file']), name='inputnode')
178188

179189
outputnode = pe.Node(niu.IdentityInterface(fields=['out_file', 'out_mask',
180190
'out_bvec']), name='outputnode')
@@ -205,7 +215,7 @@ def _gen_index(in_file):
205215
bet_dwi1 = pe.Node(fsl.BET(frac=0.3, mask=True, robust=True),
206216
name='bet_dwi_post')
207217

208-
wf = pe.Workflow('dMRI_Artifacts_FSL')
218+
wf = pe.Workflow(name=name)
209219
wf.connect([
210220
(inputnode, avg_b0_0, [('in_file', 'in_dwi'),
211221
('in_bval', 'in_bval')])
@@ -299,10 +309,13 @@ def hmc_pipeline(name='motion_correct'):
299309
outputnode.out_xfms - list of transformation matrices
300310
301311
"""
312+
from nipype.workflows.data import get_flirt_schedule
313+
302314
params = dict(dof=6, bgvalue=0, save_log=True,
303315
searchr_x=[-3, 3], searchr_y=[-3, 3], searchr_z=[-3, 3],
304316
fine_search=1, coarse_search=2,
305-
cost='mutualinfo', cost_func='mutualinfo', bins=64)
317+
#cost='mutualinfo', cost_func='mutualinfo', bins=64,
318+
schedule=get_flirt_schedule('hmc'))
306319

307320
inputnode = pe.Node(niu.IdentityInterface(fields=['in_file', 'ref_num',
308321
'in_bvec', 'in_bval', 'in_mask']), name='inputnode')
@@ -401,7 +414,10 @@ def ecc_pipeline(name='eddy_correct'):
401414
outputnode.out_file - corrected dwi file
402415
outputnode.out_xfms - list of transformation matrices
403416
"""
404-
params = dict(dof=12, no_search=True, interp='spline', bgvalue=0, save_log=True)
417+
418+
from nipype.workflows.data import get_flirt_schedule
419+
params = dict(dof=12, no_search=True, interp='spline', bgvalue=0,
420+
schedule=get_flirt_schedule('ecc'))
405421
# cost='normmi', cost_func='normmi', bins=64,
406422

407423
inputnode = pe.Node(niu.IdentityInterface(fields=['in_file', 'in_bval',

nipype/workflows/dmri/preprocess/utils.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# vi: set ft=python sts=4 ts=4 sw=4 et:
55
# @Author: oesteban
66
# @Date: 2014-08-30 10:53:13
7-
# @Last Modified by: Oscar Esteban
8-
# @Last Modified time: 2014-09-04 17:21:33
7+
# @Last Modified by: oesteban
8+
# @Last Modified time: 2014-09-05 11:31:30
99
import nipype.pipeline.engine as pe
1010
import nipype.interfaces.utility as niu
1111
from nipype.interfaces import fsl
@@ -92,17 +92,18 @@ def dwi_flirt(name='DWICoregistration', excl_nodiff=False,
9292

9393
initmat = pe.Node(niu.Function(input_names=['in_bval', 'in_xfms',
9494
'excl_nodiff'], output_names=['init_xfms'],
95-
function=_checkinitxfm), name='InitXforms')
95+
function=_checkinitxfm), name='InitXforms')
9696
initmat.inputs.excl_nodiff = excl_nodiff
97-
97+
dilate = pe.Node(fsl.maths.MathsCommand(nan2zeros=True,
98+
args='-kernel sphere 5 -dilM'), name='MskDilate')
9899
split = pe.Node(fsl.Split(dimension='t'), name='SplitDWIs')
99100
pick_ref = pe.Node(niu.Select(), name='Pick_b0')
100101
n4 = pe.Node(ants.N4BiasFieldCorrection(dimension=3), name='Bias')
101102
enhb0 = pe.Node(niu.Function(input_names=['in_file', 'in_mask',
102103
'clip_limit'], output_names=['out_file'],
103-
function=enhance), name='B0Equalize')
104+
function=enhance), name='B0Equalize')
104105
enhb0.inputs.clip_limit = 0.015
105-
enhdw = pe.MapNode(niu.Function(input_names=['in_file'],
106+
enhdw = pe.MapNode(niu.Function(input_names=['in_file', 'in_mask'],
106107
output_names=['out_file'], function=enhance),
107108
name='DWEqualize', iterfield=['in_file'])
108109
flirt = pe.MapNode(fsl.FLIRT(**flirt_param), name='CoRegistration',
@@ -115,14 +116,17 @@ def dwi_flirt(name='DWICoregistration', excl_nodiff=False,
115116
wf = pe.Workflow(name=name)
116117
wf.connect([
117118
(inputnode, split, [('in_file', 'in_file')])
119+
,(inputnode, dilate, [('ref_mask', 'in_file')])
118120
,(inputnode, enhb0, [('ref_mask', 'in_mask')])
119121
,(inputnode, initmat, [('in_xfms', 'in_xfms'),
120122
('in_bval', 'in_bval')])
121123
,(inputnode, n4, [('reference', 'input_image'),
122124
('ref_mask', 'mask_image')])
123-
,(inputnode, flirt, [('ref_mask', 'ref_weight')])
125+
,(dilate, flirt, [('out_file', 'ref_weight'),
126+
('out_file', 'in_weight')])
124127
,(n4, enhb0, [('output_image', 'in_file')])
125128
,(split, enhdw, [('out_files', 'in_file')])
129+
,(dilate, enhdw, [('out_file', 'in_mask')])
126130
,(enhb0, flirt, [('out_file', 'reference')])
127131
,(enhdw, flirt, [('out_file', 'in_file')])
128132
,(initmat, flirt, [('init_xfms', 'in_matrix_file')])

0 commit comments

Comments
 (0)