Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/api/datasets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,11 @@ PyHealth does not ship any data: you download each dataset from its source and p
- `PhysioNet <https://physionet.org/content/ecg-arrhythmia/1.0.0/>`__
- No
- —
* - :doc:`LUDB (ECG delineation) <datasets/pyhealth.datasets.LUDBDataset>`
- Open
- `PhysioNet <https://physionet.org/content/ludb/1.0.1/>`__
- No
- —
* - :doc:`Sleep-EDF <datasets/pyhealth.datasets.SleepEDFDataset>`
- Open
- `PhysioNet <https://physionet.org/content/sleep-edfx/1.0.0/>`__
Expand Down Expand Up @@ -659,6 +664,7 @@ Available Datasets
datasets/pyhealth.datasets.AHEPADementiaDataset
datasets/pyhealth.datasets.BCICompetitionIV2aDataset
PTB-XL Dataset <datasets/pyhealth.datasets.PTBXLDataset>
LUDB Dataset <datasets/pyhealth.datasets.LUDBDataset>
PhysioNet 2012 Dataset <datasets/pyhealth.datasets.PhysioNet2012Dataset>
datasets/pyhealth.datasets.TUABDataset
datasets/pyhealth.datasets.TUEVDataset
Expand Down
41 changes: 41 additions & 0 deletions docs/api/datasets/pyhealth.datasets.LUDBDataset.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
pyhealth.datasets.LUDBDataset
=============================

Overview
--------

The Lobachevsky University Electrocardiography Database (LUDB) has 200
ten-second, 12-lead ECGs sampled at 500 Hz, one per subject. For every lead,
cardiologists marked where each P wave, QRS complex and T wave starts and
ends, which makes LUDB the standard public dataset for ECG delineation.
``ludb.csv`` gives each subject's sex, age, rhythm and electric axis.

LUDB is open access on PhysioNet. Download the ZIP of version 1.0.1 (about
15 MB), unzip it and point ``root`` at the folder that holds ``ludb.csv``
and ``data/``. Reading the records needs the ``wfdb`` package
(``pip install wfdb``).

Each record is one patient. The dataset writes one metadata row per record
(the WFDB record path plus sex, age, rhythm and electric axis). The default
task, :class:`~pyhealth.tasks.ECGDelineationLUDB`, turns each lead into a
filtered signal and a point-wise P / QRS / T mask.

Source: `LUDB on PhysioNet <https://physionet.org/content/ludb/1.0.1/>`_
(Kalyakulina et al., IEEE Access 2020,
`doi:10.1109/ACCESS.2020.3029211 <https://doi.org/10.1109/ACCESS.2020.3029211>`_)

.. code-block:: python

from pyhealth.datasets import LUDBDataset

dataset = LUDBDataset(root="/path/to/ludb/1.0.1")
dataset.stats()
samples = dataset.set_task() # ECGDelineationLUDB on all 12 leads

API Reference
-------------

.. autoclass:: pyhealth.datasets.LUDBDataset
:members:
:undoc-members:
:show-inheritance:
1 change: 1 addition & 0 deletions docs/api/tasks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ Available Tasks
BCI Competition IV 2a Motor Imagery <tasks/pyhealth.tasks.BCIIV2aMotorImageryClassification>
BCI Competition IV 2a Left vs Right Hand <tasks/pyhealth.tasks.BCIIV2aLeftRightImagery>
PTB-XL Tasks <tasks/pyhealth.tasks.ptbxl>
ECG Delineation (LUDB) <tasks/pyhealth.tasks.ECGDelineationLUDB>
Sleep Staging v2 <tasks/pyhealth.tasks.sleep_staging_v2>
Benchmark EHRShot <tasks/pyhealth.tasks.benchmark_ehrshot>
EHR Text Serialization (LLM encoders) <tasks/pyhealth.tasks.ehr_text_serialization>
Expand Down
54 changes: 54 additions & 0 deletions docs/api/tasks/pyhealth.tasks.ECGDelineationLUDB.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
pyhealth.tasks.ECGDelineationLUDB
=================================

ECG delineation on :class:`~pyhealth.datasets.LUDBDataset`: label every
point of a lead as P wave, QRS complex, T wave or none.

