@@ -52,6 +52,7 @@ def script_test(func):
5252
5353DATA_PATH = abspath (pjoin (dirname (__file__ ), 'data' ))
5454
55+
5556@script_test
5657def test_nib_ls ():
5758 # test nib-ls script
@@ -84,7 +85,7 @@ def test_nib_nifti_dx():
8485
8586
8687def 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 ))
8889
8990
9091def check_conversion (cmd , pr_data , out_fname ):
@@ -184,7 +185,7 @@ def test_parrec2nii_with_data():
184185 par_root , ext = splitext (basename (par ))
185186 # NA.PAR appears to be a localizer, with three slices in each of
186187 # the three orientations: sagittal; coronal, transverse
187- if par_root == 'NA' :
188+ if par_root == 'NA' :
188189 continue
189190 # Do conversion
190191 run_command (['parrec2nii' , par ])
@@ -226,8 +227,12 @@ def test_parrec2nii_with_data():
226227 check_code = False )
227228 assert_equal (code , 1 )
228229 # 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 ])
230232 assert_almost_equal (np .loadtxt ('DTI.bvals' ), DTI_PAR_BVALS )
233+ img = load ('DTI.nii' )
234+ data = img .get_data ().copy ()
235+ del img
231236 # Bvecs in header, transposed from PSL to LPS
232237 bvecs_LPS = DTI_PAR_BVECS [:, [2 , 0 , 1 ]]
233238 # Adjust for output flip of Y axis in data and bvecs
@@ -247,3 +252,19 @@ def test_parrec2nii_with_data():
247252 with open ('DTI.dwell_time' , 'rt' ) as fobj :
248253 contents = fobj .read ().strip ()
249254 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