@@ -87,6 +87,7 @@ def setUp(self):
8787 self ._wctx = warnings .catch_warnings ()
8888 self ._wctx .__enter__ ()
8989 warnings .filterwarnings ('ignore' , 'get_zooms' , FutureWarning )
90+ warnings .filterwarnings ('ignore' , 'set_zooms' , FutureWarning )
9091 warnings .filterwarnings ('ignore' , 'Unknown (spatial|time) units' ,
9192 UserWarning )
9293
@@ -770,6 +771,7 @@ def setUp(self):
770771 self ._wctx = warnings .catch_warnings ()
771772 self ._wctx .__enter__ ()
772773 warnings .filterwarnings ('ignore' , 'get_zooms' , FutureWarning )
774+ warnings .filterwarnings ('ignore' , 'set_zooms' , FutureWarning )
773775 warnings .filterwarnings ('ignore' , 'Unknown (spatial|time) units' ,
774776 UserWarning )
775777
@@ -1117,7 +1119,6 @@ def test_zooms_edge_cases(self):
11171119 aff = np .eye (4 )
11181120 img = img_klass (arr , aff )
11191121
1120-
11211122 # Unknown units = 2 warnings
11221123 with clear_and_catch_warnings () as warns :
11231124 warnings .simplefilter ('always' )
@@ -1160,16 +1161,37 @@ def test_zooms_edge_cases(self):
11601161 assert_array_almost_equal (img .header .get_zooms (units = 'norm' ),
11611162 (1 , 1 , 1 , 0.000001 ))
11621163
1163- # Verify `set_zooms(units='norm')` resets units
11641164 img .header .set_xyzt_units (xyz = 'meter' , t = 'usec' )
11651165 assert_equal (img .header .get_xyzt_units (), ('meter' , 'usec' ))
1166+
1167+ # Verify `set_zooms(units='raw')` leaves units unchanged
1168+ img .header .set_zooms ((2 , 2 , 2 , 2.5 ), units = 'raw' )
1169+ assert_array_almost_equal (img .header .get_zooms (units = 'norm' ),
1170+ (2000 , 2000 , 2000 , 0.0000025 ))
1171+ assert_array_almost_equal (img .header .get_zooms (units = 'raw' ),
1172+ (2 , 2 , 2 , 2.5 ))
1173+ assert_equal (img .header .get_xyzt_units (), ('meter' , 'usec' ))
1174+
1175+ # Verify `set_zooms(units=<tuple>)` sets units explicitly
1176+ img .header .set_zooms ((2 , 2 , 2 , 2.5 ), units = ('micron' , 'msec' ))
1177+ assert_array_almost_equal (img .header .get_zooms (units = 'norm' ),
1178+ (0.002 , 0.002 , 0.002 , 0.0025 ))
1179+ assert_array_almost_equal (img .header .get_zooms (units = 'raw' ),
1180+ (2 , 2 , 2 , 2.5 ))
1181+ assert_equal (img .header .get_xyzt_units (), ('micron' , 'msec' ))
1182+
1183+ # Verify `set_zooms(units='norm')` resets units
11661184 img .header .set_zooms ((2 , 2 , 2 , 2.5 ), units = 'norm' )
11671185 assert_array_almost_equal (img .header .get_zooms (units = 'norm' ),
11681186 (2 , 2 , 2 , 2.5 ))
11691187 assert_array_almost_equal (img .header .get_zooms (units = 'raw' ),
11701188 (2 , 2 , 2 , 2.5 ))
11711189 assert_equal (img .header .get_xyzt_units (), ('mm' , 'sec' ))
11721190
1191+ assert_raises (ValueError , img .header .get_zooms , units = 'badparam' )
1192+ assert_raises (ValueError , img .header .set_zooms , (3 , 3 , 3 , 3.5 ),
1193+ units = 'badparam' )
1194+
11731195
11741196class TestNifti1Image (TestNifti1Pair ):
11751197 # Run analyze-flavor spatialimage tests
0 commit comments