Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

indexing at a single point #37

Open
dcherian opened this issue Mar 13, 2021 · 1 comment
Open

indexing at a single point #37

dcherian opened this issue Mar 13, 2021 · 1 comment

Comments

@dcherian
Copy link

dcherian commented Mar 13, 2021

import numpy as np
import xarray as xr
import xoak

shape = (100, 100)
lat = np.random.uniform(-90, 90, size=shape)
lon = np.random.uniform(-180, 180, size=shape)

field = lat + lon
ds_mesh = xr.Dataset(
    coords={'lat': (('x', 'y'), lat), 'lon': (('x', 'y'), lon)},
    data_vars={'field': (('x', 'y'), field)},
).expand_dims(z=10)

ds_mesh.xoak.set_index(("lat", "lon"), "scipy_kdtree")

This does not work

ds_mesh.xoak.sel(lat=50, lon=50)

This workaround does what I want:

tempdim = "__xoak_points__"

ds_mesh.xoak.sel(
    lon=xr.Variable(tempdim, [50]), lat=xr.Variable(tempdim, [50])
).squeeze(tempdim)

Would you be open to adding this workaround?

@benbovy
Copy link
Member

benbovy commented May 4, 2021

Sorry for the late reply @dcherian!

Yes, I think it would be nice to support selection of a single point with something more convenient than the workaround you've shown.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants