Skip to content

wrsamp cannot calculate calibration for physical signals with NaN or expanded layout #786

Done

Description

@tompollard

wrsamp can't work out the format and calibration for physical signals in two cases. Both fail with errors that don't explain the problem.

1. A physical signal that contains NaN

import numpy as np
import wfdb

wfdb.wrsamp("x", fs=100, units=["mV"], sig_name=["I"],
            p_signal=np.array([[0.0], [np.nan], [0.2]]))
  File ".../wfdb/io/_signal.py", in set_d_features
    res = est_res(self.p_signal)
  File ".../wfdb/io/_signal.py", in est_res
    res.append(np.where(res_levels >= nlevels)[0][0])
IndexError: index 0 is out of bounds for axis 0 with size 0

NaN marks missing samples, and when fmt, adc_gain and baseline are given, NaN is written as the format's missing-value marker. The resolution estimate in est_res doesn't skip NaN, though, so the automatic calibration path fails.

2. An expanded physical signal without calibration

wfdb.wrsamp("x", fs=100, units=["mV"], sig_name=["I"],
            e_p_signal=[np.array([0.0, 0.1, 0.2, 0.3, 0.4, 0.5])],
            samps_per_frame=[2])
Exception: Missing field required: adc_gain

For a uniform p_signal, set_d_features(do_adc=1) calculates fmt, adc_gain and baseline. With expanded=True it doesn't, so expanded physical signals can only be written if the calibration is given explicitly.

write_record (#785) goes through the same calibration path, so it fails the same way for records built in code.

Expected: both cases calculate the format and calibration the same way as uniform signals without NaN, ignoring missing samples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions