Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

interpolation periodic boundaries with xarray

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.

like image 684
P Keil Avatar asked Jan 01 '26 02:01

P Keil


1 Answers

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"))
)
like image 138
ogb119 Avatar answered Jan 03 '26 16:01

ogb119



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!