Shortcuts

torcheeg.io

EEGSignalIO

class torcheeg.io.EEGSignalIO(io_path: str, io_size: int = 1048576, io_mode: str = 'lmdb')[source][source]

Bases: object

A general-purpose, lightweight and efficient EEG signal IO APIs for converting various real-world EEG signal datasets into samples and storing them in the database. Here, we draw on the implementation ideas of industrial-grade application Caffe, and encapsulate a set of EEG signal reading and writing methods based on Lightning Memory-Mapped Database (LMDB), which not only unifies the differences of data types in different databases, but also accelerates the reading of data during training and testing.

eeg_io = EEGSignalIO('YOUR_PATH')
key = eeg_io.write_eeg(np.random.randn(32, 128))
eeg = eeg_io.read_eeg(key)
eeg.shape
>>> (32, 128)
Parameters:
  • io_path (str) – Where the database is stored.

  • io_size (int, optional) – The maximum capacity of the database. It will increase according to the size of the dataset. (default: 1024)

  • 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. Here, a file system based and a memory based EEG signal storages are 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)

eegs()[source][source]

Get all EEG signals in the EEGSignalIO.

Returns:

The list of EEG signals in the EEGSignalIO.

Return type:

list

keys()[source][source]

Get all keys in the EEGSignalIO.

Returns:

The list of keys in the EEGSignalIO.

Return type:

list

read_eeg(key: str) any[source][source]

Query the corresponding EEG signal in the database according to the index.

Parameters:

key (str) – The index of the EEG signal to be queried.

Returns:

The EEG signal sample.

Return type:

any

to_lmdb(io_path: str, io_size: int = 1048576)[source][source]

Convert to the LMDBEEGSignalIO, where the index of each sample in the database corresponds to the key, and the EEG signal stored in the database corresponds to the value.

to_memory()[source][source]

Convert to the MemoryEEGSignalIO, where the index of each sample in the database corresponds to the key, and the EEG signal stored in the database corresponds to the value.

to_pickle(io_path: str)[source][source]

Convert to the PickleEEGSignalIO, where the index of each sample in the database corresponds to the key, and the EEG signal stored in the database corresponds to the value.

write_eeg(eeg: any | Tensor, key: None | str = None) str[source][source]

Write EEG signal to database.

Parameters:
  • eeg (any) – EEG signal samples to be written into the database.

  • key (str, optional) – The key of the EEG signal to be inserted, if not specified, it will be an auto-incrementing integer.

Returns:

The index of written EEG signals in the database.

Return type:

int

MetaInfoIO

class torcheeg.io.MetaInfoIO(io_path: str)[source][source]

Bases: object

Use with torcheeg.io.EEGSignalIO to store description information for EEG signals in the form of a table, so that the user can still analyze, insert, delete and modify the corresponding information after the generation is completed.

info_io = MetaInfoIO('YOUR_PATH')
key = info_io.write_info({
    'clip_id': 0,
    'baseline_id': 1,
    'valence': 1.0,
    'arousal': 9.0
})
info = info_io.read_info(key).to_dict()
>>> {
        'clip_id': 0,
        'baseline_id': 1,
        'valence': 1.0,
        'arousal': 9.0
    }
Parameters:

io_path (str) – Where the table is stored.

read_all() DataFrame[source][source]

Get all EEG descriptions in the database in tabular form.

Returns:

The EEG descriptions.

Return type:

pd.DataFrame

read_info(key) DataFrame[source][source]

Query the corresponding EEG description in the table according to the index.

Parameters:

key (int) – The index of the EEG description to be queried.

Returns:

The EEG description.

Return type:

pd.DataFrame

write_info(obj: Dict) int[source][source]

Insert a description of the EEG signal.

Parameters:

obj (dict) – The description to be written into the table.

Returns:

The index of written EEG description in the table.

Return type:

int

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