@@ -75,14 +75,7 @@ def init_topup_wf(omp_nthreads=1, debug=False, name="pepolar_estimate_wf"):
75
75
)
76
76
outputnode = pe .Node (
77
77
niu .IdentityInterface (
78
- fields = [
79
- "fmap" ,
80
- "fmap_ref" ,
81
- "fmap_coeff" ,
82
- "jacobians" ,
83
- "xfms" ,
84
- "out_warps" ,
85
- ]
78
+ fields = ["fmap" , "fmap_ref" , "fmap_coeff" , "jacobians" , "xfms" , "out_warps" ]
86
79
),
87
80
name = "outputnode" ,
88
81
)
@@ -166,40 +159,50 @@ def init_3dQwarp_wf(omp_nthreads=1, name="pepolar_estimate_wf"):
166
159
)
167
160
from niworkflows .interfaces .freesurfer import StructuralReference
168
161
from niworkflows .func .util import init_enhance_and_skullstrip_bold_wf
162
+ from ...utils .misc import front as _front , last as _last
169
163
from ...interfaces .utils import Flatten
170
164
171
165
workflow = Workflow (name = name )
172
166
workflow .__desc__ = f"""{ _PEPOLAR_DESC } \
173
167
with `3dQwarp` @afni (AFNI { '' .join (['%02d' % v for v in afni .Info ().version () or []])} ).
174
168
"""
175
169
176
- inputnode = pe .Node (niu .IdentityInterface (fields = ["in_data" , "metadata" ]),
177
- name = "inputnode" )
170
+ inputnode = pe .Node (
171
+ niu .IdentityInterface (fields = ["in_data" , "metadata" ]), name = "inputnode"
172
+ )
178
173
179
174
outputnode = pe .Node (
180
175
niu .IdentityInterface (fields = ["fmap" , "fmap_ref" ]), name = "outputnode"
181
176
)
182
177
183
178
flatten = pe .Node (Flatten (), name = "flatten" )
184
- sort_pe = pe .Node (niu .Function (
185
- function = _sorted_pe , output_names = ["sorted" , "qwarp_args" ]),
186
- name = "sort_pe" , run_without_submitting = True )
187
-
188
- merge_pes = pe .MapNode (StructuralReference (
189
- auto_detect_sensitivity = True ,
190
- initial_timepoint = 1 ,
191
- fixed_timepoint = True , # Align to first image
192
- intensity_scaling = True ,
193
- # 7-DOF (rigid + intensity)
194
- no_iteration = True ,
195
- subsample_threshold = 200 ,
196
- out_file = 'template.nii.gz' ),
197
- name = 'merge_pes' ,
179
+ sort_pe = pe .Node (
180
+ niu .Function (function = _sorted_pe , output_names = ["sorted" , "qwarp_args" ]),
181
+ name = "sort_pe" ,
182
+ run_without_submitting = True ,
183
+ )
184
+
185
+ merge_pes = pe .MapNode (
186
+ StructuralReference (
187
+ auto_detect_sensitivity = True ,
188
+ initial_timepoint = 1 ,
189
+ fixed_timepoint = True , # Align to first image
190
+ intensity_scaling = True ,
191
+ # 7-DOF (rigid + intensity)
192
+ no_iteration = True ,
193
+ subsample_threshold = 200 ,
194
+ out_file = "template.nii.gz" ,
195
+ ),
196
+ name = "merge_pes" ,
198
197
iterfield = ["in_files" ],
199
198
)
200
199
201
- pe0_wf = init_enhance_and_skullstrip_bold_wf (omp_nthreads = omp_nthreads , name = "pe0_wf" )
202
- pe1_wf = init_enhance_and_skullstrip_bold_wf (omp_nthreads = omp_nthreads , name = "pe1_wf" )
200
+ pe0_wf = init_enhance_and_skullstrip_bold_wf (
201
+ omp_nthreads = omp_nthreads , name = "pe0_wf"
202
+ )
203
+ pe1_wf = init_enhance_and_skullstrip_bold_wf (
204
+ omp_nthreads = omp_nthreads , name = "pe1_wf"
205
+ )
203
206
204
207
align_pes = pe .Node (
205
208
Registration (
@@ -228,11 +231,7 @@ def init_3dQwarp_wf(omp_nthreads=1, name="pepolar_estimate_wf"):
228
231
cphdr_warp = pe .Node (CopyHeader (), name = "cphdr_warp" , mem_gb = 0.01 )
229
232
230
233
unwarp_reference = pe .Node (
231
- ApplyTransforms (
232
- dimension = 3 ,
233
- float = True ,
234
- interpolation = "LanczosWindowedSinc" ,
235
- ),
234
+ ApplyTransforms (dimension = 3 , float = True , interpolation = "LanczosWindowedSinc" ,),
236
235
name = "unwarp_reference" ,
237
236
)
238
237
@@ -278,7 +277,15 @@ def _fix_hdr(in_file, newpath=None):
278
277
279
278
280
279
def _pe2fsl (metadata ):
281
- """Convert ijk notation to xyz."""
280
+ """
281
+ Convert ijk notation to xyz.
282
+
283
+ Example
284
+ -------
285
+ >>> _pe2fsl([{"PhaseEncodingDirection": "j-"}, {"PhaseEncodingDirection": "i"}])
286
+ ['y-', 'x']
287
+
288
+ """
282
289
return [
283
290
m ["PhaseEncodingDirection" ]
284
291
.replace ("i" , "x" )
@@ -289,6 +296,29 @@ def _pe2fsl(metadata):
289
296
290
297
291
298
def _sorted_pe (inlist ):
299
+ """
300
+ Generate suitable inputs to ``3dQwarp``.
301
+
302
+ Example
303
+ -------
304
+ >>> paths, args = _sorted_pe([
305
+ ... ("dir-AP_epi.nii.gz", {"PhaseEncodingDirection": "j-"}),
306
+ ... ("dir-AP_bold.nii.gz", {"PhaseEncodingDirection": "j-"}),
307
+ ... ("dir-PA_epi.nii.gz", {"PhaseEncodingDirection": "j"}),
308
+ ... ("dir-PA_bold.nii.gz", {"PhaseEncodingDirection": "j"}),
309
+ ... ("dir-AP_sbref.nii.gz", {"PhaseEncodingDirection": "j-"}),
310
+ ... ("dir-PA_sbref.nii.gz", {"PhaseEncodingDirection": "j"}),
311
+ ... ])
312
+ >>> paths[0]
313
+ ['dir-AP_epi.nii.gz', 'dir-AP_bold.nii.gz', 'dir-AP_sbref.nii.gz']
314
+
315
+ >>> paths[1]
316
+ ['dir-PA_epi.nii.gz', 'dir-PA_bold.nii.gz', 'dir-PA_sbref.nii.gz']
317
+
318
+ >>> args
319
+ '-noXdis -noZdis'
320
+
321
+ """
292
322
out_ref = [inlist [0 ][0 ]]
293
323
out_opp = []
294
324
@@ -302,20 +332,9 @@ def _sorted_pe(inlist):
302
332
else :
303
333
raise ValueError ("Cannot handle orthogonal PE encodings." )
304
334
305
- return [out_ref , out_opp ], {
306
- "i" : "-noYdis -noZdis" ,
307
- "j" : "-noXdis -noZdis" ,
308
- "k" : "-noXdis -noYdis" ,
309
- }[ref_pe [0 ]]
310
-
311
-
312
- def _front (inlist ):
313
- if isinstance (inlist , (list , tuple )):
314
- return inlist [0 ]
315
- return inlist
316
-
317
-
318
- def _last (inlist ):
319
- if isinstance (inlist , (list , tuple )):
320
- return inlist [- 1 ]
321
- return inlist
335
+ return (
336
+ [out_ref , out_opp ],
337
+ {"i" : "-noYdis -noZdis" , "j" : "-noXdis -noZdis" , "k" : "-noXdis -noYdis" }[
338
+ ref_pe [0 ]
339
+ ],
340
+ )
0 commit comments