Skip to content

Commit f01a151

Browse files
committed
add custom annotation test
1 parent 99a4737 commit f01a151

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

tests/test_annotation.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import unittest
44

55
import numpy as np
6+
import pandas as pd
67

78
import wfdb
89

@@ -252,13 +253,31 @@ def test_4(self):
252253
annotation2 = wfdb.rdann("huge", "qrs")
253254
self.assertEqual(annotation1, annotation2)
254255

256+
def test_5(self):
257+
"""
258+
Write and read annotations with custom labels.
259+
"""
260+
ann_idx = np.array([1, 1000, 2000, 3000])
261+
ann_chan = np.array([3, 1, 2, 3])
262+
# write custom labels
263+
ann_label_store = np.array([ 4, 2, 1, 3])
264+
ann_custom_labels = {'label_store': [1, 2, 3, 4],
265+
'symbol': ['v','l','r','z'],
266+
'description':['pvc','lbbb','rbbb','pac']}
267+
ann_custom_labels = pd.DataFrame(data=ann_custom_labels)
268+
wfdb.wrann('CustomLabel', 'atr', ann_idx, chan=ann_chan,
269+
custom_labels=ann_custom_labels, label_store=ann_label_store)
270+
ann = wfdb.rdann('CustomLabel', 'atr')
271+
self.assertEqual(ann.symbol, ['z', 'l', 'v', 'r'])
272+
255273
@classmethod
256274
def tearDownClass(cls):
257275
writefiles = [
258276
"100.atr",
259277
"1003.atr",
260278
"12726.anI",
261279
"huge.qrs",
280+
"CustomLabel.atr"
262281
]
263282
for file in writefiles:
264283
if os.path.isfile(file):

0 commit comments

Comments
 (0)