@@ -88,6 +88,7 @@ def setUp(self):
8888 self ._wctx = warnings .catch_warnings ()
8989 self ._wctx .__enter__ ()
9090 warnings .filterwarnings ('ignore' , 'get_zooms' , FutureWarning )
91+ warnings .filterwarnings ('ignore' , 'set_zooms' , FutureWarning )
9192 warnings .filterwarnings ('ignore' , 'Unknown (spatial|time) units' ,
9293 UserWarning )
9394
@@ -782,6 +783,7 @@ def setUp(self):
782783 self ._wctx = warnings .catch_warnings ()
783784 self ._wctx .__enter__ ()
784785 warnings .filterwarnings ('ignore' , 'get_zooms' , FutureWarning )
786+ warnings .filterwarnings ('ignore' , 'set_zooms' , FutureWarning )
785787 warnings .filterwarnings ('ignore' , 'Unknown (spatial|time) units' ,
786788 UserWarning )
787789
@@ -1206,7 +1208,6 @@ def test_zooms_edge_cases(self):
12061208 aff = np .eye (4 )
12071209 img = img_klass (arr , aff )
12081210
1209-
12101211 # Unknown units = 2 warnings
12111212 with clear_and_catch_warnings () as warns :
12121213 warnings .simplefilter ('always' )
@@ -1249,16 +1250,37 @@ def test_zooms_edge_cases(self):
12491250 assert_array_almost_equal (img .header .get_zooms (units = 'norm' ),
12501251 (1 , 1 , 1 , 0.000001 ))
12511252
1252- # Verify `set_zooms(units='norm')` resets units
12531253 img .header .set_xyzt_units (xyz = 'meter' , t = 'usec' )
12541254 assert_equal (img .header .get_xyzt_units (), ('meter' , 'usec' ))
1255+
1256+ # Verify `set_zooms(units='raw')` leaves units unchanged
1257+ img .header .set_zooms ((2 , 2 , 2 , 2.5 ), units = 'raw' )
1258+ assert_array_almost_equal (img .header .get_zooms (units = 'norm' ),
1259+ (2000 , 2000 , 2000 , 0.0000025 ))
1260+ assert_array_almost_equal (img .header .get_zooms (units = 'raw' ),
1261+ (2 , 2 , 2 , 2.5 ))
1262+ assert_equal (img .header .get_xyzt_units (), ('meter' , 'usec' ))
1263+
1264+ # Verify `set_zooms(units=<tuple>)` sets units explicitly
1265+ img .header .set_zooms ((2 , 2 , 2 , 2.5 ), units = ('micron' , 'msec' ))
1266+ assert_array_almost_equal (img .header .get_zooms (units = 'norm' ),
1267+ (0.002 , 0.002 , 0.002 , 0.0025 ))
1268+ assert_array_almost_equal (img .header .get_zooms (units = 'raw' ),
1269+ (2 , 2 , 2 , 2.5 ))
1270+ assert_equal (img .header .get_xyzt_units (), ('micron' , 'msec' ))
1271+
1272+ # Verify `set_zooms(units='norm')` resets units
12551273 img .header .set_zooms ((2 , 2 , 2 , 2.5 ), units = 'norm' )
12561274 assert_array_almost_equal (img .header .get_zooms (units = 'norm' ),
12571275 (2 , 2 , 2 , 2.5 ))
12581276 assert_array_almost_equal (img .header .get_zooms (units = 'raw' ),
12591277 (2 , 2 , 2 , 2.5 ))
12601278 assert_equal (img .header .get_xyzt_units (), ('mm' , 'sec' ))
12611279
1280+ assert_raises (ValueError , img .header .get_zooms , units = 'badparam' )
1281+ assert_raises (ValueError , img .header .set_zooms , (3 , 3 , 3 , 3.5 ),
1282+ units = 'badparam' )
1283+
12621284
12631285class TestNifti1Image (TestNifti1Pair ):
12641286 # Run analyze-flavor spatialimage tests
0 commit comments