xarray_coarsened

PlasmaCalcs.tools.xarray_tools.xarray_dimensions.xarray_coarsened(array, dim, window_len, dim_coarse='window', dim_fine=None, *, assign_coarse_coords=False, boundary=UNSET, side=UNSET, stride=UNSET, fill_value=UNSET, keep_attrs=UNSET)

construct a coarsened version of array, where dim is coarsened by window_len,

and becomes two dims: dim_coarse and dim_fine.
Original dim coords will be associated with dim_coarse and dim_fine in the new array.
dim: str
dimension to coarsen.
if a non-dimension coordinate, will attempt to promote it to a dimension (e.g. via swap_dims).
window_len: int
length of the window to coarsen over.
dim_coarse: str, default ‘window’
name of coarse dimension; the i’th value here corresponds to the i’th window.
dim_fine: None or str
name of fine dimension; the j’th value here corresponds to the j’th element within a window.
if None, use ‘_’+dim, e.g. dim=’t’ –> dim_fine=’_t’.
assign_coarse_coords: bool or coords
coords to assign along the dim_coarse dimension.
True –> use np.arange.
False –> don’t assign coords.
boundary, side: UNSET or value
if provided (not UNSET), pass this value to coarsen().
boundary should be ‘exact’, ‘trim’, or ‘pad’.
side should be ‘left’ or ‘right’.
stride, fill_value, keep_attrs: UNSET or value
if provided (not UNSET), pass this value to construct().
docs for coarsen and construct are copied below, for convenience:
xarray.DataArray.coarsen
————————
Coarsen object for DataArrays.
Parameters
———-
dimmapping of hashable to int, optional
Mapping from the dimension name to the window size.
boundary{“exact”, “trim”, “pad”}, default: “exact”
If ‘exact’, a ValueError will be raised if dimension size is not a
multiple of the window size. If ‘trim’, the excess entries are
dropped. If ‘pad’, NA will be padded.

side : {“left”, “right”} or mapping of str to {“left”, “right”}, default: “left” coord_func : str or mapping of hashable to str, default: “mean”

function (name) that is applied to the coordinates,
or a mapping from coordinate name to function (name).
Returns
——-
core.rolling.DataArrayCoarsen
xr.core.rolling.DataArrayRolling.construct
——————————————
Convert this Coarsen object to a DataArray or Dataset,
where the coarsening dimension is split or reshaped to two
new dimensions.
Parameters
———-
window_dim: mapping
A mapping from existing dimension name to new dimension names.
The size of the second dimension will be the length of the
coarsening window.
keep_attrs: bool, optional
Preserve attributes if True
**window_dim_kwargs : {dim: new_name, …}
The keyword arguments form of `window_dim`.
Returns
——-
Dataset or DataArray with reshaped dimensions