Skip to content

Commit 063acc8

Browse files
committed
update fmap workflows
1 parent 776dc61 commit 063acc8

File tree

8 files changed

+168
-273
lines changed

8 files changed

+168
-273
lines changed

dmriprep/workflows/base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ def init_dmriprep_wf(
111111
output_resolution=output_resolution,
112112
bet_dwi=bet_dwi,
113113
bet_mag=bet_mag,
114-
omp_nthreads=omp_nthreads,
115114
acqp_file=acqp_file,
115+
omp_nthreads=omp_nthreads,
116116
ignore=ignore,
117117
work_dir=work_dir,
118118
synb0_dir=synb0_dir
@@ -173,8 +173,8 @@ def init_single_subject_wf(
173173
output_resolution=(1, 1, 1),
174174
bet_dwi=0.3,
175175
bet_mag=0.3,
176-
omp_nthreads=1,
177176
acqp_file='',
177+
omp_nthreads=1,
178178
ignore=[],
179179
work_dir='.',
180180
synb0_dir=''
@@ -201,10 +201,10 @@ def init_single_subject_wf(
201201
Fractional intensity threshold for BET on dwi image
202202
bet_mag: float
203203
Fractional intensity threshold for BET on magnitude image
204-
omp_nthreads: int
205-
Maximum number of threads an individual process may use
206204
acqp_file: str
207205
Optional acquisition parameters file
206+
omp_nthreads: int
207+
Maximum number of threads an individual process may use
208208
ignore: list
209209
Preprocessing steps to skip (may include 'denoise', 'unring', 'fieldmaps')
210210
work_dir: str

dmriprep/workflows/dwi/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ def init_dwi_preproc_wf(
2929
output_resolution,
3030
bet_dwi,
3131
bet_mag,
32-
omp_nthreads,
3332
acqp_file,
33+
omp_nthreads,
3434
ignore,
3535
synb0_dir
3636
):
@@ -54,8 +54,8 @@ def init_dwi_preproc_wf(
5454
output_resolution=(1, 1, 1),
5555
bet_dwi=0.3,
5656
bet_mag=0.3,
57-
omp_nthreads=1,
5857
acqp_file='',
58+
omp_nthreads=1,
5959
ignore=[],
6060
synb0_dir=''
6161
)

dmriprep/workflows/dwi/eddy.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from numba import cuda
1414

1515

16-
def init_dwi_eddy_wf(omp_nthreads, fmap_type):
16+
def init_dwi_eddy_wf(omp_nthreads, sdc_method):
1717
"""
1818
This workflow runs eddy on the input dwi image.
1919
@@ -22,12 +22,14 @@ def init_dwi_eddy_wf(omp_nthreads, fmap_type):
2222
:simple_form: yes
2323
2424
from dmriprep.workflows.dwi import init_dwi_eddy_wf
25-
wf = init_dwi_eddy_wf(omp_nthreads=1)
25+
wf = init_dwi_eddy_wf(omp_nthreads=1, sdc_method='nonlinear_reg')
2626
2727
**Parameters**
2828
2929
omp_nthreads: int
3030
Number of threads to run eddy
31+
sdc_type: str
32+
Synthetic distortion correction method (may include 'fieldmap, 'topup', 'nonlinear_reg')
3133
3234
**Inputs**
3335
@@ -97,12 +99,12 @@ def init_dwi_eddy_wf(omp_nthreads, fmap_type):
9799
('out_rotated_bvecs', 'out_bvec')])
98100
])
99101

100-
if fmap_type == 'fieldmap':
102+
if sdc_method == 'fieldmap':
101103
wf.connect([
102104
(inputnode, ecc, [('fieldmap_file', 'field')])
103105
])
104106

105-
if fmap_type == 'topup':
107+
if sdc_method == 'topup':
106108
wf.connect([
107109
(inputnode, ecc, [('topup_fieldcoef', 'in_topup_fieldcoef'),
108110
('topup_movpar', 'in_topup_movpar')])

dmriprep/workflows/fieldmap/base.py

Lines changed: 72 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,40 @@
33
from nipype.pipeline import engine as pe
44
from nipype.interfaces import utility as niu
55

6-
FMAP_PRIORITY = {"epi": 0, "fieldmap": 1, "phasediff": 2, "phase": 3, "syn": 4}
6+
FMAP_PRIORITY = {'epi': 0, 'fieldmap': 1, 'phasediff': 2, 'phase': 3, 'syn': 4}
77

88

99
def init_sdc_prep_wf(
1010
subject_id,
1111
fmaps,
1212
metadata,
1313
layout,
14-
bet_mag_frac,
14+
bet_mag,
1515
#synb0,
16-
omp_nthreads=1,
17-
fmap_bspline=False,
16+
omp_nthreads
1817
):
1918

20-
sdc_prep_wf = pe.Workflow(name="sdc_prep_wf")
19+
sdc_prep_wf = pe.Workflow(name='sdc_prep_wf')
2120

2221
inputnode = pe.Node(
23-
niu.IdentityInterface(fields=["b0_stripped"]), name="inputnode"
24-
)
22+
niu.IdentityInterface(fields=['b0_stripped']), name='inputnode')
2523

2624
outputnode = pe.Node(
2725
niu.IdentityInterface(
2826
fields=[
29-
"out_fmap",
30-
"out_topup",
31-
"bold_ref",
32-
"bold_mask",
33-
"bold_ref_brain",
34-
"out_warp",
35-
"syn_bold_ref",
36-
"method",
37-
"out_movpar",
38-
"out_enc_file",
27+
'out_fmap',
28+
'out_topup',
29+
'bold_ref',
30+
'bold_mask',
31+
'bold_ref_brain',
32+
'out_warp',
33+
'syn_bold_ref',
34+
'method',
35+
'out_movpar',
36+
'out_enc_file'
3937
]
4038
),
41-
name="outputnode",
39+
name='outputnode',
4240
)
4341
# if synb0:
4442
# from .pepolar import init_synb0_wf
@@ -50,164 +48,103 @@ def init_sdc_prep_wf(
5048
# (
5149
# inputnode,
5250
# synb0_wf,
53-
# [("b0_stripped", "inputnode.b0_stripped")],
51+
# [('b0_stripped', 'inputnode.b0_stripped')],
5452
# ),
5553
# (
5654
# synb0_wf,
5755
# outputnode,
5856
# [
59-
# ("outputnode.out_topup", "out_topup"),
60-
# ("outputnode.out_movpar", "out_movpar"),
61-
# ("outputnode.out_enc_file", "out_enc_file"),
62-
# ("outputnode.out_fmap", "out_fmap"),
57+
# ('outputnode.out_topup', 'out_topup'),
58+
# ('outputnode.out_movpar', 'out_movpar'),
59+
# ('outputnode.out_enc_file', 'out_enc_file'),
60+
# ('outputnode.out_fmap', 'out_fmap'),
6361
# ],
6462
# ),
6563
# ]
6664
# )
6765
# else:
68-
fmaps.sort(key=lambda fmap: FMAP_PRIORITY[fmap["suffix"]])
66+
fmaps.sort(key=lambda fmap: FMAP_PRIORITY[fmap['suffix']])
6967
fmap = fmaps[0]
7068

71-
if fmap["suffix"] == "epi":
69+
if fmap['suffix'] == 'epi':
7270
from .pepolar import init_pepolar_wf
7371

7472
epi_fmaps = [
75-
(fmap_["epi"], fmap_["metadata"]["PhaseEncodingDirection"])
73+
(fmap_['epi'], fmap_['metadata']['PhaseEncodingDirection'])
7674
for fmap_ in fmaps
77-
if fmap_["suffix"] == "epi"
75+
if fmap_['suffix'] == 'epi'
7876
]
7977

8078
pepolar_wf = init_pepolar_wf(subject_id, metadata, epi_fmaps)
8179

82-
sdc_prep_wf.connect(
83-
[
84-
(
85-
inputnode,
86-
pepolar_wf,
87-
[("b0_stripped", "inputnode.b0_stripped")],
88-
),
89-
(
90-
pepolar_wf,
91-
outputnode,
92-
[
93-
("outputnode.out_topup", "out_topup"),
94-
("outputnode.out_movpar", "out_movpar"),
95-
("outputnode.out_enc_file", "out_enc_file"),
96-
("outputnode.out_fmap", "out_fmap"),
97-
],
98-
),
99-
]
100-
)
80+
sdc_prep_wf.connect([
81+
(inputnode, pepolar_wf, [('b0_stripped', 'inputnode.b0_stripped')]),
82+
(pepolar_wf, outputnode, [('outputnode.out_topup', 'out_topup'),
83+
('outputnode.out_movpar', 'out_movpar'),
84+
('outputnode.out_enc_file', 'out_enc_file'),
85+
('outputnode.out_fmap', 'out_fmap')])
86+
])
10187

102-
elif fmap["suffix"] == "fieldmap":
88+
elif fmap['suffix'] == 'fieldmap':
10389
from .fmap import init_fmap_wf
10490

105-
fmap_wf = init_fmap_wf()
106-
fmap_wf.inputs.inputnode.fieldmap = fmap["fieldmap"]
107-
fmap_wf.inputs.inputnode.magnitude = fmap["magnitude"]
108-
109-
sdc_prep_wf.connect(
110-
[
111-
(
112-
inputnode,
113-
fmap_wf,
114-
[("b0_stripped", "inputnode.b0_stripped")],
115-
),
116-
(
117-
fmap_wf,
118-
outputnode,
119-
[("outputnode.out_fmap", "out_fmap")],
120-
),
121-
]
122-
)
91+
fmap_wf = init_fmap_wf(bet_mag)
92+
fmap_wf.inputs.inputnode.fieldmap = fmap['fieldmap']
93+
fmap_wf.inputs.inputnode.magnitude = fmap['magnitude']
94+
95+
sdc_prep_wf.connect([
96+
(inputnode, fmap_wf, [('b0_stripped', 'inputnode.b0_stripped')]),
97+
(fmap_wf, outputnode, [('outputnode.out_fmap', 'out_fmap')])
98+
])
12399

124-
elif fmap["suffix"] in ("phasediff", "phase"):
100+
elif fmap['suffix'] in ('phasediff', 'phase'):
125101
from .phasediff import init_phase_wf, init_phdiff_wf
126102
from .fmap import init_fmap_wf
127103

128-
if fmap["suffix"] == "phasediff":
129-
phase_wf = init_phdiff_wf(bet_mag_frac)
130-
phase_wf.inputs.inputnode.phasediff = fmap["phasediff"]
131-
104+
if fmap['suffix'] == 'phasediff':
105+
phase_wf = init_phdiff_wf(bet_mag)
106+
phase_wf.inputs.inputnode.phasediff = fmap['phasediff']
132107
phase_wf.inputs.inputnode.magnitude1 = [
133108
fmap_
134109
for key, fmap_ in sorted(fmap.items())
135-
if key.startswith("magnitude1")
110+
if key.startswith('magnitude1')
136111
][0]
137-
138112
phase_wf.inputs.inputnode.phases_meta = layout.get_metadata(
139-
phase_wf.inputs.inputnode.phasediff
140-
)
141-
post_phase_wf = init_fmap_wf()
142-
143-
sdc_prep_wf.connect(
144-
[
145-
(
146-
inputnode,
147-
post_phase_wf,
148-
[("b0_stripped", "inputnode.b0_stripped")],
149-
),
150-
(
151-
phase_wf,
152-
post_phase_wf,
153-
[("outputnode.out_fmap", "inputnode.fieldmap")],
154-
),
155-
(
156-
phase_wf,
157-
post_phase_wf,
158-
[("outputnode.out_mag", "inputnode.magnitude")],
159-
),
160-
(
161-
post_phase_wf,
162-
outputnode,
163-
[("outputnode.out_fmap", "out_fmap")],
164-
),
165-
]
166-
)
167-
168-
elif fmap["suffix"] == "phase":
169-
phase_wf = init_phase_wf(bet_mag_frac)
113+
phase_wf.inputs.inputnode.phasediff)
114+
115+
fmap_wf = init_fmap_wf(bet_mag)
116+
117+
sdc_prep_wf.connect([
118+
(inputnode, fmap_wf, [('b0_stripped', 'inputnode.b0_stripped')]),
119+
(phase_wf, fmap_wf, [('outputnode.out_fmap', 'inputnode.fieldmap')]),
120+
(phase_wf, fmap_wf, [('outputnode.out_mag', 'inputnode.magnitude')]),
121+
(fmap_wf, outputnode, [('outputnode.out_fmap', 'out_fmap')])
122+
])
123+
124+
elif fmap['suffix'] == 'phase':
125+
phase_wf = init_phase_wf(bet_mag)
170126
phase_wf.inputs.inputnode.phasediff = [
171-
fmap["phase1"],
172-
fmap["phase2"],
127+
fmap['phase1'],
128+
fmap['phase2']
173129
]
174-
175130
phase_wf.inputs.inputnode.magnitude1 = [
176131
fmap_
177132
for key, fmap_ in sorted(fmap.items())
178-
if key.startswith("magnitude1")
133+
if key.startswith('magnitude1')
179134
][0]
180-
181135
phase_wf.inputs.inputnode.phases_meta = [
182136
layout.get_metadata(i)
183137
for i in phase_wf.inputs.inputnode.phasediff
184138
]
185-
post_phase_wf = init_fmap_wf()
186-
187-
sdc_prep_wf.connect(
188-
[
189-
(
190-
inputnode,
191-
post_phase_wf,
192-
[("b0_stripped", "inputnode.b0_stripped")],
193-
),
194-
(
195-
phase_wf,
196-
post_phase_wf,
197-
[("outputnode.out_fmap", "inputnode.fieldmap")],
198-
),
199-
(
200-
phase_wf,
201-
post_phase_wf,
202-
[("outputnode.out_mag", "inputnode.magnitude")],
203-
),
204-
(
205-
post_phase_wf,
206-
outputnode,
207-
[("outputnode.out_fmap", "out_fmap")],
208-
),
209-
]
210-
)
139+
140+
fmap_wf = init_fmap_wf()
141+
142+
sdc_prep_wf.connect([
143+
(inputnode, fmap_wf, [('b0_stripped', 'inputnode.b0_stripped')]),
144+
(phase_wf, fmap_wf, [('outputnode.out_fmap', 'inputnode.fieldmap')]),
145+
(phase_wf, fmap_wf, [('outputnode.out_mag', 'inputnode.magnitude')]),
146+
(fmap_wf, outputnode, [('outputnode.out_fmap', 'out_fmap')])
147+
])
211148
else:
212-
print("No sdc correction")
149+
print('No sdc correction')
213150
return sdc_prep_wf
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
3+
# bfc -i $indir2/brain.nii.gz -o T1.bfc.nii.gz -v 1 -L 0.5 -U 1.5
4+
5+
# /KIMEL/tigrlab/quarantine/brainsuite/18a/build/bdp/bdp.sh \
6+
# T1.bfc.nii.gz \
7+
# --t1-mask $indir2/brainmaskautobet_mask.nii.gz \
8+
# --nii $indir1/data.nii.gz \
9+
# --dwi-mask $indir1/nodif_brain_mask.nii.gz \
10+
# -b $indir1/bval.txt \
11+
# -g $indir1/eddy_bvecs.txt

0 commit comments

Comments
 (0)