pyeeg.utils.chunk_data

pyeeg.utils.chunk_data(data, window_size, overlap_size=0, padding=False, win_as_samples=True)

Nd array version of shift_array().

Splits the data into (overlapping) windows along the first axis using the NumPy as_strided trick. win_as_samples controls the ordering of the first two axes of the output.

Parameters:
  • data (ndarray (nsamples, nchannels) or (nsamples,)) – Data to chunk. Must be at most 2D.

  • window_size (int) – Number of samples in one window.

  • overlap_size (int) – Number of samples overlapping between consecutive windows (0 means no overlap, default 0).

  • padding (bool) – Whether to edge-pad the data so that all samples are covered by a window (default False). If False, trailing samples that do not fit in a full window are dropped.

  • win_as_samples (bool) – If True (default), the output has shape (num_windows, window_size, nchannels); if False, the output has shape (window_size, num_windows, nchannels).

Returns:

chunks – View of the data reshaped into overlapping windows. The exact shape depends on win_as_samples (see above).

Return type:

ndarray

Notes

Please note that we expect first dim as our axis on which to apply the rolling window. Calling mean(axis=0)() works if win_as_samples is set to False, otherwise use mean(axis=1)().