@@ -85,6 +85,7 @@ def setUp(self):
85
85
self ._wctx = warnings .catch_warnings ()
86
86
self ._wctx .__enter__ ()
87
87
warnings .filterwarnings ('ignore' , 'get_zooms' , FutureWarning )
88
+ warnings .filterwarnings ('ignore' , 'set_zooms' , FutureWarning )
88
89
warnings .filterwarnings ('ignore' , 'Unknown (spatial|time) units' ,
89
90
UserWarning )
90
91
@@ -779,6 +780,7 @@ def setUp(self):
779
780
self ._wctx = warnings .catch_warnings ()
780
781
self ._wctx .__enter__ ()
781
782
warnings .filterwarnings ('ignore' , 'get_zooms' , FutureWarning )
783
+ warnings .filterwarnings ('ignore' , 'set_zooms' , FutureWarning )
782
784
warnings .filterwarnings ('ignore' , 'Unknown (spatial|time) units' ,
783
785
UserWarning )
784
786
@@ -1129,7 +1131,6 @@ def test_zooms_edge_cases(self):
1129
1131
aff = np .eye (4 )
1130
1132
img = img_klass (arr , aff )
1131
1133
1132
-
1133
1134
# Unknown units = 2 warnings
1134
1135
with clear_and_catch_warnings () as warns :
1135
1136
warnings .simplefilter ('always' )
@@ -1172,16 +1173,37 @@ def test_zooms_edge_cases(self):
1172
1173
assert_array_almost_equal (img .header .get_zooms (units = 'norm' ),
1173
1174
(1 , 1 , 1 , 0.000001 ))
1174
1175
1175
- # Verify `set_zooms(units='norm')` resets units
1176
1176
img .header .set_xyzt_units (xyz = 'meter' , t = 'usec' )
1177
1177
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
1178
1196
img .header .set_zooms ((2 , 2 , 2 , 2.5 ), units = 'norm' )
1179
1197
assert_array_almost_equal (img .header .get_zooms (units = 'norm' ),
1180
1198
(2 , 2 , 2 , 2.5 ))
1181
1199
assert_array_almost_equal (img .header .get_zooms (units = 'raw' ),
1182
1200
(2 , 2 , 2 , 2.5 ))
1183
1201
assert_equal (img .header .get_xyzt_units (), ('mm' , 'sec' ))
1184
1202
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
+
1185
1207
1186
1208
class TestNifti1Image (TestNifti1Pair ):
1187
1209
# Run analyze-flavor spatialimage tests
0 commit comments