xarray.core.rolling.DataArrayRolling.construct#
- DataArrayRolling.construct(window_dim=None, stride=1, fill_value=<NA>, keep_attrs=None, **window_dim_kwargs)[source]#
Convert this rolling object to xr.DataArray, where the window dimension is stacked as a new dimension
- Parameters
window_dim (
Hashable
or dict-like toHashable
, optional) – A mapping from dimension name to the new window dimension names.stride (
int
or mapping ofint
, default:1
) – Size of stride for the rolling window.fill_value (default:
dtypes.NA
) – Filling value to match the dimension size.keep_attrs (
bool
, default:None
) – If True, the attributes (attrs
) will be copied from the original object to the new one. If False, the new object will be returned without attributes. If None uses the global default.**window_dim_kwargs (
Hashable
, optional) – The keyword arguments form ofwindow_dim
{dim: new_name, …}.
- Returns
DataArray that is a view
ofthe original array. The returned array is
not writeable.
Examples
>>> da = xr.DataArray(np.arange(8).reshape(2, 4), dims=("a", "b"))
>>> rolling = da.rolling(b=3) >>> rolling.construct("window_dim") <xarray.DataArray (a: 2, b: 4, window_dim: 3)> Size: 192B array([[[nan, nan, 0.], [nan, 0., 1.], [ 0., 1., 2.], [ 1., 2., 3.]], [[nan, nan, 4.], [nan, 4., 5.], [ 4., 5., 6.], [ 5., 6., 7.]]]) Dimensions without coordinates: a, b, window_dim
>>> rolling = da.rolling(b=3, center=True) >>> rolling.construct("window_dim") <xarray.DataArray (a: 2, b: 4, window_dim: 3)> Size: 192B array([[[nan, 0., 1.], [ 0., 1., 2.], [ 1., 2., 3.], [ 2., 3., nan]], [[nan, 4., 5.], [ 4., 5., 6.], [ 5., 6., 7.], [ 6., 7., nan]]]) Dimensions without coordinates: a, b, window_dim