Skip to content

Commit 8726ab7

Browse files
committed
add ann streaming
1 parent 12c724b commit 8726ab7

File tree

6 files changed

+623
-284
lines changed

6 files changed

+623
-284
lines changed

devtests.ipynb

Lines changed: 44 additions & 238 deletions
Original file line numberDiff line numberDiff line change
@@ -292,349 +292,155 @@
292292
},
293293
{
294294
"cell_type": "code",
295-
"execution_count": null,
295+
"execution_count": 4,
296296
"metadata": {
297-
"collapsed": true
297+
"collapsed": false
298298
},
299299
"outputs": [],
300-
"source": []
300+
"source": [
301+
"import requests\n",
302+
"\n",
303+
"url = 'https://physionet.org/physiobank/database/a'\n",
304+
"\n",
305+
"r = requests.get(url)\n",
306+
"\n"
307+
]
301308
},
302309
{
303310
"cell_type": "code",
304-
"execution_count": 4,
311+
"execution_count": 7,
305312
"metadata": {
306313
"collapsed": false
307314
},
308315
"outputs": [
309316
{
310317
"data": {
311318
"text/plain": [
312-
"<Response [200]>"
319+
"True"
313320
]
314321
},
315-
"execution_count": 4,
322+
"execution_count": 7,
316323
"metadata": {},
317324
"output_type": "execute_result"
318325
}
319326
],
320327
"source": [
321-
"import requests\n",
322-
"from IPython.display import display\n",
323-
"url = 'http://physionet.org/physiobank/database/mitdb/100.hea'\n",
324-
"r = requests.get(url)\n",
325-
"r"
328+
"r.status_code == 404"
326329
]
327330
},
328331
{
329332
"cell_type": "code",
330-
"execution_count": 5,
333+
"execution_count": 8,
331334
"metadata": {
332335
"collapsed": false
333336
},
334337
"outputs": [
335338
{
336339
"data": {
337340
"text/plain": [
338-
"['__attrs__',\n",
339-
" '__bool__',\n",
340-
" '__class__',\n",
341-
" '__delattr__',\n",
342-
" '__dict__',\n",
343-
" '__dir__',\n",
344-
" '__doc__',\n",
345-
" '__eq__',\n",
346-
" '__format__',\n",
347-
" '__ge__',\n",
348-
" '__getattribute__',\n",
349-
" '__getstate__',\n",
350-
" '__gt__',\n",
351-
" '__hash__',\n",
352-
" '__init__',\n",
353-
" '__iter__',\n",
354-
" '__le__',\n",
355-
" '__lt__',\n",
356-
" '__module__',\n",
357-
" '__ne__',\n",
358-
" '__new__',\n",
359-
" '__nonzero__',\n",
360-
" '__reduce__',\n",
361-
" '__reduce_ex__',\n",
362-
" '__repr__',\n",
363-
" '__setattr__',\n",
364-
" '__setstate__',\n",
365-
" '__sizeof__',\n",
366-
" '__str__',\n",
367-
" '__subclasshook__',\n",
368-
" '__weakref__',\n",
369-
" '_content',\n",
370-
" '_content_consumed',\n",
371-
" 'apparent_encoding',\n",
372-
" 'close',\n",
373-
" 'connection',\n",
374-
" 'content',\n",
375-
" 'cookies',\n",
376-
" 'elapsed',\n",
377-
" 'encoding',\n",
378-
" 'headers',\n",
379-
" 'history',\n",
380-
" 'is_permanent_redirect',\n",
381-
" 'is_redirect',\n",
382-
" 'iter_content',\n",
383-
" 'iter_lines',\n",
384-
" 'json',\n",
385-
" 'links',\n",
386-
" 'ok',\n",
387-
" 'raise_for_status',\n",
388-
" 'raw',\n",
389-
" 'reason',\n",
390-
" 'request',\n",
391-
" 'status_code',\n",
392-
" 'text',\n",
393-
" 'url']"
341+
"'edf'"
394342
]
395343
},
396-
"execution_count": 5,
344+
"execution_count": 8,
397345
"metadata": {},
398346
"output_type": "execute_result"
399347
}
400348
],
401349
"source": [
402-
"dir(r)"
350+
"x = 'hello.edf'\n",
351+
"x[-3:]"
403352
]
404353
},
405354
{
406355
"cell_type": "code",
407-
"execution_count": 9,
356+
"execution_count": 10,
408357
"metadata": {
409358
"collapsed": false
410359
},
411360
"outputs": [
412361
{
413362
"data": {
414363
"text/plain": [
415-
"'http://physionet.org/physiobank/database/mitdb/100.hea'"
416-
]
417-
},
418-
"metadata": {},
419-
"output_type": "display_data"
420-
},
421-
{
422-
"data": {
423-
"text/plain": [
424-
"<requests.packages.urllib3.response.HTTPResponse at 0x7f93ee6a5198>"
425-
]
426-
},
427-
"metadata": {},
428-
"output_type": "display_data"
429-
},
430-
{
431-
"data": {
432-
"text/plain": [
433-
"b'100 2 360 650000\\r\\n100.dat 212 200 11 1024 995 -22131 0 MLII\\r\\n100.dat 212 200 11 1024 1011 20052 0 V5\\r\\n# 69 M 1085 1629 x1\\r\\n# Aldomet, Inderal\\r\\n'"
364+
"8"
434365
]
435366
},
367+
"execution_count": 10,
436368
"metadata": {},
437-
"output_type": "display_data"
438-
},
439-
{
440-
"data": {
441-
"text/plain": [
442-
"{'Server': 'Apache/2.2.22 (Debian) mod_auth_tkt/2.1.0 mod_auth_pgsql/2.0.3 mod_ssl/2.2.22 OpenSSL/1.0.1t', 'Keep-Alive': 'timeout=5, max=100', 'Last-Modified': 'Thu, 30 Jul 1992 05:36:18 GMT', 'ETag': '\"2b58628b-8f-287fdea221880\"', 'Connection': 'Keep-Alive', 'Date': 'Fri, 17 Mar 2017 19:44:43 GMT', 'Accept-Ranges': 'bytes', 'Content-Length': '143'}"
443-
]
444-
},
445-
"metadata": {},
446-
"output_type": "display_data"
447-
},
448-
{
449-
"data": {
450-
"text/plain": [
451-
"bytes"
452-
]
453-
},
454-
"metadata": {},
455-
"output_type": "display_data"
369+
"output_type": "execute_result"
456370
}
457371
],
458372
"source": [
459-
"display(r.url)\n",
460-
"display(r.raw)\n",
461-
"display(r.content)\n",
462-
"display(r.headers)\n",
463-
"display(type(r.content))"
373+
"import os\n",
374+
"os.cpu_count()"
464375
]
465376
},
466377
{
467378
"cell_type": "code",
468-
"execution_count": 15,
379+
"execution_count": 12,
469380
"metadata": {
470381
"collapsed": false
471382
},
472383
"outputs": [
473384
{
474385
"data": {
475386
"text/plain": [
476-
"'100 2 360 650000\\r\\n100.dat 212 200 11 1024 995 -22131 0 MLII\\r\\n100.dat 212 200 11 1024 1011 20052 0 V5\\r\\n# 69 M 1085 1629 x1\\r\\n# Aldomet, Inderal\\r\\n'"
387+
"True"
477388
]
478389
},
479-
"execution_count": 15,
390+
"execution_count": 12,
480391
"metadata": {},
481392
"output_type": "execute_result"
482393
}
483394
],
484395
"source": [
485-
"a = r.content.decode(\"ascii\") \n",
486-
"a"
396+
"'hello'.endswith('llo')"
487397
]
488398
},
489399
{
490400
"cell_type": "code",
491-
"execution_count": 21,
401+
"execution_count": 15,
492402
"metadata": {
493403
"collapsed": false
494404
},
495405
"outputs": [
496406
{
497-
"name": "stdout",
498-
"output_type": "stream",
499-
"text": [
500-
"['100 2 360 650000', '100.dat 212 200 11 1024 995 -22131 0 MLII', '100.dat 212 200 11 1024 1011 20052 0 V5']\n",
501-
"['# 69 M 1085 1629 x1', '# Aldomet, Inderal']\n"
407+
"ename": "AttributeError",
408+
"evalue": "'list' object has no attribute 'any'",
409+
"output_type": "error",
410+
"traceback": [
411+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
412+
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
413+
"\u001b[0;32m<ipython-input-15-a0aa019c7e14>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0ml\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m'hello'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'jello'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'coffee'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0ml\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0many\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
414+
"\u001b[0;31mAttributeError\u001b[0m: 'list' object has no attribute 'any'"
502415
]
503416
}
504417
],
505418
"source": [
506-
"import os\n",
507-
"import requests\n",
508-
"\n",
509-
"def streamheader(recordname, pbdir):\n",
510-
"\n",
511-
" # Full url of header location\n",
512-
" url = 'http://physionet.org/physiobank/database/'+os.path.join(pbdir, recordname+'.hea')\n",
513-
" r = requests.get(url)\n",
514-
" \n",
515-
" # Raise HTTPError if invalid url\n",
516-
" r.raise_for_status()\n",
517-
" \n",
518-
" # Get each line as a string\n",
519-
" filelines = r.content.decode('ascii').splitlines()\n",
520-
" \n",
521-
" # Separate content into header and comment lines\n",
522-
" headerlines = []\n",
523-
" commentlines = []\n",
524-
" \n",
525-
" for line in filelines:\n",
526-
" line = line.strip()\n",
527-
" # Comment line\n",
528-
" if line.startswith('#'): \n",
529-
" commentlines.append(line)\n",
530-
" # Non-empty non-comment line = header line.\n",
531-
" elif line: \n",
532-
" # Look for a comment in the line\n",
533-
" ci = line.find('#')\n",
534-
" if ci > 0:\n",
535-
" headerlines.append(line[:ci])\n",
536-
" # comment on same line as header line\n",
537-
" commentlines.append(line[ci:])\n",
538-
" else:\n",
539-
" headerlines.append(line)\n",
540-
" \n",
541-
" return (headerlines, commentlines) \n",
542-
"\n",
543-
"#streamheader('3045253', 'mimic2wdb/30/3045253')\n",
544-
"a, b = streamheader('100', 'mitdb')\n",
545-
"\n",
546-
"print(a)\n",
547-
"\n",
548-
"print(b)\n"
419+
"l = ['hello', 'jello', 'coffee']\n"
549420
]
550421
},
551422
{
552423
"cell_type": "code",
553-
"execution_count": 23,
424+
"execution_count": 19,
554425
"metadata": {
555426
"collapsed": false
556427
},
557428
"outputs": [
558429
{
559430
"data": {
560431
"text/plain": [
561-
"<Response [404]>"
432+
"'http://physionet.org/physiobank/database/mitdb'"
562433
]
563434
},
564-
"execution_count": 23,
435+
"execution_count": 19,
565436
"metadata": {},
566437
"output_type": "execute_result"
567438
}
568439
],
569440
"source": [
570-
"request"
571-
]
572-
},
573-
{
574-
"cell_type": "code",
575-
"execution_count": 28,
576-
"metadata": {
577-
"collapsed": false
578-
},
579-
"outputs": [
580-
{
581-
"data": {
582-
"text/plain": [
583-
"requests.exceptions.HTTPError"
584-
]
585-
},
586-
"execution_count": 28,
587-
"metadata": {},
588-
"output_type": "execute_result"
589-
}
590-
],
591-
"source": [
592-
"requests.HTTPError"
593-
]
594-
},
595-
{
596-
"cell_type": "code",
597-
"execution_count": 93,
598-
"metadata": {
599-
"collapsed": false
600-
},
601-
"outputs": [
602-
{
603-
"name": "stdout",
604-
"output_type": "stream",
605-
"text": [
606-
"http://physionet.org/physiobank/database/mitdb/100.dat\n",
607-
"{'Accept-Encoding': '*/*', 'Range': 'bytes=0-9'}\n",
608-
"206\n",
609-
"{'Server': 'Apache/2.2.22 (Debian) mod_auth_tkt/2.1.0 mod_auth_pgsql/2.0.3 mod_ssl/2.2.22 OpenSSL/1.0.1t', 'Date': 'Mon, 20 Mar 2017 20:58:50 GMT', 'Last-Modified': 'Thu, 30 Jul 1992 05:36:18 GMT', 'Content-Range': 'bytes 0-9/1950000', 'Accept-Ranges': 'bytes', 'Vary': 'Accept-Encoding', 'Keep-Alive': 'timeout=5, max=100', 'Content-Type': 'application/octet-stream', 'Connection': 'Keep-Alive', 'Content-Length': '10', 'ETag': '\"2b58628a-1dc130-287fdea221880\"'}\n",
610-
"{'Accept': '*/*', 'User-Agent': 'python-requests/2.12.4', 'Connection': 'keep-alive', 'Range': 'bytes=0-9', 'Accept-Encoding': '*/*'}\n",
611-
"10\n"
612-
]
613-
}
614-
],
615-
"source": [
616-
"r = streamdat('100.dat', 'mitdb', '212', 9, 0)\n",
617-
"\n",
618-
"print(r.status_code)\n",
619-
"\n",
620-
"# Header the server sent\n",
621-
"print(r.headers)\n",
622-
"\n",
623-
"# Header we sent\n",
624-
"print(r.request.headers)\n",
441+
"import os\n",
625442
"\n",
626-
"print(len(r.content))"
627-
]
628-
},
629-
{
630-
"cell_type": "code",
631-
"execution_count": 1,
632-
"metadata": {
633-
"collapsed": false
634-
},
635-
"outputs": [],
636-
"source": [
637-
"import wfdb"
443+
"os.path.join('http://physionet.org/physiobank/database/', 'mitdb')"
638444
]
639445
},
640446
{

wfdb/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#from ._downloadsamp import downloadsamp
2-
31
from .records import Record, MultiRecord, rdheader, rdsamp, srdsamp, wrsamp
42
from .annotations import Annotation, rdann, wrann, showanncodes
53
from .plots import plotrec, plotann

0 commit comments

Comments
 (0)