braindecode.preprocessing.create_windows_from_events#

braindecode.preprocessing.create_windows_from_events(concat_ds, trial_start_offset_samples=0, trial_stop_offset_samples=0, 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', accepted_bads_ratio=0.0, n_jobs=1, verbose='error')[source]#

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. Defaults to zero.

  • trial_stop_offset_samples (int) – Stop offset from original trial stop, in samples. Defaults to zero.

  • 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 stride 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 False, 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.

  • preload (bool) – 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.

  • drop_bad_windows (bool) – 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.

  • accepted_bads_ratio (float, optional) – Acceptable proportion of trials with inconsistent length in a raw. If the number of trials whose length is exceeded by the window size is smaller than this, then only the corresponding trials are dropped, but the computation continues. Otherwise, an error is raised. Defaults to 0.0 (raise an error).

  • n_jobs (int) – Number of jobs to use to parallelize the windowing.

  • verbose (bool | str | int | None) – Control verbosity of the logging output when calling mne.Epochs.

Returns

windows_ds – Dataset containing the extracted windows.

Return type

WindowsDataset

Examples using braindecode.preprocessing.create_windows_from_events#

Split Dataset Example

Split Dataset Example

Split Dataset Example
Load and save dataset example

Load and save dataset example

Load and save dataset example
MOABB Dataset Example

MOABB Dataset Example

MOABB Dataset Example
Hyperparameter tuning with scikit-learn

Hyperparameter tuning with scikit-learn

Hyperparameter tuning with scikit-learn
Sleep staging on the Sleep Physionet dataset using U-Sleep network

Sleep staging on the Sleep Physionet dataset using U-Sleep network

Sleep staging on the Sleep Physionet dataset using U-Sleep network
Data Augmentation on BCIC IV 2a Dataset

Data Augmentation on BCIC IV 2a Dataset

Data Augmentation on BCIC IV 2a Dataset
Sleep staging on the Sleep Physionet dataset using Eldele2021

Sleep staging on the Sleep Physionet dataset using Eldele2021

Sleep staging on the Sleep Physionet dataset using Eldele2021
Sleep staging on the Sleep Physionet dataset using Chambon2018 network

Sleep staging on the Sleep Physionet dataset using Chambon2018 network

Sleep staging on the Sleep Physionet dataset using Chambon2018 network
Searching the best data augmentation on BCIC IV 2a Dataset

Searching the best data augmentation on BCIC IV 2a Dataset

Searching the best data augmentation on BCIC IV 2a Dataset
Trialwise Decoding on BCIC IV 2a Dataset

Trialwise Decoding on BCIC IV 2a Dataset

Trialwise Decoding on BCIC IV 2a Dataset
Cropped Decoding on BCIC IV 2a Dataset

Cropped Decoding on BCIC IV 2a Dataset

Cropped Decoding on BCIC IV 2a Dataset
Self-supervised learning on EEG with relative positioning

Self-supervised learning on EEG with relative positioning

Self-supervised learning on EEG with relative positioning
How to train, test and tune your model

How to train, test and tune your model

How to train, test and tune your model