Skip to content

Commit b99ae4c

Browse files
committed
TEST: Check dim_info reorientation
1 parent 4f7d3d5 commit b99ae4c

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

nibabel/tests/test_nifti1.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from nibabel.spatialimages import HeaderDataError
2929
from nibabel.tmpdirs import InTemporaryDirectory
3030
from ..freesurfer import load as mghload
31+
from ..orientations import axcodes2ornt
3132

3233
from .test_arraywriters import rt_err_estimate, IUINT_TYPES
3334
from .test_helpers import bytesio_filemap, bytesio_round_trip
@@ -1403,6 +1404,38 @@ def test_rt_bias(self):
14031404
bias_thresh = np.max([max_miss / np.sqrt(count), eps])
14041405
assert_true(np.abs(bias) < bias_thresh)
14051406

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+
14061439

14071440
@runif_extra_has('slow')
14081441
def test_large_nifti1():

0 commit comments

Comments
 (0)