@@ -52,6 +52,7 @@ def script_test(func):
52
52
53
53
DATA_PATH = abspath (pjoin (dirname (__file__ ), 'data' ))
54
54
55
+
55
56
@script_test
56
57
def test_nib_ls ():
57
58
# test nib-ls script
@@ -84,7 +85,7 @@ def test_nib_nifti_dx():
84
85
85
86
86
87
def vox_size (affine ):
87
- return np .sqrt (np .sum (affine [:3 ,:3 ] ** 2 , axis = 0 ))
88
+ return np .sqrt (np .sum (affine [:3 , :3 ] ** 2 , axis = 0 ))
88
89
89
90
90
91
def check_conversion (cmd , pr_data , out_fname ):
@@ -184,7 +185,7 @@ def test_parrec2nii_with_data():
184
185
par_root , ext = splitext (basename (par ))
185
186
# NA.PAR appears to be a localizer, with three slices in each of
186
187
# the three orientations: sagittal; coronal, transverse
187
- if par_root == 'NA' :
188
+ if par_root == 'NA' :
188
189
continue
189
190
# Do conversion
190
191
run_command (['parrec2nii' , par ])
@@ -226,8 +227,12 @@ def test_parrec2nii_with_data():
226
227
check_code = False )
227
228
assert_equal (code , 1 )
228
229
# Writes bvals, bvecs files if asked
229
- run_command (['parrec2nii' , '--overwrite' , '--bvs' , dti_par ])
230
+ run_command (['parrec2nii' , '--overwrite' , '--keep-trace' ,
231
+ '--bvs' , dti_par ])
230
232
assert_almost_equal (np .loadtxt ('DTI.bvals' ), DTI_PAR_BVALS )
233
+ img = load ('DTI.nii' )
234
+ data = img .get_data ().copy ()
235
+ del img
231
236
# Bvecs in header, transposed from PSL to LPS
232
237
bvecs_LPS = DTI_PAR_BVECS [:, [2 , 0 , 1 ]]
233
238
# Adjust for output flip of Y axis in data and bvecs
@@ -247,3 +252,19 @@ def test_parrec2nii_with_data():
247
252
with open ('DTI.dwell_time' , 'rt' ) as fobj :
248
253
contents = fobj .read ().strip ()
249
254
assert_almost_equal (float (contents ), exp_dwell )
255
+ # ensure trace is removed by default
256
+ run_command (['parrec2nii' , '--overwrite' , '--bvs' , dti_par ])
257
+ assert_true (exists ('DTI.bvals' ))
258
+ assert_true (exists ('DTI.bvecs' ))
259
+ img = load ('DTI.nii' )
260
+ bvecs_notrace = np .loadtxt ('DTI.bvecs' ).T
261
+ bvals_notrace = np .loadtxt ('DTI.bvals' )
262
+ data_notrace = img .get_data ().copy ()
263
+ assert_equal (data_notrace .shape [- 1 ], len (bvecs_notrace ))
264
+ del img
265
+ # ensure correct volume was removed
266
+ good_mask = np .logical_or ((bvecs_notrace != 0 ).any (axis = 1 ),
267
+ bvals_notrace == 0 )
268
+ assert_almost_equal (data_notrace , data [..., good_mask ])
269
+ assert_almost_equal (bvals_notrace , np .array (DTI_PAR_BVALS )[good_mask ])
270
+ assert_almost_equal (bvecs_notrace , bvecs_LAS [good_mask ])
0 commit comments