Skip to content

Commit a658173

Browse files
committed
TEST: Explicitly test non-temporal t_units during set_zooms(units="norm")
1 parent 75c88c5 commit a658173

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

nibabel/tests/test_nifti1.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,6 +1188,36 @@ def test_zooms_edge_cases(self):
11881188
(2, 2, 2, 2.5))
11891189
assert_equal(img.header.get_xyzt_units(), ('mm', 'sec'))
11901190

1191+
# Non-temporal t units are not transformed
1192+
img.header.set_zooms((1, 1, 1, 1.5), units=('mm', 'ppm'))
1193+
with clear_and_catch_warnings() as warns:
1194+
warnings.simplefilter('always')
1195+
assert_array_almost_equal(img.header.get_zooms(units='norm'),
1196+
(1, 1, 1, 1.5))
1197+
assert_equal(len(warns), 1)
1198+
assert_array_almost_equal(img.header.get_zooms(units='raw'),
1199+
(1, 1, 1, 1.5))
1200+
1201+
# Non-temporal t units are not normalized
1202+
img.header.set_zooms((2, 2, 2, 3.5), units='norm')
1203+
with clear_and_catch_warnings() as warns:
1204+
warnings.simplefilter('always')
1205+
assert_array_almost_equal(img.header.get_zooms(units='norm'),
1206+
(2, 2, 2, 3.5))
1207+
assert_equal(len(warns), 1)
1208+
assert_array_almost_equal(img.header.get_zooms(units='raw'),
1209+
(2, 2, 2, 3.5))
1210+
assert_equal(img.header.get_xyzt_units(), ('mm', 'ppm'))
1211+
1212+
# Unknown t units are normalized to seconds
1213+
img.header.set_xyzt_units(xyz='mm', t='unknown')
1214+
img.header.set_zooms((2, 2, 2, 3.5), units='norm')
1215+
assert_array_almost_equal(img.header.get_zooms(units='norm'),
1216+
(2, 2, 2, 3.5))
1217+
assert_array_almost_equal(img.header.get_zooms(units='raw'),
1218+
(2, 2, 2, 3.5))
1219+
assert_equal(img.header.get_xyzt_units(), ('mm', 'sec'))
1220+
11911221
assert_raises(ValueError, img.header.get_zooms, units='badparam')
11921222
assert_raises(ValueError, img.header.set_zooms, (3, 3, 3, 3.5),
11931223
units='badparam')

0 commit comments

Comments
 (0)