@@ -88,6 +88,7 @@ def setUp(self):
88
88
self ._wctx = warnings .catch_warnings ()
89
89
self ._wctx .__enter__ ()
90
90
warnings .filterwarnings ('ignore' , 'get_zooms' , FutureWarning )
91
+ warnings .filterwarnings ('ignore' , 'set_zooms' , FutureWarning )
91
92
warnings .filterwarnings ('ignore' , 'Unknown (spatial|time) units' ,
92
93
UserWarning )
93
94
@@ -782,6 +783,7 @@ def setUp(self):
782
783
self ._wctx = warnings .catch_warnings ()
783
784
self ._wctx .__enter__ ()
784
785
warnings .filterwarnings ('ignore' , 'get_zooms' , FutureWarning )
786
+ warnings .filterwarnings ('ignore' , 'set_zooms' , FutureWarning )
785
787
warnings .filterwarnings ('ignore' , 'Unknown (spatial|time) units' ,
786
788
UserWarning )
787
789
@@ -1206,7 +1208,6 @@ def test_zooms_edge_cases(self):
1206
1208
aff = np .eye (4 )
1207
1209
img = img_klass (arr , aff )
1208
1210
1209
-
1210
1211
# Unknown units = 2 warnings
1211
1212
with clear_and_catch_warnings () as warns :
1212
1213
warnings .simplefilter ('always' )
@@ -1249,16 +1250,37 @@ def test_zooms_edge_cases(self):
1249
1250
assert_array_almost_equal (img .header .get_zooms (units = 'norm' ),
1250
1251
(1 , 1 , 1 , 0.000001 ))
1251
1252
1252
- # Verify `set_zooms(units='norm')` resets units
1253
1253
img .header .set_xyzt_units (xyz = 'meter' , t = 'usec' )
1254
1254
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
1255
1273
img .header .set_zooms ((2 , 2 , 2 , 2.5 ), units = 'norm' )
1256
1274
assert_array_almost_equal (img .header .get_zooms (units = 'norm' ),
1257
1275
(2 , 2 , 2 , 2.5 ))
1258
1276
assert_array_almost_equal (img .header .get_zooms (units = 'raw' ),
1259
1277
(2 , 2 , 2 , 2.5 ))
1260
1278
assert_equal (img .header .get_xyzt_units (), ('mm' , 'sec' ))
1261
1279
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
+
1262
1284
1263
1285
class TestNifti1Image (TestNifti1Pair ):
1264
1286
# Run analyze-flavor spatialimage tests
0 commit comments