@@ -103,6 +103,11 @@ def get_opt_parser():
103
103
store the corresponding settings in the NIfTI header, unless
104
104
non-uniform scaling is used, in which case the data is
105
105
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.""" )))
106
111
p .add_option (
107
112
Option ("--overwrite" , action = "store_true" , dest = "overwrite" ,
108
113
default = False ,
@@ -171,12 +176,26 @@ def proc_file(infile, opts):
171
176
ornt = io_orientation (np .diag ([- 1 , 1 , 1 , 1 ]).dot (affine ))
172
177
if np .all (ornt == [[0 , 1 ],
173
178
[1 , 1 ],
174
- [2 , 1 ]]): # already in LAS+
179
+ [2 , 1 ]]): # already in LAS+
175
180
t_aff = np .eye (4 )
176
- else : # Not in LAS+
181
+ else : # Not in LAS+
177
182
t_aff = inv_ornt_aff (ornt , pr_img .shape )
178
183
affine = np .dot (affine , t_aff )
179
184
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
+
180
199
# Make corresponding NIfTI image
181
200
nimg = nifti1 .Nifti1Image (in_data , affine , pr_hdr )
182
201
nhdr = nimg .header
@@ -208,7 +227,6 @@ def proc_file(infile, opts):
208
227
209
228
# write out bvals/bvecs if requested
210
229
if opts .bvs :
211
- bvals , bvecs = pr_hdr .get_bvals_bvecs ()
212
230
if bvals is None and bvecs is None :
213
231
verbose ('No DTI volumes detected, bvals and bvecs not written' )
214
232
else :
0 commit comments