The task follows Park et al., "Benchmarking ECG Delineation using Deep
Neural Network-based Semantic Segmentation Models", CHIL 2025
(`PMLR 287:63-88 <https://proceedings.mlr.press/v287/park25a.html>`_). As in
the paper, each lead of each record is one sample, and the signal is
filtered with a Butterworth 0.05 Hz high-pass and 150 Hz low-pass. Models
are scored by the IoU of each wave and their mean (mIoU).

Each sample holds:

- ``signal``: float32, shape ``(1, 1, n_samples)``, in mV. The extra
dimension makes it a one-row image, so PyHealth's ``UNet2D`` can use it.
- ``mask``: int64, shape ``(1, n_samples)``. Values are 0 background,
1 P wave, 2 QRS complex, 3 T wave and 255 for points the cardiologists
did not annotate (before the first and after the last wave). Pass
``ignore_index=255`` to the model.
- ``patient_id`` (the record number) and ``lead``.

The paper predicts three sigmoid channels with binary cross-entropy; one
class per point holds the same information because LUDB's waves never
overlap, and works with PyHealth's segmentation models and metrics.
Splitting with ``split_by_patient`` keeps all leads of a record together,
as the paper does.

Task parameters:

- leads: lead names (any case), default all 12
- apply_filter: bool, apply the band-pass filter, default True
- noise_snr_db: float or None, add white Gaussian noise at this
signal-to-noise ratio before filtering, default None
- noise_seed: int, default 0

.. code-block:: python

from pyhealth.datasets import LUDBDataset, split_by_patient
from pyhealth.models import UNet2D
from pyhealth.tasks import ECGDelineationLUDB

dataset = LUDBDataset(root="/path/to/ludb/1.0.1")
samples = dataset.set_task(ECGDelineationLUDB())
train, val, test = split_by_patient(samples, [0.8, 0.1, 0.1], seed=0)
model = UNet2D(train, in_channels=1, num_classes=4, ignore_index=255)

.. autoclass:: pyhealth.tasks.ECGDelineationLUDB
:members:
:undoc-members:
:show-inheritance:

.. autofunction:: pyhealth.tasks.ecg_delineation_ludb.annotations_to_mask
3 changes: 2 additions & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Older examples that no longer run, or that duplicated a maintained one, are in
| [`cxr/`](cxr/) | Chest X-ray classification (ChestX-ray14, COVID-19), saliency maps, conformal prediction, ViT, VAE and GAN image generation. The COVID-19 ViT tutorial runs except for its Chefer step, which currently fails (see its header) |
| [`eeg/`](eeg/) | EEG events and abnormality (TUEV, TUAB), sleep staging (Sleep-EDF, ISRUC), dementia classification (AHEPA), seizure onset zone localization (HUP iEEG), EEGBCI pattern discovery; SparcNet, ContraWR, BIOT, TFM-Tokenizer |
| [`conformal_eeg/`](conformal_eeg/) | Conformal prediction on TUEV/TUAB: conventional, k-means cluster, neighbourhood (NCP), covariate shift |
| [`ecg/`](ecg/) | PTB-XL multi-label ECG classification, including ProtoECGNet |
| [`ecg/`](ecg/) | PTB-XL multi-label ECG classification, including ProtoECGNet. ECG delineation on LUDB is the top-level `ludb_ecg_delineation_unet.py` |
| [`benchmark_perf/`](benchmark_perf/README.md) | Speed and memory benchmarks against PyHealth 1.x, pandas and meds_reader |

## Top-level notebooks
Expand Down Expand Up @@ -100,5 +100,6 @@ Older examples that no longer run, or that duplicated a maintained one, are in
| `physionet_deid_ner_transformer_deid.py` | Transformer de-identification (PhysioNet, credentialed) |
| `mimic4_mortality_medfuse.py` | MedFuse ablation (synthetic data) |
| `mimic4_decompensation_daft.py` | DAFT on MedMod decompensation and mortality, with ablations (synthetic data by default) |
| `ludb_ecg_delineation_unet.py` | ECG delineation (P / QRS / T segmentation) on LUDB with UNet2D, with noise-robustness and band-pass filter ablations; `--synthetic` runs without data |
| `support_survival_survival_mdn.py` (with `survival_mdn_data.py`, `survival_mdn_metrics.py`, results in `survival_mdn_results/`) | Survival mixture density network on SUPPORT |
| `yaib_mimic4_rnn_v2.py` | RNN_V2 on the five MIMIC-IV YAIB tasks |
Loading
Loading