Skip to content

Commit 36131c5

Browse files
committed
check time res refactor
1 parent 5b5d897 commit 36131c5

File tree

1 file changed

+12
-36
lines changed

1 file changed

+12
-36
lines changed

wfdb/_rdann.py

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,23 @@
66
import os
77
import math
88

9-
def check_time_resolution(filebytes,annfs,bpi):
10-
# Check the beginning of the annotation file to see if it is storing the
11-
# 'time resolution' field.
9+
def check_time_resolution(filebytes):
10+
"""Check the beginning of the annotation file to see if it is storing the
11+
'time resolution' field.
12+
"""
13+
annfs = [] # Store frequencies if they appear in the annotation file.
14+
bpi = 0 # Byte pair index, for searching through bytes of the annotation file.
1215
if filebytes.size > 24:
1316
testbytes = filebytes[:12, :].flatten()
1417
# First 2 bytes indicate dt=0 and anntype=NOTE. Next 2 indicate auxlen
1518
# and anntype=AUX. Then follows "## time resolution: "
1619
if [
1720
testbytes[i] for i in [
18-
0,
19-
1] +
21+
0,1] +
2022
list(
21-
range(
22-
3,
23-
24))] == [
24-
0,
25-
88,
26-
252,
27-
35,
28-
35,
29-
32,
30-
116,
31-
105,
32-
109,
33-
101,
34-
32,
35-
114,
36-
101,
37-
115,
38-
111,
39-
108,
40-
117,
41-
116,
42-
105,
43-
111,
44-
110,
45-
58,
46-
32]: # The file's leading bytes match the expected pattern for encoding fs.
23+
range(3,24))] == [0,88,252,35,35,32,116,105,109,101,32,114,
24+
101,115,111,108,117,116,105,111,110,58,32]:
25+
# The file's leading bytes match the expected pattern for encoding fs.
4726
# Length of the auxilliary string that includes the fs written into
4827
# the file.
4928
auxlen = testbytes[2]
@@ -97,17 +76,14 @@ def rdann(recordname, annot, sampfrom=0, sampto=[], anndisp=1):
9776
chan = np.empty(filebytes.shape[0])
9877
num = np.empty(filebytes.shape[0])
9978
aux = [''] * filebytes.shape[0]
100-
# Stores the frequencies written in the annotation file if it exists.
101-
annfs = []
79+
10280
# Annotation index, the number of annotations processed. Not to be
10381
# comfused with the 'num' field of an annotation.
10482
ai = 0
105-
# Byte pair index, for searching through bytes of the annotation file.
106-
bpi = 0
10783

10884
# Check the beginning of the annotation file to see if it is storing the
10985
# 'time resolution' field.
110-
annfs,bpi = check_time_resolution(filebytes,annfs,bpi)
86+
annfs,bpi = check_time_resolution(filebytes)
11187

11288
# Total number of samples of current annotation from beginning of record.
11389
# Annotation bytes only store dt.

0 commit comments

Comments
 (0)