Skip to content

sliding_window_ts

TimeSeriesSlidingWindow(window_size, *, features=None, stride=1, rechunk=True)

Bases: Transform

Convert single large time series into a set of smaller sub-series.

Applies a sliding window to each individual time series sample of all or selected time series features while leaving other features unchanged. As a result, the resulting data frame will contain multiple samples for each original sample, where each sample is a sub-series of the original time series. The number of features (columns) will remain the same. For this transform to work, all selected time series features of a sample must have the same time vector. Use a MatchSamplingRate or Resample transform to ensure this is the case.

Initializes the TimeSeriesSlidingWindow transform.

Parameters:

Name Type Description Default
window_size int

The size of the sliding window.

required
features str | Iterable[str] | None

The features to apply the sliding window to. If None, all time series features are selected.

None
stride int

The stride of the sliding window.

1
rechunk bool

Whether to rechunk the data after applying the transform. Rechunking improves performance of subsequent operations, but increases memory usage and may slow down the initial operation.

True
Source code in src/flowcean/polars/transforms/sliding_window_ts.py
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
def __init__(
    self,
    window_size: int,
    *,
    features: str | Iterable[str] | None = None,
    stride: int = 1,
    rechunk: bool = True,
) -> None:
    """Initializes the TimeSeriesSlidingWindow transform.

    Args:
        window_size: The size of the sliding window.
        features: The features to apply the sliding window to. If None, all
            time series features are selected.
        stride: The stride of the sliding window.
        rechunk: Whether to rechunk the data after applying the transform.
            Rechunking improves performance of subsequent operations, but
            increases memory usage and may slow down the initial operation.
    """
    self.window_size = window_size
    self.features = features
    self.stride = stride
    self.rechunk = rechunk