A fast, lightweight implementation of the WFDB library and command-line tools, with identical behavior across seven programming languages
The versions of WFDB-x, shared by its seven implementations (Python, C++, MATLAB/Octave, Rust, Julia, R and Kotlin). WFDB-x follows semantic versioning: a new patch number (1.1.x) for corrections only, a new minor number (1.x.0) for new features that do not change existing behavior, and a new major number (x.0.0) for changes that can break existing code. Every version implements version 10.7.0 of the WFDB Software Package.
Corrections reported by users, in all seven languages. The C-style functions and the command-line tools are unchanged.
write_record checks that every sample fits the storage format,
before any file is written: a sample outside the range of the format
(“signal 0 has a sample (40000) outside the range of format 16 (-32768 to
32767)”), in format 8 a sample more than 127 away from the one before it
or an invalid sample (format 8 stores differences, and has no invalid
value), and more than 8 signals in a FLAC format (a FLAC file holds at
most 8) are argument errors. Such samples were silently wrapped around
(40000 read back as -25536) or clipped, and the FLAC limit was reported
only as “can’t create signal file”, after the library’s own message.write_record warns when
samples are equal to it, or to WFDB_INVALID_SAMPLE (“1 sample(s) of
signal 0 will be read back as invalid (missing) samples (format 16 stores
an invalid sample as -32768)”), except for the NaN samples of physical
units, which mark missing samples deliberately. The new option
invalid_warning (false: no warning) is for records whose invalid
samples are deliberate.wfdbx.apps.rdsamp.main, for
example) failed with a TypeError when sys.stdout was a text stream
without a binary buffer, such as an io.StringIO installed by
contextlib.redirect_stdout; its output is now written to it as Latin-1
text. In R, the output of a tool run with wfdbx_tool went to the
process’s standard output, past sink() and capture.output(); it now
goes to the sink. (Julia’s redirect_stdout and MATLAB/Octave’s evalc
already captured it; the C++, Rust and Kotlin tools are separate
programs.)docs/TODO.md lists the features
requested with these reports: writing MATLAB files from a program, gains
at full precision, the smallest lossless format (fmt="auto"), and FLAC
records of more than 8 signals.Corrections from the fourth review of version 1.2.1, two corrections of
remote files, and three found by a review of the user’s manual, in all seven
languages. The C-style functions and the command-line tools keep the
behavior of C, except for getinfo, the URL schemes and time2sec without
a sampling frequency (below).
read_record (can't
read signal data of record REC (getvec status -3)) even when the
checksum of a signal is verified at the incomplete frame: getvec
returns the checksum status (-4) for that frame, which replaced the end of
file (-3), so read_record returned the incomplete frame as data (a
format-16 file holding the samples 1 and 2, whose header gives 3 samples,
was read as 1, 2, 257, with a checksum warning). The high-level readers
now track a read failure separately from the checksum, and never return
an incomplete frame; check_record reports such a file as shorter than
its header says, without a checksum error for the incomplete frame. A
checksum error alone is still a warning.read_record allocates no more than it can read. The result was
allocated from the length that the header gives (a header giving 10^12
samples for a file of 4 bytes attempted to allocate 3.64 TiB); at most
2^26 samples are now allocated in advance, and the array grows as the
samples are read.write_record refuses, before
any file is opened, arrays that are not 1-D or 2-D, baselines, ADC zeros
and ADC resolutions that are not whole numbers within the range of a
32-bit integer (a fraction was truncated, NaN failed after the signal
file was written), and a record name, signal names, units or comments
that cannot be written as header text (a character that is not
Latin-1 in Python: units="μV" left the existing header empty).
write_annotations refuses arrays of times that are not 1-D (a 2-D
array truncated the existing file), the annotation codes 59 to 63 (the
control codes SKIP, NUM, SUB, CHN and AUX of the MIT format,
which corrupted the file) and any code outside 0 to 58, and the times
-2^63 and 2^63 - 1, which putann refuses (“time overflow”): they were
dropped, and success reported. An error that putann reports is now an
error of write_annotations. Both writers write their files to
temporary files in the destination directory, renamed over the
destinations when all of them are complete, and removed after a failure;
the files written are unchanged, byte for byte.read_annotations checks sampfrom and sampto as read_record
does (whole numbers, sampfrom not negative; a fraction, NaN or an
infinite value is an error, before the file is opened), and closes the
annotation file whatever happens.getinfo took the first line
that does not begin with # for the record line, while the header
parser (readheader) takes the first line that holds a token not
beginning with #; for a header whose first line is empty or blank, the
comments before the record line were returned as info strings (in
comments and in the notes of wfdbdesc). getinfo now finds the
record line as readheader does, except in legacy mode, a deliberate
divergence from the C package (tests/reference/divergences.patch;
docs/DIVERGENCES.md). The metadata functions
follow the same rule in every mode. Four new cases of the conformance
suite and three of the legacy suite (now 886), and seven new cases of
the metadata tests (now 56), check it; tests/metadata/check_c.py
checks the headers with the C reference of WFDB-x, or, with
--original, with the unmodified package.http:// and https:// URLs. A name that begins with another
URL scheme (ftp://, sftp://, file://, …) was opened as a local
path (ftp://h/db/100 as the directory ftp:, then h/db/100), so that
a local directory named ftp: could be read in place of the server. Such
a name is now refused in normal mode, with or without network access,
with the message WFDB-x: can't open NAME: only http:// and https:// URLs
can be read (mount the server as a local folder, or download the files);
so too an input directory, a file named in a header, the files that a
tool reads or creates itself, and an output directory with such a scheme.
A one-letter prefix (c://x, like a drive letter) is not a scheme. FTP
and SFTP are not supported; a server reached by them can be mounted as a
local folder (sshfs, rclone mount). Legacy mode is unchanged (every
name containing :// is refused, as by the original library built
without network support). 13 new cases of the conformance suite check
both corrections.time2sec -r needs the sampling frequency of the record. For a
record whose header gives no sampling frequency, time2sec -r REC TIME
divided by 0 and printed -9223372036854775808 with the exit status 0;
it now exits with status 2 (time2sec: sampling frequency of record REC
is not specified), as do the other tools that need the frequency (also
when the header cannot be read). A deliberate divergence from the C tool,
which converted the time at its default of 250 Hz, a result unrelated to
the record, since WFDB-x assumes no frequency that a record does not give
(docs/DIVERGENCES.md); legacy mode keeps the C
behavior. Three new cases of the conformance suite (now 1155) check it.write_annotations requires a label for each annotation, in every
language: with one annotation or more and neither symbols nor codes, it
is an argument error (“symbols or codes must be given”; in R, whose
arguments are symbol and code, “symbol or code must be given”),
before any file is touched. C++, Rust and Julia wrote such annotations
with the code 0, which is not an annotation code; Python, R and Kotlin
refused even an empty list of annotations, which now writes an empty
file.write_record removes a trailing .hea from the record name, as the
readers do: write_record("x.hea", ...) writes x.hea and x.dat.
Python failed (“can’t create signal file for record x.hea”), and the
other languages named the signal file x.hea.dat.CITATION.cff and the package metadata (Python, Rust, C++, R, Kotlin)
give it.NOTICE file at the root of the repository says
which parts are under which license (the tools under the GPL, version 3
or later; everything else under the LGPL, version 2.1 or later), and
gives the copyright notice and license (BSD-3-Clause) of libFLAC 1.4.3,
whose stream decoder WFDB-x translates. It ships, with LICENSE and
LICENSE-GPL, in every package: the Python wheel and source
distribution, the R package (inst/NOTICE), the C++ installation
(share/doc/wfdbx), the Rust crate, the Julia and MATLAB/Octave
directories, and the META-INF of every Kotlin jar. The license
expressions of the Python, Rust and Kotlin packages and of
CITATION.cff add BSD-3-Clause for the translated decoder.wfdbxConfigVersion.cmake,
so find_package(wfdbx 1.2.2 CONFIG REQUIRED) works; the wfdbx target
requires C++17 of the programs that link it
(target_compile_features); the tests that run the tools find them in
the build directory of multi-configuration generators (Visual Studio,
Ninja Multi-Config).License: file LICENSE
instead of GPL (>= 3): its new file LICENSE states which parts are
under the LGPL (the library) and which under the GPL (the tools). In
MATLAB/Octave, the dispatcher of the wfdbx command
(+wfdbx/+internal/cli_main.m, app_run.m), which only the tools use,
is under the GPL, as the launchers of the other languages are.curl) called its argument-quoting function by a former name.LICENSE), so that
programs under any license, proprietary ones included, may use it on the
LGPL’s terms; it follows the license of the original C library (the GNU
Library General Public License, version 2 or later). The command-line
tools (each language’s apps and the wfdbx command), translations of
the original tools (GPL version 2 or later), stay under the GNU General
Public License, version 3 or later (LICENSE-GPL). Each
source file states its license; the package metadata (Cargo, Python, Maven,
R, CITATION) says so.New features, in all seven languages:
read_metadata, get_metadata, set_metadata,
remove_metadata and update_metadata (readMetadata, … in Kotlin)
read and change the Key: value info strings of a header, such as
# Age: 63, without changing anything else in it. read_header
returns them (metadata), and write_record writes them (its metadata
argument). The rules are in docs/DIVERGENCES.md
(Additions) and tests/metadata/README.md;
the seven implementations pass the same 49 cases and write
byte-identical headers, which the original C programs read as before.docs/user-manual/wfdb-x-user-manual.pdf,
built from the LaTeX sources in docs/user-manual/:
a complete manual, for the users of each language, with every function of
the high-level API, the C-style library functions and the command-line
tools.CITATION.cff.Also in this version: the corrections from the second and third reviews of
version 1.1.0 (listed in docs/DIVERGENCES.md and
docs/KNOWN_C_BEHAVIORS.md), and benchmarks that compare WFDB-x with the
original C library and tools (docs/BENCHMARKS.md).
No existing function or tool changes behavior, except for the corrections
below.
Corrections:
-i file of wrsamp, edf2mit, wav2mit,
a2m and ad2m, the input files of ahaecg2mit and the -S script of
xform are read from the input directory (WFDBX_INPUT_DIR), and the
WAV file of mit2wav, the EDF file of mit2edf, the master header of
snip -m and the .des, .ecg, .key and .txt files of parsescp
are created in the output directory (WFDBX_OUTPUT_DIR), as the files of
the library are; wfdbdesc measures a signal file of unknown length in
the header’s directory. They were opened relative to the current
directory: with WFDBX_OUTPUT_DIR set, mit2wav left a header-only WAV
file in the current directory and a WAV file without its header in the
output directory. In legacy mode, input files are opened as named, and
the output directory is a prefix of every output name. New library
functions: wfdbx_input_path and wfdbx_output_path. 43 new
conformance cases (37 in the suite, 6 in the legacy suite).osigopen(record, NULL, 0) returns 0 in every language (Python
raised IndexError; the C function reads out of bounds).read_header("100s.edf") (or any
high-level function that opens an EDF record), a later
write_annotations in the same process no longer records the EDF
record’s frequency (360 Hz) as the time resolution of its file, and the
getvec mode (getgvmode) no longer stays in high resolution; the C-style
functions keep the behavior of C.docs/BENCHMARKS.md).