Skip to content

[SYSTEMDS-3991] Prepare PTB-XL ECG dataset for Scuro - #2638

Open
shieru1214 wants to merge 10 commits into
apache:mainfrom
shieru1214:scuro-ptbxl
Open

shieru1214 wants to merge 10 commits into
apache:mainfrom
shieru1214:scuro-ptbxl

Conversation

@shieru1214

Copy link
Copy Markdown
Contributor

This change fixes format checks and error messages in TimeseriesLoader and adds tests for them.

TimeseriesLoader fixes

  • Remove mat and hdf5 from the supported formats because they are not implemented yet, and add csv to the format check.
  • Make the “file not found” error show the actual filename.
  • Add a helper that imports wfdb only when needed and gives an installation hint if the package is missing. This does not add file_format="wfdb" support yet.

Tests

I enabled test_timeseries_loader_loads_all_instances and test_timeseries_loader_stats. They now use ["x", "y"] as signal names. The data generator writes 10 samples with 2 signals, so the stats test can check max_length and num_signals.

The new tests check that the missing filename appears in the error, that mat, hdf5, and unknown formats are rejected, and that selecting y from a two-column CSV returns exactly the second column. I also added a test for the installation hint when wfdb is missing.

@codecov

codecov Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.23%. Comparing base (1a358e5) to head (3792b7f).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #2638      +/-   ##
============================================
+ Coverage     72.18%   72.23%   +0.04%     
- Complexity    51211    51221      +10     
============================================
  Files          2105     2105              
  Lines        230158   230348     +190     
  Branches      38694    38694              
============================================
+ Hits         166139   166388     +249     
+ Misses        52813    52753      -60     
- Partials      11206    11207       +1     
Flag Coverage Δ
java 71.49% <ø> (-0.01%) ⬇️
python 76.93% <100.00%> (+0.34%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@christinadionysio christinadionysio left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you @shieru1214, overall this looks good! Please add the wfdb dependency to the python.yml file where the test environment for Scuro is created so the tests can also run in the CI.

@shieru1214

Copy link
Copy Markdown
Contributor Author

Thank you @shieru1214, overall this looks good! Please add the wfdb dependency to the python.yml file where the test environment for Scuro is created so the tests can also run in the CI.

Thanks! wfdb is now in the Scuro test environment.

@shieru1214

Copy link
Copy Markdown
Contributor Author

TimeseriesLoader now supports file_format="wfdb". I also added staging scripts for PTB-XL.

WFDB support

  • The loader reads signals with wfdb.rdrecord using the requested data_type (float32 by default).
  • It reads only the headers to compute stats. If sampling_rate is omitted, the loader uses the rate from the header. If the given rate does not match the header, it raises an error.
  • The loader reads all leads by default. You can select leads by name with signal_names or select one lead by position with channel_index. If both are given, signal_names takes priority.

Staging

I added three scripts in scripts/staging/scuro_ptbxl/:

  • load_ptbxl.py loads the 100 Hz and 500 Hz recordings into Scuro. It also shows how to load lead II on its own.
  • ptbxl_index.py returns the record paths, labels for the five diagnostic superclasses, strat_fold, and patient IDs. It skips records without a diagnostic superclass and supports nested subsets.
  • sanity_check.py checks the loaded signals at both sampling rates. The README explains how to download the dataset and run the scripts.

Tests

The WFDB tests use small records written with wfdb.wrsamp. They check the header stats, the requested data_type, and lead selection by name or index. The Scuro CI environment now includes wfdb.

I also ran sanity_check.py on all 21,799 PTB-XL records at 100 Hz and 500 Hz. All checks passed. At each rate, the script compared five records with wfdb.rdsamp, and all five matched.

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

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

2 participants