imod.select.points_indices#
- imod.select.points_indices(da, **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
imod.select.points_in_bounds
function to detect these points.- Parameters:
da (xr.DataArray) –
points (keyword arguments of coordinates and values) –
- Returns:
indices
- Return type:
dict of {coordinate: xr.DataArray with indices}
Examples
To extract values:
>>> x = [1.0, 2.2, 3.0] >>> y = [4.0, 5.6, 7.0] >>> indices = imod.select.points_indices(da, 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 = imod.select.points_indices(da, 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) >>> empty.data[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
imod.select.points_set_values()
function will take care of the dimensions.