192192]
193193
194194
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-
204195def test_top_level_load ():
205196 # Test PARREC images can be loaded from nib.load
206197 img = top_load (EG_PAR )
@@ -332,7 +323,7 @@ def test_sorting_dual_echo_T1():
332323 t1_hdr = PARRECHeader .from_fileobj (fobj , strict_sort = True )
333324
334325 # 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 )
336327
337328 sorted_indices = t1_hdr .get_sorted_slice_indices ()
338329 sorted_echos = t1_hdr .image_defs ['echo number' ][sorted_indices ]
@@ -363,7 +354,7 @@ def test_sorting_multiple_echos_and_contrasts():
363354 t1_hdr = PARRECHeader .from_fileobj (fobj , strict_sort = True )
364355
365356 # 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 )
367358
368359 sorted_indices = t1_hdr .get_sorted_slice_indices ()
369360 sorted_slices = t1_hdr .image_defs ['slice number' ][sorted_indices ]
@@ -402,7 +393,7 @@ def test_sorting_multiecho_ASL():
402393 asl_hdr = PARRECHeader .from_fileobj (fobj , strict_sort = True )
403394
404395 # 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 )
406397
407398 sorted_indices = asl_hdr .get_sorted_slice_indices ()
408399 sorted_slices = asl_hdr .image_defs ['slice number' ][sorted_indices ]
@@ -524,7 +515,7 @@ def test_diffusion_parameters_strict_sort():
524515 dti_hdr = PARRECHeader .from_fileobj (fobj , strict_sort = True )
525516
526517 # 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 )
528519
529520 assert dti_hdr .get_data_shape () == (80 , 80 , 10 , 8 )
530521 assert dti_hdr .general_info ['diffusion' ] == 1
@@ -533,7 +524,10 @@ def test_diffusion_parameters_strict_sort():
533524 # DTI_PAR_BVECS gives bvecs copied from first slice each vol in DTI.PAR
534525 # Permute to match bvec directions to acquisition directions
535526 # 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+ )
537531 # Check q vectors
538532 assert_almost_equal (dti_hdr .get_q_vectors (), bvals [:, None ] * bvecs )
539533
0 commit comments