Repository navigation
Read WFDB files from explicit HTTP URLs - #817
Conversation
tompollard
left a comment
There was a problem hiding this comment.
Thanks, a full URL is a much clearer way to read from a custom server than set_db_index_url plus pn_dir. Reads through read_record, read_signals, read_header and read_annotations work, multi-segment headers follow their segments on the same server, URL plus pn_dir is rejected, and aiohttp is already a core dependency, so a plain install supports this. The offline suite, Ruff and the strict docs build pass locally.
Servers that gzip responses. With the existing DummyHTTPServer(..., allow_gzip=True), reading from the start of 100.dat works, but a partial read deep into the file fails with aiohttp.ClientPayloadError: 400, and a read near the end of a header without a length fails with could not broadcast input array from shape (0,) into shape (10,). fsspec's HTTP reader sends Accept-Encoding: gzip, so the server returns ranges of the compressed body. The _url reader avoids this by sending no Accept-Encoding on range requests. Passing headers={"Accept-Encoding": "identity"} from _fsspec_open for http(s):// paths fixed it in my test (correct size and bytes after a seek). Could you add that, plus a test with allow_gzip=True?
Legacy annotation writer. Record.write, write_record, Record.wrsamp, wfdb.wrsamp, Annotation.write and write_annotations all reject HTTP destinations clearly, but Annotation.wrann(write_dir="https://...") and wfdb.wrann(..., write_dir="https://...") fail with FileNotFoundError: ... 'https://mirror.example.org/files/100.atr'. Calling check_cloud_write(write_dir) there would match. (Nothing is created on disk in any case.)
Optional: a signed URL with a query string (.../100?token=abc) fails with a fsspec glob error, and joining file names onto it would drop the query anyway. A sentence in the docs saying such URLs aren't supported would help.
|
Good catches. I pushed 23bc015 to address both issues:
The HTTP tests (11), annotation and cloud-write tests (195), Ruff, and the strict docs build pass locally. |
tompollard
left a comment
There was a problem hiding this comment.
Thanks, 23bc015 fixes both. With a gzip-capable server (allow_gzip=True), the reads that failed before now match local reads: a deep partial read of 100.dat (frames 600000–600010), the last frames of a header without a length, and annotations through both read_annotations and rdann. Annotation.wrann and wfdb.wrann now raise "Writing to HTTP URLs is not supported", and local wrann writes still work. The signed-URL note is clear. The full offline suite, Ruff and the strict docs build pass locally.
Ready to merge once CI is green.
## Summary - Emit one `FutureWarning` when a public reader is called with `pn_dir`. The warning suggests a `physionet://` path or a complete HTTP URL for a custom server when the replacement can be formed without a network request. - Keep `pn_dir` calls working. Suppress warnings from internal reader calls, including `download_records`. - Update the remote-reading guide and add a changelog entry. This is stacked on #817, which adds explicit HTTP URL reads for custom servers. Merge #817 first, then retarget this PR to `main`. Related to #534 and #672. ## Checks - Offline suite: 1,543 passed, 4 skipped. - Ruff check and format: passed. - Sphinx HTML build with warnings as errors: passed.
Summary
Allow explicit HTTP and HTTPS record paths such as
wfdb.read_record("https://mirror.example.org/files/mitdb/1.0.0/100"). Header references, signal files, and annotations stay on the named server. This gives custom index servers a single-path alternative to combiningset_db_index_url(...), a record name, andpn_dir(#534).The change uses the existing
fsspecHTTP reader. It keepsphysionet://for PhysioNet access with saved credentials, preserves legacypn_dirbehavior, and rejects HTTP write destinations clearly. It does not introduce automatic fallback from a local path to a remote server.Checks
physionet0.11.0 dependency, including the existing custom-server tests.This is the first step toward retiring
pn_dir. A follow-up will add migration warnings and update examples once the explicit URL behavior is reviewed.