@@ -31,18 +31,18 @@ def cleanup_edge_pipeline(name='Cleanup'):
31
31
32
32
wf = pe .Workflow (name = name )
33
33
wf .connect ([
34
- (inputnode , fugue , [('in_file' , 'fmap_in_file' ),
35
- ('in_mask' , 'mask_file' )])
36
- , (inputnode , erode , [('in_mask' , 'in_file' )])
37
- , (inputnode , newmsk , [('in_mask' , 'in_file' )])
38
- , (erode , newmsk , [('out_file' , 'operand_files' )])
39
- , (fugue , applymsk , [('fmap_out_file' , 'in_file' )])
40
- , (newmsk , applymsk , [('out_file' , 'mask_file' )])
41
- , (erode , join , [('out_file' , 'in1' )])
42
- , (applymsk , join , [('out_file' , 'in2' )])
43
- , (inputnode , addedge , [('in_file' , 'in_file' )])
44
- , (join , addedge , [('out' , 'operand_files' )])
45
- , (addedge , outputnode , [('out_file' , 'out_file' )])
34
+ (inputnode , fugue , [('in_file' , 'fmap_in_file' ),
35
+ ('in_mask' , 'mask_file' )]),
36
+ (inputnode , erode , [('in_mask' , 'in_file' )]),
37
+ (inputnode , newmsk , [('in_mask' , 'in_file' )]),
38
+ (erode , newmsk , [('out_file' , 'operand_files' )]),
39
+ (fugue , applymsk , [('fmap_out_file' , 'in_file' )]),
40
+ (newmsk , applymsk , [('out_file' , 'mask_file' )]),
41
+ (erode , join , [('out_file' , 'in1' )]),
42
+ (applymsk , join , [('out_file' , 'in2' )]),
43
+ (inputnode , addedge , [('in_file' , 'in_file' )]),
44
+ (join , addedge , [('out' , 'operand_files' )]),
45
+ (addedge , outputnode , [('out_file' , 'out_file' )])
46
46
])
47
47
return wf
48
48
@@ -64,15 +64,14 @@ def vsm2warp(name='Shiftmap2Warping'):
64
64
65
65
wf = pe .Workflow (name = name )
66
66
wf .connect ([
67
- (inputnode , fixhdr , [('in_vsm' , 'in_file' ),
68
- ('in_ref' , 'in_file_hdr' )])
69
- ,(inputnode , vsm , [('scaling' , 'operand_value' )])
70
- ,(fixhdr , vsm , [('out_file' , 'in_file' )])
71
-
72
- ,(vsm , vsm2dfm , [('out_file' , 'shift_in_file' )])
73
- ,(inputnode , vsm2dfm , [('in_ref' , 'reference' ),
74
- ('enc_dir' , 'shift_direction' )])
75
- ,(vsm2dfm , outputnode , [('out_file' , 'out_warp' )])
67
+ (inputnode , fixhdr , [('in_vsm' , 'in_file' ),
68
+ ('in_ref' , 'in_file_hdr' )]),
69
+ (inputnode , vsm , [('scaling' , 'operand_value' )]),
70
+ (fixhdr , vsm , [('out_file' , 'in_file' )]),
71
+ (vsm , vsm2dfm , [('out_file' , 'shift_in_file' )]),
72
+ (inputnode , vsm2dfm , [('in_ref' , 'reference' ),
73
+ ('enc_dir' , 'shift_direction' )]),
74
+ (vsm2dfm , outputnode , [('out_file' , 'out_warp' )])
76
75
])
77
76
return wf
78
77
@@ -111,25 +110,25 @@ def dwi_flirt(name='DWICoregistration', excl_nodiff=False,
111
110
'out_xfms' ]), name = 'outputnode' )
112
111
wf = pe .Workflow (name = name )
113
112
wf .connect ([
114
- (inputnode , split , [('in_file' , 'in_file' )])
115
- , (inputnode , dilate , [('ref_mask' , 'in_file' )])
116
- , (inputnode , enhb0 , [('ref_mask' , 'in_mask' )])
117
- , (inputnode , initmat , [('in_xfms' , 'in_xfms' ),
118
- ('in_bval' , 'in_bval' )])
119
- , (inputnode , n4 , [('reference' , 'input_image' ),
120
- ('ref_mask' , 'mask_image' )])
121
- , (dilate , flirt , [('out_file' , 'ref_weight' ),
122
- ('out_file' , 'in_weight' )])
123
- , (n4 , enhb0 , [('output_image' , 'in_file' )])
124
- , (split , enhdw , [('out_files' , 'in_file' )])
125
- , (dilate , enhdw , [('out_file' , 'in_mask' )])
126
- , (enhb0 , flirt , [('out_file' , 'reference' )])
127
- , (enhdw , flirt , [('out_file' , 'in_file' )])
128
- , (initmat , flirt , [('init_xfms' , 'in_matrix_file' )])
129
- , (flirt , thres , [('out_file' , 'in_file' )])
130
- , (thres , merge , [('out_file' , 'in_files' )])
131
- , (merge , outputnode , [('merged_file' , 'out_file' )])
132
- , (flirt , outputnode , [('out_matrix_file' , 'out_xfms' )])
113
+ (inputnode , split , [('in_file' , 'in_file' )]),
114
+ (inputnode , dilate , [('ref_mask' , 'in_file' )]),
115
+ (inputnode , enhb0 , [('ref_mask' , 'in_mask' )]),
116
+ (inputnode , initmat , [('in_xfms' , 'in_xfms' ),
117
+ ('in_bval' , 'in_bval' )]),
118
+ (inputnode , n4 , [('reference' , 'input_image' ),
119
+ ('ref_mask' , 'mask_image' )]),
120
+ (dilate , flirt , [('out_file' , 'ref_weight' ),
121
+ ('out_file' , 'in_weight' )]),
122
+ (n4 , enhb0 , [('output_image' , 'in_file' )]),
123
+ (split , enhdw , [('out_files' , 'in_file' )]),
124
+ (dilate , enhdw , [('out_file' , 'in_mask' )]),
125
+ (enhb0 , flirt , [('out_file' , 'reference' )]),
126
+ (enhdw , flirt , [('out_file' , 'in_file' )]),
127
+ (initmat , flirt , [('init_xfms' , 'in_matrix_file' )]),
128
+ (flirt , thres , [('out_file' , 'in_file' )]),
129
+ (thres , merge , [('out_file' , 'in_files' )]),
130
+ (merge , outputnode , [('merged_file' , 'out_file' )]),
131
+ (flirt , outputnode , [('out_matrix_file' , 'out_xfms' )])
133
132
])
134
133
return wf
135
134
@@ -170,28 +169,27 @@ def apply_all_corrections(name='UnwarpArtifacts'):
170
169
171
170
wf = pe .Workflow (name = name )
172
171
wf .connect ([
173
- (inputnode , warps , [('in_sdc' , 'warp1' ),
174
- ('in_hmc' , 'premat' ),
175
- ('in_ecc' , 'postmat' ),
176
- ('in_dwi' , 'reference' )])
177
- ,(inputnode , split , [('in_dwi' , 'in_file' )])
178
- ,(split , selref , [('out_files' , 'inlist' )])
179
- ,(warps , unwarp , [('out_file' , 'field_file' )])
180
- ,(split , unwarp , [('out_files' , 'in_file' )])
181
- ,(selref , unwarp , [('out' , 'ref_file' )])
182
- ,(selref , coeffs , [('out' , 'reference' )])
183
- ,(warps , coeffs , [('out_file' , 'in_file' )])
184
- ,(selref , jacobian , [('out' , 'reference' )])
185
- ,(coeffs , jacobian , [('out_file' , 'in_file' )])
186
- ,(unwarp , jacmult , [('out_file' , 'in_file' )])
187
- ,(jacobian , jacmult , [('out_jacobian' , 'operand_files' )])
188
- ,(jacmult , thres , [('out_file' , 'in_file' )])
189
- ,(thres , merge , [('out_file' , 'in_files' )])
190
-
191
- ,(warps , outputnode , [('out_file' , 'out_warp' )])
192
- ,(coeffs , outputnode , [('out_file' , 'out_coeff' )])
193
- ,(jacobian , outputnode , [('out_jacobian' , 'out_jacobian' )])
194
- ,(merge , outputnode , [('merged_file' , 'out_file' )])
172
+ (inputnode , warps , [('in_sdc' , 'warp1' ),
173
+ ('in_hmc' , 'premat' ),
174
+ ('in_ecc' , 'postmat' ),
175
+ ('in_dwi' , 'reference' )]),
176
+ (inputnode , split , [('in_dwi' , 'in_file' )]),
177
+ (split , selref , [('out_files' , 'inlist' )]),
178
+ (warps , unwarp , [('out_file' , 'field_file' )]),
179
+ (split , unwarp , [('out_files' , 'in_file' )]),
180
+ (selref , unwarp , [('out' , 'ref_file' )]),
181
+ (selref , coeffs , [('out' , 'reference' )]),
182
+ (warps , coeffs , [('out_file' , 'in_file' )]),
183
+ (selref , jacobian , [('out' , 'reference' )]),
184
+ (coeffs , jacobian , [('out_file' , 'in_file' )]),
185
+ (unwarp , jacmult , [('out_file' , 'in_file' )]),
186
+ (jacobian , jacmult , [('out_jacobian' , 'operand_files' )]),
187
+ (jacmult , thres , [('out_file' , 'in_file' )]),
188
+ (thres , merge , [('out_file' , 'in_files' )]),
189
+ (warps , outputnode , [('out_file' , 'out_warp' )]),
190
+ (coeffs , outputnode , [('out_file' , 'out_coeff' )]),
191
+ (jacobian , outputnode , [('out_jacobian' , 'out_jacobian' )]),
192
+ (merge , outputnode , [('merged_file' , 'out_file' )])
195
193
])
196
194
return wf
197
195
@@ -281,7 +279,8 @@ def insert_mat(inlist, volid=0):
281
279
282
280
def recompose_dwi (in_dwi , in_bval , in_corrected , out_file = None ):
283
281
"""
284
- Recompose back the dMRI data accordingly the b-values table after EC correction
282
+ Recompose back the dMRI data accordingly the b-values table after EC
283
+ correction
285
284
"""
286
285
import numpy as np
287
286
import nibabel as nb
@@ -300,7 +299,8 @@ def recompose_dwi(in_dwi, in_bval, in_corrected, out_file=None):
300
299
dwis = np .where (bvals != 0 )[0 ].tolist ()
301
300
302
301
if len (dwis ) != len (in_corrected ):
303
- raise RuntimeError ('Length of DWIs in b-values table and after correction should match' )
302
+ raise RuntimeError (('Length of DWIs in b-values table and after'
303
+ 'correction should match' ))
304
304
305
305
for bindex , dwi in zip (dwis , in_corrected ):
306
306
dwidata [..., bindex ] = nb .load (dwi ).get_data ()
@@ -348,15 +348,16 @@ def b0_average(in_dwi, in_bval, out_file=None):
348
348
import os .path as op
349
349
350
350
if out_file is None :
351
- fname ,ext = op .splitext (op .basename (in_dwi ))
351
+ fname , ext = op .splitext (op .basename (in_dwi ))
352
352
if ext == ".gz" :
353
- fname ,ext2 = op .splitext (fname )
353
+ fname , ext2 = op .splitext (fname )
354
354
ext = ext2 + ext
355
355
out_file = op .abspath ("%s_avg_b0%s" % (fname , ext ))
356
356
357
357
imgs = np .array (nb .four_to_three (nb .load (in_dwi )))
358
358
bval = np .loadtxt (in_bval )
359
- b0s = [im .get_data ().astype (np .float32 ) for im in imgs [np .where (bval == 0 )]]
359
+ b0s = [im .get_data ().astype (np .float32 )
360
+ for im in imgs [np .where (bval == 0 )]]
360
361
b0 = np .average (np .array (b0s ), axis = 0 )
361
362
362
363
hdr = imgs [0 ].get_header ().copy ()
0 commit comments