Skip to content

Commit 0ff4f84

Browse files
author
Benjamin Moody
committed
Add a test case for all WFDB FLAC signal formats.
The record "flacformats" contains one signal in each of the three WFDB FLAC signal formats. As with the "binformats" record, sample j of signal i is equal to: (i + 16843019 * j) % ((1 << adcres) - 1) + 1 - (1 << (adcres - 1))) 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.
1 parent 9d3491c commit 0ff4f84

File tree

6 files changed

+35
-0
lines changed

6 files changed

+35
-0
lines changed

sample-data/flacformats.d0

524 Bytes
Binary file not shown.

sample-data/flacformats.d1

881 Bytes
Binary file not shown.

sample-data/flacformats.d2

1.26 KB
Binary file not shown.

sample-data/flacformats.hea

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
flacformats 3 200 499
2+
flacformats.d0 508 200/mV 8 0 -127 -484 0 sig 0, fmt 508
3+
flacformats.d1 516 200/mV 16 0 -32766 -750 0 sig 1, fmt 516
4+
flacformats.d2 524 200/mV 24 0 -8388605 8721 0 sig 2, fmt 524

tests/target-output/record-flac.gz

4.91 KB
Binary file not shown.

tests/test_record.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,37 @@ def test_1f(self):
218218
"Mismatch in %s" % name,
219219
)
220220

221+
def test_read_flac(self):
222+
"""
223+
All FLAC formats, multiple signal files in one record.
224+
225+
Target file created with:
226+
rdsamp -r sample-data/flacformats | cut -f 2- |
227+
gzip -9 -n > record-flac.gz
228+
"""
229+
record = wfdb.rdrecord("sample-data/flacformats", physical=False)
230+
sig_target = np.genfromtxt("tests/target-output/record-flac.gz")
231+
232+
for n, name in enumerate(record.sig_name):
233+
np.testing.assert_array_equal(
234+
record.d_signal[:, n], sig_target[:, n], f"Mismatch in {name}"
235+
)
236+
237+
for sampfrom in range(0, 3):
238+
for sampto in range(record.sig_len - 3, record.sig_len):
239+
record_2 = wfdb.rdrecord(
240+
"sample-data/flacformats",
241+
physical=False,
242+
sampfrom=sampfrom,
243+
sampto=sampto,
244+
)
245+
for n, name in enumerate(record.sig_name):
246+
np.testing.assert_array_equal(
247+
record_2.d_signal[:, n],
248+
sig_target[sampfrom:sampto, n],
249+
f"Mismatch in {name}",
250+
)
251+
221252
# ------------------ 2. Special format records ------------------ #
222253

223254
def test_2a(self):

0 commit comments

Comments
 (0)