xarray_at_min_of

PlasmaCalcs.tools.xarray_tools.xarray_indexing.xarray_at_min_of(array, of, dim=None, *, promote_dims_if_needed=True)

return array values at locations of minimum of. Roughly: array.isel(of.argmin([dim])).

But, here is nicer, in a few ways:
(1) here doesn’t require array to have all dims in dim.
E.g., if array has dims ‘x’, ‘kmod’, and of has dims ‘kmod’, ‘kang’,
and dim=[‘kmod’, ‘kang’], it will be handled in the intuitive way. Roughly:
amin = of.argmin([‘kmod’, ‘kang’])
result = array.isel(kmod=amin[‘kmod’])
(2) here allows All-NaN slice in of.
all-nan slices in of will be filled with nan values in result.
E.g., if dims=[‘d0’, ‘d1’], of has dims [‘d0’, ‘d1’, ‘nmul’, ‘fluid’],
and of.isnull().all([‘d0’, ‘d1’]) when nmul index == 4 or 5, and fluid index == 2,
then result.isel(nmul=[4,5], fluid=2) will be filled with nan values.
array: xarray.DataArray or xarray.Dataset
array to get result values from.
of: xarray.DataArray
array to find minimum values in.
dim: None, str, or list of str
dim(s) along which to find the minimum values of of.
Takes the “simultaneous” minimum along all these dims, as per argmin(dims)
None –> use of.dims.
(if dim is a list with len==0, return array, unchanged.)
promote_dims_if_needed: bool
whether to promote non-dimension coords to dimensions.
if False, raise DimensionKeyError if any relevant coord is not already a dimension.