Skip to content

Commit 5d96f5c

Browse files
committed
TEST: Explicitly test non-temporal t_units during set_zooms(units="norm")
1 parent 1620f31 commit 5d96f5c

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
@@ -1277,6 +1277,36 @@ def test_zooms_edge_cases(self):
12771277
(2, 2, 2, 2.5))
12781278
assert_equal(img.header.get_xyzt_units(), ('mm', 'sec'))
12791279

1280+
# Non-temporal t units are not transformed
1281+
img.header.set_zooms((1, 1, 1, 1.5), units=('mm', 'ppm'))
1282+
with clear_and_catch_warnings() as warns:
1283+
warnings.simplefilter('always')
1284+
assert_array_almost_equal(img.header.get_zooms(units='norm'),
1285+
(1, 1, 1, 1.5))
1286+
assert_equal(len(warns), 1)
1287+
assert_array_almost_equal(img.header.get_zooms(units='raw'),
1288+
(1, 1, 1, 1.5))
1289+
1290+
# Non-temporal t units are not normalized
1291+
img.header.set_zooms((2, 2, 2, 3.5), units='norm')
1292+
with clear_and_catch_warnings() as warns:
1293+
warnings.simplefilter('always')
1294+
assert_array_almost_equal(img.header.get_zooms(units='norm'),
1295+
(2, 2, 2, 3.5))
1296+
assert_equal(len(warns), 1)
1297+
assert_array_almost_equal(img.header.get_zooms(units='raw'),
1298+
(2, 2, 2, 3.5))
1299+
assert_equal(img.header.get_xyzt_units(), ('mm', 'ppm'))
1300+
1301+
# Unknown t units are normalized to seconds
1302+
img.header.set_xyzt_units(xyz='mm', t='unknown')
1303+
img.header.set_zooms((2, 2, 2, 3.5), units='norm')
1304+
assert_array_almost_equal(img.header.get_zooms(units='norm'),
1305+
(2, 2, 2, 3.5))
1306+
assert_array_almost_equal(img.header.get_zooms(units='raw'),
1307+
(2, 2, 2, 3.5))
1308+
assert_equal(img.header.get_xyzt_units(), ('mm', 'sec'))
1309+
12801310
assert_raises(ValueError, img.header.get_zooms, units='badparam')
12811311
assert_raises(ValueError, img.header.set_zooms, (3, 3, 3, 3.5),
12821312
units='badparam')

0 commit comments

Comments
 (0)