pyhealth.tasks.sleep_staging#
- pyhealth.tasks.sleep_staging.sleep_staging_isruc_fn(record, epoch_seconds=10, label_id=1)[source]#
Processes a single patient for the sleep staging task on ISRUC.
Sleep staging aims at predicting the sleep stages (Awake, N1, N2, N3, REM) based on the multichannel EEG signals. The task is defined as a multi-class classification.
- Parameters
record –
a singleton list of one subject from the ISRUCDataset. The (single) record is a dictionary with the following keys:
load_from_path, signal_file, label1_file, label2_file, save_to_path, subject_id
epoch_seconds – how long will each epoch be (in seconds). It has to be a factor of 30 because the original data was labeled every 30 seconds.
label_id – which set of labels to use. ISURC is labeled by two experts. By default we use the first set of labels (label_id=1).
- Returns
- a list of samples, each sample is a dict with patient_id, record_id,
and epoch_path (the path to the saved epoch {“X”: signal, “Y”: label} as key.
- Return type
samples
Note that we define the task as a multi-class classification task.
Examples
>>> from pyhealth.datasets import ISRUCDataset >>> isruc = ISRUCDataset( ... root="/srv/local/data/data/ISRUC-I", download=True, ... ) >>> from pyhealth.tasks import sleep_staging_isruc_fn >>> sleepstage_ds = isruc.set_task(sleep_staging_isruc_fn) >>> sleepstage_ds.samples[0] { 'record_id': '1-0', 'patient_id': '1', 'epoch_path': '/home/zhenlin4/.cache/pyhealth/datasets/832afe6e6e8a5c9ea5505b47e7af8125/10-1/1/0.pkl', 'label': 'W' }
- pyhealth.tasks.sleep_staging.sleep_staging_sleepedf_fn(record, epoch_seconds=30)[source]#
Processes a single patient for the sleep staging task on Sleep EDF.
Sleep staging aims at predicting the sleep stages (Awake, REM, N1, N2, N3, N4) based on the multichannel EEG signals. The task is defined as a multi-class classification.
- Parameters
patient – a list of (root, PSG, Hypnogram, save_to_path) tuples, where PSG is the signal files and Hypnogram
labels (contains the) –
epoch_seconds – how long will each epoch be (in seconds)
- Returns
- a list of samples, each sample is a dict with patient_id, record_id,
and epoch_path (the path to the saved epoch {“X”: signal, “Y”: label} as key.
- Return type
samples
Note that we define the task as a multi-class classification task.
Examples
>>> from pyhealth.datasets import SleepEDFDataset >>> sleepedf = SleepEDFDataset( ... root="/srv/local/data/SLEEPEDF/sleep-edf-database-expanded-1.0.0/sleep-cassette", ... ) >>> from pyhealth.tasks import sleep_staging_sleepedf_fn >>> sleepstage_ds = sleepedf.set_task(sleep_staging_sleepedf_fn) >>> sleepstage_ds.samples[0] { 'record_id': 'SC4001-0', 'patient_id': 'SC4001', 'epoch_path': '/home/chaoqiy2/.cache/pyhealth/datasets/70d6dbb28bd81bab27ae2f271b2cbb0f/SC4001-0.pkl', 'label': 'W' }