pyhealth.tasks.temple_university_EEG_tasks#

The temple_university_EEG_tasks module contains the tasks for the Temple University EEG Corpus.

The tasks are: - EEGEventsTUEV: EEG event classification task for the TUEV dataset. - EEGAbnormalTUAB: Binary classification task for the TUAB dataset (abnormal vs normal).

Tasks Parameters: - resample_rate: int, default=200 # Resample rate - bandpass_filter: tuple, default=(0.1, 75.0) # Bandpass filter - notch_filter: float, default=50.0 # Notch filter

class pyhealth.tasks.temple_university_EEG_tasks.EEGEventsTUEV(resample_rate=200, bandpass_filter=(0.1, 75.0), notch_filter=50.0, normalization=None, compute_stft=True)[source]#

Bases: BaseTask

Multi-class classification task for EEG event detection on TUEV.

For each EDF recording, this task:
  1. reads the EDF

  2. applies bandpass (0.1-75 Hz), notch (50 Hz), resamples to 256 Hz

  3. loads the paired .rec file (same path, .edf -> .rec)

  4. constructs 5-second event-centered windows (16 bipolar channels)

  5. returns one sample per event

Each returned sample contains:
  • “signal”: np.ndarray, shape (16, 256*5)

  • “offending_channel”: int

  • “label”: int

Examples

>>> from pyhealth.datasets import TUEVDataset
>>> from pyhealth.tasks import EEGEventsTUEV
>>> dataset = TUEVDataset(
...         root="/srv/local/data/TUH/tuh_eeg_events/v2.0.0/edf/",
...     )
>>> sample_dataset = dataset.set_task(EEGEventsTUEV())
>>> sample = sample_dataset[0]
>>> print(sample['label'])

For a complete example, see examples/conformal_eeg/tuev_eeg_quickstart.ipynb.

task_name: str = 'EEG_events'#
output_schema: Dict[str, str] = {'label': 'multiclass'}#
input_schema: Dict[str, str] = {'signal': 'tensor', 'stft': 'tensor'}#
static BuildEvents(signals, times, EventData, resample_rate=200)[source]#
Return type:

Tuple[ndarray, ndarray, ndarray]

static convert_signals(signals, Rawdata)[source]#
Return type:

ndarray

static readEDF(fileName, resample_rate=200, bandpass_filter=(0.1, 75.0), notch_filter=50.0)[source]#
Return type:

Tuple[ndarray, ndarray, ndarray, BaseRaw]

pre_filter(df)#
Return type:

LazyFrame

class pyhealth.tasks.temple_university_EEG_tasks.EEGAbnormalTUAB(resample_rate=200, bandpass_filter=(0.1, 75.0), notch_filter=50.0, normalization=None, compute_stft=True)[source]#

Bases: BaseTask

Binary classification task for abnormal EEG detection on TUAB.

For each EDF recording, this task:
  1. reads the EDF

  2. Applies bandpass (0.1-75 Hz), notch (50 Hz) and resamples to 200 Hz

  3. Constructs 16 bipolar channels from the TCP montage of non-overlapping 10 second windows # following BIOT

  4. assigns a binary label (1 = abnormal, 0 = normal) derived from the metadata label attribute

Each returned sample contains:
  • “signal”: np.ndarray, shape (16, 2000)

  • “label”: int (0 = normal, 1 = abnormal)

Examples

>>> from pyhealth.datasets import TUABDataset
>>> from pyhealth.tasks import EEGAbnormalTUAB
>>> dataset = TUABDataset(
...         root="/srv/local/data/TUH/tuh_eeg_abnormal/v3.0.0/edf/",
...     )
>>> sample_dataset = dataset.set_task(EEGAbnormalTUAB())
>>> sample = sample_dataset[0]
>>> print(sample['signal'].shape)  # (16, 2000)
>>> print(sample['label'])         # 0 or 1
task_name: str = 'EEG_abnormal'#
output_schema: Dict[str, str] = {'label': 'multiclass'}#
input_schema: Dict[str, str] = {'signal': 'tensor', 'stft': 'tensor'}#
pre_filter(df)#
Return type:

LazyFrame

static read_and_process_edf(fileName, resample_rate=200, bandpass_filter=(0.1, 75.0), notch_filter=50.0)[source]#
Return type:

Tuple[ndarray, List[str]]

static convert_to_bipolar(raw_data, ch_name)[source]#

Convert raw EEG channels to 16 bipolar montage channels following BIOT.

Return type:

ndarray

Returns:

np.ndarray of shape (16, n_samples)