@@ -103,6 +103,11 @@ def get_opt_parser():
103103 store the corresponding settings in the NIfTI header, unless
104104 non-uniform scaling is used, in which case the data is
105105 stored in the file in scaled form. Default: 'dv'""" )))
106+ p .add_option (
107+ Option ('--keep-trace' , action = "store_true" , dest = 'keep_trace' ,
108+ default = False ,
109+ help = one_line ("""Do not discard the diagnostic Philips DTI
110+ trace volume, if it exists in the data.""" )))
106111 p .add_option (
107112 Option ("--overwrite" , action = "store_true" , dest = "overwrite" ,
108113 default = False ,
@@ -171,12 +176,26 @@ def proc_file(infile, opts):
171176 ornt = io_orientation (np .diag ([- 1 , 1 , 1 , 1 ]).dot (affine ))
172177 if np .all (ornt == [[0 , 1 ],
173178 [1 , 1 ],
174- [2 , 1 ]]): # already in LAS+
179+ [2 , 1 ]]): # already in LAS+
175180 t_aff = np .eye (4 )
176- else : # Not in LAS+
181+ else : # Not in LAS+
177182 t_aff = inv_ornt_aff (ornt , pr_img .shape )
178183 affine = np .dot (affine , t_aff )
179184 in_data = apply_orientation (in_data , ornt )
185+
186+ bvals , bvecs = pr_hdr .get_bvals_bvecs ()
187+ if not opts .keep_trace : # discard Philips DTI trace if present
188+ if bvals is not None :
189+ bad_mask = np .logical_and (bvals != 0 , (bvecs == 0 ).all (axis = 1 ))
190+ if bad_mask .sum () > 0 :
191+ pl = 's' if bad_mask .sum () != 1 else ''
192+ verbose ('Removing %s DTI trace volume%s'
193+ % (bad_mask .sum (), pl ))
194+ good_mask = ~ bad_mask
195+ in_data = in_data [..., good_mask ]
196+ bvals = bvals [good_mask ]
197+ bvecs = bvecs [good_mask ]
198+
180199 # Make corresponding NIfTI image
181200 nimg = nifti1 .Nifti1Image (in_data , affine , pr_hdr )
182201 nhdr = nimg .header
@@ -208,7 +227,6 @@ def proc_file(infile, opts):
208227
209228 # write out bvals/bvecs if requested
210229 if opts .bvs :
211- bvals , bvecs = pr_hdr .get_bvals_bvecs ()
212230 if bvals is None and bvecs is None :
213231 verbose ('No DTI volumes detected, bvals and bvecs not written' )
214232 else :
0 commit comments