|
3 | 3 | import unittest
|
4 | 4 |
|
5 | 5 | import numpy as np
|
| 6 | +import pandas as pd |
6 | 7 |
|
7 | 8 | import wfdb
|
8 | 9 |
|
@@ -252,13 +253,31 @@ def test_4(self):
|
252 | 253 | annotation2 = wfdb.rdann("huge", "qrs")
|
253 | 254 | self.assertEqual(annotation1, annotation2)
|
254 | 255 |
|
| 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 | + |
255 | 273 | @classmethod
|
256 | 274 | def tearDownClass(cls):
|
257 | 275 | writefiles = [
|
258 | 276 | "100.atr",
|
259 | 277 | "1003.atr",
|
260 | 278 | "12726.anI",
|
261 | 279 | "huge.qrs",
|
| 280 | + "CustomLabel.atr" |
262 | 281 | ]
|
263 | 282 | for file in writefiles:
|
264 | 283 | if os.path.isfile(file):
|
|
0 commit comments