@@ -85,6 +85,7 @@ def setUp(self):
8585 self ._wctx = warnings .catch_warnings ()
8686 self ._wctx .__enter__ ()
8787 warnings .filterwarnings ('ignore' , 'get_zooms' , FutureWarning )
88+ warnings .filterwarnings ('ignore' , 'set_zooms' , FutureWarning )
8889 warnings .filterwarnings ('ignore' , 'Unknown (spatial|time) units' ,
8990 UserWarning )
9091
@@ -779,6 +780,7 @@ def setUp(self):
779780 self ._wctx = warnings .catch_warnings ()
780781 self ._wctx .__enter__ ()
781782 warnings .filterwarnings ('ignore' , 'get_zooms' , FutureWarning )
783+ warnings .filterwarnings ('ignore' , 'set_zooms' , FutureWarning )
782784 warnings .filterwarnings ('ignore' , 'Unknown (spatial|time) units' ,
783785 UserWarning )
784786
@@ -1129,7 +1131,6 @@ def test_zooms_edge_cases(self):
11291131 aff = np .eye (4 )
11301132 img = img_klass (arr , aff )
11311133
1132-
11331134 # Unknown units = 2 warnings
11341135 with clear_and_catch_warnings () as warns :
11351136 warnings .simplefilter ('always' )
@@ -1172,16 +1173,37 @@ def test_zooms_edge_cases(self):
11721173 assert_array_almost_equal (img .header .get_zooms (units = 'norm' ),
11731174 (1 , 1 , 1 , 0.000001 ))
11741175
1175- # Verify `set_zooms(units='norm')` resets units
11761176 img .header .set_xyzt_units (xyz = 'meter' , t = 'usec' )
11771177 assert_equal (img .header .get_xyzt_units (), ('meter' , 'usec' ))
1178+
1179+ # Verify `set_zooms(units='raw')` leaves units unchanged
1180+ img .header .set_zooms ((2 , 2 , 2 , 2.5 ), units = 'raw' )
1181+ assert_array_almost_equal (img .header .get_zooms (units = 'norm' ),
1182+ (2000 , 2000 , 2000 , 0.0000025 ))
1183+ assert_array_almost_equal (img .header .get_zooms (units = 'raw' ),
1184+ (2 , 2 , 2 , 2.5 ))
1185+ assert_equal (img .header .get_xyzt_units (), ('meter' , 'usec' ))
1186+
1187+ # Verify `set_zooms(units=<tuple>)` sets units explicitly
1188+ img .header .set_zooms ((2 , 2 , 2 , 2.5 ), units = ('micron' , 'msec' ))
1189+ assert_array_almost_equal (img .header .get_zooms (units = 'norm' ),
1190+ (0.002 , 0.002 , 0.002 , 0.0025 ))
1191+ assert_array_almost_equal (img .header .get_zooms (units = 'raw' ),
1192+ (2 , 2 , 2 , 2.5 ))
1193+ assert_equal (img .header .get_xyzt_units (), ('micron' , 'msec' ))
1194+
1195+ # Verify `set_zooms(units='norm')` resets units
11781196 img .header .set_zooms ((2 , 2 , 2 , 2.5 ), units = 'norm' )
11791197 assert_array_almost_equal (img .header .get_zooms (units = 'norm' ),
11801198 (2 , 2 , 2 , 2.5 ))
11811199 assert_array_almost_equal (img .header .get_zooms (units = 'raw' ),
11821200 (2 , 2 , 2 , 2.5 ))
11831201 assert_equal (img .header .get_xyzt_units (), ('mm' , 'sec' ))
11841202
1203+ assert_raises (ValueError , img .header .get_zooms , units = 'badparam' )
1204+ assert_raises (ValueError , img .header .set_zooms , (3 , 3 , 3 , 3.5 ),
1205+ units = 'badparam' )
1206+
11851207
11861208class TestNifti1Image (TestNifti1Pair ):
11871209 # Run analyze-flavor spatialimage tests
0 commit comments