Skip to content

Add LUDB dataset support and a per-lead ECG delineation task - #1593

Open
sidwanjara wants to merge 2 commits into
sunlabuiuc:masterfrom
shraysrivastava:ludb-ecg-delineation
Open

sidwanjara wants to merge 2 commits into
sunlabuiuc:masterfrom
shraysrivastava:ludb-ecg-delineation

Conversation

@sidwanjara

Copy link
Copy Markdown

Contributors: Shray Srivastava (ssriv5@illinois.edu), Sid Wanjara (swanj2@illinois.edu)

Contribution Type: New Dataset + New Task

Paper: J. 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

Description:
Adds the Lobachevsky University Electrocardiography Database (LUDB, PhysioNet, open access)
and an ECG delineation task that follows the paper's setup.

  • LUDBDataset indexes the 200 ten-second, 12-lead, 500 Hz records together with their
    metadata from ludb.csv (sex, age, rhythm, electric axis).
  • ECGDelineationLUDB makes one sample per lead, as the paper does. Each sample has a
    (1, 1, 5000) signal and a (1, 5000) mask (0 background, 1 P, 2 QRS, 3 T).
    • Points before the first and after the last annotated wave are set to 255 (ignore),
      since the cardiologists did not label them.
    • The paper's 0.05-150 Hz Butterworth band-pass is applied by default and can be
      turned off.
    • Optional seeded Gaussian noise (noise_snr_db) is added before filtering, for
      robustness tests.
  • The example trains PyHealth's existing UNet2D on the authors' own 160/20/20 record
    split and reports per-wave IoU and mIoU.
    • Clean test mIoU is 0.822 to 0.826 over 3 seeds, against 0.854 for the paper's UNet 3+.
    • Ablation (not in the paper): noise robustness with the filter on vs off. The filter
      has no effect on clean data but adds +0.09 mIoU at 0 dB SNR. Full results and
      findings are in the example's docstring.

No core PyHealth code is changed; the only edits outside the new files are the two
__init__.py imports and the doc/README index entries.

Files to Review:

  • pyhealth/datasets/ludb.py - dataset implementation
  • pyhealth/datasets/configs/ludb.yaml - dataset config
  • pyhealth/tasks/ecg_delineation_ludb.py - delineation task and annotations_to_mask
  • tests/core/test_ludb.py - tests on synthetic WFDB records (no real data)
  • examples/ludb_ecg_delineation_unet.py - training, evaluation and ablation; runs
    without data via --synthetic
  • docs/api/datasets/pyhealth.datasets.LUDBDataset.rst,
    docs/api/tasks/pyhealth.tasks.ECGDelineationLUDB.rst - API docs
  • docs/api/datasets.rst, docs/api/tasks.rst, examples/README.md - index entries
  • pyhealth/datasets/__init__.py, pyhealth/tasks/__init__.py - imports

@github-actions

Copy link
Copy Markdown

Test Coverage

Total: 86.26% (45526 / 52779 lines)

Modified file Coverage Lines
pyhealth/datasets/__init__.py 100.00% 81 / 81
pyhealth/datasets/ludb.py 98.28% 57 / 58
pyhealth/tasks/__init__.py 98.04% 100 / 102
pyhealth/tasks/ecg_delineation_ludb.py 93.14% 95 / 102

Workflow run · ab98846

@solarsys solarsys added the status: manual Pending maintainer's review label Nov 26, 2026
@solarsys

Copy link
Copy Markdown
Collaborator

/review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed commit ab98846

Comment thread pyhealth/datasets/ludb.py

import pandas as pd

from pyhealth.tasks import ECGDelineationLUDB

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[medium] Dataset links to its task class without the description saying so

LUDBDataset imports ECGDelineationLUDB at module level and returns it from default_task (line 197). This is a new link from a dataset to a concrete task, and the PR description does not mention it. Other datasets in the repo do the same (for example chbmit.py and isruc.py), so it is a common pattern. Either confirm the link and say in the description that default_task points to the companion task, or keep the dataset self-contained by dropping default_task.

