Skip to content

Commit e8bfb10

Browse files
author
Chen Xie
committed
doc
1 parent 1aa482c commit e8bfb10

File tree

4 files changed

+210
-19
lines changed

4 files changed

+210
-19
lines changed

README.md

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,7 @@
77
</p>
88

99
## Introduction
10-
<p>Native python scripts for reading and writing WFDB signals and annotations. Currently in development. Library files are in the <strong>wfdb</strong> directory.</p>
11-
12-
<ul>
13-
<li>15 July 2016 - <code>rdsamp</code> (for reading WFDB signals) is ready for beta usage.</li>
14-
<li>27 July 2016 - <code>rdann</code> (for reading WFDB annotations) is ready for beta usage.</li>
15-
<li>27 July 2016 - <code>plotwfdb</code> is able to plot signals and annotations output by <em>rdsamp</em> and <em>rdann</em></li>
16-
</ul>
17-
18-
10+
<p>Native python scripts for reading and writing WFDB signals and annotations.
1911

2012
## Usage
2113

@@ -25,9 +17,14 @@ See the <strong>wfdbdemo.ipynb</strong> file for example scripts on how to call
2517

2618
<strong>rdsamp</strong> - Read a WFDB file and return the signal as a numpy array and the metadata as a dictionary.
2719

20+
```
21+
sig, fields = rdsamp(recordname, sampfrom=0, sampto=[], channels=[], physical=1, stacksegments=1, pbdl=0, dldir=os.cwd(), keepfiles=0)
22+
```
23+
24+
Example Usage:
2825
```
2926
import wfdb
30-
sig, fields = wfdb.rdsamp(recordname, sampfrom, sampto, channels, physical, stacksegments)
27+
sig, fields = wfdb.rdsamp('mitdb/100', sampto=2000, pbdl=1)
3128
```
3229

3330
Input Arguments:
@@ -38,6 +35,9 @@ Input Arguments:
3835
<li><code>channels</code> (default=all channels) - Indices specifying the channel to be returned.</li>
3936
<li><code>physical</code> (default=1) - Flag that specifies whether to return signals in physical (1) or digital (0) units.</li>
4037
<li><code>stacksegments</code> (default=1) - Flag used only for multi-segment files. Specifies whether to return the signal as a single stacked/concatenated numpy array (1) or as a list of one numpy array for each segment (0). </li>
38+
<li>pbdl (default=0): If this argument is set, the function will assume that the user is trying to download a physiobank file. Therefore the 'recordname' argument will be interpreted as a physiobank record name including the database subdirectory, rather than a local directory.</li>
39+
<li>dldir (default=os.getcwd()): The directory to download physiobank files to.</li>
40+
<li>keepfiles (default=0): Flag specifying whether to keep physiobank files newly downloaded through the function call.</li>
4141
</ul>
4242

4343
Output Arguments:
@@ -56,9 +56,14 @@ Output Arguments:
5656

5757
<strong>rdann</strong> - Read a WFDB annotation file <code>recordname.annot</code> and return the fields as lists or arrays.
5858

59+
```
60+
annsamp, anntype, subtype, chan, num, aux, annfs = wfdb.rdann(recordname, annot, sampfrom=0, sampto=[], anndisp=1)
61+
```
62+
63+
Example Usage:
5964
```
6065
import wfdb
61-
annsamp, anntype, subtype, chan, num, aux, annfs) = wfdb.rdann(recordname, annot, sampfrom, sampto, anndisp)
66+
annsamp, anntype, subtype, chan, num, aux, annfs = wfdb.rdann('100', 'atr')
6267
```
6368

6469
Input Arguments:
@@ -89,11 +94,16 @@ Output arguments:
8994

9095
<strong>plotwfdb</strong> - Subplot and label each channel of an nxm signal on a graph. Also subplot annotation locations on selected channels if present.
9196

