Skip to content

Commit 54c386b

Browse files
committed
dev
1 parent b20988d commit 54c386b

File tree

2 files changed

+59
-16
lines changed

2 files changed

+59
-16
lines changed

devtests.ipynb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,6 +1776,30 @@
17761776
"5.astype('i1')"
17771777
]
17781778
},
1779+
{
1780+
"cell_type": "code",
1781+
"execution_count": 49,
1782+
"metadata": {
1783+
"collapsed": false
1784+
},
1785+
"outputs": [
1786+
{
1787+
"data": {
1788+
"text/plain": [
1789+
"[65, 101, 101, 102, 97, 101, 102, 97, 101, 102]"
1790+
]
1791+
},
1792+
"execution_count": 49,
1793+
"metadata": {},
1794+
"output_type": "execute_result"
1795+
}
1796+
],
1797+
"source": [
1798+
"x='Aeefaefaef'\n",
1799+
"\n",
1800+
"[ord(i) for i in x]"
1801+
]
1802+
},
17791803
{
17801804
"cell_type": "code",
17811805
"execution_count": null,

wfdb/annotations.py

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def checkfield(self, field):
7575
fielditem = getattr(self, field)
7676

7777
# Ensure the field item is a list
78-
if type(fielditem) != list
78+
if type(fielditem) != list:
7979
print('The ', field, ' field must be a list')
8080
sys.exit()
8181

@@ -131,7 +131,6 @@ def checkfieldcohesion(self):
131131

132132
def wrannfile(self):
133133

134-
135134
# If there is an fs, write it
136135
if self.fs is not None:
137136
databytes = insert_fs(self.fs)
@@ -182,9 +181,6 @@ def allfieldbytes(self):
182181
fieldbytes[field] = self.fieldbytes(field)
183182

184183

185-
186-
187-
188184
# Only need to write annsamp and anntype
189185
#if extrawritefields == []:
190186
# for i in range(0, len(self.annsamp)):
@@ -202,10 +198,6 @@ def fieldbytes(self, field):
202198

203199
databytes = []
204200

205-
206-
'num', 'subtype', 'chan', 'aux'
207-
208-
209201
# annsamp and anntype bytes come together
210202
if field == 'annsamp_anntype':
211203
# Difference values for annotation samples
@@ -230,18 +222,45 @@ def fieldbytes(self, field):
230222

231223
databytes.append(indexbytes)
232224

225+
# All other fields are optional
233226
elif field == 'num':
234227
for i in range(0, len(self.num)):
235-
# First byte gives
236-
databytes.append([ , + 240])
237-
238-
228+
if self.num[i] is None:
229+
databytes.append(None)
230+
else:
231+
# First byte stores num
232+
# second byte stores 60*4 indicator
233+
databytes.append([self.num[i], + 240])
239234
elif field == 'subtype':
240-
print('on it')
235+
for i in range(0, len(self.subtype)):
236+
if self.subtype[i] is None:
237+
databytes.append(None)
238+
else:
239+
# First byte stores subtype
240+
# second byte stores 61*4 indicator
241+
databytes.append([self.subtype[i], + 244])
241242
elif field == 'chan':
242-
print('on it')
243+
for i in range(0, len(self.chan)):
244+
if self.chan[i] is None:
245+
databytes.append(None)
246+
else:
247+
# First byte stores num
248+
# second byte stores 62*4 indicator
249+
databytes.append([self.chan[i], + 248])
243250
elif field == 'aux':
244-
print('on it')
251+
for i in range(0, len(self.aux)):
252+
if self.aux[i] is None:
253+
databytes.append(None)
254+
else:
255+
aux = self.aux[i]
256+
# - First byte stores length of aux field
257+
# - Second byte stores 63*4 indicator
258+
# - Then store the aux string characters
259+
auxbytes = [len(aux), + 252] + [ord(i) for i in x]
260+
# Zero pad odd length aux strings
261+
if len(aux) % 2:
262+
auxbytes.append([0])
263+
databytes.append(auxbytes)
245264

246265
return databytes
247266

0 commit comments

Comments
 (0)