Skip to content

Commit 651e0ff

Browse files
committed
Adds original signame function
Adds the signame function from the original WFDB software package. This version maintains the original functionality including the -s option for specific signal numbers. Since the -h option just prints help for the function, this was omitted since it can be recreated using help(wfdb.signame).
1 parent cdb396b commit 651e0ff

File tree

3 files changed

+57
-2
lines changed

3 files changed

+57
-2
lines changed

wfdb/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from .io.record import (Record, MultiRecord, rdheader, rdrecord, rdsamp,
2-
wrsamp, dl_database, edf2mit, sampfreq)
2+
wrsamp, dl_database, edf2mit, sampfreq, signame)
33
from .io.annotation import (Annotation, rdann, wrann, show_ann_labels,
44
show_ann_classes)
55
from .io.download import get_dbs, get_record_list, dl_files, set_db_index_url

wfdb/io/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from .record import (Record, MultiRecord, rdheader, rdrecord, rdsamp, wrsamp,
2-
dl_database, edf2mit, sampfreq, SIGNAL_CLASSES)
2+
dl_database, edf2mit, sampfreq, signame, SIGNAL_CLASSES)
33
from ._signal import est_res, wr_dat_file
44
from .annotation import (Annotation, rdann, wrann, show_ann_labels,
55
show_ann_classes)

wfdb/io/record.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2061,6 +2061,61 @@ def sampfreq(record_name, pn_dir=None):
20612061
print('{}\t{}'.format(sig,samp))
20622062

20632063

2064+
def signame(record_name, pn_dir=None, sig_nums=[]):
2065+
"""
2066+
Read a WFDB record file and return the signal names.
2067+
2068+
Parameters
2069+
----------
2070+
record_name : str
2071+
The name of the WFDB record to be read, without any file
2072+
extensions. If the argument contains any path delimiter
2073+
characters, the argument will be interpreted as PATH/BASE_RECORD.
2074+
Both relative and absolute paths are accepted. If the `pn_dir`
2075+
parameter is set, this parameter should contain just the base
2076+
record name, and the files fill be searched for remotely.
2077+
Otherwise, the data files will be searched for in the local path.
2078+
pn_dir : str, optional
2079+
Option used to stream data from Physionet. The Physionet
2080+
database directory from which to find the required record files.
2081+
eg. For record '100' in 'http://physionet.org/content/mitdb'
2082+
pn_dir='mitdb'.
2083+
sig_nums : list, optional
2084+
A list of the signal numbers to be outputted.
2085+
2086+
Returns
2087+
-------
2088+
N/A
2089+
2090+
Examples
2091+
--------
2092+
>>> wfdb.signame('sample-data/test01_00s')
2093+
>>> ECG 1
2094+
>>> ECG 2
2095+
>>> ECG 3
2096+
>>> ECG 4
2097+
2098+
>>> wfdb.signame('sample-data/test01_00s', sig_nums=[1,3])
2099+
>>> ECG 2
2100+
>>> ECG 4
2101+
2102+
"""
2103+
if (pn_dir is not None) and ('.' not in pn_dir):
2104+
dir_list = pn_dir.split(os.sep)
2105+
pn_dir = posixpath.join(dir_list[0], get_version(dir_list[0]),
2106+
*dir_list[1:])
2107+
2108+
record = rdheader(record_name, pn_dir=pn_dir)
2109+
if len(sig_nums) > 0:
2110+
for n in sig_nums:
2111+
try:
2112+
print(record.sig_name[n])
2113+
except IndexError:
2114+
raise Exception('sig_nums value {} out of range'.format(n))
2115+
else:
2116+
print(*record.sig_name, sep='\n')
2117+
2118+
20642119
def _get_wanted_channels(wanted_sig_names, record_sig_names, pad=False):
20652120
"""
20662121
Given some wanted signal names, and the signal names contained in a

0 commit comments

Comments
 (0)