@@ -87,6 +87,7 @@ def setUp(self):
87
87
self ._wctx = warnings .catch_warnings ()
88
88
self ._wctx .__enter__ ()
89
89
warnings .filterwarnings ('ignore' , 'get_zooms' , FutureWarning )
90
+ warnings .filterwarnings ('ignore' , 'set_zooms' , FutureWarning )
90
91
warnings .filterwarnings ('ignore' , 'Unknown (spatial|time) units' ,
91
92
UserWarning )
92
93
@@ -770,6 +771,7 @@ def setUp(self):
770
771
self ._wctx = warnings .catch_warnings ()
771
772
self ._wctx .__enter__ ()
772
773
warnings .filterwarnings ('ignore' , 'get_zooms' , FutureWarning )
774
+ warnings .filterwarnings ('ignore' , 'set_zooms' , FutureWarning )
773
775
warnings .filterwarnings ('ignore' , 'Unknown (spatial|time) units' ,
774
776
UserWarning )
775
777
@@ -1117,7 +1119,6 @@ def test_zooms_edge_cases(self):
1117
1119
aff = np .eye (4 )
1118
1120
img = img_klass (arr , aff )
1119
1121
1120
-
1121
1122
# Unknown units = 2 warnings
1122
1123
with clear_and_catch_warnings () as warns :
1123
1124
warnings .simplefilter ('always' )
@@ -1160,16 +1161,37 @@ def test_zooms_edge_cases(self):
1160
1161
assert_array_almost_equal (img .header .get_zooms (units = 'norm' ),
1161
1162
(1 , 1 , 1 , 0.000001 ))
1162
1163
1163
- # Verify `set_zooms(units='norm')` resets units
1164
1164
img .header .set_xyzt_units (xyz = 'meter' , t = 'usec' )
1165
1165
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
1166
1184
img .header .set_zooms ((2 , 2 , 2 , 2.5 ), units = 'norm' )
1167
1185
assert_array_almost_equal (img .header .get_zooms (units = 'norm' ),
1168
1186
(2 , 2 , 2 , 2.5 ))
1169
1187
assert_array_almost_equal (img .header .get_zooms (units = 'raw' ),
1170
1188
(2 , 2 , 2 , 2.5 ))
1171
1189
assert_equal (img .header .get_xyzt_units (), ('mm' , 'sec' ))
1172
1190
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
+
1173
1195
1174
1196
class TestNifti1Image (TestNifti1Pair ):
1175
1197
# Run analyze-flavor spatialimage tests
0 commit comments