You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit d7087ea
Browse filesBrowse the repository at this point in the historyBrowse files
Read EDF and WAV files from physionet:// and other URIs (#674)
Part of #534: the first step towards phasing out `pn_dir`, which is that
every function that takes `pn_dir` also takes a `physionet://` URI.
Of the 15 public functions that take `pn_dir`, all but three already
accepted a `physionet://` URI as `record_name`, because they read
through `rdrecord`, `rdheader` or `rdann`. The other three, `read_edf`,
`rdedfann` and `read_wav`, opened the path with `open()`, so
`read_edf("physionet://chbmit/1.0.0/chb01/chb01_01.edf")` failed with
`FileNotFoundError`. They also couldn't read `s3://` or `memory://`
paths.
- A new helper, `_coreio._open_input_file`, opens a local file as
before, or reads a URI into memory (through `fsspec`, so `physionet://`
uses the physionet package, with its cache and sign-in).
- `read_edf` and `read_wav` read the samples with `np.frombuffer` and
the file size with `seek`, instead of `np.fromfile` and
`os.path.getsize`, which need a local file. `read_wav` now also closes
its file.
- Output names (`record_name` of the returned record, and the files
written by `wfdb_to_edf` and `wfdb_to_wav`) use the last part of a URI
on every platform, instead of splitting on `os.sep`.
URIs are read without saving a copy, unlike `pn_dir`, which downloads
the file into the current directory (and `read_edf` leaves it there).
That `pn_dir` behaviour is unchanged here.
## Testing
- New offline tests read `n16.edf`, `SC4001E0-PSG.wav` and
`test_edfann.edf` with `physionet://` (from the cache) and `memory://`
URIs, and compare them with the local files. They also check that
nothing is written to the current directory. These fail on `main`.
Another test checks that `wfdb_to_mat` and `sigavg` read `physionet://`
URIs, as they already did.
- Local files give identical results to `main` (signals, names, initial
values and checksums) for `n16.edf`, `wave_4.edf`, `SC4001E0-PSG.wav`
and the `rdedfann` output of `test_edfann.edf`.
- `read_edf("physionet://chbmit/1.0.0/chb01/chb01_01.edf")` reads all 23
signals from PhysioNet in about 14 seconds.
- `pytest`: all offline and network tests pass, also with `--resolution
lowest-direct`. Ruff and the docs build pass.
<sub>@tompollard 🟥 red 🦥 sloth · aspen</sub>
0 commit comments