@@ -268,12 +268,16 @@ def test_get_sorted_slice_indices():
268
268
def test_sorting_dual_echo_T1 ():
269
269
# For this .PAR file, instead of getting 1 echo per volume, they get
270
270
# mixed up unless strict_sort=True
271
- dti_par = pjoin (DATA_PATH , 'T1_dual_echo.PAR' )
272
- with open (dti_par , 'rt' ) as fobj :
273
- dti_hdr = PARRECHeader .from_fileobj (fobj , strict_sort = True )
274
- sorted_indices = dti_hdr .get_sorted_slice_indices ()
275
- sorted_echos = dti_hdr .image_defs ['echo number' ][sorted_indices ]
276
- n_half = len (dti_hdr .image_defs ) // 2
271
+ t1_par = pjoin (DATA_PATH , 'T1_dual_echo.PAR' )
272
+ with open (t1_par , 'rt' ) as fobj :
273
+ t1_hdr = PARRECHeader .from_fileobj (fobj , strict_sort = True )
274
+
275
+ # should get the correct order even if we randomly shuffle the order
276
+ np .random .shuffle (t1_hdr .image_defs )
277
+
278
+ sorted_indices = t1_hdr .get_sorted_slice_indices ()
279
+ sorted_echos = t1_hdr .image_defs ['echo number' ][sorted_indices ]
280
+ n_half = len (t1_hdr .image_defs ) // 2
277
281
# first half (volume 1) should all correspond to echo 1
278
282
assert_equal (np .all (sorted_echos [:n_half ] == 1 ), True )
279
283
# second half (volume 2) should all correspond to echo 2
@@ -290,15 +294,19 @@ def test_sorting_multiple_echos_and_contrasts():
290
294
# Type 1, Echo 1, Slices 1-30
291
295
# ...
292
296
# Type 3, Echo 3, Slices 1-30
293
- dti_par = pjoin (DATA_PATH , 'T1_3echo_mag_real_imag_phase.PAR' )
294
- with open (dti_par , 'rt' ) as fobj :
295
- dti_hdr = PARRECHeader .from_fileobj (fobj , strict_sort = True )
296
- sorted_indices = dti_hdr .get_sorted_slice_indices ()
297
- sorted_slices = dti_hdr .image_defs ['slice number' ][sorted_indices ]
298
- sorted_echos = dti_hdr .image_defs ['echo number' ][sorted_indices ]
299
- sorted_types = dti_hdr .image_defs ['image_type_mr' ][sorted_indices ]
297
+ t1_par = pjoin (DATA_PATH , 'T1_3echo_mag_real_imag_phase.PAR' )
298
+ with open (t1_par , 'rt' ) as fobj :
299
+ t1_hdr = PARRECHeader .from_fileobj (fobj , strict_sort = True )
300
300
301
- ntotal = len (dti_hdr .image_defs )
301
+ # should get the correct order even if we randomly shuffle the order
302
+ np .random .shuffle (t1_hdr .image_defs )
303
+
304
+ sorted_indices = t1_hdr .get_sorted_slice_indices ()
305
+ sorted_slices = t1_hdr .image_defs ['slice number' ][sorted_indices ]
306
+ sorted_echos = t1_hdr .image_defs ['echo number' ][sorted_indices ]
307
+ sorted_types = t1_hdr .image_defs ['image_type_mr' ][sorted_indices ]
308
+
309
+ ntotal = len (t1_hdr .image_defs )
302
310
nslices = sorted_slices .max ()
303
311
nechos = sorted_echos .max ()
304
312
for slice_offset in range (ntotal // nslices ):
@@ -321,15 +329,19 @@ def test_sorting_multiple_echos_and_contrasts():
321
329
def test_sorting_multiecho_ASL ():
322
330
# For this .PAR file has 3 keys corresponding to volumes:
323
331
# 'echo number', 'label type', 'dynamic scan number'
324
- dti_par = pjoin (DATA_PATH , 'ASL_3D_Multiecho.PAR' )
325
- with open (dti_par , 'rt' ) as fobj :
326
- dti_hdr = PARRECHeader .from_fileobj (fobj , strict_sort = True )
327
- sorted_indices = dti_hdr .get_sorted_slice_indices ()
328
- sorted_slices = dti_hdr .image_defs ['slice number' ][sorted_indices ]
329
- sorted_echos = dti_hdr .image_defs ['echo number' ][sorted_indices ]
330
- sorted_dynamics = dti_hdr .image_defs ['dynamic scan number' ][sorted_indices ]
331
- sorted_labels = dti_hdr .image_defs ['label type' ][sorted_indices ]
332
- ntotal = len (dti_hdr .image_defs )
332
+ asl_par = pjoin (DATA_PATH , 'ASL_3D_Multiecho.PAR' )
333
+ with open (asl_par , 'rt' ) as fobj :
334
+ asl_hdr = PARRECHeader .from_fileobj (fobj , strict_sort = True )
335
+
336
+ # should get the correct order even if we randomly shuffle the order
337
+ np .random .shuffle (asl_hdr .image_defs )
338
+
339
+ sorted_indices = asl_hdr .get_sorted_slice_indices ()
340
+ sorted_slices = asl_hdr .image_defs ['slice number' ][sorted_indices ]
341
+ sorted_echos = asl_hdr .image_defs ['echo number' ][sorted_indices ]
342
+ sorted_dynamics = asl_hdr .image_defs ['dynamic scan number' ][sorted_indices ]
343
+ sorted_labels = asl_hdr .image_defs ['label type' ][sorted_indices ]
344
+ ntotal = len (asl_hdr .image_defs )
333
345
nslices = sorted_slices .max ()
334
346
nechos = sorted_echos .max ()
335
347
nlabels = sorted_labels .max ()
@@ -439,6 +451,10 @@ def test_diffusion_parameters_strict_sort():
439
451
dti_par = pjoin (DATA_PATH , 'DTI.PAR' )
440
452
with open (dti_par , 'rt' ) as fobj :
441
453
dti_hdr = PARRECHeader .from_fileobj (fobj , strict_sort = True )
454
+
455
+ # should get the correct order even if we randomly shuffle the order
456
+ np .random .shuffle (dti_hdr .image_defs )
457
+
442
458
assert_equal (dti_hdr .get_data_shape (), (80 , 80 , 10 , 8 ))
443
459
assert_equal (dti_hdr .general_info ['diffusion' ], 1 )
444
460
bvals , bvecs = dti_hdr .get_bvals_bvecs ()
0 commit comments