Repository navigation
Commit cd242ef
authored
Keep invalid samples invalid in smooth_frames (#608)
When a signal has more than one sample per frame, `smooth_frames`
averages each frame in digital units. It doesn't check for the invalid
sample value, so an invalid sample is averaged with the others and gives
a large value that looks valid:
```python
import numpy as np, wfdb
# fmt 16, 2 samples per frame, gain 200. -32768 is the invalid sample value.
np.array([0, 1, -1, -2, -32768, 100], dtype="<i2").tofile("r.dat")
open("r.hea", "w").write("r 1 100 3\nr.dat 16x2 200/mV 16 0 0 0 0 sig\n")
wfdb.rdrecord("r", smooth_frames=False).e_p_signal[0]
# [ 0. 0.005 -0.005 -0.01 nan 0.5 ]
wfdb.rdrecord("r").p_signal[:, 0]
# [ 0. -0.005 -81.67] (last frame should be NaN)
```
The WFDB library returns an invalid value for any frame that contains an
invalid sample (`meansamp()` in `lib/signal.c`), so this does the same:
after averaging a chunk of frames in digital units, frames with an
invalid sample are set to the invalid value for the channel's format.
That then becomes NaN when converted to physical units. Physical
smoothing (`sigtype="physical"`) already gave NaN, since NaN propagates
through the sum.
This doesn't change the rounding of valid frames, which is #335.
Tests: a fmt 16 record with two samples per frame and one invalid sample
reads back as `[3, -32768, 7]` (digital) and `[0.015, nan, 0.035]`
(physical). This fails on `main`. `pytest -m "not network"` passes (97
tests), and the docs build passes.3 files changed
Lines changed: 29 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
20 | 23 | | |
21 | 24 | | |
22 | 25 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1060 | 1060 | | |
1061 | 1061 | | |
1062 | 1062 | | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
1063 | 1068 | | |
1064 | 1069 | | |
1065 | 1070 | | |
1066 | | - | |
1067 | | - | |
1068 | | - | |
1069 | | - | |
1070 | | - | |
| 1071 | + | |
| 1072 | + | |
1071 | 1073 | | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
1072 | 1077 | | |
1073 | 1078 | | |
1074 | 1079 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
857 | 857 | | |
858 | 858 | | |
859 | 859 | | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
860 | 876 | | |
861 | 877 | | |
862 | 878 | | |
| |||
0 commit comments