Closed aaronspring closed 3 years ago
I've always used this approach: https://github.com/bradyrx/esmtools/blob/master/esmtools/spatial.py (see extract_region
). I think it's fairly quick since it uses numpy to minimize the xy coordinate and find the closest index on the curvilinear grid to that coordinate pair. Then I use the indices for the corners of the box with .isel()
to extract the region.
do you think it would make sense adding this to the accessors? couldnt xgrid
and ygrid
be determined automatically xygrid
something with x or y by default? use grid.extract_region(ds, coords)
I'll reopen this. I think it would be nice to have it as accessors.
xarray will soon have this
Ocean output is often on curvilinear grids. Therefore the lon, lat info is not stored in x,y. I often just want to have a look at a certain lon, lat box.
This is a long standing xr issue: https://github.com/pydata/xarray/issues/2028 https://github.com/pydata/xarray/issues/1603 a few idea how to accomplish this but apparently some performance issues. The implemention with
to_index()
doesnt suit us becauselon(x,y)
andlat(x,y)
. I also tried to implement this withslice
but failed.Would you also need something like this @bradyrx ? Do you have any other ideas?
csel
could be a nice accessor forgrid