Skip to content

Commit cdb396b

Browse files
authored
Merge pull request MIT-LCP#233 from MIT-LCP/sampfreq
Adds original sampfreq function
2 parents 9b97885 + 8ae7124 commit cdb396b

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-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)
2+
wrsamp, dl_database, edf2mit, sampfreq)
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, SIGNAL_CLASSES)
2+
dl_database, edf2mit, sampfreq, 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: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2014,6 +2014,53 @@ def rdsamp(record_name, sampfrom=0, sampto=None, channels=None, pn_dir=None,
20142014
return signals, fields
20152015

20162016

2017+
def sampfreq(record_name, pn_dir=None):
2018+
"""
2019+
Read a WFDB header file and return the sampling frequency of
2020+
each of the signals in the record.
2021+
2022+
Parameters
2023+
----------
2024+
record_name : str
2025+
The name of the WFDB record to be read, without any file
2026+
extensions. If the argument contains any path delimiter
2027+
characters, the argument will be interpreted as PATH/BASE_RECORD.
2028+
Both relative and absolute paths are accepted. If the `pn_dir`
2029+
parameter is set, this parameter should contain just the base
2030+
record name, and the files fill be searched for remotely.
2031+
Otherwise, the data files will be searched for in the local path.
2032+
pn_dir : str, optional
2033+
Option used to stream data from Physionet. The Physionet
2034+
database directory from which to find the required record files.
2035+
eg. For record '100' in 'http://physionet.org/content/mitdb'
2036+
pn_dir='mitdb'.
2037+
2038+
Returns
2039+
-------
2040+
N/A
2041+
2042+
Examples
2043+
--------
2044+
>>> wfdb.sampfreq('sample-data/test01_00s')
2045+
>>> ECG 1 500
2046+
>>> ECG 2 500
2047+
>>> ECG 3 500
2048+
>>> ECG 4 500
2049+
2050+
"""
2051+
if (pn_dir is not None) and ('.' not in pn_dir):
2052+
dir_list = pn_dir.split(os.sep)
2053+
pn_dir = posixpath.join(dir_list[0], get_version(dir_list[0]),
2054+
*dir_list[1:])
2055+
2056+
record = rdheader(record_name, pn_dir=pn_dir)
2057+
samps_per_frame = [record.fs*samp for samp in record.samps_per_frame]
2058+
sig_name = record.sig_name
2059+
2060+
for sig,samp in zip(sig_name, samps_per_frame):
2061+
print('{}\t{}'.format(sig,samp))
2062+
2063+
20172064
def _get_wanted_channels(wanted_sig_names, record_sig_names, pad=False):
20182065
"""
20192066
Given some wanted signal names, and the signal names contained in a

0 commit comments

Comments
 (0)