2424
2525# It was created by the "OFS subsetter"
2626
27+
2728@pytest .mark .parametrize ("test_file" , RGRID_FILES )
2829def test_recognize (test_file ):
2930 """
@@ -77,8 +78,6 @@ def create_synthetic_rectangular_grid_dataset(decreasing=False):
7778 return ds
7879
7980
80-
81-
8281def test_grid_vars ():
8382 """
8483 Check if the grid vars are defined properly
@@ -88,7 +87,7 @@ def test_grid_vars():
8887 grid_vars = ds .xsg .grid_vars
8988
9089 # ['mesh', 'nv', 'lon', 'lat', 'lonc', 'latc']
91- assert grid_vars == {' lat' , ' lon' }
90+ assert grid_vars == {" lat" , " lon" }
9291
9392
9493def test_data_vars ():
@@ -106,27 +105,28 @@ def test_data_vars():
106105 # the extra "time" variables are not using the grid
107106 # so they should not be listed as data_vars
108107 assert data_vars == {
109- ' water_w' ,
110- ' salinity' ,
111- ' surf_roughness' ,
112- ' surf_temp_flux' ,
113- ' water_v' ,
108+ " water_w" ,
109+ " salinity" ,
110+ " surf_roughness" ,
111+ " surf_temp_flux" ,
112+ " water_v" ,
114113 # 'time_offset',
115- ' water_temp' ,
116- ' water_baro_v' ,
117- ' surf_atm_press' ,
118- ' surf_el' ,
119- ' surf_salt_flux' ,
120- ' water_u' ,
121- ' surf_wnd_stress_gridy' ,
122- ' water_baro_u' ,
123- ' watdep' ,
124- ' surf_solar_flux' ,
114+ " water_temp" ,
115+ " water_baro_v" ,
116+ " surf_atm_press" ,
117+ " surf_el" ,
118+ " surf_salt_flux" ,
119+ " water_u" ,
120+ " surf_wnd_stress_gridy" ,
121+ " water_baro_u" ,
122+ " watdep" ,
123+ " surf_solar_flux" ,
125124 # 'time1_run',
126- ' surf_wnd_stress_gridx' ,
125+ " surf_wnd_stress_gridx" ,
127126 # 'time1_offset'
128127 }
129128
129+
130130# might not be needed if tested elsewhere.
131131def test_data_vars2 ():
132132 """
@@ -141,7 +141,7 @@ def test_data_vars2():
141141 data_vars = ds .xsg .data_vars
142142 print (f"data_vars: { data_vars } " )
143143
144- assert data_vars == {' salt' , ' temp' }
144+ assert data_vars == {" salt" , " temp" }
145145
146146
147147def test_extra_vars ():
@@ -154,42 +154,43 @@ def test_extra_vars():
154154
155155 # the extra "time" variables are not using the grid
156156 # so they should be listed as extra_vars
157- assert extra_vars == {
158- 'time_offset' ,
159- 'time1_run' ,
160- 'time1_offset'
161- }
157+ assert extra_vars == {"time_offset" , "time1_run" , "time1_offset" }
158+
162159
163160def test_subset_to_bb ():
164161 """
165162 Not a complete test by any means, but the basics are there.
166163
167- NOTE: it doesn't test if the variables got subset corectly ...
164+ NOTE: it doesn't test if the variables got subset correctly ...
168165
169166 """
170167 ds = xr .open_dataset (EXAMPLE_DATA / "2D-rectangular_grid_wind.nc" )
171168
172- print ("initial bounds:" , ds ['lon' ].data .min (),
173- ds ['lat' ].data .min (),
174- ds ['lon' ].data .max (),
175- ds ['lat' ].data .max (),
176- )
169+ print (
170+ "initial bounds:" ,
171+ ds ["lon" ].data .min (),
172+ ds ["lat" ].data .min (),
173+ ds ["lon" ].data .max (),
174+ ds ["lat" ].data .max (),
175+ )
177176
178177 bbox = (- 0.5 , 0 , 0.5 , 0.5 )
179178
180179 ds2 = ds .xsg .subset_bbox (bbox )
181180
182- assert ds2 [' lat' ].size == 15
183- assert ds2 [' lon' ].size == 29
181+ assert ds2 [" lat" ].size == 15
182+ assert ds2 [" lon" ].size == 29
184183
185- new_bounds = (ds2 ['lon' ].data .min (),
186- ds2 ['lat' ].data .min (),
187- ds2 ['lon' ].data .max (),
188- ds2 ['lat' ].data .max (),
189- )
184+ new_bounds = (
185+ ds2 ["lon" ].data .min (),
186+ ds2 ["lat" ].data .min (),
187+ ds2 ["lon" ].data .max (),
188+ ds2 ["lat" ].data .max (),
189+ )
190190 print ("new bounds:" , new_bounds )
191191 assert new_bounds == bbox
192192
193+
193194def test_decreasing_latitude ():
194195 """
195196 Some datasets have the latitude or longitude decreasing: 10, 9, 8 etc.
@@ -200,27 +201,31 @@ def test_decreasing_latitude():
200201 """
201202 ds = xr .open_dataset (EXAMPLE_DATA / "rectangular_grid_decreasing.nc" )
202203
203- print ("initial bounds:" , ds ['lon' ].data .min (),
204- ds ['lat' ].data .min (),
205- ds ['lon' ].data .max (),
206- ds ['lat' ].data .max (),
207- )
204+ print (
205+ "initial bounds:" ,
206+ ds ["lon" ].data .min (),
207+ ds ["lat" ].data .min (),
208+ ds ["lon" ].data .max (),
209+ ds ["lat" ].data .max (),
210+ )
208211
209212 bbox = (- 0.5 , 0 , 0.5 , 0.5 )
210213
211214 ds2 = ds .xsg .subset_bbox (bbox )
212215
213- assert ds2 [' lat' ].size == 15
214- assert ds2 [' lon' ].size == 29
216+ assert ds2 [" lat" ].size == 15
217+ assert ds2 [" lon" ].size == 29
215218
216- new_bounds = (ds2 ['lon' ].data .min (),
217- ds2 ['lat' ].data .min (),
218- ds2 ['lon' ].data .max (),
219- ds2 ['lat' ].data .max (),
220- )
219+ new_bounds = (
220+ ds2 ["lon" ].data .min (),
221+ ds2 ["lat" ].data .min (),
222+ ds2 ["lon" ].data .max (),
223+ ds2 ["lat" ].data .max (),
224+ )
221225 print ("new bounds:" , new_bounds )
222226 assert new_bounds == bbox
223227
228+
224229def test_decreasing_coords ():
225230 """
226231 Redundant with above, but already written ...
@@ -239,20 +244,23 @@ def test_decreasing_coords():
239244 assert subset .sizes ["lat" ] > 0
240245 assert subset .sizes ["lon" ] > 0
241246
247+
242248def test_subset_polygon ():
243249 """
244250 Not a complete test by any means, but the basics are there.
245251
246- NOTE: it doesn't test if the variables got subset corectly ...
252+ NOTE: it doesn't test if the variables got subset correctly ...
247253
248254 """
249255 ds = xr .open_dataset (EXAMPLE_DATA / "2D-rectangular_grid_wind.nc" )
250256
251- print ("initial bounds:" , ds ['lon' ].data .min (),
252- ds ['lat' ].data .min (),
253- ds ['lon' ].data .max (),
254- ds ['lat' ].data .max (),
255- )
257+ print (
258+ "initial bounds:" ,
259+ ds ["lon" ].data .min (),
260+ ds ["lat" ].data .min (),
261+ ds ["lon" ].data .max (),
262+ ds ["lat" ].data .max (),
263+ )
256264
257265 poly = [(- 0.5 , 0.0 ), (0.0 , 0.5 ), (0.5 , 0.5 ), (0.5 , 0.0 ), (0 , 0.0 )]
258266 # this poly has this bounding box:
@@ -261,19 +269,19 @@ def test_subset_polygon():
261269
262270 ds2 = ds .xsg .subset_polygon (poly )
263271
264- assert ds2 [' lat' ].size == 15
265- assert ds2 [' lon' ].size == 29
272+ assert ds2 [" lat" ].size == 15
273+ assert ds2 [" lon" ].size == 29
266274
267- new_bounds = (ds2 ['lon' ].data .min (),
268- ds2 ['lat' ].data .min (),
269- ds2 ['lon' ].data .max (),
270- ds2 ['lat' ].data .max (),
271- )
275+ new_bounds = (
276+ ds2 ["lon" ].data .min (),
277+ ds2 ["lat" ].data .min (),
278+ ds2 ["lon" ].data .max (),
279+ ds2 ["lat" ].data .max (),
280+ )
272281 print ("new bounds:" , new_bounds )
273282 assert new_bounds == (- 0.5 , 0 , 0.5 , 0.5 )
274283
275284
276-
277285# def test_vertical_levels():
278286# ds = xr.open_dataset(EXAMPLE_DATA / "SFBOFS_subset1.nc")
279287# ds = ugrid.assign_ugrid_topology(ds, **grid_topology)
0 commit comments