Shortcuts

torcheeg.io

EEGSignalIO

class torcheeg.io.EEGSignalIO(io_path: str, io_size: int = 10485760, 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: 10485760)

  • 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. (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

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

Read all the EEGSignalIO into memory, and index the specified EEG signal in memory with the given key.

Warning

This method will read all the data in EEGSignalIO into memory, which may cause memory overflow. Thus, it is only recommended for fast reading of small-scale datasets.

Parameters:

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

Returns:

The EEG signal sample.

Return type:

any

to_dict()[source][source]

Convert EEGSignalIO to an in-memory dictionary, 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.

Returns:

The dict of samples in the EEGSignalIO.

Return type:

dict

write_eeg(eeg: any | Tensor, key: str | None = 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

write_eeg_in_memory(eeg: any, key: str) None[source][source]

Write EEG signal to memory.

Warning

This method will write all the data in EEGSignalIO into memory, which may cause memory overflow. Thus, it is only recommended for fast reading of small-scale datasets.

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

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

property write_pointer

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

Read the Docs v: v1.1.0
Versions
latest
stable
v1.1.0
v1.0.11
v1.0.10
v1.0.9
v1.0.8.post1
v1.0.8
v1.0.7
v1.0.6
v1.0.4
v1.0.3
v1.0.2
v1.0.1
Downloads
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.

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