xarray_at_max_of
- PlasmaCalcs.tools.xarray_tools.xarray_indexing.xarray_at_max_of(array, of, dim=None, *, promote_dims_if_needed=True)
return array values at locations of maximum
of. Roughly: array.isel(of.argmax([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’, andofhas dims ‘kmod’, ‘kang’,and dim=[‘kmod’, ‘kang’], it will be handled in the intuitive way. Roughly:amax = of.argmax([‘kmod’, ‘kang’])result = array.isel(kmod=amax[‘kmod’])(2) here allows All-NaN slice inof.all-nan slices inofwill be filled with nan values in result.E.g., if dims=[‘d0’, ‘d1’],ofhas 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 maximum values in.
- dim: None, str, or list of str
- dim(s) along which to find the maximum values of
of.Takes the “simultaneous” maximum along all these dims, as per argmax(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.