Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reading formats 8, 310, and 311 #327

Merged
merged 8 commits into from
Oct 14, 2021
Merged

Fix reading formats 8, 310, and 311 #327

merged 8 commits into from
Oct 14, 2021

Commits on Sep 24, 2021

  1. Add .gitattributes file.

    Mark Python source files as "diff=python" to show the correct function
    names, and mark various types of binary files as binary to avoid
    attempting to diff/merge them.
    Benjamin Moody committed Sep 24, 2021
    Configuration menu
    Copy the full SHA
    f6e5179 View commit details
    Browse the repository at this point in the history
  2. _rd_segment: reformat for readability/maintainability.

    In each branch, the calls to _rd_dat_signals with and without
    'no_file=True, sig_data=sig_data' were otherwise identical.  sig_data
    is ignored if no_file is false, so this is equivalent to simply
    passing 'no_file=no_file, sig_data=sig_data'.
    
    Furthermore, since _rd_dat_signals takes a huge number of arguments,
    convert all of them to keyword style to avoid confusion.
    Benjamin Moody committed Sep 24, 2021
    Configuration menu
    Copy the full SHA
    f2b8ab6 View commit details
    Browse the repository at this point in the history
  3. rdrecord: reformat for readability/maintainability.

    All four of the calls to _rd_segment were identical apart from the
    'no_file' and 'sig_data' arguments.  Rearrange the code so there is
    only one call to _rd_segment, to avoid redundancy.
    
    Furthermore, since _rd_segment takes a huge number of arguments,
    convert all of them to keyword style to avoid confusion.
    Benjamin Moody committed Sep 24, 2021
    Configuration menu
    Copy the full SHA
    d2406cf View commit details
    Browse the repository at this point in the history
  4. _rd_segment: add init_value argument.

    This should be a list containing the initial sample value for each
    signal; this is required in order to correctly read format-8 dat
    files.
    Benjamin Moody committed Sep 24, 2021
    Configuration menu
    Copy the full SHA
    4d18c53 View commit details
    Browse the repository at this point in the history
  5. _rd_dat_signals: add init_value argument.

    This should be a list containing the initial sample value for each
    signal; this is required in order to correctly read format-8 dat
    files.
    Benjamin Moody committed Sep 24, 2021
    Configuration menu
    Copy the full SHA
    ce1834d View commit details
    Browse the repository at this point in the history
  6. _rd_dat_signals: fix conversion of format 8.

    In signal format 8, each sample is stored as an 8-bit signed
    difference from the previous sample.  This means that after reading
    the raw byte values, they must be translated to absolute sample values
    by calling cumsum() and adding the initial value.
    Benjamin Moody committed Sep 24, 2021
    Configuration menu
    Copy the full SHA
    6bede91 View commit details
    Browse the repository at this point in the history
  7. _blocks_to_samples: handle partial blocks in formats 310/311.

    In formats 310 and 311, each block of three samples is written as four
    bytes.  _rd_dat_signals will retrieve the minimum range of bytes (as
    determined by _dat_read_params and _required_byte_num) that are needed
    in order to decode the desired samples; thus, the data passed to
    _blocks_to_samples may include an incomplete block at the end.
    
    The previous implementation of _blocks_to_samples was meant to pad the
    input data to a multiple of four bytes.  However, this logic was
    wrong: added_samps was always set to zero, so the intended extra bytes
    were not appended, and (if the lack of extra bytes didn't cause an
    error) the wrong number of samples was returned to the caller.
    
    In fact, the subsequent statements for decoding blocks into samples
    already worked correctly for an unpadded input array (since each input
    slice is correctly truncated to the length of the output slice.)  So
    remove the padding logic entirely.
    Benjamin Moody committed Sep 24, 2021
    Configuration menu
    Copy the full SHA
    8b3d307 View commit details
    Browse the repository at this point in the history
  8. Add a test case for all WFDB binary signal formats.

    The record "binformats" contains one signal in each of the ten WFDB
    binary formats (8, 16, 61, 80, 160, 212, 310, 311, 24, and 32.)  In
    this record, sample j of signal i is equal to:
    
      (i + 16843019 * j) % ((1 << adcres) - 1) + 1 - (1 << (adcres - 1)))
    
    Note that the length of the record is 499 samples, so each of the
    bit-packed data files ends with an incomplete data block.
    
    Use this record to test that it is possible to read all of the formats
    correctly, including when we skip one or two samples from the start
    and/or end of the record.  (Skipping samples is expected to give
    incorrect results for format 8, so that signal is not required to
    match.)
    
    We do not test writing, since not all formats are currently supported
    by wr_dat_file.
    Benjamin Moody committed Sep 24, 2021
    Configuration menu
    Copy the full SHA
    14048dd View commit details
    Browse the repository at this point in the history