Skip to content

Multi-frequency data with wfdb.wrsamp #336

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

Closed
bemoody opened this issue Nov 15, 2021 · 2 comments
Closed

Multi-frequency data with wfdb.wrsamp #336

bemoody opened this issue Nov 15, 2021 · 2 comments

Comments

@bemoody
Copy link
Collaborator

bemoody commented Nov 15, 2021

If you have some multi-frequency data and are trying to save it as a WFDB record, currently the only way to do so is to create a Record object and call Record.wrsamp. This is laborious and error-prone because of all the auxiliary fields that Record.wrsamp requires.

It'd be nice to be able to pass an e_d_signal or e_p_signal parameter to wfdb.wrsamp instead, e.g.:

wfdb.wrsamp(
    'example',
    fs=125,
    units=['mV', 'mmHg'],
    sig_name=['ECG', 'ABP'],
    samps_per_frame=[4, 1],
    e_p_signal=[
        numpy.array([0.282, 0.297, 0.304, 0.304,
                     0.311, 0.311, 0.333, 0.333]),
        numpy.array([70.093, 75.623])])
@bemoody
Copy link
Collaborator Author

bemoody commented Mar 7, 2024

Related warts:

  • set_d_features(expanded=True, do_adc=True) is broken (it stores the data incorrectly in d_signal rather than e_d_signal)

  • adc(expanded=True) fails if n_sig is unset (it doesn't do that with expanded=False)

tompollard added a commit that referenced this issue Apr 19, 2024
Fix several bugs in `Record.adc`:

1. Previously, the function would try to convert all samples to integers
and then, for any samples that were NaN, replace the corresponding
elements with the appropriate sentinel value. Even though this was
probably safe in most cases, casting NaN to an integer is
implementation-defined behavior, and raises a warning by default (issue
#480).

2. NaN just plain wasn't handled for the `inplace=True, expanded=False`
case. (Currently, we don't use `inplace=True` anywhere internally;
although it saves a bit of memory, it's destructive and so it's probably
wise for high-level functions like `wrsamp` to avoid it.)

3. The `expanded=True` case relied on `self.n_sig` (in contrast to
`expanded=False`, which operates based on the dimensions of `p_signal`.)
This meant it would fail if the caller didn't explicitly set `n_sig`,
which was an annoying inconsistency.

Also, tidy up duplicated code and make things a little more efficient.

A side note: I don't think the `inplace=True` mode is particularly great
to have. It conflates two things (modifying the Record object
attributes, which many applications want; and modifying the array
contents, which you may think you want until you realize it subtly
breaks something.) It does save some memory, but not as much as you'd
hope. (That `copy=False` is pretty much a lie.) And of course I don't
like functions whose return type is dependent on their arguments. So I
would definitely put `inplace` on the chopping block for 5.0.0. Still, I
think the updated code here isn't too terribly ugly.

This set of changes is the first step to making `wfdb.wrsamp` work for
multi-frequency (issue #336). Next is to fix `Record.calc_adc_params`,
then `Record.set_d_features`.
@bemoody
Copy link
Collaborator Author

bemoody commented Nov 25, 2024

Fixed by pull #510.

@bemoody bemoody closed this as completed Nov 25, 2024
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

No branches or pull requests

1 participant