Comment thread pyhealth/datasets/ludb.py
rows.append(
{
"patient_id": str(record_id),
"signal_file": str((record_dir / str(record_id)).absolute()),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[low] Cached metadata stores absolute record paths that go stale when the folder moves

signal_file is stored as an absolute path in ludb-pyhealth.csv, which lives inside the dataset folder. If the folder is moved, prepare_metadata skips rebuilding the CSV, and ECGDelineationLUDB.call catches the FileNotFoundError from wfdb.rdsamp and skips every record with only a warning. Consider storing paths relative to root, or raising an error when no records can be read. Other datasets in the repo also use absolute paths, so this need not block the merge.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI Review

suggestion: approve
decision: human review

Thank you for this contribution. It adds LUDBDataset and a per-lead ECG delineation task, ECGDelineationLUDB. It also adds a reproducible UNet2D example with noise and filter ablations, API docs and tests. It looks ready to merge.

  • Correctness: The mask construction, band-pass filter, seeded noise and metadata parsing all look correct. The behaviour matches the description and docs. The dataset cites its PhysioNet source and the LUDB paper.
  • Coverage: This meets the bar. The whole repository is at 86.3%, against the 60% guideline. ludb.py is at 98.3% and ecg_delineation_ludb.py is at 93.1%, both above the 80% guideline.
  • Links between components: LUDBDataset.default_task returns ECGDelineationLUDB. The dataset and task are submitted together as a pair, and the docs name the task as the default, so I read this as intended. The example reuses the existing UNet2D, and the description explains why.

Optional suggestions:

  • Add a sentence to the description saying that LUDBDataset.default_task points to ECGDelineationLUDB on purpose.
  • The cached ludb-pyhealth.csv stores absolute record paths. If the data folder is moved, records are skipped with only a warning. Consider a note in the docs about deleting the CSV after moving the data.
  • The --synthetic mode could be shortened or mentioned in the docs, but this is not needed.

Reviewed commit ab98846

@solarsys

Copy link
Copy Markdown
Collaborator

Why this PR has status: manual: three open PRs add a LUDB dataset and an ECG delineation task: #1593, #1615 and #1594. PyHealth keeps one implementation per component. Our suggestion to the maintainers is to take #1593 (dataset and task only, and the AI suggests approve) as the LUDB base. #1615 and #1594 would then add only their models (UNet3+; MedTsLLM with MIT-BIH) on top of it. The decision is tracked in #1668.

Nothing more is needed from you right now. If you see something in #1615's or #1594's LUDB code that yours lacks, say so here.

@solarsys

Copy link
Copy Markdown
Collaborator

Picked as PyHealth's LUDB dataset and delineation task. We compared #1593, #1615 and #1594. Yours has the best training target and careful signal handling:

  • LUDB's unannotated first and last beats get 255 (ignore) instead of background.
  • Filtering uses 0.05–150 Hz sosfiltfilt with full-length even padding.
  • Leads with missing files are skipped gracefully.
  • It works with master's UNet2D and segmentation metrics, and the AI review suggests approve.

It was also opened first.

Before it can merge. Two models will build on this, so a few things are worth settling now:

  1. Move the Park 160/20/20 split from the example into LUDBDataset.default_subject_split(), returning a SubjectSplit as CHB-MIT does.
  2. Rebuild the cached metadata CSV when its signal paths no longer exist. See _metadata_is_current in Add LUDB ECG delineation full pipeline: LUDBDataset, ECGDelineationLUDB, UNet3Plus (Park et al., CHIL 2025) #1615.
  3. Settle the signal shape: (1, N) by default, with an option for the (1, 1, N) image layout UNet2D needs.
  4. Nice to have:
    • has_p_wave, and numeric age with a censored flag;
    • a citation of Kalyakulina et al. 2020;
    • a wfdb ImportError that mentions the pyhealth[ptbxl] extra.

Once these fixes are pushed, we'll move this PR to status: automatic and request an AI review. If the review approves, it merges.

@solarsys solarsys left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved by a maintainer. The AI review suggests approve on the current commit, and the build passes.

@solarsys

solarsys commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Approved by a maintainer, and ready to merge once it no longer conflicts with master. Recent merges touched the same registration lines in docs/api/tasks.rst and examples/README.md. Please merge master into your branch (or rebase), keep both sides' entries, and push. Once the build passes, comment /review so the AI review runs on the new commit. We'll merge after that.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: manual Pending maintainer's review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants