-
Notifications
You must be signed in to change notification settings - Fork 3
Closed
Description
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.
def cslice(ds, cx='lon', xmin=0, xmax=360, cy='lat', ymin=0, ymax=90):
"""Subselect from non-dimensional coordinates.
Args:
ds (xro): large xarray object with dim non-dim coords `cx` and `cy`.
cx (str): coordinate name in x direction. Defaults to 'lon'.
xmin (int, float): minimum x coordinate. Defaults to 0.
xmax (int, float): maximum x coordinate. Defaults to 360.
cy (str): coordinate name in y direction. Defaults to 'lat'.
ymin (int, float): minimum y coordinate. Defaults to 0.
ymax (int, float): maximum y coordinate. Defaults to 90.
Returns:
xro: subset of input ds.
"""
assert xmin < xmax
assert ymin < ymax
ds_sub = ds.where((ds[cx] >= xmin) & (ds[cx] <= xmax))
ds_sub = ds_sub.where((ds[cy] >= ymin) & (ds[cy] <= ymax))
return ds_sub
This is a long standing xr issue: pydata/xarray#2028 pydata/xarray#1603 a few idea how to accomplish this but apparently some performance issues. The implemention with to_index()
doesnt suit us because lon(x,y)
and lat(x,y)
.
I also tried to implement this with slice
but failed.
Would you also need something like this @bradyrx ? Do you have any other ideas? csel
could be a nice accessor for grid
Metadata
Metadata
Assignees
Labels
No labels