Convert this rolling object to xr.DataArray, where the window dimension is stacked as a new dimension Parameters ---------- window_dim : Hashable or dict-like to Hashable, optional A mapping from dimension name to the new window dimension names.
(
self,
window_dim: Hashable | Mapping[Any, Hashable] | None = None,
*,
stride: int | Mapping[Any, int] = 1,
fill_value: Any = dtypes.NA,
keep_attrs: bool | None = None,
sliding_window_view_kwargs: Mapping[Any, Any] | None = None,
**window_dim_kwargs: Hashable,
)
| 325 | |
| 326 | @_deprecate_positional_args("v2024.11.0") |
| 327 | def construct( |
| 328 | self, |
| 329 | window_dim: Hashable | Mapping[Any, Hashable] | None = None, |
| 330 | *, |
| 331 | stride: int | Mapping[Any, int] = 1, |
| 332 | fill_value: Any = dtypes.NA, |
| 333 | keep_attrs: bool | None = None, |
| 334 | sliding_window_view_kwargs: Mapping[Any, Any] | None = None, |
| 335 | **window_dim_kwargs: Hashable, |
| 336 | ) -> DataArray: |
| 337 | """ |
| 338 | Convert this rolling object to xr.DataArray, |
| 339 | where the window dimension is stacked as a new dimension |
| 340 | |
| 341 | Parameters |
| 342 | ---------- |
| 343 | window_dim : Hashable or dict-like to Hashable, optional |
| 344 | A mapping from dimension name to the new window dimension names. |
| 345 | stride : int or mapping of int, default: 1 |
| 346 | Size of stride for the rolling window. |
| 347 | fill_value : default: dtypes.NA |
| 348 | Filling value to match the dimension size. |
| 349 | keep_attrs : bool, default: None |
| 350 | If True, the attributes (``attrs``) will be copied from the original |
| 351 | object to the new one. If False, the new object will be returned |
| 352 | without attributes. If None uses the global default. |
| 353 | sliding_window_view_kwargs : Mapping |
| 354 | Keyword arguments that should be passed to the underlying array type's |
| 355 | ``sliding_window_view`` function. |
| 356 | **window_dim_kwargs : Hashable, optional |
| 357 | The keyword arguments form of ``window_dim`` {dim: new_name, ...}. |
| 358 | |
| 359 | Returns |
| 360 | ------- |
| 361 | DataArray |
| 362 | a view of the original array. By default, the returned array is not writeable. |
| 363 | For numpy arrays, one can pass ``writeable=True`` in ``sliding_window_view_kwargs``. |
| 364 | |
| 365 | See Also |
| 366 | -------- |
| 367 | numpy.lib.stride_tricks.sliding_window_view |
| 368 | dask.array.lib.stride_tricks.sliding_window_view |
| 369 | |
| 370 | Notes |
| 371 | ----- |
| 372 | With dask arrays, it's possible to pass the ``automatic_rechunk`` kwarg as |
| 373 | ``sliding_window_view_kwargs={"automatic_rechunk": True}``. This controls |
| 374 | whether dask should automatically rechunk the output to avoid |
| 375 | exploding chunk sizes. Automatically rechunking is the default behaviour. |
| 376 | Importantly, each chunk will be a view of the data so large chunk sizes are |
| 377 | only safe if *no* copies are made later. |
| 378 | |
| 379 | Examples |
| 380 | -------- |
| 381 | >>> da = xr.DataArray(np.arange(8).reshape(2, 4), dims=("a", "b")) |
| 382 | |
| 383 | >>> rolling = da.rolling(b=3) |
| 384 | >>> rolling.construct("window_dim") |
nothing calls this directly
no test coverage detected