Skip to content

Commit 7af6e72

Browse files
committed
TEST: Explicitly test non-temporal t_units during set_zooms(units="norm")
1 parent 82e74d4 commit 7af6e72

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
@@ -1200,6 +1200,36 @@ def test_zooms_edge_cases(self):
12001200
(2, 2, 2, 2.5))
12011201
assert_equal(img.header.get_xyzt_units(), ('mm', 'sec'))
12021202

1203+
# Non-temporal t units are not transformed
1204+
img.header.set_zooms((1, 1, 1, 1.5), units=('mm', 'ppm'))
1205+
with clear_and_catch_warnings() as warns:
1206+
warnings.simplefilter('always')
1207+
assert_array_almost_equal(img.header.get_zooms(units='norm'),
1208+
(1, 1, 1, 1.5))
1209+
assert_equal(len(warns), 1)
1210+
assert_array_almost_equal(img.header.get_zooms(units='raw'),
1211+
(1, 1, 1, 1.5))
1212+
1213+
# Non-temporal t units are not normalized
1214+
img.header.set_zooms((2, 2, 2, 3.5), units='norm')
1215+
with clear_and_catch_warnings() as warns:
1216+
warnings.simplefilter('always')
1217+
assert_array_almost_equal(img.header.get_zooms(units='norm'),
1218+
(2, 2, 2, 3.5))
1219+
assert_equal(len(warns), 1)
1220+
assert_array_almost_equal(img.header.get_zooms(units='raw'),
1221+
(2, 2, 2, 3.5))
1222+
assert_equal(img.header.get_xyzt_units(), ('mm', 'ppm'))
1223+
1224+
# Unknown t units are normalized to seconds
1225+
img.header.set_xyzt_units(xyz='mm', t='unknown')
1226+
img.header.set_zooms((2, 2, 2, 3.5), units='norm')
1227+
assert_array_almost_equal(img.header.get_zooms(units='norm'),
1228+
(2, 2, 2, 3.5))
1229+
assert_array_almost_equal(img.header.get_zooms(units='raw'),
1230+
(2, 2, 2, 3.5))
1231+
assert_equal(img.header.get_xyzt_units(), ('mm', 'sec'))
1232+
12031233
assert_raises(ValueError, img.header.get_zooms, units='badparam')
12041234
assert_raises(ValueError, img.header.set_zooms, (3, 3, 3, 3.5),
12051235
units='badparam')

0 commit comments

Comments
 (0)