Skip to content

Commit 0e1faf2

Browse files
committed
Adds original sampfreq function
Adds the sampfreq function from the original WFDB software package. This version will display the equivalent of using the -a option from the original sampfreq command since this displays the most information and the -H option can be reproduced using the output of the -a option. The -h option does not appear to do anything in the original source code.
1 parent c616cb6 commit 0e1faf2

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-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: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2014,6 +2014,56 @@ 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+
dir_name, base_record_name = os.path.split(record_name)
2052+
dir_name = os.path.abspath(dir_name)
2053+
2054+
if (pn_dir is not None) and ('.' not in pn_dir):
2055+
dir_list = pn_dir.split(os.sep)
2056+
pn_dir = posixpath.join(dir_list[0], get_version(dir_list[0]),
2057+
*dir_list[1:])
2058+
2059+
record = rdheader(record_name, pn_dir=pn_dir).__dict__
2060+
samps_per_frame = [record['fs']*samp for samp in record['samps_per_frame']]
2061+
sig_name = record['sig_name']
2062+
2063+
for sig,samp in zip(sig_name, samps_per_frame):
2064+
print('{}\t{}'.format(sig,samp))
2065+
2066+
20172067
def _get_wanted_channels(wanted_sig_names, record_sig_names, pad=False):
20182068
"""
20192069
Given some wanted signal names, and the signal names contained in a

0 commit comments

Comments
 (0)