Skip to content

Commit

Permalink
Add a test case for all WFDB binary signal formats.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Benjamin Moody committed Sep 24, 2021
1 parent 89ca194 commit d16dd96
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 0 deletions.
Binary file added sample-data/binformats.d0
Binary file not shown.
Binary file added sample-data/binformats.d1
Binary file not shown.
Binary file added sample-data/binformats.d2
Binary file not shown.
3 changes: 3 additions & 0 deletions sample-data/binformats.d3
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
 .<JXft���������+9GUcq��������� (6DR`n|��������� %3AO]ky���������"0>LZhv���������-;IWes����������*8FTbp~��������� '5CQ_m{���������$2@N\jx���������!/=KYgu���������,:HVdr����������)7ESao}���������
&4BP^lz���������#1?M[iw��������� .<JXft���������+9GUcq��������� (6DR`n|��������� %3AO]ky���������"0>LZhv���������-;IWes����������*8FTbp~��������� '5CQ_m{���������$2@N\jx���������!/=KYgu���������,:HVdr����������)7ESao}���������
&4BP^lz���������#1?M[
Expand Down
Binary file added sample-data/binformats.d4
Binary file not shown.
Binary file added sample-data/binformats.d5
Binary file not shown.
Binary file added sample-data/binformats.d6
Binary file not shown.
Binary file added sample-data/binformats.d7
Binary file not shown.
Binary file added sample-data/binformats.d8
Binary file not shown.
Binary file added sample-data/binformats.d9
Binary file not shown.
11 changes: 11 additions & 0 deletions sample-data/binformats.hea
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
binformats 10 200 499
binformats.d0 8 200/mV 12 0 -2047 -31143 0 sig 0, fmt 8
binformats.d1 16 200/mV 16 0 -32766 -750 0 sig 1, fmt 16
binformats.d2 61 200/mV 16 0 -32765 -251 0 sig 2, fmt 61
binformats.d3 80 200/mV 8 0 -124 -517 0 sig 3, fmt 80
binformats.d4 160 200/mV 16 0 -32763 747 0 sig 4, fmt 160
binformats.d5 212 200/mV 12 0 -2042 -6824 0 sig 5, fmt 212
binformats.d6 310 200/mV 10 0 -505 -1621 0 sig 6, fmt 310
binformats.d7 311 200/mV 10 0 -504 -2145 0 sig 7, fmt 311
binformats.d8 24 200/mV 24 0 -8388599 11715 0 sig 8, fmt 24
binformats.d9 32 200/mV 32 0 -2147483638 19035 0 sig 9, fmt 32
Binary file added tests/target-output/record-1f.gz
Binary file not shown.
29 changes: 29 additions & 0 deletions tests/test_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,35 @@ def test_1e(self):
assert record.__eq__(record_pn)
assert record_2.__eq__(record_write)

def test_1f(self):
"""
All binary formats, multiple signal files in one record.
Target file created with:
rdsamp -r sample-data/binformats | cut -f 2- |
gzip -9 -n > record-1f.gz
"""
record = wfdb.rdrecord('sample-data/binformats', physical=False)
sig_target = np.genfromtxt('tests/target-output/record-1f.gz')

for n, name in enumerate(record.sig_name):
np.testing.assert_array_equal(
record.d_signal[:, n],
sig_target[:, n],
"Mismatch in %s" % name)

for sampfrom in range(0, 3):
for sampto in range(record.sig_len - 3, record.sig_len):
record_2 = wfdb.rdrecord('sample-data/binformats',
physical=False,
sampfrom=sampfrom, sampto=sampto)
for n, name in enumerate(record.sig_name):
if record.fmt[n] != '8':
np.testing.assert_array_equal(
record_2.d_signal[:, n],
sig_target[sampfrom:sampto, n],
"Mismatch in %s" % name)

# ------------------ 2. Special format records ------------------ #

def test_2a(self):
Expand Down

0 comments on commit d16dd96

Please sign in to comment.