Shortcuts

MNERawDataset

class torcheeg.datasets.MNERawDataset(raw_list: List, info_list: List, chunk_size: int = 3000, overlap: int = 0, online_transform: None | Callable = None, offline_transform: None | Callable = None, label_transform: None | Callable = None, io_path: None | str = None, io_size: int = 1048576, io_mode: str = 'lmdb', num_worker: int = 0, verbose: bool = True, **kwargs)[source][source]

Process a list of MNE Raw objects and corresponding information dictionaries. This dataset is particularly useful for working with pre-loaded MNE Raw objects, such as those obtained from various EEG datasets like Physionet EEG Motor Movement/Imagery Dataset.

The dataset splits the continuous EEG data into epochs based on the specified chunk size and overlap. Each epoch is associated with the corresponding information from the info_list.

import mne
from torcheeg.datasets import MNERawDataset
from torcheeg import transforms

subject_id = 22
event_codes = [5, 6, 9, 10, 13, 14]

physionet_paths = mne.datasets.eegbci.load_data(
    subject_id, event_codes, update_path=False)

# Load each of the files
raw_list = [mne.io.read_raw_edf(path, preload=True, stim_channel='auto')
         for path in physionet_paths]

info_list = [{"trial_id": event_code, "subject_id": subject_id}
                for event_code in event_codes]

dataset = MNERawDataset(raw_list=raw_list,
                        info_list=info_list,
                        chunk_size=500,
                        overlap=0,
                        online_transform=transforms.ToTensor(),
                        label_transform=transforms.Select('trial_id'))
Parameters:
  • raw_list (List) – A list of MNE Raw objects containing the EEG data.

  • info_list (List) – A list of dictionaries containing metadata for each Raw object. Each dictionary should correspond to the Raw object at the same index in raw_list.

  • chunk_size (int) – The size of each epoch in samples. (default: 3000)

  • overlap (int) – The number of overlapping samples between consecutive epochs. (default: 0)

  • online_transform (Callable, optional) – The transformation of the EEG signals and baseline EEG signals. The input is a np.ndarray, and the ouput is used as the first and second value of each element in the dataset. (default: None)

  • offline_transform (Callable, optional) – The usage is the same as online_transform, but executed before generating IO intermediate results. (default: None)

  • label_transform (Callable, optional) – The transformation of the label. The input is an information dictionary, and the ouput is used as the third value of each element in the dataset. (default: None)

  • io_path (str) – The path to generated unified data IO, cached as an intermediate result. If set to None, a random path will be generated. (default: None)

  • io_size (int) – Maximum size database may grow to; used to size the memory mapping. If database grows larger than map_size, an exception will be raised and the user must close and reopen. (default: 1048576)

  • io_mode (str) – Storage mode of EEG signal. When io_mode is set to lmdb, TorchEEG provides an efficient database (LMDB) for storing EEG signals. LMDB may not perform well on limited operating systems, where a file system based EEG signal storage is also provided. When io_mode is set to pickle, pickle-based persistence files are used. When io_mode is set to memory, memory are used. (default: lmdb)

  • num_worker (int) – Number of subprocesses to use for data loading. 0 means that the data will be loaded in the main process. (default: 0)

  • verbose (bool) – Whether to display logs during processing, such as progress bars, etc. (default: True)

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources