I would like to interpolate many xarray datasets containig global climate data to one common grid. xarray actually has an interp() method which works fine, but as far as I can tell does not take any periodic boundries into account, although this is necessary when interpolating on a sphere. Instead, datapoints which are outside of the old grid are extrapolated or filled with NaNs. The interpolation is based on the scipy package, and I think other interpolation methods from scipy also do not support periodic boundaries.
I am considering using xesmf, but was wondering if there is an easier solution for this just using xarray?
I would prefer linear interpolation but am flexible in this regard.
Note that the xr_add_cyclic_points function in @markmuetz's answer can also be achieved using xarray's pad method:
ds_lon_wrapped = (
ds.pad(lon=1, mode="wrap")
.assign_coords(lon=ds.lon.pad(lon=1, mode="reflect", reflect_type="odd"))
.assign(lon_bnds=ds.lon_bnds.pad(lon=1, mode="reflect", reflect_type="odd"))
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With