imod.select.points_indices#

imod.select.points_indices(da: DataArray | UgridDataArray, out_of_bounds: str = 'raise', **points) dict[str, DataArray][source]#

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

Not all points may be located in the bounds of the DataArray. By default, this function raises an error. This behavior can be controlled with the out_of_bounds argument. If out_of_bounds is set to “warn” or “ignore”, out of bounds point are removed. Which points have been removed is visible in the index coordinate of the resulting selection.

Parameters:
  • da (xarray.DataArray | xu.UgridDataArray)

  • out_of_bounds ({"raise", "warn", "ignore"}, default: "raise") – What to do if the points are not located in the bounds of the DataArray: - “raise”: raise an exception - “warn”: raise a warning, and ignore the missing points - “ignore”: ignore the missing points

  • 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.