@@ -79,15 +79,6 @@ def init_sdc_estimate_wf(fmaps, epi_meta, omp_nthreads=1, debug=False, ignore=No
79
79
method (for reporting purposes)
80
80
81
81
"""
82
- if ignore is None :
83
- ignore = tuple ()
84
-
85
- if not isinstance (ignore , (list , tuple )):
86
- ignore = tuple (ignore )
87
-
88
- # TODO: To be removed (filter out unsupported fieldmaps):
89
- fmaps = [fmap for fmap in fmaps if fmap ['suffix' ] in FMAP_PRIORITY ]
90
-
91
82
workflow = Workflow (name = 'sdc_estimate_wf' if fmaps else 'sdc_bypass_wf' )
92
83
inputnode = pe .Node (niu .IdentityInterface (
93
84
fields = ['epi_file' , 'epi_brain' , 'epi_mask' , 't1w_brain' , 'std2anat_xfm' ]),
@@ -99,7 +90,8 @@ def init_sdc_estimate_wf(fmaps, epi_meta, omp_nthreads=1, debug=False, ignore=No
99
90
name = 'outputnode' )
100
91
101
92
# No fieldmaps - forward inputs to outputs
102
- if not fmaps or 'fieldmaps' in ignore :
93
+ ignored = False if ignore is None else 'fieldmaps' in ignore
94
+ if not fmaps or ignored :
103
95
workflow .__postdesc__ = """\
104
96
Susceptibility distortion correction (SDC) has been skipped because the
105
97
dataset does not contain extra field map acquisitions correctly described
@@ -119,18 +111,26 @@ def init_sdc_estimate_wf(fmaps, epi_meta, omp_nthreads=1, debug=False, ignore=No
119
111
accurate co-registration with the anatomical reference.
120
112
"""
121
113
122
- # In case there are multiple fieldmaps prefer EPI
123
- fmaps .sort (key = lambda fmap : FMAP_PRIORITY [fmap ['suffix' ]])
124
- fmap = fmaps [0 ]
114
+ only_syn = 'syn' in fmaps and len (fmaps ) == 1
125
115
126
116
# PEPOLAR path
127
117
if 'epi' in fmaps :
128
118
from .pepolar import init_pepolar_unwarp_wf , check_pes
119
+
120
+ # SyN works without this metadata
121
+ if epi_meta .get ('PhaseEncodingDirection' ) is None :
122
+ raise ValueError (
123
+ 'PhaseEncodingDirection is not defined within the metadata retrieved '
124
+ 'for the intended EPI (DWI, BOLD, or SBRef) run.' )
129
125
outputnode .inputs .method = 'PEB/PEPOLAR (phase-encoding based / PE-POLARity)'
130
126
131
- # Filter out EPI fieldmaps to be used
132
- fmaps_epi = [(epi .path , epi .get_metadata ()['PhaseEncodingDirection' ])
133
- for epi in fmaps ['epi' ]]
127
+ fmaps_epi = [(v [0 ], v [1 ].get ('PhaseEncodingDirection' ))
128
+ for v in fmaps ['epi' ]]
129
+
130
+ if not all (list (zip (* fmaps_epi ))[1 ]):
131
+ raise ValueError (
132
+ 'At least one of the EPI runs with alternative phase-encoding '
133
+ 'blips is missing the required "PhaseEncodingDirection" metadata entry.' )
134
134
135
135
# Find matched PE directions
136
136
matched_pe = check_pes (fmaps_epi , epi_meta ['PhaseEncodingDirection' ])
@@ -150,32 +150,34 @@ def init_sdc_estimate_wf(fmaps, epi_meta, omp_nthreads=1, debug=False, ignore=No
150
150
])
151
151
152
152
# FIELDMAP path
153
- elif 'fieldmap' in fmaps :
153
+ elif 'fieldmap' in fmaps or 'phasediff' in fmaps :
154
154
from .unwarp import init_sdc_unwarp_wf
155
- # Import specific workflows here, so we don't break everything with one
156
- # unused workflow.
157
- suffices = {f .suffix for f in fmaps ['fieldmap' ]}
158
- if 'fieldmap' in suffices :
155
+
156
+ # SyN works without this metadata
157
+ if epi_meta .get ('PhaseEncodingDirection' ) is None :
158
+ raise ValueError (
159
+ 'PhaseEncodingDirection is not defined within the metadata retrieved '
160
+ 'for the intended EPI (DWI, BOLD, or SBRef) run.' )
161
+
162
+ if 'fieldmap' in fmaps :
159
163
from .fmap import init_fmap_wf
160
- outputnode .inputs .method = 'FMB (fieldmap-based)'
164
+ outputnode .inputs .method = 'FMB (fieldmap-based) - directly measured B0 map '
161
165
fmap_wf = init_fmap_wf (
162
166
omp_nthreads = omp_nthreads ,
163
167
fmap_bspline = False )
164
168
# set inputs
165
- fmap_wf .inputs .inputnode .magnitude = fmap ['magnitude' ]
166
- fmap_wf .inputs .inputnode .fieldmap = fmap ['fieldmap' ]
167
- elif 'phasediff' in suffices :
169
+ fmap_wf .inputs .inputnode .magnitude = [
170
+ m for m , _ in fmaps ['fieldmap' ]['magnitude' ]]
171
+ fmap_wf .inputs .inputnode .fieldmap = [
172
+ m for m , _ in fmaps ['fieldmap' ]['fieldmap' ]]
173
+ elif 'phasediff' in fmaps :
168
174
from .phdiff import init_phdiff_wf
175
+ outputnode .inputs .method = 'FMB (fieldmap-based) - phase-difference map'
169
176
fmap_wf = init_phdiff_wf (omp_nthreads = omp_nthreads )
170
177
# set inputs
171
- fmap_wf .inputs .inputnode .phasediff = fmap ['phasediff' ]
172
178
fmap_wf .inputs .inputnode .magnitude = [
173
- fmap_ for key , fmap_ in sorted (fmap .items ())
174
- if key .startswith ("magnitude" )
175
- ]
176
- else :
177
- raise ValueError ('Fieldmaps of types %s are not supported' %
178
- ', ' .join (['"%s"' % f for f in suffices ]))
179
+ m for m , _ in fmaps ['phasediff' ]['magnitude' ]]
180
+ fmap_wf .inputs .inputnode .phasediff = fmaps ['phasediff' ]['phases' ]
179
181
180
182
sdc_unwarp_wf = init_sdc_unwarp_wf (
181
183
omp_nthreads = omp_nthreads ,
@@ -193,24 +195,27 @@ def init_sdc_estimate_wf(fmaps, epi_meta, omp_nthreads=1, debug=False, ignore=No
193
195
('outputnode.fmap_ref' , 'inputnode.fmap_ref' ),
194
196
('outputnode.fmap_mask' , 'inputnode.fmap_mask' )]),
195
197
])
198
+ elif not only_syn :
199
+ raise ValueError ('Fieldmaps of types %s are not supported' %
200
+ ', ' .join (['"%s"' % f for f in fmaps ]))
196
201
197
202
# FIELDMAP-less path
198
- if any ( fm [ 'suffix' ] == ' syn' for fm in fmaps ) :
203
+ if ' syn' in fmaps :
199
204
from .syn import init_syn_sdc_wf
200
205
syn_sdc_wf = init_syn_sdc_wf (
201
206
epi_pe = epi_meta .get ('PhaseEncodingDirection' , None ),
202
207
omp_nthreads = omp_nthreads )
203
208
204
209
workflow .connect ([
205
210
(inputnode , syn_sdc_wf , [
211
+ ('epi_file' , 'inputnode.in_reference' ),
212
+ ('epi_brain' , 'inputnode.in_reference_brain' ),
206
213
('t1w_brain' , 'inputnode.t1w_brain' ),
207
- ('epi_file' , 'inputnode.epi_file' ),
208
- ('epi_brain' , 'inputnode.epi_brain' ),
209
214
('std2anat_xfm' , 'inputnode.std2anat_xfm' )]),
210
215
])
211
216
212
217
# XXX Eliminate branch when forcing isn't an option
213
- if fmap [ 'suffix' ] == 'syn' : # No fieldmaps, but --use-syn
218
+ if only_syn : # No fieldmaps, but --use-syn
214
219
outputnode .inputs .method = 'FLB ("fieldmap-less", SyN-based)'
215
220
sdc_unwarp_wf = syn_sdc_wf
216
221
else : # --force-syn was called when other fieldmap was present
0 commit comments