|
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,40 @@ 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 freq, phas, slic 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(freq, phas, slic) |
| 1428 | + fdir = 'RAS'[freq] if freq is not None else None |
| 1429 | + pdir = 'RAS'[phas] if phas is not None else None |
| 1430 | + sdir = 'RAS'[slic] if slic is not None else None |
| 1431 | + for axcode in axcodes: |
| 1432 | + ornt = axcodes2ornt(axcode) |
| 1433 | + rimg = simg.as_reoriented(ornt) |
| 1434 | + dirs = axcode.replace('P', 'A') # Polarity doesn't matter |
| 1435 | + new_freq, new_phas, new_slic = rimg.header.get_dim_info() |
| 1436 | + new_fdir = dirs[new_freq] if new_freq is not None else None |
| 1437 | + new_pdir = dirs[new_phas] if new_phas is not None else None |
| 1438 | + new_sdir = dirs[new_slic] if new_slic is not None else None |
| 1439 | + assert_equal((new_fdir, new_pdir, new_sdir), (fdir, pdir, sdir)) |
| 1440 | + |
1406 | 1441 |
|
1407 | 1442 | @runif_extra_has('slow')
|
1408 | 1443 | def test_large_nifti1():
|
|
0 commit comments