Repository navigation
Document source location contract for record I/O - #780
Conversation
tompollard
left a comment
There was a problem hiding this comment.
The decisions here are right: no implicit fallback to PhysioNet, and keeping pn_dir until custom servers have another option. I checked each claim against the code, including live PhysioNet reads. Most hold, but three sentences don't match what the code does.
Verified:
physionet://mitdb/1.0.0/100andphysionet://mitdb/latest/100both work withrdrecord,rdann,read_header,read_signal_values,read_multi_segment_headersandann2rr.- There's no fallback:
rdrecord("100")in an empty folder raisesFileNotFoundError. - A
physionet://URI ignoresset_db_index_url. With the index set to a custom server, the URI still read from PhysioNet, andpn_dirread from the custom server. - Cloud archives raise "Reading .wfdb archives from cloud storage is not supported".
read_edf,rdedfannandread_wavreadmemory://andphysionet://paths that include the extension.
Mismatches
-
Combining a URI with
pn_dirbehaves inconsistently. The section says the two "should not be combined", but what actually happens depends on the reader:rdrecord,rdannandread_signal_valuesfail with a doubled path, for exampleFileNotFoundError: physionet://mitdb/1.0.0/physionet://mitdb/1.0.0/100.hea.read_header(URI, pn_dir="nonexistentdb")succeeds and ignorespn_dir, because the cloud check in_read_header_fieldsruns before thepn_dirbranch.
This also contradicts "the name is the only difference in how these readers locate files". There's a precedent for handling it:
_check_archive_read_argsraisesValueError("pn_dir cannot be used to read a .wfdb archive"). A matchingValueErrorfor a URI pluspn_dirwould make the contract true. It could be added here or in a follow-up. Either way, the docs could describe combining the two as an error. -
The version lookup always asks PhysioNet. "Without a version in
pn_dir, WFDB-Python looks up the database's latest version" holds for PhysioNet. With a custom index set, though, the lookup still asks PhysioNet:pn_dir="mitdb"against a custom server requested/files/mitdb/1.0.0/100.hea. A mirror that lacks PhysioNet's latest version would then fail. Since custom servers are the reason given for keepingpn_dir, it would help to say thatpn_dirshould include the version when using one. -
wranncan't write archives. The write paragraph nameswrsampandwrann, then says to passwfdb_archive. NeitherAnnotation.wrannnorwfdb.wranntakes that argument, so the paragraph should say that onlywrsampwrites archives.
Fit with the rest of the docs
- "Reading From PhysioNet" already covers
latest, howpn_dirmaps to URIs, the version lookup andset_db_index_url. "Cloud Storage Access" and "WFDB Archives" overlap with the new section too. Keeping the new section as a short summary that links to those would leave one place for each rule. Otherwise, item 2 has to be fixed in two places. - The section recommends URIs for new code reading from PhysioNet. However, the
iter_dataframesexample (io.rst:320) and the README quick-start (README.md:34-35) still usepn_dir. Updating those two would make the examples match the advice.
44e9e2a to
fc58e70
Compare
|
Thanks for checking the contract against the code. I fixed all three mismatches:
I shortened the source-location overview and linked it to the existing archive, cloud, and PhysioNet sections. The README quick start and The full offline suite passes (1,066 passed, 4 skipped), as do Ruff and the strict Sphinx build. |
Summary
Document one source-location contract for WFDB record and annotation reads before introducing more public API names:
physionet://URI, or local.wfdbarchive path. EDF and WAV converters take a file path with its extension.pn_dirnow raises a clearValueErroracross record, annotation, EDF, and WAV readers.pn_dirsupported for custom index servers configured withset_db_index_url; an explicitphysionet://URI always targets PhysioNet. A versionlesspn_dirstill asks PhysioNet for the latest version, so custom servers should be used with an explicit version. Do not deprecatepn_diruntil a replacement for custom servers exists.write_dir; onlywrsampacceptswfdb_archive, whileSignalRead.write(path)takes a full destination stem or archive path.The concise overview links to the existing archive, cloud, and PhysioNet sections. New readers use
path; existingrecord_namearguments remain unchanged. The README quick start anditer_dataframesexample now use explicit PhysioNet URIs.Closes #748. Related: #534 and #672.
Verification
The offline suite passes (1,066 passed, 4 skipped, 22 network tests deselected). Ruff check and format pass. Sphinx HTML documentation builds with warnings treated as errors.