JiaweiZhuang / xESMF

Universal Regridder for Geospatial Data
http://xesmf.readthedocs.io/
MIT License
269 stars 49 forks source link

regridder with dask is failing when multi-variables with differing dimensions #109

Open ahuang11 opened 3 years ago

ahuang11 commented 3 years ago
import xesmf as xe
import xarray as xr
air =  xr.tutorial.open_dataset('air_temperature').chunk({'time': 20}).sortby('lat')
airl = xr.merge([air, xr.concat([air.assign_coords({'lev': [1]}), air.assign_coords({'lev': [2]})], 'lev').rename({'air': 'airl'})])
regridder = xe.Regridder(
    airl,
    xr.Dataset(coords=dict({
        'lat': np.arange(air['lat'].min(), air['lat'].max(), 0.5),
        'lon': np.arange(air['lon'].min(), air['lon'].max(), 0.5)
    })), 'bilinear'
)
print(airl)
regridder(airl.chunk({'lev': -1}))
<xarray.Dataset>
Dimensions:  (lat: 25, lev: 2, lon: 53, time: 2920)
Coordinates:
  * lat      (lat) float32 15.0 17.5 20.0 22.5 25.0 ... 65.0 67.5 70.0 72.5 75.0
  * lon      (lon) float32 200.0 202.5 205.0 207.5 ... 322.5 325.0 327.5 330.0
  * time     (time) datetime64[ns] 2013-01-01 ... 2014-12-31T18:00:00
  * lev      (lev) int64 1 2
Data variables:
    air      (time, lat, lon) float32 dask.array<chunksize=(20, 25, 53), meta=np.ndarray>
    airl     (lev, time, lat, lon) float32 dask.array<chunksize=(1, 20, 25, 53), meta=np.ndarray>
~/anaconda3/envs/py3/lib/python3.7/site-packages/xesmf/frontend.py:486: FutureWarning: ``output_sizes`` should be given in the ``dask_gufunc_kwargs`` parameter. It will be removed as direct parameter in a future version.
  keep_attrs=keep_attrs

ValueError: dimension 'dim1' in 'output_sizes' must correspond to output_core_dims

airl.chunk({'lev': -1}).apply(regridder) works though

chdzero commented 3 years ago

Hi, When I use xesmf to do interpolation. get the issue(which list below). The same mistake as yours.Some code from my side: import xarray as xr import xesmf as xe import numpy as np import matplotlib.pyplot as plt import cartopy.crs as ccrs url = 'http://dapds00.nci.org.au/thredds/dodsC/rr3/CMIP5/output1/CSIRO-BOM/ACCESS1-3/historical/mon/atmos/Amon/r1i1p1/latest/tas/tas_Amon_ACCESS1-3_historical_r1i1p1_185001-200512.nc' ds = xr.open_dataset(url) ds1 = ds['tas'] ds_out = xr.Dataset({'lat': (['lat'], np.arange(-90, 90, 2.5)), 'lon': (['lon'], np.arange(0, 360, 2.5)), } ) regridder = xe.Regridder(ds, ds_out, 'bilinear')

~/anaconda3/envs/xesmf1/lib/python3.7/site-packages/xesmf/frontend.py:478: FutureWarning: output_sizes should be given in the dask_gufunc_kwargs parameter. It will be removed as direct parameter in a future version.Could you tell me how to solve it? Thanks keep_attrs=keep_attrs,