19
19
# The base WFDB class to extend to create Record and MultiRecord. Contains shared helper functions and fields.
20
20
class BaseRecord ():
21
21
# Constructor
22
-
23
22
def __init__ (self , recordname = None , nsig = None ,
24
23
fs = None , counterfreq = None , basecounter = None ,
25
24
siglen = None , basetime = None , basedate = None ,
@@ -219,8 +218,8 @@ class Record(BaseRecord, _headers.HeadersMixin, _signals.SignalsMixin):
219
218
The attributes of the Record object give information about the record as specified
220
219
by https://www.physionet.org/physiotools/wag/header-5.htm
221
220
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.
221
+ In addition, the d_signals and p_signals attributes store the digital and physical
222
+ signals of WFDB records with at least one channel.
224
223
"""
225
224
# Constructor
226
225
def __init__ (self , p_signals = None , d_signals = None ,
@@ -341,16 +340,18 @@ class MultiRecord(BaseRecord, _headers.MultiHeadersMixin):
341
340
MultiRecord objects can be created as with any other class, or by reading a multi-segment
342
341
WFDB record using 'rdsamp' with the 'm2s' (multi to single) input parameter set to False.
343
342
344
- The attributes of the MultiRecord object give information about the record as specified
343
+ The attributes of the MultiRecord object give information about the entire record as specified
345
344
by https://www.physionet.org/physiotools/wag/header-5.htm
346
345
347
346
In addition, the 'segments' parameter is a list of Record objects representing each
348
- individual segment of the entire multi-segment record.
349
-
350
- Noteably, the 'multi_to_single' instance method can be called on MultiRecord objects
351
- to return a single segment representation of the record as a Record object. The resulting
352
- Record object will have its 'p_signals' field set.
347
+ individual segment, or 'None' representing empty segments, of the entire multi-segment record.
353
348
349
+ Noteably, this class has no attribute representing the signals as a whole. The 'multi_to_single'
350
+ instance method can be called on MultiRecord objects to return a single segment representation
351
+ of the record as a Record object. The resulting Record object will have its 'p_signals' field set.
352
+
353
+ eg. record1 = wfdb.rdsamp('s00001-2896-10-10-00-31', m2s = False)
354
+ record1 = record1.multi_to_single()
354
355
"""
355
356
# Constructor
356
357
def __init__ (self , segments = None , layout = None ,
@@ -669,7 +670,9 @@ def rdsamp(recordname, sampfrom=0, sampto=None, channels = None, physical = True
669
670
'srdsamp' returns two arguments: the physical signals array, and a dictionary of a
670
671
few select fields, a subset of the original wfdb Record attributes.
671
672
672
- Example Usage: record1 = wfdb.rdsamp('macecgdb/test01_00s', sampfrom=800, channels = [1,3])
673
+ Example Usage:
674
+ import wfdb
675
+ record1 = wfdb.rdsamp('macecgdb/test01_00s', sampfrom=800, channels = [1,3])
673
676
"""
674
677
675
678
dirname , baserecordname = os .path .split (recordname )
@@ -822,7 +825,42 @@ def wanted_siginds(wanted_signames, record_signames):
822
825
# A simple version of rdsamp for ease of use
823
826
# Return the physical signals and a few essential fields
824
827
def srdsamp (recordname , sampfrom = 0 , sampto = None , channels = None ):
828
+ """Read a WFDB record and return the signal and record descriptors as attributes in a wfdb.Record object
829
+
830
+ Usage:
831
+ record = rdsamp(recordname, sampfrom=0, sampto=None, channels=None, physical=True, m2s=True)
832
+
833
+ Input arguments:
834
+ - recordname (required): The name of the WFDB record to be read (without any file extensions).
835
+ If the argument contains any path delimiter characters, the argument will be interpreted as
836
+ PATH/baserecord and the data files will be searched for in the local path.
837
+ - sampfrom (default=0): The starting sample number to read for each channel.
838
+ - sampto (default=None): The sample number at which to stop reading for each channel.
839
+ - channels (default=all): Indices specifying the channel to be returned.
825
840
841
+ Output arguments:
842
+ - signals: A 2d numpy array storing the physical signals from the record.
843
+ - fields: A dictionary specifying several key attributes of the read record:
844
+ - fs: The sampling frequency of the record
845
+ - units: The units for each channel
846
+ - signame: The signal name for each channel
847
+ - comments: Any comments written in the header
848
+
849
+ Note: If a signal range or channel selection is specified when calling this function, the
850
+ the resulting attributes of the returned object will be set to reflect the section
851
+ of the record that is actually read, rather than necessarily what is in the header file.
852
+ For example, if channels = [0, 1, 2] is specified when reading a 12 channel record, the
853
+ 'nsig' attribute will be 3, not 12.
854
+
855
+ Note: The 'rdsamp' function exists as a simple alternative to 'rdsamp' for the most common
856
+ purpose of extracting the physical signals and a few important descriptor fields.
857
+ 'srdsamp' returns two arguments: the physical signals array, and a dictionary of a
858
+ few select fields, a subset of the original wfdb Record attributes.
859
+
860
+ Example Usage:
861
+ import wfdb
862
+ sig, fields = wfdb.srdsamp('macecgdb/test01_00s', sampfrom=800, channels = [1,3])
863
+ """
826
864
record = rdsamp (recordname , sampfrom , sampto , channels , True , True )
827
865
828
866
signals = record .p_signals
@@ -835,12 +873,18 @@ def srdsamp(recordname, sampfrom=0, sampto=None, channels = None):
835
873
#------------------- /Reading Records -------------------#
836
874
837
875
838
- # Simple function for single segment wrsamp
839
- def wrsamp (recordname , fs , units , signames , p_signals = None , d_signals = None , fmt = None , comments = None ):
876
+ # Function for writing single segment records
877
+ def wrsamp (recordname , fs , units , signames , p_signals = None , d_signals = None ,
878
+ fmt = None , gain = None , baseline = None , comments = None ):
879
+ """
840
880
881
+ """
841
882
# Check input field combinations
842
883
if p_signals is not None and d_signals is not None :
843
884
sys .exit ('Must only give one of the inputs: p_signals or d_signals' )
885
+ if d_signals is not none :
886
+ if fmt is None or gain is None or baseline is None :
887
+ sys .exit ("When using d_signals, must also specify 'fmt', 'gain', and 'baseline' fields." )
844
888
845
889
# Create the Record object
846
890
record = Record (recordname = recordname , p_signals = p_signals , fs = fs , fmt = fmt , units = units , signame = signames , comments = comments )
0 commit comments