@@ -53,7 +53,8 @@ def all_fmb_pipeline(name='hmc_sdc_ecc',
53
53
wf = pe .Workflow ('dMRI_Artifacts' )
54
54
wf .connect ([
55
55
(inputnode , hmc , [('in_file' , 'inputnode.in_file' ),
56
- ('in_bvec' , 'inputnode.in_bvec' )])
56
+ ('in_bvec' , 'inputnode.in_bvec' ),
57
+ ('in_bval' , 'inputnode.in_bval' )])
57
58
,(inputnode , avg_b0_0 , [('in_file' , 'in_dwi' ),
58
59
('in_bval' , 'in_bval' )])
59
60
,(avg_b0_0 , bet_dwi0 , [('out_file' , 'in_file' )])
@@ -120,7 +121,8 @@ def all_peb_pipeline(name='hmc_sdc_ecc',
120
121
wf = pe .Workflow ('dMRI_Artifacts' )
121
122
wf .connect ([
122
123
(inputnode , hmc , [('in_file' , 'inputnode.in_file' ),
123
- ('in_bvec' , 'inputnode.in_bvec' )])
124
+ ('in_bvec' , 'inputnode.in_bvec' ),
125
+ ('in_bval' , 'inputnode.in_bval' )])
124
126
,(inputnode , avg_b0_0 , [('in_file' , 'in_dwi' ),
125
127
('in_bval' , 'in_bval' )])
126
128
,(avg_b0_0 , bet_dwi0 , [('out_file' ,'in_file' )])
@@ -257,6 +259,7 @@ def hmc_pipeline(name='motion_correct'):
257
259
>>> hmc = hmc_pipeline()
258
260
>>> hmc.inputs.inputnode.in_file = 'diffusion.nii'
259
261
>>> hmc.inputs.inputnode.in_bvec = 'diffusion.bvec'
262
+ >>> hmc.inputs.inputnode.in_bval = 'diffusion.bval'
260
263
>>> hmc.inputs.inputnode.in_mask = 'mask.nii'
261
264
>>> hmc.run() # doctest: +SKIP
262
265
@@ -276,48 +279,35 @@ def hmc_pipeline(name='motion_correct'):
276
279
outputnode.out_xfms - list of transformation matrices
277
280
278
281
"""
282
+ params = dict (interp = 'spline' , cost = 'normmi' ,
283
+ cost_func = 'normmi' , dof = 6 , bins = 64 , save_log = True ,
284
+ searchr_x = [- 4 , 4 ], searchr_y = [- 4 , 4 ], searchr_z = [- 4 , 4 ],
285
+ fine_search = 1 , coarse_search = 10 , padding_size = 1 )
286
+
279
287
inputnode = pe .Node (niu .IdentityInterface (fields = ['in_file' , 'ref_num' ,
280
- 'in_bvec' , 'in_mask' ]), name = 'inputnode' )
281
- split = pe .Node (fsl .Split (dimension = 't' ), name = 'SplitDWIs' )
282
- pick_ref = pe .Node (niu .Select (), name = 'Pick_b0' )
283
- enhb0 = pe .Node (niu .Function (input_names = ['in_file' ],
284
- output_names = ['out_file' ], function = enhance ),
285
- name = 'B0Equalize' )
286
- enhdw = pe .MapNode (niu .Function (input_names = ['in_file' ],
287
- output_names = ['out_file' ], function = enhance ),
288
- name = 'DWEqualize' , iterfield = ['in_file' ])
289
- flirt = pe .MapNode (fsl .FLIRT (interp = 'spline' , cost = 'normmi' ,
290
- cost_func = 'normmi' , dof = 6 , bins = 64 , save_log = True ,
291
- searchr_x = [- 4 , 4 ], searchr_y = [- 4 , 4 ], searchr_z = [- 4 , 4 ],
292
- fine_search = 1 , coarse_search = 10 , padding_size = 1 ),
293
- name = 'CoRegistration' , iterfield = ['in_file' ])
288
+ 'in_bvec' , 'in_bval' , 'in_mask' ]), name = 'inputnode' )
289
+ pick_ref = pe .Node (fsl .ExtractROI (t_size = 1 ), name = 'GetB0' )
290
+ flirt = dwi_flirt (flirt_param = params )
294
291
rot_bvec = pe .Node (niu .Function (input_names = ['in_bvec' , 'in_matrix' ],
295
292
output_names = ['out_file' ], function = rotate_bvecs ),
296
293
name = 'Rotate_Bvec' )
297
- thres = pe .MapNode (fsl .Threshold (thresh = 0.0 ), iterfield = ['in_file' ],
298
- name = 'RemoveNegative' )
299
- merge = pe .Node (fsl .Merge (dimension = 't' ), name = 'MergeDWIs' )
300
294
outputnode = pe .Node (niu .IdentityInterface (fields = ['out_file' ,
301
295
'out_bvec' , 'out_xfms' ]),
302
296
name = 'outputnode' )
303
297
304
298
wf = pe .Workflow (name = name )
305
299
wf .connect ([
306
- (inputnode , split , [('in_file' , 'in_file' )])
307
- ,(split , pick_ref , [('out_files' , 'inlist' )])
308
- ,(inputnode , pick_ref , [(('ref_num' , _checkrnum ), 'index' )])
309
- ,(inputnode , flirt , [('in_mask' , 'ref_weight' )])
310
- ,(pick_ref , enhb0 , [('out' , 'in_file' )])
311
- ,(split , enhdw , [('out_files' , 'in_file' )])
312
- ,(enhb0 , flirt , [('out_file' , 'reference' )])
313
- ,(enhdw , flirt , [('out_file' , 'in_file' )])
300
+ (inputnode , pick_ref , [('in_file' , 'in_file' ),
301
+ (('ref_num' , _checkrnum ), 't_min' )])
302
+ ,(inputnode , flirt , [('in_file' , 'inputnode.in_file' ),
303
+ ('in_mask' , 'inputnode.ref_mask' ),
304
+ ('in_bval' , 'inputnode.in_bval' )])
305
+ ,(pick_ref , flirt , [('roi_file' , 'inputnode.reference' )])
314
306
,(inputnode , rot_bvec , [('in_bvec' , 'in_bvec' )])
315
- ,(flirt , rot_bvec , [('out_matrix_file' , 'in_matrix' )])
316
- ,(flirt , thres , [('out_file' , 'in_file' )])
317
- ,(thres , merge , [('out_file' , 'in_files' )])
318
- ,(merge , outputnode , [('merged_file' , 'out_file' )])
307
+ ,(flirt , rot_bvec , [('outputnode.out_xfms' , 'in_matrix' )])
319
308
,(rot_bvec , outputnode , [('out_file' , 'out_bvec' )])
320
- ,(flirt , outputnode , [('out_matrix_file' , 'out_xfms' )])
309
+ ,(flirt , outputnode , [('outputnode.out_xfms' , 'out_xfms' ),
310
+ ('outputnode.out_file' , 'out_file' )])
321
311
])
322
312
return wf
323
313
@@ -376,19 +366,21 @@ def ecc_pipeline(name='eddy_correct'):
376
366
outputnode.out_file - corrected dwi file
377
367
outputnode.out_xfms - list of transformation matrices
378
368
"""
369
+ params = dict (no_search = True , interp = 'spline' , cost = 'normmi' ,
370
+ cost_func = 'normmi' , dof = 12 , bins = 64 ,
371
+ padding_size = 1 )
372
+
379
373
inputnode = pe .Node (niu .IdentityInterface (fields = ['in_file' , 'in_bval' ,
380
374
'in_mask' , 'in_xfms' ]), name = 'inputnode' )
381
- split = pe .Node (fsl .Split (dimension = 't' ), name = 'SplitDWIs' )
382
375
avg_b0 = pe .Node (niu .Function (input_names = ['in_dwi' , 'in_bval' ],
383
- output_names = ['out_file' ], function = b0_average ), name = 'b0_avg' )
384
- pick_dwi = pe .Node (niu .Select (), name = 'Pick_DWIs' )
385
- flirt = pe .MapNode (fsl .FLIRT (no_search = True , interp = 'spline' , cost = 'normmi' ,
386
- cost_func = 'normmi' , dof = 12 , bins = 64 , save_log = True ,
387
- padding_size = 1 ), name = 'CoRegistration' ,
388
- iterfield = ['in_file' , 'in_matrix_file' ])
389
- initmat = pe .Node (niu .Function (input_names = ['in_bval' , 'in_xfms' ],
390
- output_names = ['init_xfms' ], function = _checkinitxfm ),
391
- name = 'InitXforms' )
376
+ output_names = ['out_file' ], function = b0_average ),
377
+ name = 'b0_avg' )
378
+ pick_dws = pe .Node (niu .Function (input_names = ['in_dwi' , 'in_bval' , 'b' ],
379
+ output_names = ['out_file' ], function = extract_bval ),
380
+ name = 'ExtractDWI' )
381
+ pick_dws .inputs .b = 'diff'
382
+
383
+ flirt = dwi_flirt (flirt_param = params , excl_nodiff = True )
392
384
393
385
mult = pe .MapNode (fsl .BinaryMaths (operation = 'mul' ), name = 'ModulateDWIs' ,
394
386
iterfield = ['in_file' , 'operand_value' ])
@@ -406,23 +398,22 @@ def ecc_pipeline(name='eddy_correct'):
406
398
407
399
wf = pe .Workflow (name = name )
408
400
wf .connect ([
409
- (inputnode , split , [('in_file' , 'in_file' )])
410
- ,(inputnode , avg_b0 , [('in_file' , 'in_dwi' ),
401
+ (inputnode , avg_b0 , [('in_file' , 'in_dwi' ),
411
402
('in_bval' , 'in_bval' )])
412
- ,(inputnode , merge , [('in_file' , 'in_dwi' ),
403
+ ,(inputnode , pick_dws , [('in_file' , 'in_dwi' ),
413
404
('in_bval' , 'in_bval' )])
414
- ,(inputnode , initmat , [('in_xfms ' , 'in_xfms ' ),
405
+ ,(inputnode , merge , [('in_file ' , 'in_dwi ' ),
415
406
('in_bval' , 'in_bval' )])
407
+ ,(inputnode , flirt , [('in_mask' , 'inputnode.ref_mask' ),
408
+ ('in_xfms' , 'inputnode.in_xfms' ),
409
+ ('in_bval' , 'inputnode.in_bval' )])
416
410
,(inputnode , get_mat , [('in_bval' , 'in_bval' )])
417
- ,(split , pick_dwi , [('out_files' , 'inlist' )])
418
- ,(inputnode , pick_dwi , [(('in_bval' , _nonb0 ), 'index' )])
419
- ,(inputnode , flirt , [('in_mask' , 'ref_weight' )])
420
- ,(avg_b0 , flirt , [('out_file' , 'reference' )])
421
- ,(pick_dwi , flirt , [('out' , 'in_file' )])
422
- ,(initmat , flirt , [('init_xfms' , 'in_matrix_file' )])
423
- ,(flirt , get_mat , [('out_matrix_file' , 'in_xfms' )])
424
- ,(flirt , mult , [(('out_matrix_file' ,_xfm_jacobian ), 'operand_value' )])
425
- ,(flirt , mult , [('out_file' , 'in_file' )])
411
+ ,(avg_b0 , flirt , [('out_file' , 'inputnode.reference' )])
412
+ ,(pick_dws , flirt , [('out_file' , 'inputnode.in_file' )])
413
+ ,(flirt , get_mat , [('outputnode.out_xfms' , 'in_xfms' )])
414
+ ,(flirt , mult , [(('outputnode.out_xfms' ,_xfm_jacobian ),
415
+ 'operand_value' )])
416
+ ,(flirt , mult , [('outputnode.out_file' , 'in_file' )])
426
417
,(mult , thres , [('out_file' , 'in_file' )])
427
418
,(thres , merge , [('out_file' , 'in_corrected' )])
428
419
,(get_mat , outputnode , [('out_files' , 'out_xfms' )])
@@ -710,24 +701,6 @@ def _checkrnum(ref_num):
710
701
return ref_num
711
702
712
703
713
- def _checkinitxfm (in_bval , in_xfms = None ):
714
- from nipype .interfaces .base import isdefined
715
- import numpy as np
716
- import os .path as op
717
- bvals = np .loadtxt (in_bval )
718
- non_b0 = np .where (bvals != 0 )[0 ].tolist ()
719
-
720
- init_xfms = []
721
- if (in_xfms is None ) or (not isdefined (in_xfms )) or (len (in_xfms )!= len (bvals )):
722
- for i in non_b0 :
723
- xfm_file = op .abspath ('init_%04d.mat' % i )
724
- np .savetxt (xfm_file , np .eye (4 ))
725
- init_xfms .append (xfm_file )
726
- else :
727
- for i in non_b0 :
728
- init_xfms .append (in_xfms [i ])
729
- return init_xfms
730
-
731
704
def _nonb0 (in_bval ):
732
705
import numpy as np
733
706
bvals = np .loadtxt (in_bval )
0 commit comments