Skip to content

Commit a78a7a8

Browse files
committed
documentation
1 parent 06402da commit a78a7a8

File tree

1 file changed

+67
-30
lines changed

1 file changed

+67
-30
lines changed

wfdb/records.py

Lines changed: 67 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -207,26 +207,27 @@ def checkreadinputs(self, sampfrom, sampto, channels):
207207
if c>self.nsig-1:
208208
sys.exit('Input channels must all be lower than the total number of channels')
209209

210-
"""
211-
The class representing WFDB headers, and single segment WFDB records.
212210

213-
Record objects can be created as with any other class, or by reading a WFDB header
214-
with 'rdheader', or a WFDB record (header and associated dat files) with rdsamp'
215-
or 'srdsamp'.
211+
class Record(BaseRecord, _headers.HeadersMixin, _signals.SignalsMixin):
212+
"""
213+
The class representing WFDB headers, and single segment WFDB records.
216214
217-
The attributes of the Record object give information about the record as specified
218-
by <insert>
215+
Record objects can be created as with any other class, or by reading a WFDB header
216+
with 'rdheader', or a WFDB record (header and associated dat files) with rdsamp'
217+
or 'srdsamp'.
219218
220-
In addition, the d_signals and p_signals attributes represent the digital and physical
221-
signals of WFDB records with at least one channel.
222-
"""
223-
class Record(BaseRecord, _headers.HeadersMixin, _signals.SignalsMixin):
224-
219+
The attributes of the Record object give information about the record as specified
220+
by https://www.physionet.org/physiotools/wag/header-5.htm
221+
222+
In addition, the d_signals and p_signals attributes represent the digital and physical
223+
signals of WFDB records with at least one channel.
224+
"""
225225
# Constructor
226226
def __init__(self, p_signals=None, d_signals=None,
227227
recordname=None, nsig=None,
228228
fs=None, counterfreq=None, basecounter=None,
229-
siglen=None, basetime=None, basedate=None,
229+
siglen=N
230+
one, basetime=None, basedate=None,
230231
filename=None, fmt=None, sampsperframe=None,
231232
skew=None, byteoffset=None, adcgain=None,
232233
baseline=None, units=None, adcres=None,
@@ -334,7 +335,20 @@ def arrangefields(self, channels):
334335

335336
# Class for multi segment WFDB records.
336337
class MultiRecord(BaseRecord, _headers.MultiHeadersMixin):
337-
338+
"""
339+
The class representing multi-segment WFDB records.
340+
341+
MultiRecord objects can be created as with any other class, or by reading a multi-segment
342+
WFDB record using 'rdsamp' with 'm2s' (multi to single) set to False.
343+
344+
The attributes of the MultiRecord object give information about the record as specified
345+
by https://www.physionet.org/physiotools/wag/header-5.htm
346+
347+
In addition, the
348+
349+
Noteably, the 'multi_to_single' instance method can be called on MultiRecord objects
350+
to return a single segment representation of the record as a Record object.
351+
"""
338352
# Constructor
339353
def __init__(self, segments = None, layout = None,
340354
recordname=None, nsig=None, fs=None,
@@ -618,19 +632,42 @@ def multi_to_single(self):
618632
#------------------- Reading Records -------------------#
619633

620634
# Read a WFDB single or multi segment record. Return a Record or MultiRecord object
621-
def rdsamp(recordname, sampfrom=0, sampto=None, channels = None, physical = True, stackmulti = True, returnobj = True):
635+
def rdsamp(recordname, sampfrom=0, sampto=None, channels = None, physical = True, m2s = True):
636+
"""Read a WFDB record and return the signal and record descriptors as attributes in a wfdb.Record object
637+
638+
Usage:
639+
record = rdsamp(recordname, sampfrom=0, sampto=None, channels=None, physical=True, m2s=True)
640+
641+
Input arguments:
642+
- recordname (required): The name of the WFDB record to be read (without any file extensions).
643+
If the argument contains any path delimiter characters, the argument will be interpreted as
644+
PATH/baserecord and the data files will be searched for in the local path.
645+
- sampfrom (default=0): The starting sample number to read for each channel.
646+
- sampto (default=None): The sample number at which to stop reading for each channel.
647+
- channels (default=all): Indices specifying the channel to be returned.
648+
- physical (default=True): Flag that specifies whether to return signals in physical (true) or
649+
digital (False) units.
650+
- m2s (default=True): Flag used when reading multi-segment records. Specifies whether to
651+
directly return a wfdb MultiRecord object (false), or to convert it into and return a wfdb
652+
Record object (True).
653+
654+
Output argument:
655+
- record: The wfdb Record or MultiRecord object representing the contents of the record read.
656+
Notable atributes of the object include
657+
658+
Note: If a signal range or channel selection is specified when calling this function, the
659+
the resulting attributes of the returned object will be set to reflect the section
660+
of the record that is actually read, rather than necessarily what is in the header file.
661+
For example, if channels = [0, 1, 2] is specified when reading a 12 channel record, the
662+
'nsig' attribute will be 3, not 12.
663+
664+
Note: The 'srdsamp' function exists as a simple alternative to 'rdsamp' for the most common
665+
purpose of extracting the physical signals and a few important descriptor fields.
666+
'srdsamp' returns two arguments: the physical signals array, and a dictionary of a
667+
few select fields, a subset of the original wfdb Record attributes.
668+
669+
Example Usage: record1 = wfdb.rdsamp('macecgdb/test01_00s', sampfrom=800, channels = [1,3])
622670
"""
623-
624-
"""
625-
626-
627-
# If the user specifies a sample or signal range, some fields
628-
# of the output object will be updated from the fields directly
629-
# read from the header, which represent the entire record.
630-
631-
# The goal of this function is to create an object, or objects,
632-
# with description fields that reflect the state its contents
633-
# when created.
634671

635672
dirname, baserecordname = os.path.split(recordname)
636673

@@ -680,11 +717,11 @@ def rdsamp(recordname, sampfrom=0, sampto=None, channels = None, physical = True
680717
# Segments field is a list of Record objects
681718
# Empty segments store None.
682719

683-
# If stackmulti == True, Physical must be true. There is no
720+
# If m2s == True, Physical must be true. There is no
684721
# meaningful representation of digital signals transferred
685722
# from individual segments.
686-
if stackmulti == True and physical != True:
687-
sys.exit('If stackmulti is True, physical must also be True.')
723+
if m2s == True and physical != True:
724+
sys.exit('If m2s is True, physical must also be True.')
688725

689726
record.segments = [None]*record.nseg
690727

@@ -717,7 +754,7 @@ def rdsamp(recordname, sampfrom=0, sampto=None, channels = None, physical = True
717754
record.arrangefields(readsegs, segranges, channels)
718755

719756
# Convert object into a single segment Record object
720-
if stackmulti:
757+
if m2s:
721758
record = record.multi_to_single()
722759

723760
return record

0 commit comments

Comments
 (0)