@@ -147,6 +147,36 @@ def test_dataset(method):
147
147
)
148
148
149
149
150
+ @pytest .mark .parametrize ("method" , [None , "rasterize" , "iterate" , "exactextract" ])
151
+ def test_dataset_flat (method ):
152
+ ds = xr .tutorial .open_dataset ("eraint_uvz" ).isel (month = 0 ).isel (level = 0 )
153
+ world = gpd .read_file (geodatasets .get_path ("naturalearth land" ))
154
+ result = ds .xvec .zonal_stats (world .geometry , "longitude" , "latitude" , method = method )
155
+
156
+ if method in ["exactextract" , None ]:
157
+ xr .testing .assert_allclose (
158
+ xr .Dataset (
159
+ {
160
+ "z" : np .array (114857.63685302 ),
161
+ "u" : np .array (9.84182437 ),
162
+ "v" : np .array (- 0.00330402 ),
163
+ }
164
+ ),
165
+ result .mean (),
166
+ )
167
+ else :
168
+ xr .testing .assert_allclose (
169
+ xr .Dataset (
170
+ {
171
+ "z" : np .array (114302.08524294 ),
172
+ "u" : np .array (9.5196515 ),
173
+ "v" : np .array (0.29297792 ),
174
+ }
175
+ ),
176
+ result .drop_vars (["month" , "level" ]).mean (),
177
+ )
178
+
179
+
150
180
@pytest .mark .parametrize ("method" , [None , "rasterize" , "iterate" , "exactextract" ])
151
181
def test_dataarray (method ):
152
182
ds = xr .tutorial .open_dataset ("eraint_uvz" )
@@ -163,6 +193,24 @@ def test_dataarray(method):
163
193
assert result .mean () == pytest .approx (61367.76185577 )
164
194
165
195
196
+ @pytest .mark .parametrize ("method" , [None , "rasterize" , "iterate" , "exactextract" ])
197
+ def test_dataarray_flat (method ):
198
+ ds = xr .tutorial .open_dataset ("eraint_uvz" )
199
+ world = gpd .read_file (geodatasets .get_path ("naturalearth land" ))
200
+ result = (
201
+ ds .z .isel (month = 0 )
202
+ .isel (level = 0 )
203
+ .xvec .zonal_stats (world .geometry , "longitude" , "latitude" , method = method )
204
+ )
205
+
206
+ assert result .shape == (127 ,)
207
+ assert result .dims == ("geometry" ,)
208
+ if method in ["exactextract" , None ]:
209
+ assert result .mean () == pytest .approx (114857.63685302 )
210
+ else :
211
+ assert result .mean () == pytest .approx (114302.08524294 )
212
+
213
+
166
214
@pytest .mark .parametrize ("method" , [None , "rasterize" , "iterate" , "exactextract" ])
167
215
def test_stat (method ):
168
216
ds = xr .tutorial .open_dataset ("eraint_uvz" )
0 commit comments