Skip to content

Commit c13756d

Browse files
committed
TEST: Check world direction of encoding remains consistent
1 parent 4f7d3d5 commit c13756d

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

nibabel/tests/test_nifti1.py

Lines changed: 35 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,40 @@ 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 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+
14061441

14071442
@runif_extra_has('slow')
14081443
def test_large_nifti1():

0 commit comments

Comments
 (0)