11import numpy as np
22from wfdb import rdsamp
3-
3+
4+
45class test_rdsamp ():
5-
6- # Test 1 - Format 212/Entire signal/Physical
7- # Target file created with: rdsamp -r sampledata/100 -P | cut -f 2- > target1
6+
7+ # Test 1 - Format 212/Entire signal/Physical
8+ # Target file created with: rdsamp -r sampledata/100 -P | cut -f 2- >
9+ # target1
810 def test_1 (self ):
9- sig , fields = rdsamp ('sampledata/100' )
10- sig = np .round (sig , decimals = 8 )
11- targetsig = np .genfromtxt ('tests/targetoutputdata/target1' )
11+ sig , fields = rdsamp ('sampledata/100' )
12+ sig = np .round (sig , decimals = 8 )
13+ targetsig = np .genfromtxt ('tests/targetoutputdata/target1' )
1214 assert np .array_equal (sig , targetsig )
13-
14- # Test 2 - Format 212/Selected Duration/Selected Channel/Digital.
15- # Target file created with: rdsamp -r sampledata/100 -f 0.002 -t 30 -s 1 | cut -f 2- > target2
16- def test_2 (self ):
17- sig , fields = rdsamp ('sampledata/100' , sampfrom = 1 , sampto = 10800 , channels = [1 ], physical = 0 )
18- targetsig = np .genfromtxt ('tests/targetoutputdata/target2' )
19- targetsig = targetsig .reshape (len (targetsig ), 1 )
15+
16+ # Test 2 - Format 212/Selected Duration/Selected Channel/Digital.
17+ # Target file created with: rdsamp -r sampledata/100 -f 0.002 -t 30 -s 1 |
18+ # cut -f 2- > target2
19+ def test_2 (self ):
20+ sig , fields = rdsamp ('sampledata/100' , sampfrom = 1 ,
21+ sampto = 10800 , channels = [1 ], physical = 0 )
22+ targetsig = np .genfromtxt ('tests/targetoutputdata/target2' )
23+ targetsig = targetsig .reshape (len (targetsig ), 1 )
2024 assert np .array_equal (sig , targetsig )
21-
25+
2226 # Test 3 - Format 16/Entire signal/Digital
23- # Target file created with: rdsamp -r sampledata/test01_00s | cut -f 2- > target3
27+ # Target file created with: rdsamp -r sampledata/test01_00s | cut -f 2- >
28+ # target3
2429 def test_3 (self ):
25- sig , fields = rdsamp ('sampledata/test01_00s' , physical = 0 )
26- targetsig = np .genfromtxt ('tests/targetoutputdata/target3' )
30+ sig , fields = rdsamp ('sampledata/test01_00s' , physical = 0 )
31+ targetsig = np .genfromtxt ('tests/targetoutputdata/target3' )
2732 assert np .array_equal (sig , targetsig )
28-
33+
2934 # Test 4 - Format 16 with byte offset/Selected Duration/Selected Channels/Physical
30- # Target file created with: rdsamp -r sampledata/a103l -f 50 -t 160 -s 2 0 -P | cut -f 2- > target4
35+ # Target file created with: rdsamp -r sampledata/a103l -f 50 -t 160 -s 2 0
36+ # -P | cut -f 2- > target4
3137 def test_4 (self ):
32- sig , fields = rdsamp ('sampledata/a103l' , sampfrom = 12500 , sampto = 40000 , channels = [2 , 0 ])
33- sig = np .round (sig , decimals = 8 )
34- targetsig = np .genfromtxt ('tests/targetoutputdata/target4' )
35- assert np .array_equal (sig , targetsig )
36-
38+ sig , fields = rdsamp ('sampledata/a103l' ,
39+ sampfrom = 12500 , sampto = 40000 , channels = [2 , 0 ])
40+ sig = np .round (sig , decimals = 8 )
41+ targetsig = np .genfromtxt ('tests/targetoutputdata/target4' )
42+ assert np .array_equal (sig , targetsig )
43+
3744 # Test 5 - Format 16 with byte offset/Selected Duration/Selected Channels/Digital
38- # Target file created with: rdsamp -r sampledata/a103l -f 80 -s 0 1 | cut -f 2- > target5
45+ # Target file created with: rdsamp -r sampledata/a103l -f 80 -s 0 1 | cut
46+ # -f 2- > target5
3947 def test_5 (self ):
40- sig , fields = rdsamp ('sampledata/a103l' , sampfrom = 20000 , physical = 0 , channels = [0 , 1 ])
41- targetsig = np .genfromtxt ('tests/targetoutputdata/target5' )
42- assert np .array_equal (sig , targetsig )
43-
48+ sig , fields = rdsamp ('sampledata/a103l' ,
49+ sampfrom = 20000 , physical = 0 , channels = [0 , 1 ])
50+ targetsig = np .genfromtxt ('tests/targetoutputdata/target5' )
51+ assert np .array_equal (sig , targetsig )
52+
4453 # Test 6 - Format 80/Selected Duration/Selected Channels/Physical
45- # Target file created with: rdsamp -r sampledata/3000003_0003 -f 1 -t 8 -s 1 -P | cut -f 2- > target6
54+ # Target file created with: rdsamp -r sampledata/3000003_0003 -f 1 -t 8 -s
55+ # 1 -P | cut -f 2- > target6
4656 def test_6 (self ):
47- sig , fields = rdsamp ('sampledata/3000003_0003' , sampfrom = 125 , sampto = 1000 , channels = [1 ])
48- sig = np .round (sig , decimals = 8 )
49- targetsig = np .genfromtxt ('tests/targetoutputdata/target6' )
50- targetsig = targetsig .reshape (len (targetsig ), 1 )
51- assert np .array_equal (sig , targetsig )
52-
57+ sig , fields = rdsamp ('sampledata/3000003_0003' ,
58+ sampfrom = 125 , sampto = 1000 , channels = [1 ])
59+ sig = np .round (sig , decimals = 8 )
60+ targetsig = np .genfromtxt ('tests/targetoutputdata/target6' )
61+ targetsig = targetsig .reshape (len (targetsig ), 1 )
62+ assert np .array_equal (sig , targetsig )
63+
5364 # Test 7 - Multi-dat/Entire signal/Digital
54- # Target file created with: rdsamp -r sampledata/s0010_re | cut -f 2- > target7
65+ # Target file created with: rdsamp -r sampledata/s0010_re | cut -f 2- >
66+ # target7
5567 def test_7 (self ):
56- sig , fields = rdsamp ('sampledata/s0010_re' , physical = 0 )
57- targetsig = np .genfromtxt ('tests/targetoutputdata/target7' )
58- assert np .array_equal (sig , targetsig )
59-
68+ sig , fields = rdsamp ('sampledata/s0010_re' , physical = 0 )
69+ targetsig = np .genfromtxt ('tests/targetoutputdata/target7' )
70+ assert np .array_equal (sig , targetsig )
71+
6072 # Test 8 - Multi-dat/Selected Duration/Selected Channels/Physical
61- # Target file created with: rdsamp -r sampledata/s0010_re -f 5 -t 38 -P -s 13 0 4 8 3 | cut -f 2- > target8
73+ # Target file created with: rdsamp -r sampledata/s0010_re -f 5 -t 38 -P -s
74+ # 13 0 4 8 3 | cut -f 2- > target8
6275 def test_8 (self ):
63- sig , fields = rdsamp ('sampledata/s0010_re' , sampfrom = 5000 , sampto = 38000 , channels = [13 , 0 , 4 , 8 , 3 ])
64- sig = np .round (sig , decimals = 8 )
65- targetsig = np .genfromtxt ('tests/targetoutputdata/target8' )
66- assert np .array_equal (sig , targetsig )
67-
76+ sig , fields = rdsamp ('sampledata/s0010_re' , sampfrom = 5000 ,
77+ sampto = 38000 , channels = [13 , 0 , 4 , 8 , 3 ])
78+ sig = np .round (sig , decimals = 8 )
79+ targetsig = np .genfromtxt ('tests/targetoutputdata/target8' )
80+ assert np .array_equal (sig , targetsig )
81+
6882 # Test 9 - Format 12 multi-samples per frame and skew/Entire Signal/Digital
69- # Target file created with: rdsamp -r sampledata/03700181 | cut -f 2- > target9
83+ # Target file created with: rdsamp -r sampledata/03700181 | cut -f 2- >
84+ # target9
7085 def test_9 (self ):
71- sig , fields = rdsamp ('sampledata/03700181' , physical = 0 )
72- sig = sig [:- 4 ,:] # The WFDB library rdsamp does not return the final N samples for all channels due to the skew.
73- # The WFDB python rdsamp does return the final N samples, filling in NANs for end of skewed channels only.
74- targetsig = np .genfromtxt ('tests/targetoutputdata/target9' )
86+ sig , fields = rdsamp ('sampledata/03700181' , physical = 0 )
87+ # The WFDB library rdsamp does not return the final N samples for all
88+ # channels due to the skew.
89+ sig = sig [:- 4 , :]
90+ # The WFDB python rdsamp does return the final N samples, filling in
91+ # NANs for end of skewed channels only.
92+ targetsig = np .genfromtxt ('tests/targetoutputdata/target9' )
7593 assert np .array_equal (sig , targetsig )
76-
94+
7795 # Test 10 - Format 12 multi-samples per frame and skew/Selected Duration/Selected Channels/Physical
78- # Target file created with: rdsamp -r sampledata/03700181 -f 8 -t 128 -s 0 2 -P | cut -f 2- > target10
96+ # Target file created with: rdsamp -r sampledata/03700181 -f 8 -t 128 -s 0
97+ # 2 -P | cut -f 2- > target10
7998 def test_10 (self ):
80- sig , fields = rdsamp ('sampledata/03700181' , channels = [0 ,2 ], sampfrom = 1000 , sampto = 16000 )
81- sig = np .round (sig , decimals = 8 )
82- targetsig = np .genfromtxt ('tests/targetoutputdata/target10' )
99+ sig , fields = rdsamp ('sampledata/03700181' ,
100+ channels = [0 , 2 ], sampfrom = 1000 , sampto = 16000 )
101+ sig = np .round (sig , decimals = 8 )
102+ targetsig = np .genfromtxt ('tests/targetoutputdata/target10' )
83103 assert np .array_equal (sig , targetsig )
84-
85-
86- #### Temporarily removing multi-segment tests due to differences in function. See iss14 #####
87-
104+
105+ #### Temporarily removing multi-segment tests due to differences in functi
106+
88107 # Test 11 - Multi-segment variable layout/Entire signal/Physical
89108 # Target file created with: rdsamp -r sampledata/matched/s25047/s25047-2704-05-04-10-44 -P | cut -f 2- > target11
90- #def test_11(self):
109+ # def test_11(self):
91110 #sig, fields=rdsamp('sampledata/matched/s25047/s25047-2704-05-04-10-44')
92111 #sig=np.round(sig, decimals=8)
93- #targetsig=np.genfromtxt('tests/targetoutputdata/target11')
112+ # targetsig=np.genfromtxt('tests/targetoutputdata/target11')
94113 #assert np.array_equal(sig, targetsig)
95-
114+
96115 # Test 12 - Multi-segment variable layout/Selected duration/Selected Channels/Physical
97116 # Target file created with: rdsamp -r sampledata/matched/s00001/s00001-2896-10-10-00-31 -f 70 -t 4000 -s 3 0 -P | cut -f 2- > target12
98- #def test_12(self):
117+ # def test_12(self):
99118 #sig, fields=rdsamp('sampledata/matched/s00001/s00001-2896-10-10-00-31', sampfrom=8750, sampto=500000, channels=[3, 0])
100119 #sig=np.round(sig, decimals=8)
101- #targetsig=np.genfromtxt('tests/targetoutputdata/target12')
120+ # targetsig=np.genfromtxt('tests/targetoutputdata/target12')
102121 #assert np.array_equal(sig, targetsig)
103-
122+
104123 #################
105-
124+
106125 # Test 13 - Format 310/Selected Duration/Digital
107126 # Target file created with: rdsamp -r sampledata/3000003_0003 -f 0 -t 8.21 | cut -f 2- | wrsamp -o 310derive -O 310
108127 # rdsamp -r 310derive -f 0.007 | cut -f 2- > target13
109128 def test_13 (self ):
110- sig , fields = rdsamp ('sampledata/310derive' , sampfrom = 2 , physical = 0 )
111- targetsig = np .genfromtxt ('tests/targetoutputdata/target13' )
112- assert np .array_equal (sig , targetsig )
113-
129+ sig , fields = rdsamp ('sampledata/310derive' , sampfrom = 2 , physical = 0 )
130+ targetsig = np .genfromtxt ('tests/targetoutputdata/target13' )
131+ assert np .array_equal (sig , targetsig )
132+
114133 # Test 14 - Format 311/Selected Duration/Physical
115134 # Target file created with: rdsamp -r sampledata/3000003_0003 -f 0 -t 8.21 -s 1 | cut -f 2- | wrsamp -o 311derive -O 311
116135 # rdsamp -r 311derive -f 0.005 -t 3.91 -P | cut -f 2- > target14
117136 def test_14 (self ):
118- sig , fields = rdsamp ('sampledata/311derive' , sampfrom = 1 , sampto = 978 )
119- sig = np .round (sig , decimals = 8 )
120- targetsig = np .genfromtxt ('tests/targetoutputdata/target14' )
121- targetsig = targetsig .reshape ([977 ,1 ])
122- assert np .array_equal (sig , targetsig )
123-
124-
125-
137+ sig , fields = rdsamp ('sampledata/311derive' , sampfrom = 1 , sampto = 978 )
138+ sig = np .round (sig , decimals = 8 )
139+ targetsig = np .genfromtxt ('tests/targetoutputdata/target14' )
140+ targetsig = targetsig .reshape ([977 , 1 ])
141+ assert np .array_equal (sig , targetsig )
0 commit comments