Skip to content

Commit 93625da

Browse files
committed
update docstrings
1 parent 7dcf871 commit 93625da

File tree

9 files changed

+505
-378
lines changed

9 files changed

+505
-378
lines changed

demo.ipynb

Lines changed: 54 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
"Run this script from the base directory of the git repository to access the included demo files"
1010
]
1111
},
12+
{
13+
"cell_type": "markdown",
14+
"metadata": {},
15+
"source": [
16+
"## Documentation Site\n",
17+
"\n"
18+
]
19+
},
1220
{
1321
"cell_type": "code",
1422
"execution_count": null,
@@ -19,7 +27,7 @@
1927
"source": [
2028
"from IPython.display import display\n",
2129
"import matplotlib.pyplot as plt\n",
22-
"%matplotlib qt\n",
30+
"%matplotlib inline\n",
2331
"import numpy as np\n",
2432
"import os\n",
2533
"import shutil\n",
@@ -31,9 +39,7 @@
3139
"cell_type": "markdown",
3240
"metadata": {},
3341
"source": [
34-
"## Package Information and Documentation\n",
35-
"\n",
36-
"Documentation site: "
42+
"## Reading Records and Annotations"
3743
]
3844
},
3945
{
@@ -43,30 +49,6 @@
4349
"collapsed": true
4450
},
4551
"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": [],
7052
"source": [
7153
"# Demo 1 - Read a wfdb record using the 'rdrecord' function into a wfdb.Record object.\n",
7254
"# Plot the signals, and show the data.\n",
@@ -83,7 +65,9 @@
8365
{
8466
"cell_type": "code",
8567
"execution_count": null,
86-
"metadata": {},
68+
"metadata": {
69+
"collapsed": true
70+
},
8771
"outputs": [],
8872
"source": [
8973
"# Demo 2 - Read certain channels and sections of the WFDB record using the simplified 'rdsamp' function\n",
@@ -99,7 +83,9 @@
9983
{
10084
"cell_type": "code",
10185
"execution_count": null,
102-
"metadata": {},
86+
"metadata": {
87+
"collapsed": true
88+
},
10389
"outputs": [],
10490
"source": [
10591
"# Demo 3 - Read a WFDB header file only (without the signals)\n",
@@ -113,7 +99,9 @@
11399
{
114100
"cell_type": "code",
115101
"execution_count": null,
116-
"metadata": {},
102+
"metadata": {
103+
"collapsed": true
104+
},
117105
"outputs": [],
118106
"source": [
119107
"# Demo 4 - Read part of a WFDB annotation file into a wfdb.Annotation object, and plot the samples\n",
@@ -157,7 +145,9 @@
157145
{
158146
"cell_type": "code",
159147
"execution_count": null,
160-
"metadata": {},
148+
"metadata": {
149+
"collapsed": true
150+
},
161151
"outputs": [],
162152
"source": [
163153
"# Demo 6 - Read the multi-segment record and plot waveforms from the MIMIC matched waveform database. \n",
@@ -172,7 +162,9 @@
172162
{
173163
"cell_type": "code",
174164
"execution_count": null,
175-
"metadata": {},
165+
"metadata": {
166+
"collapsed": true
167+
},
176168
"outputs": [],
177169
"source": [
178170
"# Demo 7 - Read the multi-segment record and plot waveforms from the MIMIC matched waveform database.\n",
@@ -209,7 +201,9 @@
209201
{
210202
"cell_type": "code",
211203
"execution_count": null,
212-
"metadata": {},
204+
"metadata": {
205+
"collapsed": true
206+
},
213207
"outputs": [],
214208
"source": [
215209
"# Demo 8 - Read a wfdb record in which one channel has multiple samples/frame. Return a smoothed uniform array.\n",
@@ -220,7 +214,9 @@
220214
{
221215
"cell_type": "code",
222216
"execution_count": null,
223-
"metadata": {},
217+
"metadata": {
218+
"collapsed": true
219+
},
224220
"outputs": [],
225221
"source": [
226222
"# Demo 9 - Read a wfdb record in which one channel has multiple samples/frame. Return a list of all the expanded samples.\n",
@@ -269,7 +265,9 @@
269265
{
270266
"cell_type": "code",
271267
"execution_count": null,
272-
"metadata": {},
268+
"metadata": {
269+
"collapsed": true
270+
},
273271
"outputs": [],
274272
"source": [
275273
"# Demo 11 - Write a WFDB record without using a Record object via the gateway wrsamp function.\n",
@@ -292,7 +290,9 @@
292290
{
293291
"cell_type": "code",
294292
"execution_count": null,
295-
"metadata": {},
293+
"metadata": {
294+
"collapsed": true
295+
},
296296
"outputs": [],
297297
"source": [
298298
"# Demo 12 - Write a WFDB record with multiple samples/frame in a channel\n",
@@ -364,7 +364,9 @@
364364
{
365365
"cell_type": "code",
366366
"execution_count": null,
367-
"metadata": {},
367+
"metadata": {
368+
"collapsed": true
369+
},
368370
"outputs": [],
369371
"source": [
370372
"# Demo 15 - View the standard WFDB annotation labels\n",
@@ -385,7 +387,9 @@
385387
{
386388
"cell_type": "code",
387389
"execution_count": null,
388-
"metadata": {},
390+
"metadata": {
391+
"collapsed": true
392+
},
389393
"outputs": [],
390394
"source": [
391395
"# Demo 16 - List the Physiobank Databases\n",
@@ -397,7 +401,9 @@
397401
{
398402
"cell_type": "code",
399403
"execution_count": null,
400-
"metadata": {},
404+
"metadata": {
405+
"collapsed": true
406+
},
401407
"outputs": [],
402408
"source": [
403409
"# Demo 17 - Download all the WFDB records and annotations from a small Physiobank Database\n",
@@ -422,7 +428,9 @@
422428
{
423429
"cell_type": "code",
424430
"execution_count": null,
425-
"metadata": {},
431+
"metadata": {
432+
"collapsed": true
433+
},
426434
"outputs": [],
427435
"source": [
428436
"# Demo 18 - Download specified files from a Physiobank database\n",
@@ -476,7 +484,7 @@
476484
"def peaks_hr(x, peak_indices, fs, title, figsize=(20, 10), saveto=None):\n",
477485
" \"Plot a signal with its peaks and heart rate\"\n",
478486
" # 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",
480488
" \n",
481489
" N = x.shape[0]\n",
482490
" \n",
@@ -526,37 +534,15 @@
526534
},
527535
{
528536
"cell_type": "code",
529-
"execution_count": 2,
537+
"execution_count": null,
530538
"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": [],
554540
"source": [
555541
"# Demo 20 - Use the xqrs detection algorithm and compare results to reference annotations\n",
556542
"import wfdb\n",
557543
"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",
560546
"\n",
561547
"# Run qrs detection on signal\n",
562548
"xqrs = processing.XQRS(sig=sig[:,0], fs=fields['fs'])\n",

tests/test_processing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def test_normalize(self):
3838
lb = -5
3939
ub = 15
4040

41-
x = processing.normalize(sig[:, 0], lb, ub)
41+
x = processing.normalize_bound(sig[:, 0], lb, ub)
4242
assert x.shape[0] == sig.shape[0]
4343
assert numpy.min(x) >= lb
4444
assert numpy.max(x) <= ub
@@ -66,7 +66,7 @@ def test_gqrs(self):
6666
8216, 8503, 8785, 9070, 9377, 9682]
6767

6868
peaks = processing.gqrs_detect(d_sig=record.d_signal[:,0],
69-
fs=record.fs,
69+
fs=record.fs,
7070
adc_gain=record.adc_gain[0],
7171
adc_zero=record.adc_zero[0],
7272
threshold=1.0)

0 commit comments

Comments
 (0)