xarray.core.rolling.DatasetCoarsen.construct#
- DatasetCoarsen.construct(window_dim=None, keep_attrs=None, **window_dim_kwargs)[source]#
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 ofwindow_dim
.
- Returns:
Dataset
orDataArray with reshaped dimensions
Examples
>>> da = xr.DataArray(np.arange(24), dims="time") >>> da.coarsen(time=12).construct(time=("year", "month")) <xarray.DataArray (year: 2, month: 12)> Size: 192B array([[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]]) Dimensions without coordinates: year, month