xarray_squeeze_close
- PlasmaCalcs.tools.xarray_tools.xarray_dimensions.xarray_squeeze_close(array, dim=None, tol=0.001, *, closeness_as='coords', 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.(Special case: if array.isel(dim=0) is all 0s, closeness=0 if array is all 0, else inf.)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 strsif provided, only consider dropping these dims.tol: numberdrops dim with tol >= (array.isel(dim=0)/array).std().Use tol=0 to only drop dims with exactly 0 variation along them,i.e., only dims with all(array.isel(dim=0) == array).closeness_as: ‘coords’, ‘attrs’, or Nonewhere to put information about closeness == pre-squeeze variation along each dim,for each dim dropped. (closeness = array.isel(dim=0)/array).std())(smaller is closer.) (always 0 for dims of size 1.)‘coords’ –> put info in result.coords‘attrs’ –> put info in result.attrsNone –> do not include closeness values in the result.closeness_name: str, default ‘closeness_{dim}’name for closeness info (seecloseness_asabove for details).keep: None, str, or list of strsif provided, do not consider dropping these dims.(can provide dim or keep, but not both.)drop: boolwhether to drop coord for size-1 redundant dims.if False, will keep scalar coord for size-1 redundant dims.See also: xarray_closeness