Skip to content

Commit e32c895

Browse files
committed
dev
1 parent d6cb083 commit e32c895

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

wfdb/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#from ._downloadsamp import downloadsamp
33

44
from .records import Record, MultiRecord, rdheader, rdsamp, srdsamp, wrsamp
5-
from .annotations import Annotation, rdann, showanncodes
5+
from .annotations import Annotation, rdann, wrann, showanncodes
66

77

88
#from ._plot import plotrec

wfdb/annotations.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,12 @@ def field2bytes(field, value):
298298
return databytes
299299

300300

301+
# Function for writing annotations
302+
def wrann(recordname, annotator, annsamp, anntype, num = None, subtype = None, chan = None, aux = None, fs = None):
303+
# Create Annotation object
304+
annotation = Annotation(recordname, annotator, annsamp, anntype, num, subtype, chan, aux, fs)
305+
# Perform field checks and write the annotation file
306+
annotation.wrann()
301307

302308
# Display the annotation symbols and the codes they represent
303309
def showanncodes():

wfdb/records.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ def multi_to_single(self):
607607
#------------------- Reading Records -------------------#
608608

609609
# Read a WFDB single or multi segment record. Return a Record or MultiRecord object
610-
def rdsamp(recordname, sampfrom=0, sampto=None, channels = None, physical = True, stackmulti = True):
610+
def rdsamp(recordname, sampfrom=0, sampto=None, channels = None, physical = True, stackmulti = True, returnobj = True):
611611

612612
# If the user specifies a sample or signal range, some fields
613613
# of the output object will be updated from the fields directly
@@ -762,38 +762,43 @@ def wanted_siginds(wanted_signames, record_signames):
762762
return [record_signames.index(s) for s in contained_signals]
763763

764764

765-
# A simple version of rdsamp for the average user
765+
# A simple version of rdsamp for ease of use
766766
# Return the physical signals and a few essential fields
767767
def srdsamp(recordname, sampfrom=0, sampto=None, channels = None):
768768

769769
record = rdsamp(recordname, sampfrom, sampto, channels, True, True)
770770

771771
signals = record.p_signals
772772
fields = {}
773-
for field in ['fs','units','signame']:
773+
for field in ['fs','units','signame', 'comments']:
774774
fields[field] = getattr(record, field)
775775

776776
return signals, fields
777777

778778
#------------------- /Reading Records -------------------#
779779

780780

781-
# Gateway function for single segment wrsamp
782-
def wrsamp(recordname, p_signals = None, d_signals = None, fs, units, signames, fmt = None, comments=[]):
781+
# Simple function for single segment wrsamp
782+
def wrsamp(recordname, fs, units, signames, p_signals = None, d_signals = None, fmt = None, comments= None):
783783

784784
# Check input field combinations
785785
if p_signals is not None and d_signals is not None:
786786
sys.exit('Must only give one of the inputs: p_signals or d_signals')
787787

788-
789-
790788
# Create the Record object
791789
record = Record(recordname = recordname, p_signals = p_signals, fs = fs, fmt = fmt, units = units, signame = signames, comments = comments)
792-
# 2. Compute optimal fields to store the digital signal, carry out adc, and set the fields.
793-
record.set_d_features(do_adc = 1)
794-
# 3. Set default values of any missing field dependencies
790+
791+
# Depending on whether d_signals or p_signals was used, set other required features.
792+
if p_signals is not none:
793+
# Compute optimal fields to store the digital signal, carry out adc, and set the fields.
794+
record.set_d_features(do_adc = 1)
795+
else:
796+
# No need to do adc. Just use d_signals to set the fields
797+
record.set_d_features()
798+
799+
# Set default values of any missing field dependencies
795800
record.setdefaults()
796-
# 4. Write the record files - header and associated dat
801+
# Write the record files - header and associated dat
797802
record.wrsamp()
798803

799804

0 commit comments

Comments
 (0)