Skip to content

Read PhysioNet records whose names include folders - #666

Merged
tompollard merged 2 commits into
mainfrom
pn-dir-subfolders
Nov 23, 2026
Merged

tompollard merged 2 commits into
mainfrom
pn-dir-subfolders

Conversation

@tompollard

Copy link
Copy Markdown
Member

Fixes #467.

rdheader, rdrecord, rdsamp and rdann with pn_dir dropped any folders at the start of the record name. So rdrecord("files/p1000/p10000032/s40689238/40689238", pn_dir="mimic-iv-ecg/1.0") looked for 40689238.hea at the top of the database, and failed with "file not found". The folders now move to the end of pn_dir, so the folders can be given in either argument.

  • A new helper, _resolve_pn_dir, does this and also adds the latest version when pn_dir has none. That code was repeated in each of the three functions.
  • Segments of multi-segment records on PhysioNet are now read by name from pn_dir. Before, the local working directory was joined to the segment name and then dropped along with any other folders. A network test (test_multi_variable_d[physionet]) caught this.
  • docs/io.rst describes folders in either argument.

Testing

  • New offline tests read a single-segment record (header, signal and annotations) and a multi-segment record from folders in a cached database, with pn_dir with a version, without one, and with some of the folders in pn_dir. They fail on main. A network test reads the MIMIC-IV-ECG record from the issue.
  • pytest: all offline and network tests pass, also with --resolution lowest-direct. Ruff and the docs build pass.

@tompollard 🟥 red 🦥 sloth · aspen

rdheader, rdrecord and rdann with pn_dir dropped any folders at the start of
the record name, so rdrecord("files/p1000/.../40689238",
pn_dir="mimic-iv-ecg/1.0") looked for 40689238.hea at the top of the database.
Move those folders to the end of pn_dir instead, in one helper that also
adds the latest version, which was repeated in each function.

Segments of multi-segment records on PhysioNet are now read by name from
pn_dir, without the local directory that used to be joined to them and
then dropped.

Fixes #467.

@tompollard tompollard left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The folder-path handling looks sound. I ran the 29 focused offline tests and separately checked a cached variable-layout multi-segment record in a nested folder against the same local record; the signals matched. All 18 PR checks pass. I found no code issue.

One documentation fix: the public rdheader, rdrecord, and rdsamp docstrings still say that when pn_dir is set, record_name should contain only the base record name (src/wfdb/io/record.py:1883, :2108, and :2507). That contradicts the folder paths this PR now supports and could steer users away from the fix. Could those descriptions say that folders may be included in either record_name or pn_dir, as the new docs/io.rst example shows?

@tompollard

Copy link
Copy Markdown
Member Author

Thanks, agreed. In e7c1441, the record_name description now says that with pn_dir, "the files are read from PhysioNet, and folders in the database may be given in record_name, in pn_dir, or split between them."

The same old sentence was in 10 docstrings, so I changed all of them:

  • rdheader, rdrecord and rdsamp;
  • sampfreq, signame, wfdbdesc and wfdbtime, which read the header through rdheader and so also accept folders;
  • the copies in the BaseRecord, Record and MultiRecord class docstrings.

rdann's pn_dir description says the same. The docs build with warnings as errors, ruff and the offline tests pass.

@tompollard
tompollard merged commit 11a56cf into main Nov 23, 2026
18 checks passed
@tompollard
tompollard deleted the pn-dir-subfolders branch November 23, 2026 22:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Accessing a file in a subfolder on PhysioNet using pn_dir

1 participant