Skip to content

Selecting point closest to (lon0, lat0) when lon,lat coordinates are 2D #10157

Open
@rsignell

Description

@rsignell

It's very common to want to extract a time series at a specified coordinate location, and I'm wondering whether xarray could support this directly without using xoak. Currently I'm using xoak, as in this reproducible example:

import xarray as xr
import intake
import xoak

intake_catalog_url = 'https://usgs-coawst.s3.amazonaws.com/useast-archive/coawst_intake.yml'
cat = intake.open_catalog(intake_catalog_url)
ds = cat['COAWST-USEAST'].to_dask()

lat, lon = 42.5, -70.0  # Gulf of Maine, 100km east of Boston, MA

da = ds['Hwave']
da.xoak.set_index(['lat_rho', 'lat_rho'], 'scipy_kdtree')
ds_point = xr.Dataset({"lon": ("point", [lon]), "lat": ("point", [lat])})
da.xoak.sel(lat_rho=ds_point.lat, lon_rho=ds_point.lon).sel(ocean_time='2012-10-01')

which produces:

Image

Would it be possible to enable this in xarray or is this too specific a functionality to consider?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions