wfdb-python icon indicating copy to clipboard operation
wfdb-python copied to clipboard

[Draft]: Add new record

Open cx1111 opened this issue 2 years ago • 1 comments

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 the RecordInfo object. (Composition vs inheritance, so no more mixins.)
  • The Record object should contain a SignalHandler object or something similar. This class/object will be responsible for reading/writing the signal data from/to the files. The Record object will contain methods which call the underlying SignalHander object.

cx1111 avatar Jun 07 '22 21:06 cx1111

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?

cx1111 avatar Jun 10 '22 17:06 cx1111