wfdb-python
wfdb-python copied to clipboard
[Draft]: Add new record
New record class addressing #376, #371.
def read_header(record_name: str) -> RecordInfo:
"""
Reads a header file, and returns a RecordInfo object containing the
metadata fields
"""
# ...Bunch of header parsing logic
return info
def open_record(record_name: str) -> Record:
"""
Returns a Record object containing the info read from the header file.
This can be used to read/write the signals belonging to the record.
"""
info = read_header(record_name=record_name)
record = Record(info=info)
return record
def read_record_data(record_name: str, samp_from: int, samp_to: int):
"""
The new rdsamp. No streaming. That would be too complicated.
"""
record = open_record(record_name) # Does NOT read the signals.
signals = record.read(samp_from=samp_from, samp_to=samp_to)
return record.info, signals
Workflow:
- Read the .hea file to get a
RecordInfo
object. - Create a
Record
object, and attach theRecordInfo
object. (Composition vs inheritance, so no more mixins.) - The
Record
object should contain aSignalHandler
object or something similar. This class/object will be responsible for reading/writing the signal data from/to the files. TheRecord
object will contain methods which call the underlyingSignalHander
object.
I considered having an individual SignalHandler
or Signal
class for each channel. But I think having one object represent all the channels makes more sense, especially regarding reading/writing multiplexed signal files, ie. a single dat file containing interleaved samples of multiple channels.
It would probably be more difficult to coordinate the logic across a collection of objects. For example, if two signals share the same file, which object(s) should contain the file handler?