File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed
Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change 1+ from pathlib import Path
2+
3+ import pytest
4+ import xarray as xr
5+
6+ import xarray_regrid
7+
8+ DATA_PATH = Path (__file__ ).parent .parent / "benchmarks" / "data"
9+
10+ CDO_DATA = {
11+ "linear" : DATA_PATH / "cdo_bilinear_64b.nc" ,
12+ "nearest" : DATA_PATH / "cdo_nearest_64b.nc" ,
13+ }
14+
15+ @pytest .fixture
16+ def sample_input_data () -> xr .Dataset :
17+ return xr .open_dataset (DATA_PATH / "era5_2m_dewpoint_temperature_2000_monthly.nc" )
18+
19+ @pytest .fixture
20+ def sample_grid_ds ():
21+ grid = xarray_regrid .Grid (
22+ north = 90 ,
23+ east = 180 ,
24+ south = 45 ,
25+ west = 90 ,
26+ resolution_lat = 0.17 ,
27+ resolution_lon = 0.17 ,
28+ )
29+
30+ return xarray_regrid .create_regridding_dataset (grid )
31+
32+ @pytest .mark .parametrize (
33+ "method, cdo_file" , [
34+ ("linear" , CDO_DATA ["linear" ]),
35+ ("nearest" , CDO_DATA ["nearest" ]),
36+ ])
37+ def test_regridder (sample_input_data , sample_grid_ds , method , cdo_file ):
38+ ds_regrid = sample_input_data .regrid .regrid (sample_grid_ds , method = method )
39+ ds_cdo = xr .open_dataset (cdo_file )
40+ xr .testing .assert_allclose (ds_regrid .compute (), ds_cdo .compute ())
You can’t perform that action at this time.
0 commit comments