torcheeg.io
EEGSignalIO
- class torcheeg.io.EEGSignalIO(cache_path: str, cache_size: int = 1099511627776)[source]
Bases:
object
A general-purpose, lightweight and efficient EEG signal IO APIs for converting various real-world EEG signal datasets into
np.ndarray
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
cache_path (str) – Where the database is stored.
cache_size (int) – The maximum capacity of the database. (default:
1099511627776
)
- get_eeg_format() Tuple[ndarray, str] [source]
Get the sample data shapes and types acceptable to the database.
- Returns
the sample data shapes and types acceptable to the database.
- Return type
tuple(np.ndarray, str)
- read_eeg(key: str) ndarray [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
np.ndarray
- set_eeg_format(eeg: ndarray) None [source]
Set the sample data shapes and types acceptable to the database based on the inserted EEG signals.
- Parameters
eeg (np.ndarray) – The EEG signal sample to be written into the database.
- write_eeg(eeg: ndarray, key: Optional[str] = None) str [source]
Write EEG signal to database.
- Parameters
eeg (np.ndarray) – 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(cache_path: str)[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
cache_path (str) – Where the table is stored.
- read_all() DataFrame [source]
Get all EEG descriptions in the database in tabular form.
- Returns
The EEG descriptions.
- Return type
pd.DataFrame