Skip to content

Commit af64b44

Browse files
author
Chen Xie
committed
more flat readdat
1 parent 04c5c5b commit af64b44

File tree

2 files changed

+156
-163
lines changed

2 files changed

+156
-163
lines changed

devtests.ipynb

Lines changed: 78 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
"outputs": [],
1717
"source": [
1818
"import numpy as np\n",
19-
"from wfdb import readsignal\n",
19+
"from wfdb import rdsamp\n",
2020
"# Testing rdsamp format 212\n",
21-
"sig, fields=readsignal.rdsamp('sampledata/100', channels=[1], sampfrom=114, physical=0) # Default physical values\n",
21+
"sig, fields=rdsamp('sampledata/100', channels=[1], sampfrom=114, physical=0) # Default physical values\n",
2222
"print(sig)\n",
2323
"print(len(sig))\n",
2424
"\n",
@@ -35,10 +35,10 @@
3535
},
3636
"outputs": [],
3737
"source": [
38-
"from wfdb import readsignal\n",
38+
"from wfdb import rdsamp\n",
3939
"\n",
4040
"# Testing rdsamp format 16\n",
41-
"sig, fields=readsignal.rdsamp('sampledata/test01_00s')\n",
41+
"sig, fields=rdsamp('sampledata/test01_00s')\n",
4242
"print(sig)\n",
4343
"print(fields)\n"
4444
]
@@ -52,8 +52,8 @@
5252
"outputs": [],
5353
"source": [
5454
"# Testing rdsamp multiple samples per frame (and fmt 12)\n",
55-
"from wfdb import readsignal\n",
56-
"sig, fields=readsignal.rdsamp('sampledata/03700181', physical=0)\n",
55+
"from wfdb import rdsamp\n",
56+
"sig, fields=rdsamp('sampledata/03700181', physical=0)\n",
5757
"print(sig[:20,:])\n",
5858
"print(\"\\n\\n\", sig.shape, \"\\n\\n\")\n",
5959
"print(fields)\n",
@@ -72,7 +72,7 @@
7272
"outputs": [],
7373
"source": [
7474
"# Testing rdsamp format 80\n",
75-
"sig, fields=readsignal.rdsamp('sampledata/3000003_0003')\n",
75+
"sig, fields=rdsamp('sampledata/3000003_0003')\n",
7676
"print(sig)\n",
7777
"print(fields)"
7878
]
@@ -87,8 +87,8 @@
8787
"source": [
8888
"# Testing rdsamp format 16 with byte offset (actually a .mat file too)\n",
8989
"import numpy as np\n",
90-
"from wfdb import readsignal\n",
91-
"sig, fields=readsignal.rdsamp('sampledata/a103l') \n",
90+
"from wfdb import rdsamp\n",
91+
"sig, fields=rdsamp('sampledata/a103l') \n",
9292
"#print(sig)\n",
9393
"#print(sig.shape)\n",
9494
"#print(fields)\n",
@@ -116,10 +116,10 @@
116116
"source": [
117117
"# Testing rdsamp multi-segment variable layout record (from https://physionet.org/physiobank/database/mimic2wdb/matched/s00001/)\n",
118118
"import numpy as np\n",
119-
"from wfdb import readsignal\n",
119+
"from wfdb import rdsamp\n",
120120
"\n",
121121
"# Return list of arrays\n",
122-
"sig, fields=readsignal.rdsamp('sampledata/matched/s00001/s00001-2896-10-10-00-31', sampfrom=3200, sampto=20000, stacksegments=0)\n",
122+
"sig, fields=rdsamp('sampledata/matched/s00001/s00001-2896-10-10-00-31', sampfrom=3200, sampto=20000, stacksegments=0)\n",
123123
"#print(\"len(sig): \", len(sig))\n",
124124
"#print(len(fields))\n",
125125
"\n",
@@ -146,11 +146,11 @@
146146
"source": [
147147
"# Testing rdsamp multi-segment variable layout record - stacksegments\n",
148148
"import numpy as np\n",
149-
"from wfdb import readsignal\n",
149+
"from wfdb import rdsamp\n",
150150
"\n",
151151
"\n",
152152
"# Return single numpy array\n",
153-
"sig, fields=readsignal.rdsamp('sampledata/multisegmentV/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', stacksegments=1, sampto=10000, channels=[1, 2])\n",
154154
"\n",
155155
"print(sig)\n",
156156
"print(sig.shape)\n",
@@ -172,9 +172,9 @@
172172
"source": [
173173
"# Testing rdsamp multi-dat signals (from https://physionet.org/physiobank/database/ptbdb/patient001/)\n",
174174
"import numpy as np\n",
175-
"from wfdb import readsignal\n",
175+
"from wfdb import rdsamp\n",
176176
"\n",
177-
"sig, fields=readsignal.rdsamp('sampledata/s0010_re', channels=[14, 0, 5, 10, 11], sampfrom=100, sampto=20000)\n",
177+
"sig, fields=rdsamp('sampledata/s0010_re', channels=[14, 0, 5, 10, 11], sampfrom=100, sampto=20000)\n",
178178
"from wfdb import plotwfdb\n",
179179
"plotwfdb.plotsigs(sig, fields)\n",
180180
"print(\"\\n\\n\\n\", sig, \"\\n\\n\\n\")\n",
@@ -192,27 +192,18 @@
192192
"source": [
193193
"# Testing rdsamp multi-segment record with sampfrom, sampto, and channel selection\n",
194194
"import numpy as np\n",
195-
"from wfdb import readsignal\n",
195+
"from wfdb import rdsamp\n",
196196
"\n",
197197
"# Return list of arrays\n",
198-
"sig, fields=readsignal.rdsamp('sampledata/multisegmentV/s00001-2896-10-10-00-31', sampfrom=10, sampto=10200, channels=[2,3], stacksegments=0)\n",
198+
"sig, fields=rdsamp('sampledata/matched/s00001/s00001-2896-10-10-00-31', sampfrom=10, sampto=10200, channels=[2,3], stacksegments=0)\n",
199199
"\n",
200200
"print(sig)\n",
201201
"# Return single array\n",
202-
"sig, fields=readsignal.rdsamp('sampledata/multisegmentV/s00001-2896-10-10-00-31', sampfrom=10, sampto=10200, channels=[1,0,2],stacksegments=1)\n",
202+
"sig, fields=rdsamp('sampledata/matched/s00001/s00001-2896-10-10-00-31', sampfrom=10, sampto=10200, channels=[1,0,2],stacksegments=1)\n",
203203
"\n",
204204
"print(sig)"
205205
]
206206
},
207-
{
208-
"cell_type": "code",
209-
"execution_count": null,
210-
"metadata": {
211-
"collapsed": false
212-
},
213-
"outputs": [],
214-
"source": []
215-
},
216207
{
217208
"cell_type": "markdown",
218209
"metadata": {},
@@ -223,56 +214,83 @@
223214
},
224215
{
225216
"cell_type": "code",
226-
"execution_count": null,
217+
"execution_count": 1,
227218
"metadata": {
228-
"collapsed": true
219+
"collapsed": false
229220
},
230-
"outputs": [],
221+
"outputs": [
222+
{
223+
"name": "stdout",
224+
"output_type": "stream",
225+
"text": [
226+
"[[-0.39341784 -0.107 ]\n",
227+
" [-0.32661104 -0.1185 ]\n",
228+
" [-0.23247418 -0.1305 ]\n",
229+
" ..., \n",
230+
" [-0.00472371 0.148 ]\n",
231+
" [-0.00303667 0.1375 ]\n",
232+
" [-0.00303667 0.127 ]]\n",
233+
"yay\n"
234+
]
235+
}
236+
],
231237
"source": [
232238
"import numpy as np\n",
233-
"from wfdb import readsignal\n",
239+
"from wfdb import rdsamp\n",
234240
"\n",
235241
"# Test 1 - Format 212/Entire signal/Physical \n",
236242
"# Target file created with: rdsamp -r sampledata/100 -P | cut -f 2- > target1\n",
237-
"sig, fields=readsignal.rdsamp('sampledata/100') \n",
243+
"sig, fields=rdsamp('sampledata/100') \n",
238244
"\n",
239245
"# Test 2 - Format 212/Selected Duration/Selected Channel/Digital\n",
240246
"# Target file created with: rdsamp -r sampledata/100 -f 1 -t 30 -s 1 | cut -f 2- > target2\n",
241-
"sig, fields=readsignal.rdsamp('sampledata/100', sampfrom=360, sampto=10800, channels=[1], physical=0) \n",
247+
"sig, fields=rdsamp('sampledata/100', sampfrom=360, sampto=10800, channels=[1], physical=0) \n",
242248
"\n",
243249
"# Test 3 - Format 16/Entire signal/Digital\n",
244250
"# Target file created with: rdsamp -r sampledata/test01_00s | cut -f 2- > target3\n",
245-
"sig, fields=readsignal.rdsamp('sampledata/test01_00s', physical=0)\n",
251+
"sig, fields=rdsamp('sampledata/test01_00s', physical=0)\n",
246252
"\n",
247253
"# Test 4 - Format 16 with byte offset/Selected Duration/Selected Channels/Physical\n",
248254
"# Target file created with: rdsamp -r sampledata/a103l -f 50 -t 160 -s 2 0 -P | cut -f 2- > target4\n",
249-
"sig, fields=readsignal.rdsamp('sampledata/a103l', sampfrom=12500, sampto=40000, channels=[2, 0])\n",
255+
"sig, fields=rdsamp('sampledata/a103l', sampfrom=12500, sampto=40000, channels=[2, 0])\n",
250256
"\n",
251257
"# Test 5 - Format 16 with byte offset/Selected Duration/Selected Channels/Digital\n",
252258
"# Target file created with: rdsamp -r sampledata/a103l -f 80 -s 0 1 | cut -f 2- > target5\n",
253-
"sig, fields=readsignal.rdsamp('sampledata/a103l', sampfrom=20000, physical=0, channels=[0, 1])\n",
259+
"sig, fields=rdsamp('sampledata/a103l', sampfrom=20000, physical=0, channels=[0, 1])\n",
254260
"\n",
255261
"# Test 6 - Format 80/Selected Duration/Selected Channels/Physical\n",
256262
"# Target file created with: rdsamp -r sampledata/3000003_0003 -f 1 -t 8 -s 1 -P | cut -f 2- > target6\n",
257-
"sig, fields=readsignal.rdsamp('sampledata/3000003_0003', sampfrom=125, sampto=1000, channels=[1])\n",
263+
"sig, fields=rdsamp('sampledata/3000003_0003', sampfrom=125, sampto=1000, channels=[1])\n",
258264
"\n",
259265
"# Test 7 - Multi-dat/Entire signal/Digital\n",
260266
"# Target file created with: rdsamp -r sampledata/s0010_re | cut -f 2- > target7\n",
261-
"sig, fields=readsignal.rdsamp('sampledata/s0010_re', physical=0)\n",
267+
"sig, fields=rdsamp('sampledata/s0010_re', physical=0)\n",
262268
"\n",
263269
"# Test 8 - Multi-dat/Selected Duration/Selected Channels/Physical\n",
264270
"# Target file created with: rdsamp -r sampledata/s0010_re -f 5 -t 38 -P -s 13 0 4 8 3 | cut -f 2- > target8\n",
265-
"sig, fields=readsignal.rdsamp('sampledata/s0010_re', sampfrom=5000, sampto=38000, channels=[13, 0, 4, 8, 3])\n",
271+
"sig, fields=rdsamp('sampledata/s0010_re', sampfrom=5000, sampto=38000, channels=[13, 0, 4, 8, 3])\n",
266272
"\n",
267273
"# Test 9 - Format 12 multi-samples/frame and skew/Entire Signal/Digital\n",
268274
"# Target file created with: rdsamp -r sampledata/03700181 | cut -f 2- > target9\n",
269-
"sig, fields=readsignal.rdsamp('sampledata/03700181', physical=0)\n",
275+
"sig, fields=rdsamp('sampledata/03700181', physical=0)\n",
270276
"\n",
271277
"# Test 10 - Format 12 multi-samples/frame and skew/Selected Duration/Selected channel/Physical\n",
272-
"# Target file created with: rdsamp -r sampledata/03700181 -f 8 -t 16000 | cut -f 2- > target10\n",
273-
"sig, fields=readsignal.rdsamp('sampledata/03700181', physical=0)"
278+
"# Target file created with: rdsamp -r sampledata/03700181 -f 8 -t 128 -P | cut -f 2- > target10\n",
279+
"sig, fields=rdsamp('sampledata/03700181', channels=[0, 2], sampfrom=1000, sampto=16000)\n",
280+
"print(sig)\n",
281+
"\n",
282+
"print('yay')"
274283
]
275284
},
285+
{
286+
"cell_type": "code",
287+
"execution_count": null,
288+
"metadata": {
289+
"collapsed": false
290+
},
291+
"outputs": [],
292+
"source": []
293+
},
276294
{
277295
"cell_type": "markdown",
278296
"metadata": {},
@@ -290,16 +308,16 @@
290308
"outputs": [],
291309
"source": [
292310
"import numpy as np\n",
293-
"from wfdb import readannot\n",
311+
"from wfdb import rdann\n",
294312
"\n",
295313
"# Test 1 - \n",
296314
"# Target file created with: rdann -r 100 -a atr > anntarget1\n",
297-
"annsamp, anntype, num, subtype, chan, aux, annfs=readannot.rdann('sampledata/100', 'atr')\n",
315+
"annsamp, anntype, num, subtype, chan, aux, annfs=rdann('sampledata/100', 'atr')\n",
298316
"\n",
299317
"\n",
300318
"# Test 2\n",
301319
"# Target file created with: rdann -r chb01_03.edf -a seizures > anntarget2\n",
302-
"annsamp, anntype, num, subtype, chan, aux, annfs=readannot.rdann('sampledata/chb01_03', 'seizures')\n"
320+
"annsamp, anntype, num, subtype, chan, aux, annfs=rdann('sampledata/chb01_03', 'seizures')\n"
303321
]
304322
},
305323
{
@@ -310,8 +328,8 @@
310328
},
311329
"outputs": [],
312330
"source": [
313-
"from wfdb import readannot\n",
314-
"annsamp, anntype, num, subtype, chan, aux, annfs=readannot.rdann('sampledata/100', 'fake2', sampfrom=17)\n",
331+
"from wfdb import rdann\n",
332+
"annsamp, anntype, num, subtype, chan, aux, annfs=rdann('sampledata/100', 'fake2', sampfrom=17)\n",
315333
"print(\"annsamp: \", annsamp)\n",
316334
"print(\"anntype: \", anntype)\n",
317335
"print(\"num: \", num)\n",
@@ -337,8 +355,8 @@
337355
},
338356
"outputs": [],
339357
"source": [
340-
"from wfdb import readannot\n",
341-
"annsamp, anntype, num, subtype, chan, aux, annfs=readannot.rdann('sampledata/chb01_03.edf', 'seizures', sampfrom=766977, sampto=777326)\n",
358+
"from wfdb import rdann\n",
359+
"annsamp, anntype, num, subtype, chan, aux, annfs=rdann('sampledata/chb01_03.edf', 'seizures', sampfrom=766977, sampto=777326)\n",
342360
"print(\"annsamp: \", annsamp)\n",
343361
"print(\"anntype: \", anntype)\n",
344362
"print(\"num: \", num)\n",
@@ -356,8 +374,8 @@
356374
},
357375
"outputs": [],
358376
"source": [
359-
"from wfdb import readannot\n",
360-
"annsamp, anntype, num, subtype, chan, aux, annfs=readannot.rdann('sampledata/100', 'fake3', anndisp=1)\n",
377+
"from wfdb import rdann\n",
378+
"annsamp, anntype, num, subtype, chan, aux, annfs=rdann('sampledata/100', 'fake3', anndisp=1)\n",
361379
"print(\"annsamp: \", annsamp)\n",
362380
"print(\"anntype: \", anntype)\n",
363381
"print(\"num: \", num)\n",
@@ -412,8 +430,8 @@
412430
"indata.tofile(f)\n",
413431
"f.close()\n",
414432
"\n",
415-
"from wfdb import readsignal\n",
416-
"sig, fields=readsignal.rdsamp('tmp')\n",
433+
"from wfdb import rdsamp\n",
434+
"sig, fields=rdsamp('tmp')\n",
417435
"print(sig)\n"
418436
]
419437
},
@@ -471,8 +489,8 @@
471489
"outputs": [],
472490
"source": [
473491
"# Testing format 310 record. Written using rdsamp -r sampledata/100 | cut -f 2- | wrsamp -o test310 -O 310 \n",
474-
"from wfdb import readsignal\n",
475-
"sig, fields=readsignal.rdsamp('sampledata/test310', physical=0, sampto=1)\n",
492+
"from wfdb import rdsamp\n",
493+
"sig, fields=rdsamp('sampledata/test310', physical=0, sampto=1)\n",
476494
"print(\"sig final output:\\n\", sig)\n",
477495
"#print(sig.shape)\n",
478496
"\n",
@@ -490,8 +508,8 @@
490508
"outputs": [],
491509
"source": [
492510
"# Testing format 311 record. Written using rdsamp -r sampledata/100 | cut -f 2- | wrsamp -o test311 -O 311\n",
493-
"from wfdb import readsignal\n",
494-
"sig, fields=readsignal.rdsamp('sampledata/test311', physical=0)\n",
511+
"from wfdb import rdsamp\n",
512+
"sig, fields=rdsamp('sampledata/test311', physical=0)\n",
495513
"print(\"sig final output:\\n\", sig)\n",
496514
"#print(sig.shape)\n",
497515
"\n",
@@ -508,8 +526,8 @@
508526
},
509527
"outputs": [],
510528
"source": [
511-
"from wfdb import readsignal\n",
512-
"sig, fields=readsignal.rdsamp('sampledata/s0010_re', sampfrom=5000, sampto=38000, channels=[13, 0, 4, 8, 3])\n",
529+
"from wfdb import rdsamp\n",
530+
"sig, fields=rdsamp('sampledata/s0010_re', sampfrom=5000, sampto=38000, channels=[13, 0, 4, 8, 3])\n",
513531
"sig=sig[:-4,:]\n",
514532
"\n",
515533
"\n",
@@ -713,28 +731,6 @@
713731
" "
714732
]
715733
},
716-
{
717-
"cell_type": "code",
718-
"execution_count": null,
719-
"metadata": {
720-
"collapsed": false
721-
},
722-
"outputs": [],
723-
"source": [
724-
"# Testing the results of getPBfiles, seeing if rdsamp works after files have been downloaded. \n",
725-
"import os\n",
726-
"\n",
727-
"\n",
728-
"\n",
729-
"os.chdir('/home/cx1111/Downloads')\n",
730-
"from wfdb import readsignal\n",
731-
"\n",
732-
"sig, fields=readsignal.rdsamp('mimic2wdb/matched/s25047/s25047-2704-05-04-10-44')\n",
733-
"#sig, fields=readsignal.rdsamp('Testfolder/s25047-2704-05-04-10-44')\n",
734-
"\n",
735-
"print(sig)"
736-
]
737-
},
738734
{
739735
"cell_type": "code",
740736
"execution_count": null,
@@ -813,15 +809,6 @@
813809
" "
814810
]
815811
},
816-
{
817-
"cell_type": "code",
818-
"execution_count": null,
819-
"metadata": {
820-
"collapsed": false
821-
},
822-
"outputs": [],
823-
"source": []
824-
},
825812
{
826813
"cell_type": "code",
827814
"execution_count": null,
@@ -848,7 +835,7 @@
848835
"name": "python",
849836
"nbconvert_exporter": "python",
850837
"pygments_lexer": "ipython3",
851-
"version": "3.5.1"
838+
"version": "3.5.2"
852839
}
853840
},
854841
"nbformat": 4,

0 commit comments

Comments
 (0)