xarray.core.rolling.DataArrayCoarsen.construct#

DataArrayCoarsen.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 of window_dim.

Returns:

Dataset or DataArray 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)>
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