|
148 | 148 | ] |
149 | 149 |
|
150 | 150 |
|
| 151 | +def _shuffle(arr): |
| 152 | + """Return a copy of the array with entries shuffled. |
| 153 | +
|
| 154 | + Needed to avoid a bug in np.random.shuffle for numpy 1.7. |
| 155 | + see: numpy/numpy#4286 |
| 156 | + """ |
| 157 | + return arr[np.argsort(np.random.randn(len(arr)))] |
| 158 | + |
| 159 | + |
151 | 160 | def test_top_level_load(): |
152 | 161 | # Test PARREC images can be loaded from nib.load |
153 | 162 | img = top_load(EG_PAR) |
@@ -285,7 +294,7 @@ def test_sorting_dual_echo_T1(): |
285 | 294 | t1_hdr = PARRECHeader.from_fileobj(fobj, strict_sort=True) |
286 | 295 |
|
287 | 296 | # should get the correct order even if we randomly shuffle the order |
288 | | - np.random.shuffle(t1_hdr.image_defs) |
| 297 | + t1_hdr.image_defs = _shuffle(t1_hdr.image_defs) |
289 | 298 |
|
290 | 299 | sorted_indices = t1_hdr.get_sorted_slice_indices() |
291 | 300 | sorted_echos = t1_hdr.image_defs['echo number'][sorted_indices] |
@@ -316,7 +325,7 @@ def test_sorting_multiple_echos_and_contrasts(): |
316 | 325 | t1_hdr = PARRECHeader.from_fileobj(fobj, strict_sort=True) |
317 | 326 |
|
318 | 327 | # should get the correct order even if we randomly shuffle the order |
319 | | - np.random.shuffle(t1_hdr.image_defs) |
| 328 | + t1_hdr.image_defs = _shuffle(t1_hdr.image_defs) |
320 | 329 |
|
321 | 330 | sorted_indices = t1_hdr.get_sorted_slice_indices() |
322 | 331 | sorted_slices = t1_hdr.image_defs['slice number'][sorted_indices] |
@@ -358,7 +367,7 @@ def test_sorting_multiecho_ASL(): |
358 | 367 | asl_hdr = PARRECHeader.from_fileobj(fobj, strict_sort=True) |
359 | 368 |
|
360 | 369 | # should get the correct order even if we randomly shuffle the order |
361 | | - np.random.shuffle(asl_hdr.image_defs) |
| 370 | + asl_hdr.image_defs = _shuffle(asl_hdr.image_defs) |
362 | 371 |
|
363 | 372 | sorted_indices = asl_hdr.get_sorted_slice_indices() |
364 | 373 | sorted_slices = asl_hdr.image_defs['slice number'][sorted_indices] |
@@ -486,7 +495,7 @@ def test_diffusion_parameters_strict_sort(): |
486 | 495 | dti_hdr = PARRECHeader.from_fileobj(fobj, strict_sort=True) |
487 | 496 |
|
488 | 497 | # should get the correct order even if we randomly shuffle the order |
489 | | - np.random.shuffle(dti_hdr.image_defs) |
| 498 | + dti_hdr.image_defs = _shuffle(dti_hdr.image_defs) |
490 | 499 |
|
491 | 500 | assert_equal(dti_hdr.get_data_shape(), (80, 80, 10, 8)) |
492 | 501 | assert_equal(dti_hdr.general_info['diffusion'], 1) |
|
0 commit comments