, **points)[source]#

Get the indices for points as defined by the arrays x and y.

This function will raise a ValueError if the points fall outside of the bounds of the DataArray to avoid undefined behavior. Use the function to detect these points.

  • da (xr.DataArray) –

  • points (keyword arguments of coordinates and values) –



Return type:

dict of {coordinate: xr.DataArray with indices}


To extract values:

>>> x = [1.0, 2.2, 3.0]
>>> y = [4.0, 5.6, 7.0]
>>> indices =, x=x, y=y)
>>> ind_y = indices["y"]
>>> ind_x = indices["x"]
>>> selection = da.isel(x=ind_x, y=ind_y)

Or shorter, using dictionary unpacking:

>>> indices =, x=x, y=y)
>>> selection = da.isel(**indices)

To set values (in a new array), the following will do the trick:

>>> empty = xr.full_like(da, np.nan)
>>>[indices["y"].values, indices["x"].values] = values_to_set

Unfortunately, at the time of writing, xarray’s .sel method does not support setting values yet. The method here works for both numpy and dask arrays, but you’ll have to manage dimensions yourself!

The function will take care of the dimensions.