PlasmaCalcs.tools.xarray_tools.xarray_indexing.xarray_sort_array_along

PlasmaCalcs.tools.xarray_tools.xarray_indexing.xarray_sort_array_along(array, dim, newname='{dim}_sort', *, ascending=True, nkeep=None, index=False, store_original=False, newname_original='{dim}_orig', promote_dims_if_needed=True, squeeze_argsort=True, kind=None)
returns array, sorted along dim.
array: xarray.DataArray
array to sort.
dim: str
dimension along which to sort.
newname: str
result dim will be replaced by newname.format(dim=dim). Default: ‘{dim}_sort’.
ascending: bool
result sorted in ascending order if True, descending if False.
nkeep: None or int
number of sorted values to keep. E.g. nkeep=2 –> keep only the first 2 values.
equivalent to using result.isel(newdim=(0, nkeep)), where newdim=newname.format(dim=dim).
index: bool
whether to use indexes for result’s dim coord values, instead of original coord values.
Either way, the relevant coord is multidimensional, varying across all array.dims except dim.
True –> result[‘{dim}_index’] will be the indexes along original dim
False –> result[dim] will be the original coord values.
store_original: bool
whether to store original dim’s coord values in result.
True –> result will be a Dataset with data_vars array.name and ‘{dim}_orig’;
result[array.name] = sorted values (dims=array.dims but replace dim with newname.format(dim=dim))
result[‘{dim}_orig’] = original values of dim (dims=’{dim}_orig’)
False –> result will be a DataArray which does not track original dim’s coord values separately.
newname_original: str
name to use for original dim’s coord values if store_original=True. Default: ‘{dim}_orig’.
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.
squeeze_argsort: bool
whether to drop redundant dims for argsort result.
This means any dims with np.all(array==array.isel(dim=0)). (This includes dims with len=1.)
kind: None or str from {‘quicksort’, ‘mergesort’, ‘heapsort’, ‘stable’}
sorting algorithm. Passed directly to numpy.argsort; see help(numpy.argsort) for details.