I want to interpolate 2D lat/lon data to a list of points, with the lon dimension being periodic. If I naively do this using xarray, then any value beyond the maximum lon in my dataset (359.75) is set to nan. I have a solution that involves wrapping or padding the data: https://stackoverflow.com/a/73557332/54557, but would like to find something that didn’t involve copying the data values first. I had thought that xgcm might be able to handle this: https://stackoverflow.com/questions/73557652/using-xgcm-to-interpolate-2d-periodic-data-to-points, but it turns out it cannot. Does anyone know of an easy way of doing this?
If nearest-neighbor interpolation is enough for your case, you can use Xoak: Xarray extension for indexing irregular grids — xoak documentation either with the “'s2point” or “sklearn_geo_balltree” index. Although not optimal, it should work with regular grids too.
Thanks for this, but I need linear interpolation, so don’t think xoak
will work. I will be processing a fair bit of data so whatever solution would need to be comparable in terms of computation time to wrapping/padding the data (i.e. I’d need to benchmark both).
Would xESMF or Verde (Verde v1.7.0) work?
I have used xESMF before for regridding data, specifically coarsening from a high-resolution grid to a lower-resolution one. I do not think that it can handle interpolation to points, but I am not sure of this and would love to be proven wrong. I will investigate again…
As for Verde - I had not come across this before - thanks. Again, I will check it out. In a cursory search of the documentation, I cannot see how to do interpolation to points, and similarly to xESMF it seems to be more geared for grid-to-grid regridding (/interpolation). It looks very powerful though, and I like the idea of an API that allows chaining of operations etc., although it looks like a slightly different way of building an analysis pipeline and I would have to get my head round it properly.