@@ -14,57 +14,59 @@ def test_1(self):
14
14
15
15
# This is not the fault of the script. The annotation file specifies a
16
16
# length 3
17
- annotation .aux [0 ] = '(N'
18
- # aux field with a null written after '(N' which the script correctly picks up. I am just
17
+ annotation .aux_note [0 ] = '(N'
18
+ # aux_note field with a null written after '(N' which the script correctly picks up. I am just
19
19
# getting rid of the null in this unit test to compare with the regexp output below which has
20
20
# no null to detect in the output text file of rdann.
21
21
22
22
# Target data from WFDB software package
23
23
lines = tuple (open ('tests/targetoutputdata/anntarget1' , 'r' ))
24
24
nannot = len (lines )
25
25
26
- Ttime = [None ] * nannot
27
- Tannsamp = np .empty (nannot , dtype = 'object' )
28
- Tanntype = [None ] * nannot
29
- Tsubtype = np .empty (nannot , dtype = 'object' )
30
- Tchan = np .empty (nannot , dtype = 'object' )
31
- Tnum = np .empty (nannot , dtype = 'object' )
32
- Taux = [None ] * nannot
26
+ target_time = [None ] * nannot
27
+ target_sample = np .empty (nannot , dtype = 'object' )
28
+ target_symbol = [None ] * nannot
29
+ target_subtype = np .empty (nannot , dtype = 'object' )
30
+ target_chan = np .empty (nannot , dtype = 'object' )
31
+ target_num = np .empty (nannot , dtype = 'object' )
32
+ target_aux_note = [None ] * nannot
33
33
34
34
RXannot = re .compile (
35
- '[ \t ]*(?P<time>[\[\]\w\.:]+) +(?P<annsamp >\d+) +(?P<anntype >.) +(?P<subtype>\d+) +(?P<chan>\d+) +(?P<num>\d+)\t ?(?P<aux >.*)' )
35
+ '[ \t ]*(?P<time>[\[\]\w\.:]+) +(?P<sample >\d+) +(?P<symbol >.) +(?P<subtype>\d+) +(?P<chan>\d+) +(?P<num>\d+)\t ?(?P<aux_note >.*)' )
36
36
37
37
for i in range (0 , nannot ):
38
- Ttime [i ], Tannsamp [i ], Tanntype [i ], Tsubtype [i ], Tchan [
39
- i ], Tnum [i ], Taux [i ] = RXannot .findall (lines [i ])[0 ]
38
+ target_time [i ], target_sample [i ], target_symbol [i ], target_subtype [i ], target_chan [
39
+ i ], target_num [i ], target_aux_note [i ] = RXannot .findall (lines [i ])[0 ]
40
40
41
41
# Convert objects into integers
42
- Tannsamp = Tannsamp .astype ('int' )
43
- Tnum = Tnum .astype ('int' )
44
- Tsubtype = Tsubtype .astype ('int' )
45
- Tchan = Tchan .astype ('int' )
42
+ target_sample = target_sample .astype ('int' )
43
+ target_num = target_num .astype ('int' )
44
+ target_subtype = target_subtype .astype ('int' )
45
+ target_chan = target_chan .astype ('int' )
46
46
47
47
# Compare
48
- comp = [np .array_equal (annotation .annsamp , Tannsamp ),
49
- np .array_equal (annotation .anntype , Tanntype ),
50
- np .array_equal (annotation .subtype , Tsubtype ),
51
- np .array_equal (annotation .chan , Tchan ),
52
- np .array_equal (annotation .num , Tnum ),
53
- annotation .aux == Taux ]
48
+ comp = [np .array_equal (annotation .sample , target_sample ),
49
+ np .array_equal (annotation .symbol , target_symbol ),
50
+ np .array_equal (annotation .subtype , target_subtype ),
51
+ np .array_equal (annotation .chan , target_chan ),
52
+ np .array_equal (annotation .num , target_num ),
53
+ annotation .aux_note == target_aux_note ]
54
54
55
55
# Test file streaming
56
- pbannotation = wfdb .rdann ('100' , 'atr' , pbdir = 'mitdb' )
57
- pbannotation .aux [0 ] = '(N'
56
+ pbannotation = wfdb .rdann ('100' , 'atr' , pbdir = 'mitdb' , return_label_elements = ['label_store' , 'symbol' ])
57
+ pbannotation .aux_note [0 ] = '(N'
58
+ pbannotation .create_label_map ()
58
59
59
60
# Test file writing
60
61
annotation .wrann (writefs = True )
61
- annotationwrite = wfdb .rdann ('100' , 'atr' )
62
+ writeannotation = wfdb .rdann ('100' , 'atr' , return_label_elements = ['label_store' , 'symbol' ])
63
+ writeannotation .create_label_map ()
62
64
63
65
assert (comp == [True ] * 6 )
64
66
assert annotation .__eq__ (pbannotation )
65
- assert annotation .__eq__ (annotationwrite )
67
+ assert annotation .__eq__ (writeannotation )
66
68
67
- # Test 2 - Annotation file 12726.anI with many aux strings.
69
+ # Test 2 - Annotation file 12726.anI with many aux_note strings.
68
70
# Target file created with: rdann -r sampledata/100 -a atr > anntarget2
69
71
def test_2 (self ):
70
72
@@ -75,44 +77,46 @@ def test_2(self):
75
77
lines = tuple (open ('tests/targetoutputdata/anntarget2' , 'r' ))
76
78
nannot = len (lines )
77
79
78
- Ttime = [None ] * nannot
79
- Tannsamp = np .empty (nannot , dtype = 'object' )
80
- Tanntype = [None ] * nannot
81
- Tsubtype = np .empty (nannot , dtype = 'object' )
82
- Tchan = np .empty (nannot , dtype = 'object' )
83
- Tnum = np .empty (nannot , dtype = 'object' )
84
- Taux = [None ] * nannot
80
+ target_time = [None ] * nannot
81
+ target_sample = np .empty (nannot , dtype = 'object' )
82
+ target_symbol = [None ] * nannot
83
+ target_subtype = np .empty (nannot , dtype = 'object' )
84
+ target_chan = np .empty (nannot , dtype = 'object' )
85
+ target_num = np .empty (nannot , dtype = 'object' )
86
+ target_aux_note = [None ] * nannot
85
87
86
88
RXannot = re .compile (
87
- '[ \t ]*(?P<time>[\[\]\w\.:]+) +(?P<annsamp >\d+) +(?P<anntype >.) +(?P<subtype>\d+) +(?P<chan>\d+) +(?P<num>\d+)\t ?(?P<aux >.*)' )
89
+ '[ \t ]*(?P<time>[\[\]\w\.:]+) +(?P<sample >\d+) +(?P<symbol >.) +(?P<subtype>\d+) +(?P<chan>\d+) +(?P<num>\d+)\t ?(?P<aux_note >.*)' )
88
90
89
91
for i in range (0 , nannot ):
90
- Ttime [i ], Tannsamp [i ], Tanntype [i ], Tsubtype [i ], Tchan [
91
- i ], Tnum [i ], Taux [i ] = RXannot .findall (lines [i ])[0 ]
92
+ target_time [i ], target_sample [i ], target_symbol [i ], target_subtype [i ], target_chan [
93
+ i ], target_num [i ], target_aux_note [i ] = RXannot .findall (lines [i ])[0 ]
92
94
93
95
# Convert objects into integers
94
- Tannsamp = Tannsamp .astype ('int' )
95
- Tnum = Tnum .astype ('int' )
96
- Tsubtype = Tsubtype .astype ('int' )
97
- Tchan = Tchan .astype ('int' )
96
+ target_sample = target_sample .astype ('int' )
97
+ target_num = target_num .astype ('int' )
98
+ target_subtype = target_subtype .astype ('int' )
99
+ target_chan = target_chan .astype ('int' )
98
100
99
101
# Compare
100
- comp = [np .array_equal (annotation .annsamp , Tannsamp ),
101
- np .array_equal (annotation .anntype , Tanntype ),
102
- np .array_equal (annotation .subtype , Tsubtype ),
103
- np .array_equal (annotation .chan , Tchan ),
104
- np .array_equal (annotation .num , Tnum ),
105
- annotation .aux == Taux ]
102
+ comp = [np .array_equal (annotation .sample , target_sample ),
103
+ np .array_equal (annotation .symbol , target_symbol ),
104
+ np .array_equal (annotation .subtype , target_subtype ),
105
+ np .array_equal (annotation .chan , target_chan ),
106
+ np .array_equal (annotation .num , target_num ),
107
+ annotation .aux_note == target_aux_note ]
106
108
# Test file streaming
107
- pbannotation = wfdb .rdann ('12726' , 'anI' , pbdir = 'prcp' )
109
+ pbannotation = wfdb .rdann ('12726' , 'anI' , pbdir = 'prcp' , return_label_elements = ['label_store' , 'symbol' ])
110
+ pbannotation .create_label_map ()
108
111
109
112
# Test file writing
110
113
annotation .wrann (writefs = True )
111
- annotationwrite = wfdb .rdann ('12726' , 'anI' )
114
+ writeannotation = wfdb .rdann ('12726' , 'anI' , return_label_elements = ['label_store' , 'symbol' ])
115
+ writeannotation .create_label_map ()
112
116
113
117
assert (comp == [True ] * 6 )
114
118
assert annotation .__eq__ (pbannotation )
115
- assert annotation .__eq__ (annotationwrite )
119
+ assert annotation .__eq__ (writeannotation )
116
120
117
121
# Test 3 - Annotation file 1003.atr with custom annotation types
118
122
# Target file created with: rdann -r sampledata/1003 -a atr > anntarget3
@@ -125,42 +129,44 @@ def test_3(self):
125
129
lines = tuple (open ('tests/targetoutputdata/anntarget3' , 'r' ))
126
130
nannot = len (lines )
127
131
128
- Ttime = [None ] * nannot
129
- Tannsamp = np .empty (nannot , dtype = 'object' )
130
- Tanntype = [None ] * nannot
131
- Tsubtype = np .empty (nannot , dtype = 'object' )
132
- Tchan = np .empty (nannot , dtype = 'object' )
133
- Tnum = np .empty (nannot , dtype = 'object' )
134
- Taux = [None ] * nannot
132
+ target_time = [None ] * nannot
133
+ target_sample = np .empty (nannot , dtype = 'object' )
134
+ target_symbol = [None ] * nannot
135
+ target_subtype = np .empty (nannot , dtype = 'object' )
136
+ target_chan = np .empty (nannot , dtype = 'object' )
137
+ target_num = np .empty (nannot , dtype = 'object' )
138
+ target_aux_note = [None ] * nannot
135
139
136
140
RXannot = re .compile (
137
- '[ \t ]*(?P<time>[\[\]\w\.:]+) +(?P<annsamp >\d+) +(?P<anntype >.) +(?P<subtype>\d+) +(?P<chan>\d+) +(?P<num>\d+)\t ?(?P<aux >.*)' )
141
+ '[ \t ]*(?P<time>[\[\]\w\.:]+) +(?P<sample >\d+) +(?P<symbol >.) +(?P<subtype>\d+) +(?P<chan>\d+) +(?P<num>\d+)\t ?(?P<aux_note >.*)' )
138
142
139
143
for i in range (0 , nannot ):
140
- Ttime [i ], Tannsamp [i ], Tanntype [i ], Tsubtype [i ], Tchan [
141
- i ], Tnum [i ], Taux [i ] = RXannot .findall (lines [i ])[0 ]
144
+ target_time [i ], target_sample [i ], target_symbol [i ], target_subtype [i ], target_chan [
145
+ i ], target_num [i ], target_aux_note [i ] = RXannot .findall (lines [i ])[0 ]
142
146
143
147
# Convert objects into integers
144
- Tannsamp = Tannsamp .astype ('int' )
145
- Tnum = Tnum .astype ('int' )
146
- Tsubtype = Tsubtype .astype ('int' )
147
- Tchan = Tchan .astype ('int' )
148
+ target_sample = target_sample .astype ('int' )
149
+ target_num = target_num .astype ('int' )
150
+ target_subtype = target_subtype .astype ('int' )
151
+ target_chan = target_chan .astype ('int' )
148
152
149
153
# Compare
150
- comp = [np .array_equal (annotation .annsamp , Tannsamp ),
151
- np .array_equal (annotation .anntype , Tanntype ),
152
- np .array_equal (annotation .subtype , Tsubtype ),
153
- np .array_equal (annotation .chan , Tchan ),
154
- np .array_equal (annotation .num , Tnum ),
155
- annotation .aux == Taux ]
154
+ comp = [np .array_equal (annotation .sample , target_sample ),
155
+ np .array_equal (annotation .symbol , target_symbol ),
156
+ np .array_equal (annotation .subtype , target_subtype ),
157
+ np .array_equal (annotation .chan , target_chan ),
158
+ np .array_equal (annotation .num , target_num ),
159
+ annotation .aux_note == target_aux_note ]
156
160
157
161
# Test file streaming
158
- pbannotation = wfdb .rdann ('1003' , 'atr' , pbdir = 'challenge/2014/set-p2' )
159
-
162
+ pbannotation = wfdb .rdann ('1003' , 'atr' , pbdir = 'challenge/2014/set-p2' , return_label_elements = ['label_store' , 'symbol' ])
163
+ pbannotation .create_label_map ()
164
+
160
165
# Test file writing
161
166
annotation .wrann (writefs = True )
162
- annotationwrite = wfdb .rdann ('1003' , 'atr' )
167
+ writeannotation = wfdb .rdann ('1003' , 'atr' , return_label_elements = ['label_store' , 'symbol' ])
168
+ writeannotation .create_label_map ()
163
169
164
170
assert (comp == [True ] * 6 )
165
171
assert annotation .__eq__ (pbannotation )
166
- assert annotation .__eq__ (annotationwrite )
172
+ assert annotation .__eq__ (writeannotation )
0 commit comments