192
192
]
193
193
194
194
195
- def _shuffle (arr ):
196
- """Return a copy of the array with entries shuffled.
197
-
198
- Needed to avoid a bug in np.random.shuffle for numpy 1.7.
199
- see: numpy/numpy#4286
200
- """
201
- return arr [np .argsort (np .random .randn (len (arr )))]
202
-
203
-
204
195
def test_top_level_load ():
205
196
# Test PARREC images can be loaded from nib.load
206
197
img = top_load (EG_PAR )
@@ -332,7 +323,7 @@ def test_sorting_dual_echo_T1():
332
323
t1_hdr = PARRECHeader .from_fileobj (fobj , strict_sort = True )
333
324
334
325
# should get the correct order even if we randomly shuffle the order
335
- t1_hdr . image_defs = _shuffle (t1_hdr .image_defs )
326
+ np . random . shuffle (t1_hdr .image_defs )
336
327
337
328
sorted_indices = t1_hdr .get_sorted_slice_indices ()
338
329
sorted_echos = t1_hdr .image_defs ['echo number' ][sorted_indices ]
@@ -363,7 +354,7 @@ def test_sorting_multiple_echos_and_contrasts():
363
354
t1_hdr = PARRECHeader .from_fileobj (fobj , strict_sort = True )
364
355
365
356
# should get the correct order even if we randomly shuffle the order
366
- t1_hdr . image_defs = _shuffle (t1_hdr .image_defs )
357
+ np . random . shuffle (t1_hdr .image_defs )
367
358
368
359
sorted_indices = t1_hdr .get_sorted_slice_indices ()
369
360
sorted_slices = t1_hdr .image_defs ['slice number' ][sorted_indices ]
@@ -402,7 +393,7 @@ def test_sorting_multiecho_ASL():
402
393
asl_hdr = PARRECHeader .from_fileobj (fobj , strict_sort = True )
403
394
404
395
# should get the correct order even if we randomly shuffle the order
405
- asl_hdr . image_defs = _shuffle (asl_hdr .image_defs )
396
+ np . random . shuffle (asl_hdr .image_defs )
406
397
407
398
sorted_indices = asl_hdr .get_sorted_slice_indices ()
408
399
sorted_slices = asl_hdr .image_defs ['slice number' ][sorted_indices ]
@@ -524,7 +515,7 @@ def test_diffusion_parameters_strict_sort():
524
515
dti_hdr = PARRECHeader .from_fileobj (fobj , strict_sort = True )
525
516
526
517
# should get the correct order even if we randomly shuffle the order
527
- dti_hdr . image_defs = _shuffle (dti_hdr .image_defs )
518
+ np . random . shuffle (dti_hdr .image_defs )
528
519
529
520
assert dti_hdr .get_data_shape () == (80 , 80 , 10 , 8 )
530
521
assert dti_hdr .general_info ['diffusion' ] == 1
@@ -533,7 +524,10 @@ def test_diffusion_parameters_strict_sort():
533
524
# DTI_PAR_BVECS gives bvecs copied from first slice each vol in DTI.PAR
534
525
# Permute to match bvec directions to acquisition directions
535
526
# note that bval sorting occurs prior to bvec sorting
536
- assert_almost_equal (bvecs , DTI_PAR_BVECS [np .ix_ (np .argsort (DTI_PAR_BVALS ), [2 , 0 , 1 ])])
527
+ assert_almost_equal (
528
+ bvecs ,
529
+ DTI_PAR_BVECS [np .ix_ (np .argsort (DTI_PAR_BVALS , kind = 'stable' ), [2 , 0 , 1 ])],
530
+ )
537
531
# Check q vectors
538
532
assert_almost_equal (dti_hdr .get_q_vectors (), bvals [:, None ] * bvecs )
539
533
0 commit comments