|
28 | 28 | from nibabel.spatialimages import HeaderDataError
|
29 | 29 | from nibabel.tmpdirs import InTemporaryDirectory
|
30 | 30 | from ..freesurfer import load as mghload
|
| 31 | +from ..orientations import axcodes2ornt |
31 | 32 |
|
32 | 33 | from .test_arraywriters import rt_err_estimate, IUINT_TYPES
|
33 | 34 | from .test_helpers import bytesio_filemap, bytesio_round_trip
|
@@ -1403,6 +1404,38 @@ def test_rt_bias(self):
|
1403 | 1404 | bias_thresh = np.max([max_miss / np.sqrt(count), eps])
|
1404 | 1405 | assert_true(np.abs(bias) < bias_thresh)
|
1405 | 1406 |
|
| 1407 | + def test_reoriented_dim_info(self): |
| 1408 | + # Check that dim_info is reoriented correctly |
| 1409 | + arr = np.arange(24).reshape((2, 3, 4)) |
| 1410 | + # Start as RAS |
| 1411 | + aff = np.diag([2, 3, 4, 1]) |
| 1412 | + simg = self.single_class(arr, aff) |
| 1413 | + axcodes = ('RAS', 'RPS', # Include a flip |
| 1414 | + 'RSA', 'RSP', # Include a flip + reorientation |
| 1415 | + 'ARS', |
| 1416 | + 'ASR', |
| 1417 | + 'SRA', |
| 1418 | + 'SAR') |
| 1419 | + for info in ((0, 1, 2), |
| 1420 | + (0, 2, 1), |
| 1421 | + (None, None, None), |
| 1422 | + (0, 2, None), |
| 1423 | + (0, None, None), |
| 1424 | + (None, 2, 1), |
| 1425 | + (None, None, 1), |
| 1426 | + ): |
| 1427 | + simg.header.set_dim_info(*info) |
| 1428 | + for axcode in axcodes: |
| 1429 | + ornt = axcodes2ornt(axcode) |
| 1430 | + reorder = ornt[:, 0].astype(int) |
| 1431 | + rimg = simg.as_reoriented(ornt) |
| 1432 | + # Check shape and zooms to ensure the test is correct |
| 1433 | + assert_equal(simg.shape, tuple(np.array(rimg.shape)[reorder])) |
| 1434 | + assert_equal(simg.header.get_zooms(), |
| 1435 | + tuple(np.array(rimg.header.get_zooms())[reorder])) |
| 1436 | + assert_equal(simg.header.get_dim_info(), |
| 1437 | + tuple(np.array(rimg.header.get_dim_info())[reorder])) |
| 1438 | + |
1406 | 1439 |
|
1407 | 1440 | @runif_extra_has('slow')
|
1408 | 1441 | def test_large_nifti1():
|
|
0 commit comments