Skip to content

Commit e9285f3

Browse files
committed
documentation
1 parent 0680e02 commit e9285f3

File tree

8 files changed

+413
-168
lines changed

8 files changed

+413
-168
lines changed

README.rst

Lines changed: 328 additions & 141 deletions
Large diffs are not rendered by default.

demo.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
{
1313
"cell_type": "code",
14-
"execution_count": 3,
14+
"execution_count": null,
1515
"metadata": {
1616
"collapsed": false
1717
},
@@ -94,8 +94,8 @@
9494
"source": [
9595
"# Demo 4 - Read part of a WFDB annotation file into a wfdb.Annotation object, and plot the samples\n",
9696
"annotation = wfdb.rdann('sampledata/100', 'atr', sampfrom = 100000, sampto = 110000)\n",
97-
"#annotation.fs = 360\n",
98-
"#wfdb.plotann(annotation, timeunits = 'minutes')\n",
97+
"annotation.fs = 360\n",
98+
"wfdb.plotann(annotation, timeunits = 'minutes')\n",
9999
"\n",
100100
"# Can also read the same file hosted on PhysioBank \n",
101101
"annotation2 = wfdb.rdann('100', 'atr', sampfrom = 100000, sampto = 110000, pbdir = 'mitdb')"
@@ -215,7 +215,7 @@
215215
},
216216
{
217217
"cell_type": "code",
218-
"execution_count": 7,
218+
"execution_count": null,
219219
"metadata": {
220220
"collapsed": false
221221
},
@@ -237,7 +237,7 @@
237237
},
238238
{
239239
"cell_type": "code",
240-
"execution_count": 8,
240+
"execution_count": null,
241241
"metadata": {
242242
"collapsed": true
243243
},

devtests.ipynb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
"cell_type": "markdown",
55
"metadata": {},
66
"source": [
7-
"<h2>This script is for internal developer testing.</h2>"
7+
"<h2>This script is for internal developer testing.</h2>\n",
8+
"\n",
9+
"This is different from the unit tests located in the `tests` directory."
810
]
911
},
1012
{

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# Versions should comply with PEP440. For a discussion on single-sourcing
2121
# the version across setup.py and the project code, see
2222
# https://packaging.python.org/en/latest/single_source_version.html
23-
version='0.2.0',
23+
version='1.0.0',
2424

2525
description='The WFDB Python Toolbox',
2626
long_description=long_description,

wfdb/annotations.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,21 @@ class Annotation():
2525
- aux: The auxiliary information string for the annotation.
2626
- fs: The sampling frequency of the record if contained in the annotation file.
2727
28+
Constructor function:
29+
def __init__(self, recordname, annotator, annsamp, anntype, subtype = None,
30+
chan = None, num = None, aux = None, fs = None)
31+
2832
Call 'showanncodes()' to see the list of standard annotation codes. Any text used to label
2933
annotations that are not one of these codes should go in the 'aux' field rather than the
3034
'anntype' field.
35+
36+
Example usage:
37+
import wfdb
38+
ann1 = wfdb.Annotation(recordname='ann1', annotator='atr', annsamp=[10,20,400],
39+
anntype = ['N','N','['], aux=[None, None, 'Serious Vfib'])
3140
"""
32-
def __init__(self, recordname, annotator, annsamp, anntype, subtype = None, chan = None, num = None, aux = None, fs = None):
41+
def __init__(self, recordname, annotator, annsamp, anntype, subtype = None,
42+
chan = None, num = None, aux = None, fs = None):
3343
self.recordname = recordname
3444
self.annotator = annotator
3545

@@ -358,18 +368,24 @@ def wrann(recordname, annotator, annsamp, anntype, subtype = None, chan = None,
358368
359369
Input arguments:
360370
- recordname (required): The string name of the WFDB record to be written (without any file extensions).
361-
- annsamp (required): The annotation location in samples relative to the beginning of the record.
362-
- anntype (required): The annotation type according the the standard WFDB codes.
363-
- subtype (default=None): The marked class/category of the annotation.
364-
- chan (default=None): The signal channel associated with the annotations.
365-
- num (default=None): The labelled annotation number.
366-
- aux (default=None): The auxiliary information string for the annotation.
371+
- annotator (required): The string annotation file extension.
372+
- annsamp (required): The annotation location in samples relative to the beginning of the record. List or numpy array.
373+
- anntype (required): The annotation type according the the standard WFDB codes. List or numpy array.
374+
- subtype (default=None): The marked class/category of the annotation. List or numpy array.
375+
- chan (default=None): The signal channel associated with the annotations. List or numpy array.
376+
- num (default=None): The labelled annotation number. List or numpy array.
377+
- aux (default=None): The auxiliary information string for the annotation. List or numpy array.
367378
- fs (default=None): The numerical sampling frequency of the record to be written to the file.
368379
369380
Note: This gateway function was written to enable a simple way to write WFDB annotation files without
370381
needing to explicity create an Annotation object beforehand.
371382
372383
You may also create an Annotation object, manually set its attributes, and call its wrann() instance method.
384+
385+
Note: Each annotation stored in a WFDB annotation file contains an annsamp and an anntype field. All other fields
386+
may or may not be present. Therefore in order to save space, when writing additional features such
387+
as 'aux' that are not present for every annotation, it is recommended to make the field a list, with empty
388+
indices set to None so that they are not written to the file.
373389
374390
Example Usage:
375391
import wfdb
@@ -426,7 +442,7 @@ def rdann(recordname, annotator, sampfrom=0, sampto=None, pbdir=None):
426442
427443
Example usage:
428444
import wfdb
429-
ann = wfdb.rdann('100', 'atr', sampto = 300000)
445+
ann = wfdb.rdann('sampledata/100', 'atr', sampto = 300000)
430446
"""
431447

432448
if sampto and sampto <= sampfrom:

wfdb/downloads.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,10 @@ def streamannotation(filename, pbdir):
8787
return annbytes
8888

8989

90-
# Return a list of all the physiobank databases available
90+
9191
def getdblist():
92-
"""
92+
"""Return a list of all the physiobank databases available.
93+
9394
Usage:
9495
dblist = getdblist()
9596
"""

wfdb/plots.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,27 @@ def plotrec(record=None, title = None, annotation = None, annch = [0], timeunits
1111
""" Subplot and label each channel of a WFDB Record.
1212
Optionally, subplot annotation locations over selected channels.
1313
14-
Usage: plotrec(record=None, title = None, annotation = None, annch = [0], timeunits='samples', returnfig=False)
14+
Usage:
15+
plotrec(record=None, title = None, annotation = None, annch = [0], timeunits='samples', returnfig=False)
1516
1617
Input arguments:
1718
- record (required): A wfdb Record object. The p_signals attribute will be plotted.
18-
- title (optional): A string containing the title of the graph.
19-
- annotation (optional): An Annotation object. The annsamp attribute locations will be overlaid on the signal.
19+
- title (default=None): A string containing the title of the graph.
20+
- annotation (default=None): An Annotation object. The annsamp attribute locations will be overlaid on the signal.
2021
- annch (default=[0]): A list of channels on which to plot the annotation samples.
2122
- timeunits (default='samples'): String specifying the x axis unit.
2223
Allowed options are: 'samples', 'seconds', 'minutes', and 'hours'.
2324
- returnfig (default=False): Specifies whether the figure is to be returned as an output argument
2425
2526
Output argument:
2627
- figure: The matplotlib figure generated. Only returned if the 'returnfig' option is set to True.
28+
29+
Example Usage:
30+
import wfdb
31+
record = wfdb.rdsamp('sampledata/100', sampto = 15000)
32+
annotation = wfdb.rdann('sampledata/100', 'atr', sampto = 15000)
33+
34+
wfdb.plotrec(record, annotation = annotation, title='Record 100 from MIT-BIH Arrhythmia Database', timeunits = 'seconds')
2735
"""
2836

2937
# Check the validity of items used to make the plot
@@ -154,7 +162,7 @@ def plotann(annotation, title = None, timeunits = 'samples', returnfig = False):
154162
155163
Input arguments:
156164
- annotation (required): An Annotation object. The annsamp attribute locations will be overlaid on the signal.
157-
- title (optional): A string containing the title of the graph.
165+
- title (default=None): A string containing the title of the graph.
158166
- timeunits (default='samples'): String specifying the x axis unit.
159167
Allowed options are: 'samples', 'seconds', 'minutes', and 'hours'.
160168
- returnfig (default=False): Specifies whether the figure is to be returned as an output argument
@@ -163,6 +171,12 @@ def plotann(annotation, title = None, timeunits = 'samples', returnfig = False):
163171
- figure: The matplotlib figure generated. Only returned if the 'returnfig' option is set to True.
164172
165173
Note: The plotrec function is useful for plotting annotations on top of signal waveforms.
174+
175+
Example Usage:
176+
import wfdb
177+
annotation = wfdb.rdann('sampledata/100', 'atr', sampfrom = 100000, sampto = 110000)
178+
annotation.fs = 360
179+
wfdb.plotann(annotation, timeunits = 'minutes')
166180
"""
167181

168182
# Check the validity of items used to make the plot

wfdb/records.py

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,22 @@ class Record(BaseRecord, _headers.HeadersMixin, _signals.SignalsMixin):
310310
311311
In addition, the d_signals and p_signals attributes store the digital and physical
312312
signals of WFDB records with at least one channel.
313+
314+
Contructor function:
315+
def __init__(self, p_signals=None, d_signals=None,
316+
recordname=None, nsig=None,
317+
fs=None, counterfreq=None, basecounter=None,
318+
siglen=None, basetime=None, basedate=None,
319+
filename=None, fmt=None, sampsperframe=None,
320+
skew=None, byteoffset=None, adcgain=None,
321+
baseline=None, units=None, adcres=None,
322+
adczero=None, initvalue=None, checksum=None,
323+
blocksize=None, signame=None, comments=None)
324+
325+
Example Usage:
326+
import wfdb
327+
record1 = wfdb.Record(recordname='r1', fs=250, nsig=2, siglen=1000, filename=['r1.dat','r1.dat'])
328+
313329
"""
314330
# Constructor
315331
def __init__(self, p_signals=None, d_signals=None,
@@ -423,8 +439,20 @@ class MultiRecord(BaseRecord, _headers.MultiHeadersMixin):
423439
instance method can be called on MultiRecord objects to return a single segment representation
424440
of the record as a Record object. The resulting Record object will have its 'p_signals' field set.
425441
426-
eg. record1 = wfdb.rdsamp('s00001-2896-10-10-00-31', m2s = False)
427-
record1 = record1.multi_to_single()
442+
Contructor function:
443+
def __init__(self, segments = None, layout = None,
444+
recordname=None, nsig=None, fs=None,
445+
counterfreq=None, basecounter=None,
446+
siglen=None, basetime=None, basedate=None,
447+
segname = None, seglen = None, comments=None)
448+
449+
Example Usage:
450+
import wfdb
451+
recordM = wfdb.MultiRecord(recordname='rm', fs=50, nsig=8, siglen=9999,
452+
segname=['rm_1', '~', rm_2'], seglen=[800, 200, 900])
453+
454+
recordL = wfdb.rdsamp('s00001-2896-10-10-00-31', m2s = False)
455+
recordL = recordL.multi_to_single()
428456
"""
429457

430458
# Constructor
@@ -972,7 +1000,7 @@ def wrsamp(recordname, fs, units, signames, p_signals = None, d_signals = None,
9721000
# Write a local WFDB record (manually inserting fields)
9731001
wfdb.wrsamp('ecgrecord', fs = 250, units = ['mV', 'mV'], signames = ['I', 'II'], p_signals = sig, fmt = ['16', '16'])
9741002
"""
975-
1003+
9761004
# Check input field combinations
9771005
if p_signals is not None and d_signals is not None:
9781006
sys.exit('Must only give one of the inputs: p_signals or d_signals')
@@ -1229,9 +1257,6 @@ def dldatabasefiles(pbdb, dlbasedir, files, keepsubdirs = True, overwrite = Fals
12291257
- pbdb (required): The Physiobank database directory to download.
12301258
eg. For database 'http://physionet.org/physiobank/database/mitdb', pbdb = 'mitdb'.
12311259
- dlbasedir (required): The full local directory path in which to download the files.
1232-
- records (default='all'): Specifier of the WFDB records to download. Is either a list of strings
1233-
which each specify a record, or 'all' to download all records listed in the database's RECORDS file.
1234-
eg. records = ['test01_00s', test02_45s] for database https://physionet.org/physiobank/database/macecgdb/
12351260
- files (required): A list of strings specifying the file names to download relative to the database
12361261
base directory
12371262
- keepsubdirs (default=True): Whether to keep the relative subdirectories of downloaded files

0 commit comments

Comments
 (0)