# braindecode.datautil.create_windows_from_events¶

braindecode.datautil.create_windows_from_events(concat_ds, trial_start_offset_samples, trial_stop_offset_samples, window_size_samples=None, window_stride_samples=None, drop_last_window=False, mapping=None, preload=False, drop_bad_windows=True, picks=None, reject=None, flat=None, on_missing='error')

Create windows based on events in mne.Raw.

This function extracts windows of size window_size_samples in the interval [trial onset + trial_start_offset_samples, trial onset + trial duration + trial_stop_offset_samples] around each trial, with a separation of window_stride_samples between consecutive windows. If the last window around an event does not end at trial_stop_offset_samples and drop_last_window is set to False, an additional overlapping window that ends at trial_stop_offset_samples is created.

Windows are extracted from the interval defined by the following:

trial onset +

trial onset duration

|--------------------|——————————|---------------------| trial onset - trial onset + trial_start_offset_samples duration +

trial_stop_offset_samples

Parameters
concat_ds: BaseConcatDataset

A concat of base datasets each holding raw and description.

trial_start_offset_samples: int

Start offset from original trial onsets, in samples.

trial_stop_offset_samples: int

Stop offset from original trial stop, in samples.

window_size_samples: int | None

Window size. If None, the window size is inferred from the original trial size of the first trial and trial_start_offset_samples and trial_stop_offset_samples.

window_stride_samples: int | None

Stride between windows, in samples. If None, the window size is inferred from the original trial size of the first trial and trial_start_offset_samples and trial_stop_offset_samples.

drop_last_window: bool

If True, an additional overlapping window that ends at trial_stop_offset_samples will be extracted around each event when the last window does not end exactly at trial_stop_offset_samples.

mapping: dict(str: int)

Mapping from event description to numerical target value.

If True, preload the data of the Epochs objects. This is useful to reduce disk reading overhead when returning windows in a training scenario, however very large data might not fit into memory.

If True, call .drop_bad() on the resulting mne.Epochs object. This step allows identifying e.g., windows that fall outside of the continuous recording. It is suggested to run this step here as otherwise the BaseConcatDataset has to be updated as well.

picks: str | list | slice | None

Channels to include. If None, all available channels are used. See mne.Epochs.

reject: dict | None

Epoch rejection parameters based on peak-to-peak amplitude. If None, no rejection is done based on peak-to-peak amplitude. See mne.Epochs.

flat: dict | None

Epoch rejection parameters based on flatness of signals. If None, no rejection based on flatness is done. See mne.Epochs.

on_missing: str

What to do if one or several event ids are not found in the recording. Valid keys are ‘error’ | ‘warning’ | ‘ignore’. See mne.Epochs.

Returns
windows_ds: WindowsDataset

Dataset containing the extracted windows.