@@ -53,6 +53,33 @@ def copy_prev(AT,ts,filebytes,bpi,annsamp,anntype,ai):
5353 bpi = bpi + 1
5454 return ts ,annsamp ,anntype ,bpi
5555
56+ def proc_extra_fields (AT ,subtype ,ai ,filebytes ,bpi ,num ,chan ,cpychan ,cpynum ,aux ):
57+ if AT == 61 : # SUB
58+ # sub is interpreted as signed char. Remember to limit writing
59+ # range.
60+ subtype [ai ] = filebytes [bpi , 0 ].astype ('i1' )
61+ bpi = bpi + 1
62+ elif AT == 62 : # CHAN
63+ # chan is interpreted as unsigned char
64+ chan [ai ] = filebytes [bpi , 0 ]
65+ cpychan = 0
66+ bpi = bpi + 1
67+ elif AT == 60 : # NUM
68+ # num is interpreted as signed char
69+ num [ai ] = filebytes [bpi , 0 ].astype ('i1' )
70+ cpynum = 0
71+ bpi = bpi + 1
72+ elif AT == 63 : # AUX
73+ # length of aux string. Max 256? No need to check other bits of
74+ # second byte?
75+ auxlen = filebytes [bpi , 0 ]
76+ auxbytes = filebytes [bpi + 1 :bpi + 1 + math .ceil (auxlen / 2. ),:].flatten ()
77+ if auxlen & 1 :
78+ auxbytes = auxbytes [:- 1 ]
79+ aux [ai ] = "" .join ([chr (char ) for char in auxbytes ]) # The aux string
80+ bpi = bpi + 1 + math .ceil (auxlen / 2. )
81+ return subtype ,bpi ,num ,chan ,cpychan ,cpynum ,aux
82+
5683def rdann (recordname , annot , sampfrom = 0 , sampto = [], anndisp = 1 ):
5784 """ Read a WFDB annotation file recordname.annot and return the fields as lists or arrays
5885
@@ -133,42 +160,14 @@ def rdann(recordname, annot, sampfrom=0, sampto=[], anndisp=1):
133160 cpychan = 1
134161 cpynum = 1
135162 ts ,annsamp ,anntype ,bpi = copy_prev (AT ,ts ,filebytes ,bpi ,annsamp ,anntype ,ai )
136-
163+
137164 AT = filebytes [bpi , 1 ] >> 2
138165
139166 while (AT > 59 ): # Process any other fields belonging to this annotation
140- if AT == 61 : # SUB
141- # sub is interpreted as signed char. Remember to limit writing
142- # range.
143- subtype [ai ] = filebytes [bpi , 0 ].astype ('i1' )
144- bpi = bpi + 1
145- elif AT == 62 : # CHAN
146- # chan is interpreted as unsigned char
147- chan [ai ] = filebytes [bpi , 0 ]
148- cpychan = 0
149- bpi = bpi + 1
150- elif AT == 60 : # NUM
151- # num is interpreted as signed char
152- num [ai ] = filebytes [bpi , 0 ].astype ('i1' )
153- cpynum = 0
154- bpi = bpi + 1
155- elif AT == 63 : # AUX
156- # length of aux string. Max 256? No need to check other bits of
157- # second byte?
158- auxlen = filebytes [bpi , 0 ]
159- auxbytes = filebytes [
160- bpi +
161- 1 :bpi +
162- 1 +
163- math .ceil (
164- auxlen /
165- 2. ),
166- :].flatten () # The aux bytes
167- if auxlen & 1 :
168- auxbytes = auxbytes [:- 1 ]
169- aux [ai ] = "" .join ([chr (char )
170- for char in auxbytes ]) # The aux string
171- bpi = bpi + 1 + math .ceil (auxlen / 2. )
167+
168+ subtype ,bpi ,num ,chan ,cpychan ,cpynum ,aux = proc_extra_fields (AT ,
169+ subtype ,ai ,filebytes ,bpi ,num ,chan ,cpychan ,cpynum ,aux )
170+
172171 # Only aux and sub are reset between annotations. Chan and num keep
173172 # previous value if missing.
174173 AT = filebytes [bpi , 1 ] >> 2
0 commit comments