pyhealth.datasets.EEGBCIDataset#
- class pyhealth.datasets.EEGBCIDataset(root, dataset_name=None, config_path=None, subjects=None, runs=None, download=False, **kwargs)[source]#
Bases:
BaseDatasetPhysioNet EEG Motor Movement/Imagery metadata dataset.
The source dataset is PhysioNet’s EEG Motor Movement/Imagery Dataset (
eegmmidb), version 1.0.0, licensed under the Open Data Commons Attribution License v1.0. Cite Schalk (2009), https://doi.org/10.13026/C28G6P.- Parameters:
root (
str) – Directory containing or receiving EEGBCI EDF files and metadata.dataset_name (
Optional[str]) – Optional dataset name prefix. Defaults to"eegbci".config_path (
Optional[str]) – Optional dataset configuration path.subjects (
Optional[list[int]]) – Subject identifiers to include. Defaults to[1, 2, 3].runs (
Optional[list[int]]) – Run identifiers to include. Defaults to runs 3 through 14.download (
bool) – Whether MNE may download missing EDF files.**kwargs – Additional arguments forwarded to
BaseDataset.
- Raises:
FileNotFoundError – If a requested EDF is unavailable and downloading is disabled.
Examples
>>> dataset = EEGBCIDataset( ... root="/path/to/eegbci", subjects=[1], runs=[3], download=True ... ) >>> dataset.stats()
- prepare_metadata()[source]#
Reuse valid metadata or write rows for every requested EDF.
- Raises:
FileNotFoundError – If a requested EDF is unavailable and downloading is disabled.
- Return type:
- property default_task: EEGMotorImageryEEGBCI#
Return the canonical supervised EEGBCI task.
- Return type:
- Returns:
An
EEGMotorImageryEEGBCItask.
- create_tmpdir()#
Creates and returns a new temporary directory within the cache.
- Returns:
The path to the new temporary directory.
- Return type:
- get_patient(patient_id)#
Retrieves a Patient object for the given patient ID.
- Parameters:
patient_id (str) – The ID of the patient to retrieve.
- Returns:
The Patient object for the given ID.
- Return type:
- Raises:
AssertionError – If the patient ID is not found in the dataset.
- property global_event_df: LazyFrame#
Returns the path to the cached event dataframe.
- Returns:
The path to the cached event dataframe.
- Return type:
- iter_patients(df=None)#
Yields Patient objects for each unique patient in the dataset.
- load_data()#
Loads data from the specified tables.
- Returns:
A concatenated lazy frame of all tables.
- Return type:
dd.DataFrame
- load_table(table_name)#
Loads a table and processes joins if specified.
- Parameters:
table_name (str) – The name of the table to load.
- Returns:
The processed Dask dataframe for the table.
- Return type:
dd.DataFrame
- Raises:
ValueError – If the table is not found in the config.
FileNotFoundError – If the CSV file for the table or join is not found.
- set_task(task=None, num_workers=None, input_processors=None, output_processors=None)#
Processes the base dataset to generate the task-specific sample dataset. The cache structure is as follows:
{task_name}_{task_uuid}/ # Cached data for specific task based on task name, schema, and args task_df.ld/ # Intermediate task dataframe based on schema samples_{proc_uuid}.ld/ # Final processed samples after applying processors schema.pkl # Saved SampleBuilder schema *.bin # Processed sample files
- Parameters:
task (Optional[BaseTask]) – The task to set. Uses default task if None.
num_workers (int) – Number of workers for multi-threading. Default is self.num_workers.
input_processors (Optional[Dict[str, FeatureProcessor]]) – Pre-fitted input processors. If provided, these will be used instead of creating new ones from task’s input_schema. Defaults to None.
output_processors (Optional[Dict[str, FeatureProcessor]]) – Pre-fitted output processors. If provided, these will be used instead of creating new ones from task’s output_schema. Defaults to None.
- Returns:
The generated sample dataset.
- Return type:
- Raises:
AssertionError – If no default task is found and task is None.