97+
```
98+
plotwfdb(sig, fields, annsamp=[], annch=[0], title=[], plottime=1)
99+
```
100+
101+
Example Usage:
92102
```
93103
import wfdb
94-
sig, fields = wfdb.rdsamp(recordname)
95-
annsamp=wfdb.rdann('recordname', 'annot')[0]
96-
wfdb.plotwfdb(sig, fields, annsamp, annch, title, plottime):
104+
sig, fields = wfdb.rdsamp('100')
105+
annsamp=wfdb.rdann('100', 'atr')[0]
106+
wfdb.plotwfdb(sig, fields, annsamp, 'mitdb record 100'):
97107
98108
```
99109

devtests.ipynb

Lines changed: 182 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -803,14 +803,31 @@
803803
},
804804
{
805805
"cell_type": "code",
806-
"execution_count": null,
806+
"execution_count": 5,
807807
"metadata": {
808808
"collapsed": false
809809
},
810-
"outputs": [],
810+
"outputs": [
811+
{
812+
"name": "stdout",
813+
"output_type": "stream",
814+
"text": [
815+
"Created local directory: /home/cx1111/Downloads/wfdbrecords/macecgdb\n",
816+
"Downloading missing file(s) into directory: /home/cx1111/Downloads/wfdbrecords/macecgdb\n",
817+
"Downloaded all missing files for record.\n",
818+
"[[ 1.00000000e-01 -3.05110000e+02 -2.87190000e+02 -2.66720000e+02]\n",
819+
" [ -2.87190000e+02 -2.71830000e+02 -2.87190000e+02 1.10000000e-01]\n",
820+
" [ -2.99990000e+02 -2.87190000e+02 -2.64160000e+02 -2.87190000e+02]\n",
821+
" ..., \n",
822+
" [ -2.79520000e+02 -2.87190000e+02 -2.66710000e+02 -2.87190000e+02]\n",
823+
" [ 1.20000000e-01 -2.00160000e+02 -2.87190000e+02 -2.79520000e+02]\n",
824+
" [ -2.87190000e+02 -2.84640000e+02 -2.87190000e+02 1.20000000e-01]]\n"
825+
]
826+
}
827+
],
811828
"source": [
812829
"import wfdb\n",
813-
"sig, fields=wfdb.rdsamp('macecgdb/test01_00s', pbdl=1, dldir='/home/cx1111/Downloads/wfdbrecords/macecgdb', keepfiles=1)\n",
830+
"sig, fields=wfdb.rdsamp('macecgdb/test01_00s', pbdl=1, dldir='/home/cx1111/Downloads/wfdbrecords/macecgdb')\n",
814831
"\n",
815832
"print(sig)"
816833
]
@@ -829,6 +846,168 @@
829846
"print(sig)"
830847
]
831848
},
849+
{
850+
"cell_type": "code",
851+
"execution_count": 2,
852+
"metadata": {
853+
"collapsed": false
854+
},
855+
"outputs": [
856+
{
857+
"name": "stdout",
858+
"output_type": "stream",
859+
"text": [
860+
"Help on built-in function array in module numpy.core.multiarray:\n",
861+
"\n",
862+
"array(...)\n",
863+
" array(object, dtype=None, copy=True, order=None, subok=False, ndmin=0)\n",
864+
" \n",
865+
" Create an array.\n",
866+
" \n",
867+
" Parameters\n",
868+
" ----------\n",
869+
" object : array_like\n",
870+
" An array, any object exposing the array interface, an\n",
871+
" object whose __array__ method returns an array, or any\n",
872+
" (nested) sequence.\n",
873+
" dtype : data-type, optional\n",
874+
" The desired data-type for the array. If not given, then\n",
875+
" the type will be determined as the minimum type required\n",
876+
" to hold the objects in the sequence. This argument can only\n",
877+
" be used to 'upcast' the array. For downcasting, use the\n",
878+
" .astype(t) method.\n",
879+
" copy : bool, optional\n",
880+
" If true (default), then the object is copied. Otherwise, a copy\n",
881+
" will only be made if __array__ returns a copy, if obj is a\n",
882+
" nested sequence, or if a copy is needed to satisfy any of the other\n",
883+
" requirements (`dtype`, `order`, etc.).\n",
884+
" order : {'C', 'F', 'A'}, optional\n",
885+
" Specify the order of the array. If order is 'C', then the array\n",
886+
" will be in C-contiguous order (last-index varies the fastest).\n",
887+
" If order is 'F', then the returned array will be in\n",
888+
" Fortran-contiguous order (first-index varies the fastest).\n",
889+
" If order is 'A' (default), then the returned array may be\n",
890+
" in any order (either C-, Fortran-contiguous, or even discontiguous),\n",
891+
" unless a copy is required, in which case it will be C-contiguous.\n",
892+
" subok : bool, optional\n",
893+
" If True, then sub-classes will be passed-through, otherwise\n",
894+
" the returned array will be forced to be a base-class array (default).\n",
895+
" ndmin : int, optional\n",
896+
" Specifies the minimum number of dimensions that the resulting\n",
897+
" array should have. Ones will be pre-pended to the shape as\n",
898+
" needed to meet this requirement.\n",
899+
" \n",
900+
" Returns\n",
901+
" -------\n",
902+
" out : ndarray\n",
903+
" An array object satisfying the specified requirements.\n",
904+
" \n",
905+
" See Also\n",
906+
" --------\n",
907+
" empty, empty_like, zeros, zeros_like, ones, ones_like, fill\n",
908+
" \n",
909+
" Examples\n",
910+
" --------\n",
911+
" >>> np.array([1, 2, 3])\n",
912+
" array([1, 2, 3])\n",
913+
" \n",
914+
" Upcasting:\n",
915+
" \n",
916+
" >>> np.array([1, 2, 3.0])\n",
917+
" array([ 1., 2., 3.])\n",
918+
" \n",
919+
" More than one dimension:\n",
920+
" \n",
921+
" >>> np.array([[1, 2], [3, 4]])\n",
922+
" array([[1, 2],\n",
923+
" [3, 4]])\n",
924+
" \n",
925+
" Minimum dimensions 2:\n",
926+
" \n",
927+
" >>> np.array([1, 2, 3], ndmin=2)\n",
928+
" array([[1, 2, 3]])\n",
929+
" \n",
930+
" Type provided:\n",
931+
" \n",
932+
" >>> np.array([1, 2, 3], dtype=complex)\n",
933+
" array([ 1.+0.j, 2.+0.j, 3.+0.j])\n",
934+
" \n",
935+
" Data-type consisting of more than one element:\n",
936+
" \n",
937+
" >>> x = np.array([(1,2),(3,4)],dtype=[('a','<i4'),('b','<i4')])\n",
938+
" >>> x['a']\n",
939+
" array([1, 3])\n",
940+
" \n",
941+
" Creating an array from sub-classes:\n",
942+
" \n",
943+
" >>> np.array(np.mat('1 2; 3 4'))\n",
944+
" array([[1, 2],\n",
945+
" [3, 4]])\n",
946+
" \n",
947+
" >>> np.array(np.mat('1 2; 3 4'), subok=True)\n",
948+
" matrix([[1, 2],\n",
949+
" [3, 4]])\n",
950+
"\n"
951+
]
952+
}
953+
],
954+
"source": [
955+
"import numpy as np\n",
956+
"\n",
957+
"help(np.array)"
958+
]
959+
},
960+
{
961+
"cell_type": "code",
962+
"execution_count": 6,
963+
"metadata": {
964+
"collapsed": false
965+
},
966+
"outputs": [
967+
{
968+
"name": "stdout",
969+
"output_type": "stream",
970+
"text": [
971+
"Help on function rdann in module wfdb._rdann:\n",
972+
"\n",
973+
"rdann(recordname, annot, sampfrom=0, sampto=[], anndisp=1)\n",
974+
" Read a WFDB annotation file recordname.annot and return the fields as lists or arrays\n",
975+
" \n",
976+
" Usage: annsamp, anntype, num, subtype, chan, aux, annfs = rdann(recordname, annot, \n",
977+
" sampfrom=0, sampto=[], \n",
978+
" anndisp=1)\n",
979+
" \n",
980+
" Input arguments:\n",
981+
" - recordname (required): The record name of the WFDB annotation file. ie. for \n",
982+
" file '100.atr', recordname='100'\n",
983+
" - annot (required): The annotator extension of the annotation file. ie. for \n",
984+
" file '100.atr', annot='atr'\n",
985+
" - sampfrom (default=0): The minimum sample number for annotations to be returned.\n",
986+
" - sampto (default=the final annotation sample): The maximum sample number for \n",
987+
" annotations to be returned.\n",
988+
" - anndisp (default = 1): The annotation display flag that controls the data type \n",
989+
" of the 'anntype' output parameter. 'anntype' will either be an integer key(0), \n",
990+
" a shorthand display symbol(1), or a longer annotation code.\n",
991+
" \n",
992+
" Output arguments:\n",
993+
" - annsamp: The annotation location in samples relative to the beginning of the record.\n",
994+
" - anntype: The annotation type according the the standard WFDB keys.\n",
995+
" - subtype: The marked class/category of the annotation.\n",
996+
" - chan: The signal channel associated with the annotations.\n",
997+
" - num: The marked annotation number. This is not equal to the index of the current annotation.\n",
998+
" - aux: The auxiliary information string for the annotation.\n",
999+
" - annfs: The sampling frequency written in the beginning of the annotation file if present.\n",
1000+
" \n",
1001+
" *NOTE: Every annotation contains the 'annsamp' and 'anntype' field. All \n",
1002+
" other fields default to 0 or empty if not present.\n",
1003+
"\n"
1004+
]
1005+
}
1006+
],
1007+
"source": [
1008+
"help(wfdb.rdann)"
1009+
]
1010+
},
8321011
{
8331012
"cell_type": "code",
8341013
"execution_count": null,

wfdb/_rdann.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def rdann(recordname, annot, sampfrom=0, sampto=[], anndisp=1):
162162
annotations to be returned.
163163
- anndisp (default = 1): The annotation display flag that controls the data type
164164
of the 'anntype' output parameter. 'anntype' will either be an integer key(0),
165-
a shorthand display symbol(1), or a longer annotation code.
165+
a shorthand display symbol(1), or a longer annotation code(2).
166166
167167
Output arguments:
168168
- annsamp: The annotation location in samples relative to the beginning of the record.

wfdb/_rdsamp.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,7 @@ def rdsamp(
993993
"""Read a WFDB record and return the signal as a numpy array and the metadata as a dictionary.
994994
995995
Usage:
996-
sig, fields = rdsamp(recordname, sampfrom, sampto, channels, physical, stacksegments)
996+
sig, fields = rdsamp(recordname, sampfrom=0, sampto=[], channels=[], physical=1, stacksegments=1, pbdl=0, dldir=os.cwd(), keepfiles=0)
997997
998998
Input arguments:
999999
- recordname (required): The name of the WFDB record to be read (without any file extensions). If the argument contains any path delimiter characters, the argument will be interpreted as PATH/baserecord and the data files will be searched for in the local path. If the pbdownload flag is set to 1, recordname will be interpreted as a physiobank record name including the database subdirectory.
@@ -1019,6 +1019,8 @@ def rdsamp(
10191019
of metadata about the layout specification header.
10201020
: The last list element will be a list of dictionaries of metadata for each segment.
10211021
For empty segments, the dictionary will be replaced by a single string: 'Empty Segment'
1022+
1023+
Example: sig, fields = wfdb.rdsamp('macecgdb/test01_00s', sampfrom=800, pbdl=1, dldir='/home/username/Downloads/wfdb')
10221024
"""
10231025

10241026
if sampfrom < 0:

0 commit comments

Comments
 (0)