Skip to content

Commit e5aface

Browse files
author
Chen Xie
committed
rst readme and fixed python2 download file bug
1 parent 859e952 commit e5aface

File tree

4 files changed

+194
-119
lines changed

4 files changed

+194
-119
lines changed

README.md

Lines changed: 0 additions & 116 deletions
This file was deleted.

README.rst

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
wfdb-python
2+
===========
3+
4+
|Build Status|
5+
6+
.. figure:: https://raw.githubusercontent.com/MIT-LCP/wfdb-python/master/demoimg1.png
7+
:alt: wfdb signals
8+
9+
Introduction
10+
------------
11+
12+
Native python scripts for reading and writing WFDB signals and
13+
annotations.
14+
15+
Usage
16+
-----
17+
18+
Distribution hosted on pypi. No need to manualy download or clone this
19+
repository. To install the package, run from your terminal:
20+
``pip install wfdb``
21+
22+
See the **wfdbdemo.ipynb** file for example scripts on how to call the
23+
functions.
24+
25+
Reading Signals
26+
~~~~~~~~~~~~~~~
27+
28+
**rdsamp** - Read a WFDB file and return the signal as a numpy array and
29+
the metadata as a dictionary.
30+
31+
::
32+
33+
sig, fields = rdsamp(recordname, sampfrom=0, sampto=[], channels=[], physical=1, stacksegments=1, pbdl=0, dldir=os.cwd(), keepfiles=0)
34+
35+
Example Usage:
36+
37+
::
38+
39+
import wfdb
40+
sig, fields = wfdb.rdsamp('mitdb/100', sampto=2000, pbdl=1)
41+
42+
Input Arguments:
43+
44+
- ``recordname`` (mandatory) - The name of the WFDB record to be read
45+
(without any file extensions).
46+
- ``sampfrom`` (default=0) - The starting sample number to read for
47+
each channel.
48+
- ``sampto`` (default=length of entire signal)- The final sample number
49+
to read for each channel.
50+
- ``channels`` (default=all channels) - Indices specifying the channel
51+
to be returned.
52+
- ``physical`` (default=1) - Flag that specifies whether to return
53+
signals in physical (1) or digital (0) units.
54+
- ``stacksegments`` (default=1) - Flag used only for multi-segment
55+
files. Specifies whether to return the signal as a single
56+
stacked/concatenated numpy array (1) or as a list of one numpy array
57+
for each segment (0).
58+
- ``pbdl`` (default=0): If this argument is set, the function will
59+
assume that the user is trying to download a physiobank file.
60+
Therefore the ‘recordname’ argument will be interpreted as a
61+
physiobank record name including the database subdirectory, rather
62+
than a local directory.
63+
- ``dldir`` (default=os.getcwd()): The directory to download physiobank
64+
files to.
65+
- ``keepfiles`` (default=0): Flag specifying whether to keep physiobank
66+
files newly downloaded through the function call.
67+
68+
Output Arguments:
69+
70+
- ``sig`` - An nxm numpy array where n is the signal length and m is
71+
the number of channels. If the input record is a multi-segment
72+
record, depending on the input stacksegments flag, sig will either be
73+
a single stacked/concatenated numpy array (1) or a list of one numpy
74+
array for each segment (0). For empty segments, stacked format will
75+
contain Nan values, and non-stacked format will contain a single
76+
integer specifying the length of the empty segment.
77+
- ``fields`` - A dictionary of metadata about the record extracted or
78+
deduced from the header/signal file. If the input record is a
79+
multi-segment record, the output argument will be a list of
80+
dictionaries:
81+
82+
- The first list element will be a dictionary of metadata about the
83+
master header.
84+
- If the record is in variable layout format, the next list element
85+
will be a dictionary of metadata about the layout specification
86+
header.
87+
- The last list element will be a list of dictionaries of metadata
88+
for each segment. For empty segments, the dictionary will be
89+
replaced by a single string: ‘Empty Segment’
90+
91+
Reading Annotations
92+
~~~~~~~~~~~~~~~~~~~
93+
94+
**rdann** - Read a WFDB annotation file ``recordname.annot`` and return
95+
the fields as lists or arrays.
96+
97+
::
98+
99+
annsamp, anntype, subtype, chan, num, aux, annfs = wfdb.rdann(recordname, annot, sampfrom=0, sampto=[], anndisp=1)
100+
101+
Example Usage:
102+
103+
::
104+
105+
import wfdb
106+
annsamp, anntype, subtype, chan, num, aux, annfs = wfdb.rdann('100', 'atr')
107+
108+
Input Arguments:
109+
110+
- ``recordname`` (required) - The record name of the WFDB annotation
111+
file. ie. for file ``100.atr`` recordname=‘100’.
112+
- ``annot`` (required) - The annotator extension of the annotation
113+
file. ie. for file ``100.atr`` annot=‘atr’.
114+
- ``sampfrom`` (default=0)- The minimum sample number for annotations
115+
to be returned.
116+
- ``sampto`` (default=the final annotation sample) - The maximum sample
117+
number for annotations to be returned.
118+
- ``anndisp`` (default=1) - The annotation display flag that controls
119+
the data type of the ``anntype`` output parameter. ``anntype`` will
120+
either be an integer key(0), a shorthand display symbol(1), or a
121+
longer annotation code(2).
122+
123+
Output arguments:
124+
125+
- ``annsamp`` - The annotation location in samples relative to the
126+
beginning of the record.
127+
- ``anntype`` - The annotation type according the the standard WFDB
128+
keys.
129+
- ``subtype`` - The marked class/category of the annotation.
130+
- ``chan`` - The signal channel associated with the annotations.
131+
- ``num`` - The marked annotation number. This is not equal to the
132+
index of the current annotation.
133+
- ``aux`` - The auxiliary information string for the annotation.
134+
- ``annfs`` - The sampling frequency written in the beginning of the
135+
annotation file if present.
136+
137+
\*\ **NOTE**: Every annotation contains the ‘annsamp’ and ‘anntype’
138+
field. All other fields default to 0 or empty if not present.
139+
140+
141+
Plotting Data
142+
~~~~~~~~~~~~~
143+
144+
**plotwfdb** - Subplot and label each channel of an nxm signal on a
145+
graph. Also subplot annotation locations on selected channels if
146+
present.
147+
148+
::
149+
150+
plotwfdb(sig, fields, annsamp=[], annch=[0], title=[], plottime=1)
151+
152+
Example Usage:
153+
154+
::
155+
156+
import wfdb
157+
sig, fields = wfdb.rdsamp('100')
158+
annsamp=wfdb.rdann('100', 'atr')[0]
159+
wfdb.plotwfdb(sig, fields, annsamp, 'mitdb record 100'):
160+
161+
162+
Input Arguments:
163+
164+
- ``sig`` (required)- An nxm numpy array containing the signal to be
165+
plotted - the first output argument of ``wfdb.rdsamp``.
166+
- ``fields`` (required) - A dictionary of metadata about the record -
167+
the second output argument of ``wfdb.rdsamp``.
168+
- ``annsamp`` (optional) - A 1d numpy array of annotation locations to
169+
be plotted on top of selected channels - first output argument of
170+
``rdann``.
171+
- ``annch`` (default=[0]) - A list of channels on which to plot the
172+
annotations.
173+
- ``title`` (optional)- A string containing the title of the graph.
174+
- ``plottime`` (default=1) - Flag that specifies whether to plot the x
175+
axis as time (1) or samples (0). Defaults to samples if the input
176+
``fields`` dictionary does not contain a value for ``fs``.
177+
178+
Based on the original WFDB software package specifications
179+
----------------------------------------------------------
180+
181+
| `WFDB Software Package`_
182+
| `WFDB Applications Guide`_
183+
| `WFDB Header File Specifications`_
184+
185+
.. _WFDB Software Package: http://physionet.org/physiotools/wfdb.shtml
186+
.. _WFDB Applications Guide: http://physionet.org/physiotools/wag/
187+
.. _WFDB Header File Specifications: https://physionet.org/physiotools/wag/header-5.htm
188+
189+
190+
.. |Build Status| image:: https://travis-ci.org/MIT-LCP/wfdb-python.svg?branch=master
191+
:target: https://travis-ci.org/MIT-LCP/wfdb-python

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
here = path.abspath(path.dirname(__file__))
1212

1313
# Get the long description from the README file
14-
with open(path.join(here, 'README.md'), encoding='utf-8') as f:
14+
with open(path.join(here, 'README.rst'), encoding='utf-8') as f:
1515
long_description = f.read()
1616

1717
setup(

wfdb/_rdsamp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ def dlorexit(url, filename, displaydlmsg=0, targetdir=[]):
9393
print('Downloading missing file(s) into directory: {}'.format(targetdir))
9494
try:
9595
r = requests.get(url)
96-
with open(filename, "w") as text_file:
97-
text_file.write(r.text)
96+
with open(filename, "wb") as writefile:
97+
writefile.write(r.content)
9898
return filename
9999
except requests.HTTPError:
100100
sys.exit("Attempted to download invalid target file: " + url)

0 commit comments

Comments
 (0)