|
6 | 6 | import os |
7 | 7 | import math |
8 | 8 |
|
9 | | -def get_sample_freq(filebytes): |
| 9 | +def get_sample_freq(filebytes,bpi): |
10 | 10 | """Check the beginning of the annotation file to see if it is storing the |
11 | 11 | 'time resolution' field. |
12 | 12 | """ |
13 | 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. |
15 | 14 | if filebytes.size > 24: |
16 | 15 | testbytes = filebytes[:12, :].flatten() |
17 | 16 | # 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) |
116 | 115 | aux = aux[ik0:ik1 + 1] |
117 | 116 | return annsamp,anntype,num,subtype,chan,aux |
118 | 117 |
|
| 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 | + |
119 | 125 | def rdann(recordname, annot, sampfrom=0, sampto=[], anndisp=1): |
120 | 126 | """ Read a WFDB annotation file recordname.annot and return the fields as lists or arrays |
121 | 127 |
|
@@ -171,7 +177,8 @@ def rdann(recordname, annot, sampfrom=0, sampto=[], anndisp=1): |
171 | 177 |
|
172 | 178 | # Check the beginning of the annotation file to see if it is storing the |
173 | 179 | # '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) |
175 | 182 |
|
176 | 183 | # Total number of samples of current annotation from beginning of record. |
177 | 184 | # Annotation bytes only store dt. |
@@ -229,16 +236,11 @@ def rdann(recordname, annot, sampfrom=0, sampto=[], anndisp=1): |
229 | 236 | annsamp,anntype,num,subtype,chan,aux = apply_annotation_range(annsamp, |
230 | 237 | sampfrom,sampto,anntype,num,subtype,chan,aux) |
231 | 238 |
|
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) |
238 | 241 |
|
239 | 242 | return (annsamp, anntype, subtype, chan, num, aux, annfs) |
240 | 243 |
|
241 | | - |
242 | 244 | # Annotation print symbols for 'anntype' field as specified in annot.c |
243 | 245 | # from wfdb software library 10.5.24 |
244 | 246 | annsyms = { |
|
0 commit comments