torcheeg.io¶
A set of unified input and output API is used to store the processing results of various EEG databases for more efficient and convenient use.
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 topickle
, 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: Union[any, Tensor], key: Optional[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
- 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