Skip to content

Commit 2dd4845

Browse files
author
Benjamin Moody
committed
rdann: handle multiple consecutive SKIPs.
In WFDB-format annotation files, annotation timestamps are represented as an offset from the previous annotation. When this offset is less than 0 or greater than 1023, a SKIP pseudo-annotation is used; when the offset is greater than 2**31 - 1 or less than -2**31, multiple SKIPs must be used. Thus, proc_core_fields must be able to handle an arbitrary number of SKIPs in a row, preceding the actual annotation, and add all of the offsets together to obtain the final timestamp.
1 parent 04ae55f commit 2dd4845

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

wfdb/io/annotation.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1869,31 +1869,26 @@ def proc_core_fields(filebytes, bpi):
18691869
The index to start the conversion.
18701870
18711871
"""
1872-
label_store = filebytes[bpi, 1] >> 2
1872+
sample_diff = 0
18731873

18741874
# The current byte pair will contain either the actual d_sample + annotation store value,
18751875
# or 0 + SKIP.
1876-
1877-
# Not a skip - it is the actual sample number + annotation type store value
1878-
if label_store != 59:
1879-
sample_diff = filebytes[bpi, 0] + 256 * (filebytes[bpi, 1] & 3)
1880-
bpi = bpi + 1
1881-
# Skip. Note: Could there be another skip after the first?
1882-
else:
1876+
while filebytes[bpi, 1] >> 2 == 59:
18831877
# 4 bytes storing dt
1884-
sample_diff = 65536 * filebytes[bpi + 1,0] + 16777216 * filebytes[bpi + 1,1] \
1878+
skip_diff = 65536 * filebytes[bpi + 1,0] + 16777216 * filebytes[bpi + 1,1] \
18851879
+ filebytes[bpi + 2,0] + 256 * filebytes[bpi + 2,1]
18861880

18871881
# Data type is long integer (stored in two's complement). Range -2**31 to 2**31 - 1
1888-
if sample_diff > 2147483647:
1889-
sample_diff = sample_diff - 4294967296
1882+
if skip_diff > 2147483647:
1883+
skip_diff = skip_diff - 4294967296
18901884

1891-
# After the 4 bytes, the next pair's samp is also added
1892-
sample_diff = sample_diff + filebytes[bpi + 3, 0] + 256 * (filebytes[bpi + 3, 1] & 3)
1885+
sample_diff += skip_diff
1886+
bpi = bpi + 3
18931887

1894-
# The label is stored after the 4 bytes. Samples here should be 0.
1895-
label_store = filebytes[bpi + 3, 1] >> 2
1896-
bpi = bpi + 4
1888+
# Not a skip - it is the actual sample number + annotation type store value
1889+
label_store = filebytes[bpi, 1] >> 2
1890+
sample_diff += filebytes[bpi, 0] + 256 * (filebytes[bpi, 1] & 3)
1891+
bpi = bpi + 1
18971892

18981893
return sample_diff, label_store, bpi
18991894

0 commit comments

Comments
 (0)