Skip to content

Commit 5394ad2

Browse files
author
Chen Xie
committed
splitting rdsamp functions
1 parent a30ff5e commit 5394ad2

File tree

3 files changed

+217
-209
lines changed

3 files changed

+217
-209
lines changed

devtests.ipynb

Lines changed: 44 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,11 @@
99
},
1010
{
1111
"cell_type": "code",
12-
"execution_count": 1,
12+
"execution_count": null,
1313
"metadata": {
1414
"collapsed": false
1515
},
16-
"outputs": [
17-
{
18-
"name": "stdout",
19-
"output_type": "stream",
20-
"text": [
21-
"[[ 988]\n",
22-
" [ 990]\n",
23-
" [ 989]\n",
24-
" ..., \n",
25-
" [ 951]\n",
26-
" [ 957]\n",
27-
" [1024]]\n",
28-
"649886\n"
29-
]
30-
}
31-
],
16+
"outputs": [],
3217
"source": [
3318
"import numpy as np\n",
3419
"from wfdb import rdsamp\n",
@@ -153,46 +138,19 @@
153138
},
154139
{
155140
"cell_type": "code",
156-
"execution_count": 3,
141+
"execution_count": null,
157142
"metadata": {
158143
"collapsed": false
159144
},
160-
"outputs": [
161-
{
162-
"name": "stdout",
163-
"output_type": "stream",
164-
"text": [
165-
"[[ nan nan]\n",
166-
" [ nan nan]\n",
167-
" [ nan nan]\n",
168-
" ..., \n",
169-
" [-21. nan]\n",
170-
" [-21. nan]\n",
171-
" [-20. nan]]\n",
172-
"(10000, 2)\n",
173-
"\n",
174-
"\n",
175-
"\n",
176-
"{'nsampseg': [0, 3261, 6750, 125, 1354, 512, 906259, 2604, 1304941, 1280, 512, 2210767, 172500, 5760000, 157500, 3900000, 4425, 18075, 7500, 37500, 22500], 'nsig': 4, 'fmt': [], 'fs': 125.0, 'nseg': 21, 'nsamp': 14518365, 'signame': [], 'units': [], 'skew': [], 'baseline': [], 'sampsperframe': [], 'initvalue': [], 'gain': [], 'comments': [' <age>: 60 <sex>: F'], 'basedate': '10/10/2896', 'filename': ['3975656_layout', '~', '3975656_0001', '3975656_0002', '3975656_0003', '3975656_0004', '3975656_0005', '~', '3975656_0006', '3975656_0007', '3975656_0008', '3975656_0009', '~', '3975656_0010', '~', '3975656_0011', '3975656_0012', '3975656_0013', '3975656_0014', '3975656_0015', '3975656_0016'], 'byteoffset': [], 'basetime': '00:31:25.894'}\n",
177-
"\n",
178-
"\n",
179-
"\n",
180-
"{'nsampseg': [], 'nsig': 4, 'fmt': ['0', '0', '0', '0'], 'fs': 125.0, 'nseg': 1, 'nsamp': 0, 'signame': ['II', 'V', 'MCL1', 'ABP'], 'units': ['mV', 'mV', 'mV', 'mmHg'], 'skew': [0, 0, 0, 0], 'baseline': [0, 0, 0, 0], 'sampsperframe': [1, 1, 1, 1], 'initvalue': [-16384, -8192, -1024, -256], 'gain': [83.0, 55.0, 122.0, 1.0], 'comments': [], 'basedate': '', 'filename': ['~', '~', '~', '~'], 'byteoffset': [0, 0, 0, 0], 'basetime': '31:25.894'}\n",
181-
"\n",
182-
"\n",
183-
"\n",
184-
"['Empty Segment', {'nsampseg': [], 'nsig': 1, 'fmt': ['80', 'No Channel'], 'fs': 125.0, 'nseg': 1, 'nsamp': 6750, 'signame': ['V', 'No Channel'], 'units': ['mV', 'No Channel'], 'skew': [0, 'No Channel'], 'baseline': [0, 'No Channel'], 'sampsperframe': [1, 'No Channel'], 'initvalue': [0, 'No Channel'], 'gain': [1.0, 'No Channel'], 'comments': [], 'basedate': '', 'filename': ['3975656_0001.dat', 'No Channel'], 'byteoffset': [0, 'No Channel'], 'basetime': '31:51.982'}]\n"
185-
]
186-
}
187-
],
145+
"outputs": [],
188146
"source": [
189147
"# Testing rdsamp multi-segment variable layout record - stacksegments\n",
190148
"import numpy as np\n",
191149
"from wfdb import rdsamp\n",
192150
"\n",
193151
"\n",
194152
"# Return single numpy array\n",
195-
"sig, fields=rdsamp('sampledata/matched/s00001/s00001-2896-10-10-00-31', stacksegments=1, sampto=10000, channels=[1, 2])\n",
153+
"sig, fields=rdsamp('sampledata/matched/s00001/s00001-2896-10-10-00-31', sampfrom=1, sampto=10000, channels=[1, 2], physical=1)\n",
196154
"\n",
197155
"print(sig)\n",
198156
"print(sig.shape)\n",
@@ -204,6 +162,19 @@
204162
"print(fields[2])"
205163
]
206164
},
165+
{
166+
"cell_type": "code",
167+
"execution_count": null,
168+
"metadata": {
169+
"collapsed": false
170+
},
171+
"outputs": [],
172+
"source": [
173+
"x=[1,2,3]\n",
174+
"y=[x]*3\n",
175+
"y[1]"
176+
]
177+
},
207178
{
208179
"cell_type": "code",
209180
"execution_count": null,
@@ -226,24 +197,42 @@
226197
},
227198
{
228199
"cell_type": "code",
229-
"execution_count": null,
200+
"execution_count": 1,
230201
"metadata": {
231202
"collapsed": false
232203
},
233-
"outputs": [],
204+
"outputs": [
205+
{
206+
"ename": "UnboundLocalError",
207+
"evalue": "local variable 'returninds' referenced before assignment",
208+
"output_type": "error",
209+
"traceback": [
210+
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
211+
"\u001b[1;31mUnboundLocalError\u001b[0m Traceback (most recent call last)",
212+
"\u001b[1;32m<ipython-input-1-4902248f2f9c>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[1;31m# Return list of arrays\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 6\u001b[1;33m \u001b[0msig\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfields\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mrdsamp\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'sampledata/matched/s00001/s00001-2896-10-10-00-31'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0msampfrom\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m10\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0msampto\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m10250\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mchannels\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m3\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mstacksegments\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 7\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 8\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"\\n\\nOutput of rdsamp:\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
213+
"\u001b[1;32m/home/cx1111/PhysionetProjects/wfdb-python/wfdb/_rdsamp.py\u001b[0m in \u001b[0;36mrdsamp\u001b[1;34m(recordname, sampfrom, sampto, channels, physical, stacksegments)\u001b[0m\n\u001b[0;32m 1216\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1217\u001b[0m \u001b[1;31m# Work out the relative channels to return this segment\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1218\u001b[1;33m \u001b[0msegchannels\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mreturninds\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0memptyinds\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mgetsegmentchannels\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mstartseg\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0msegrecordname\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdirname\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mlayoutfields\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mchannels\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 1219\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1220\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
214+
"\u001b[1;32m/home/cx1111/PhysionetProjects/wfdb-python/wfdb/_rdsamp.py\u001b[0m in \u001b[0;36mgetsegmentchannels\u001b[1;34m(startseg, segrecordname, dirname, layoutfields, channels)\u001b[0m\n\u001b[0;32m 1124\u001b[0m \u001b[0msegchannels\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1125\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1126\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0msegchannels\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mreturninds\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0memptyinds\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 1127\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1128\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
215+
"\u001b[1;31mUnboundLocalError\u001b[0m: local variable 'returninds' referenced before assignment"
216+
]
217+
}
218+
],
234219
"source": [
235220
"# Testing rdsamp multi-segment record with sampfrom, sampto, and channel selection\n",
236221
"import numpy as np\n",
237222
"from wfdb import rdsamp\n",
238223
"\n",
239224
"# Return list of arrays\n",
240-
"sig, fields=rdsamp('sampledata/matched/s00001/s00001-2896-10-10-00-31', sampfrom=10, sampto=10200, channels=[2,3], stacksegments=0)\n",
225+
"sig, fields=rdsamp('sampledata/matched/s00001/s00001-2896-10-10-00-31', sampfrom=10, sampto=10250, channels=[2,3], stacksegments=0)\n",
226+
"\n",
227+
"print(\"\\n\\nOutput of rdsamp:\")\n",
228+
"print(\"sig: \", sig)\n",
229+
"print(\"fields: \", fields)\n",
230+
"\n",
241231
"\n",
242-
"print(sig)\n",
243232
"# Return single array\n",
244-
"sig, fields=rdsamp('sampledata/matched/s00001/s00001-2896-10-10-00-31', sampfrom=10, sampto=10200, channels=[1,0,2],stacksegments=1)\n",
233+
"#sig, fields=rdsamp('sampledata/matched/s00001/s00001-2896-10-10-00-31', sampfrom=10, sampto=10250, channels=[1,0,2],stacksegments=1)\n",
245234
"\n",
246-
"print(sig)"
235+
"#print(sig)\n"
247236
]
248237
},
249238
{
@@ -256,26 +245,11 @@
256245
},
257246
{
258247
"cell_type": "code",
259-
"execution_count": 2,
248+
"execution_count": null,
260249
"metadata": {
261250
"collapsed": false
262251
},
263-
"outputs": [
264-
{
265-
"name": "stdout",
266-
"output_type": "stream",
267-
"text": [
268-
"[[-0.39341784 -0.107 ]\n",
269-
" [-0.32661104 -0.1185 ]\n",
270-
" [-0.23247418 -0.1305 ]\n",
271-
" ..., \n",
272-
" [-0.00472371 0.148 ]\n",
273-
" [-0.00303667 0.1375 ]\n",
274-
" [-0.00303667 0.127 ]]\n",
275-
"yay\n"
276-
]
277-
}
278-
],
252+
"outputs": [],
279253
"source": [
280254
"import numpy as np\n",
281255
"from wfdb import rdsamp\n",
@@ -319,7 +293,6 @@
319293
"# Test 10 - Format 12 multi-samples/frame and skew/Selected Duration/Selected channel/Physical\n",
320294
"# Target file created with: rdsamp -r sampledata/03700181 -f 8 -t 128 -P | cut -f 2- > target10\n",
321295
"sig, fields=rdsamp('sampledata/03700181', channels=[0, 2], sampfrom=1000, sampto=16000)\n",
322-
"print(sig)\n",
323296
"\n",
324297
"print('yay')"
325298
]

tests/test_readsignal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def test_10(self):
102102
targetsig = np.genfromtxt('tests/targetoutputdata/target10')
103103
assert np.array_equal(sig, targetsig)
104104

105-
#### Temporarily removing multi-segment tests due to differences in functi
105+
#### Temporarily removing multi-segment tests due to differences in function workings
106106

107107
# Test 11 - Multi-segment variable layout/Entire signal/Physical
108108
# Target file created with: rdsamp -r sampledata/matched/s25047/s25047-2704-05-04-10-44 -P | cut -f 2- > target11

0 commit comments

Comments
 (0)