Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open/read/close API for WFDB format #100

Merged
merged 1 commit into from
Oct 18, 2024
Merged

Open/read/close API for WFDB format #100

merged 1 commit into from
Oct 18, 2024

Conversation

bemoody
Copy link
Collaborator

@bemoody bemoody commented Oct 17, 2024

Here's a (basic) implementation of the new open/read/close API for the WFDB format classes.

As we've discussed elsewhere, the wfdb-python package doesn't currently have any API for doing this sort of thing (which is certainly on the wishlist!)

So this is a quick re-implementation that just handles the specific (single-segment, format 16/516) formats that we're using for benchmarking.

Since it is a re-implementation, it avoids a lot of the overhead of the wfdb.rdrecord function and consequently the performance numbers are not going to be directly comparable to what you get when using rdrecord - I expect the performance will be better, because there are a number of things in wfdb-python that are not optimally implemented. But let's try it and see. :)

You might also notice that the array returned by read_opened_waveforms is slightly different from the array returned by read_waveforms, due to FP rounding errors. Probably because the former multiplies by 1/gain where the latter divides by gain.

This does rely on having a fairly recent version of libsndfile. I think (but I'm not 100% sure) that the soundfile packages on PyPI are sufficiently recent.

Implement the open_waveforms / close_waveforms / read_opened_waveforms
API as defined in BaseFormat.

Since wfdb-python doesn't have any API for doing this, we implement
I/O for formats 16 and 516 "by hand".  This isn't a complete or
conformant implementation of the WFDB format and not recommended for
applications to use as-is - it should work for the data files produced
by write_waveforms, but not for arbitrary WFDB records.  But it should
be useful in better quantifying the performance overhead of the
wfdb-python API.

For each signal format, a custom reader class is implemented.  Format
16 is implemented using numpy, much like wfdb-python does; this class
could be adapted to handle formats 80, 61, 160, 24, or 32 if needed.

Format 516 is implemented using soundfile, again much like wfdb-python
does (but lacks the workaround for libsndfile bug #431), and could be
adapted to handle formats 508 or 524 if needed.
@briangow
Copy link
Collaborator

@bemoody , thanks, this looks good to me!

@briangow briangow merged commit 260733d into main Oct 18, 2024
1 of 2 checks passed
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.

2 participants