PlasmaCalcs.tools.xarray_tools.xarray_dimensions.xarray_squeeze_close

PlasmaCalcs.tools.xarray_tools.xarray_dimensions.xarray_squeeze_close(array, dim=None, tol=0.001, *, closeness_name='closeness_{dim}', keep=None, drop=True)
return array but drop redundant dims, with an tolerance when checking equality.
dims are redundant if all values are close along that dim.
Closeness check here is: (array.isel(dim=0)/array).std() < tol.
For each removed dim:
result will just use array.isel(dim=0).
result will add coord ‘closeness_{dim}’ == std(array.isel(dim=0)/array).
This is a much more aggressive version of array.squeeze():
all dims with size 1 are trivially redundant and will be dropped;
but here, additionally, all dims which are redundant in any way will be dropped.

NOTE: performs all closeness checks before dropping any dims.

dim: None, str, or list of strs
if provided, only consider dropping these dims.
tol: number
drops dim with tol > (array.isel(dim=0)/array).std().
closeness_name: None or str, default ‘closeness_{dim}’
add new coord with this name, with value == (array.isel(dim=0)/array).std(),
for each dim dropped. (smaller is closer.) (always 0 for dims of size 1.)
(closeness_{dim} value tells the pre-squeeze variation along that dim.)
None –> do not add this coord.
keep: None, str, or list of strs
if provided, do not consider dropping these dims.
(can provide dim or keep, but not both.)
drop: bool
whether to drop coord for size-1 redundant dims.
if False, will keep scalar coord for size-1 redundant dims.
See also: xarray_closeness