imod.util.where#
- imod.util.where(condition, if_true, if_false, keep_nan: bool = True) DataArray [source]#
Wrapped version of xarray’s
.where
.This wrapped version does two differently:
Firstly, it prioritizes the dimensions as:
if_true > if_false > condition
.xarray.where(cond, a, b)
will choose the dimension overa
orb
. This may result in unwanted dimension orders such as("y", "x", "layer)
rather than("layer", "y', "x")
.Secondly, it preserves the NaN values of
if_true
by default. If we wish to replace all values over 5 by 5, yet keep the NoData parts, this requires two operations with with xarray’swhere
.- Parameters:
condition (DataArray, Dataset) – Locations at which to preserve this object’s values. dtype must be bool.
if_true (scalar, DataArray or Dataset, optional) – Value to use for locations where
cond
is True.if_false (scalar, DataArray or Dataset, optional) – Value to use for locations where
cond
is False.keep_nan (bool, default: True) – Whether to keep the NaN values in place of
if_true
.