PlasmaCalcs.tools.xarray_tools.xarray_indexing.xarray_max_coord_where

PlasmaCalcs.tools.xarray_tools.xarray_indexing.xarray_max_coord_where(array, coord, where, *, promote_dims_if_needed=True)
return (array of) maximum value(s) of coord, where condition is True.
array: xarray.DataArray
array to find maximum value in.
coord: str
coord whose maximum value will appear in the result.
Must correspond with a single dimension of array.
where: xarray.DataArray or callable
locations at which to consider values of coord.
callable –> use where=where(array)
(will promote coord to dim first, if coord not dim yet.)
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.
Example:
xarray_max_coord_where(growth, ‘kmod’, lambda arr: arr>0)
# returns the maximum value(s) of kmod across all regions where growth>0.
# (result has no ‘kmod’ dim, but does retain any other dims from array.)
Compare to xarray_cmax(growth.where(growth>0), ‘kmod’),
which tells the value of kmod at the location of max growth (where growth>0)
(but not necessarily the maximum kmod across all regions with growth>0).