|
9 | 9 | "Run this script from the base directory of the git repository to access the included demo files"
|
10 | 10 | ]
|
11 | 11 | },
|
| 12 | + { |
| 13 | + "cell_type": "markdown", |
| 14 | + "metadata": {}, |
| 15 | + "source": [ |
| 16 | + "## Documentation Site\n", |
| 17 | + "\n" |
| 18 | + ] |
| 19 | + }, |
12 | 20 | {
|
13 | 21 | "cell_type": "code",
|
14 | 22 | "execution_count": null,
|
|
19 | 27 | "source": [
|
20 | 28 | "from IPython.display import display\n",
|
21 | 29 | "import matplotlib.pyplot as plt\n",
|
22 |
| - "%matplotlib qt\n", |
| 30 | + "%matplotlib inline\n", |
23 | 31 | "import numpy as np\n",
|
24 | 32 | "import os\n",
|
25 | 33 | "import shutil\n",
|
|
31 | 39 | "cell_type": "markdown",
|
32 | 40 | "metadata": {},
|
33 | 41 | "source": [
|
34 |
| - "## Package Information and Documentation\n", |
35 |
| - "\n", |
36 |
| - "Documentation site: " |
| 42 | + "## Reading Records and Annotations" |
37 | 43 | ]
|
38 | 44 | },
|
39 | 45 | {
|
|
43 | 49 | "collapsed": true
|
44 | 50 | },
|
45 | 51 | "outputs": [],
|
46 |
| - "source": [ |
47 |
| - "# View the wfdb classes and functions\n", |
48 |
| - "#dir(wfdb)\n", |
49 |
| - "\n", |
50 |
| - "# View the docstrings of specific functions\n", |
51 |
| - "\n", |
52 |
| - "#help(wfdb.rdrecord)\n", |
53 |
| - "#help(wfdb.rdsamp)\n", |
54 |
| - "#help(wfdb.rdann)\n", |
55 |
| - "\n" |
56 |
| - ] |
57 |
| - }, |
58 |
| - { |
59 |
| - "cell_type": "markdown", |
60 |
| - "metadata": {}, |
61 |
| - "source": [ |
62 |
| - "## Reading Records and Annotations" |
63 |
| - ] |
64 |
| - }, |
65 |
| - { |
66 |
| - "cell_type": "code", |
67 |
| - "execution_count": null, |
68 |
| - "metadata": {}, |
69 |
| - "outputs": [], |
70 | 52 | "source": [
|
71 | 53 | "# Demo 1 - Read a wfdb record using the 'rdrecord' function into a wfdb.Record object.\n",
|
72 | 54 | "# Plot the signals, and show the data.\n",
|
|
83 | 65 | {
|
84 | 66 | "cell_type": "code",
|
85 | 67 | "execution_count": null,
|
86 |
| - "metadata": {}, |
| 68 | + "metadata": { |
| 69 | + "collapsed": true |
| 70 | + }, |
87 | 71 | "outputs": [],
|
88 | 72 | "source": [
|
89 | 73 | "# Demo 2 - Read certain channels and sections of the WFDB record using the simplified 'rdsamp' function\n",
|
|
99 | 83 | {
|
100 | 84 | "cell_type": "code",
|
101 | 85 | "execution_count": null,
|
102 |
| - "metadata": {}, |
| 86 | + "metadata": { |
| 87 | + "collapsed": true |
| 88 | + }, |
103 | 89 | "outputs": [],
|
104 | 90 | "source": [
|
105 | 91 | "# Demo 3 - Read a WFDB header file only (without the signals)\n",
|
|
113 | 99 | {
|
114 | 100 | "cell_type": "code",
|
115 | 101 | "execution_count": null,
|
116 |
| - "metadata": {}, |
| 102 | + "metadata": { |
| 103 | + "collapsed": true |
| 104 | + }, |
117 | 105 | "outputs": [],
|
118 | 106 | "source": [
|
119 | 107 | "# Demo 4 - Read part of a WFDB annotation file into a wfdb.Annotation object, and plot the samples\n",
|
|
157 | 145 | {
|
158 | 146 | "cell_type": "code",
|
159 | 147 | "execution_count": null,
|
160 |
| - "metadata": {}, |
| 148 | + "metadata": { |
| 149 | + "collapsed": true |
| 150 | + }, |
161 | 151 | "outputs": [],
|
162 | 152 | "source": [
|
163 | 153 | "# Demo 6 - Read the multi-segment record and plot waveforms from the MIMIC matched waveform database. \n",
|
|
172 | 162 | {
|
173 | 163 | "cell_type": "code",
|
174 | 164 | "execution_count": null,
|
175 |
| - "metadata": {}, |
| 165 | + "metadata": { |
| 166 | + "collapsed": true |
| 167 | + }, |
176 | 168 | "outputs": [],
|
177 | 169 | "source": [
|
178 | 170 | "# Demo 7 - Read the multi-segment record and plot waveforms from the MIMIC matched waveform database.\n",
|
|
209 | 201 | {
|
210 | 202 | "cell_type": "code",
|
211 | 203 | "execution_count": null,
|
212 |
| - "metadata": {}, |
| 204 | + "metadata": { |
| 205 | + "collapsed": true |
| 206 | + }, |
213 | 207 | "outputs": [],
|
214 | 208 | "source": [
|
215 | 209 | "# Demo 8 - Read a wfdb record in which one channel has multiple samples/frame. Return a smoothed uniform array.\n",
|
|
220 | 214 | {
|
221 | 215 | "cell_type": "code",
|
222 | 216 | "execution_count": null,
|
223 |
| - "metadata": {}, |
| 217 | + "metadata": { |
| 218 | + "collapsed": true |
| 219 | + }, |
224 | 220 | "outputs": [],
|
225 | 221 | "source": [
|
226 | 222 | "# Demo 9 - Read a wfdb record in which one channel has multiple samples/frame. Return a list of all the expanded samples.\n",
|
|
269 | 265 | {
|
270 | 266 | "cell_type": "code",
|
271 | 267 | "execution_count": null,
|
272 |
| - "metadata": {}, |
| 268 | + "metadata": { |
| 269 | + "collapsed": true |
| 270 | + }, |
273 | 271 | "outputs": [],
|
274 | 272 | "source": [
|
275 | 273 | "# Demo 11 - Write a WFDB record without using a Record object via the gateway wrsamp function.\n",
|
|
292 | 290 | {
|
293 | 291 | "cell_type": "code",
|
294 | 292 | "execution_count": null,
|
295 |
| - "metadata": {}, |
| 293 | + "metadata": { |
| 294 | + "collapsed": true |
| 295 | + }, |
296 | 296 | "outputs": [],
|
297 | 297 | "source": [
|
298 | 298 | "# Demo 12 - Write a WFDB record with multiple samples/frame in a channel\n",
|
|
364 | 364 | {
|
365 | 365 | "cell_type": "code",
|
366 | 366 | "execution_count": null,
|
367 |
| - "metadata": {}, |
| 367 | + "metadata": { |
| 368 | + "collapsed": true |
| 369 | + }, |
368 | 370 | "outputs": [],
|
369 | 371 | "source": [
|
370 | 372 | "# Demo 15 - View the standard WFDB annotation labels\n",
|
|
385 | 387 | {
|
386 | 388 | "cell_type": "code",
|
387 | 389 | "execution_count": null,
|
388 |
| - "metadata": {}, |
| 390 | + "metadata": { |
| 391 | + "collapsed": true |
| 392 | + }, |
389 | 393 | "outputs": [],
|
390 | 394 | "source": [
|
391 | 395 | "# Demo 16 - List the Physiobank Databases\n",
|
|
397 | 401 | {
|
398 | 402 | "cell_type": "code",
|
399 | 403 | "execution_count": null,
|
400 |
| - "metadata": {}, |
| 404 | + "metadata": { |
| 405 | + "collapsed": true |
| 406 | + }, |
401 | 407 | "outputs": [],
|
402 | 408 | "source": [
|
403 | 409 | "# Demo 17 - Download all the WFDB records and annotations from a small Physiobank Database\n",
|
|
422 | 428 | {
|
423 | 429 | "cell_type": "code",
|
424 | 430 | "execution_count": null,
|
425 |
| - "metadata": {}, |
| 431 | + "metadata": { |
| 432 | + "collapsed": true |
| 433 | + }, |
426 | 434 | "outputs": [],
|
427 | 435 | "source": [
|
428 | 436 | "# Demo 18 - Download specified files from a Physiobank database\n",
|
|
476 | 484 | "def peaks_hr(x, peak_indices, fs, title, figsize=(20, 10), saveto=None):\n",
|
477 | 485 | " \"Plot a signal with its peaks and heart rate\"\n",
|
478 | 486 | " # Calculate heart rate\n",
|
479 |
| - " hrs = processing.compute_hr(sig_len=x.shape[0], peak_indices=peak_indices, fs=fs)\n", |
| 487 | + " hrs = processing.compute_hr(sig_len=x.shape[0], qrs_inds=peak_indices, fs=fs)\n", |
480 | 488 | " \n",
|
481 | 489 | " N = x.shape[0]\n",
|
482 | 490 | " \n",
|
|
526 | 534 | },
|
527 | 535 | {
|
528 | 536 | "cell_type": "code",
|
529 |
| - "execution_count": 2, |
| 537 | + "execution_count": null, |
530 | 538 | "metadata": {},
|
531 |
| - "outputs": [ |
532 |
| - { |
533 |
| - "name": "stdout", |
534 |
| - "output_type": "stream", |
535 |
| - "text": [ |
536 |
| - "Learning initial signal parameters...\n", |
537 |
| - "Found 8 beats during learning. Initializing using learned parameters\n", |
538 |
| - "Running QRS detection...\n", |
539 |
| - "QRS detection complete.\n" |
540 |
| - ] |
541 |
| - }, |
542 |
| - { |
543 |
| - "ename": "AttributeError", |
544 |
| - "evalue": "'numpy.ndarray' object has no attribute 'qrs_inds'", |
545 |
| - "output_type": "error", |
546 |
| - "traceback": [ |
547 |
| - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", |
548 |
| - "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", |
549 |
| - "\u001b[0;32m<ipython-input-2-ba181adf2560>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 14\u001b[0m \u001b[0;31m# Note, first sample in 100.atr is not a qrs.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 15\u001b[0m comparitor = processing.compare_annotations(ref_sample=ann_ref.sample[1:],\n\u001b[0;32m---> 16\u001b[0;31m \u001b[0mtest_sample\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mxqrs\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mqrs_inds\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 17\u001b[0m \u001b[0mwindow_width\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m0.1\u001b[0m \u001b[0;34m*\u001b[0m \u001b[0mfields\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'fs'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 18\u001b[0m signal=sig[:,0])\n", |
550 |
| - "\u001b[0;31mAttributeError\u001b[0m: 'numpy.ndarray' object has no attribute 'qrs_inds'" |
551 |
| - ] |
552 |
| - } |
553 |
| - ], |
| 539 | + "outputs": [], |
554 | 540 | "source": [
|
555 | 541 | "# Demo 20 - Use the xqrs detection algorithm and compare results to reference annotations\n",
|
556 | 542 | "import wfdb\n",
|
557 | 543 | "from wfdb import processing\n",
|
558 |
| - "sig, fields = wfdb.rdsamp('sample-data/100', channels=[0])\n", |
559 |
| - "ann_ref = wfdb.rdann('sample-data/100','atr')\n", |
| 544 | + "sig, fields = wfdb.rdsamp('sample-data/100', channels=[0], sampto=15000)\n", |
| 545 | + "ann_ref = wfdb.rdann('sample-data/100','atr', sampto=15000)\n", |
560 | 546 | "\n",
|
561 | 547 | "# Run qrs detection on signal\n",
|
562 | 548 | "xqrs = processing.XQRS(sig=sig[:,0], fs=fields['fs'])\n",
|
|
0 commit comments