Skip to content

Commit e45d7e1

Browse files
committed
format anntype
1 parent d647453 commit e45d7e1

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

wfdb/_rdann.py

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

9-
def get_sample_freq(filebytes):
9+
def get_sample_freq(filebytes,bpi):
1010
"""Check the beginning of the annotation file to see if it is storing the
1111
'time resolution' field.
1212
"""
1313
annfs = [] # Store frequencies if they appear in the annotation file.
14-
bpi = 0 # Byte pair index, for searching through bytes of the annotation file.
1514
if filebytes.size > 24:
1615
testbytes = filebytes[:12, :].flatten()
1716
# First 2 bytes indicate dt=0 and anntype=NOTE. Next 2 indicate auxlen
@@ -116,6 +115,13 @@ def apply_annotation_range(annsamp,sampfrom,sampto,anntype,num,subtype,chan,aux)
116115
aux = aux[ik0:ik1 + 1]
117116
return annsamp,anntype,num,subtype,chan,aux
118117

118+
def format_anntype(anndisp,anntype):
119+
if anndisp == 1:
120+
anntype = [annsyms[code] for code in anntype]
121+
elif anndisp == 2:
122+
anntype = [anncodes[code] for code in anntype]
123+
return anntype
124+
119125
def rdann(recordname, annot, sampfrom=0, sampto=[], anndisp=1):
120126
""" Read a WFDB annotation file recordname.annot and return the fields as lists or arrays
121127
@@ -171,7 +177,8 @@ def rdann(recordname, annot, sampfrom=0, sampto=[], anndisp=1):
171177

172178
# Check the beginning of the annotation file to see if it is storing the
173179
# 'time resolution' field.
174-
annfs,bpi = get_sample_freq(filebytes)
180+
bpi = 0 # Byte pair index, for searching through bytes of the annotation file.
181+
annfs,bpi = get_sample_freq(filebytes,bpi)
175182

176183
# Total number of samples of current annotation from beginning of record.
177184
# Annotation bytes only store dt.
@@ -229,16 +236,11 @@ def rdann(recordname, annot, sampfrom=0, sampto=[], anndisp=1):
229236
annsamp,anntype,num,subtype,chan,aux = apply_annotation_range(annsamp,
230237
sampfrom,sampto,anntype,num,subtype,chan,aux)
231238

232-
# Return the annotation types as symbols or strings depending on input
233-
# parameter
234-
if anndisp == 1:
235-
anntype = [annsyms[code] for code in anntype]
236-
elif anndisp == 2:
237-
anntype = [anncodes[code] for code in anntype]
239+
# Format the annotation types as symbols or strings
240+
anntype = format_anntype(anndisp,anntype)
238241

239242
return (annsamp, anntype, subtype, chan, num, aux, annfs)
240243

241-
242244
# Annotation print symbols for 'anntype' field as specified in annot.c
243245
# from wfdb software library 10.5.24
244246
annsyms = {

0 commit comments

Comments
 (0)