Repository navigation
Fix wfdb_to_mat encoding, slicing, and header metadata - #633
Open
goktugozkanmd wants to merge 1 commit into
Open
goktugozkanmd wants to merge 1 commit into
goktugozkanmd wants to merge 1 commit into
Conversation
Co-authored-by: OpenBot <335604065+openbotgit[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes several crashes and data-corruption bugs in
wfdb_to_mat(src/wfdb/io/convert/matlab.py), which previously had no unit tests:channels):channelswas not forwarded tordrecord(), so all channels were written to.matwhilerecord.n_sigwas overwritten tolen(channels), causingrecord.wrheader()to raiseValueError.sampfromwithoutsampto):desired_length = sampto - sampfromsubtractedsampfroma second time afterrdrecord()had already sliced the signal, corrupting the declared matrix dimensions or raisingstruct.errorwhensampfrom > sig_len / 2.80) and 24/32-bit (24/32) binary encoding & MAT v5 padding: signal samples were always packed withstruct.pack("<%sh", ...)regardless ofbytes_per_element, corrupting format80files (TypeErrorinscipy.io.loadmat, missing the+128offset-binary shift) and crashing on 32-bit values outsideint16range. Trailing 8-byte MAT v5 alignment padding (bytes_remain) was also accounted for inmaster_bytesbut never written.physical=False(d_signal) avoids float round-trip errors andNaN-cast warnings; missing/invalid samples (_digi_nan) are mapped to the target format's sentinel instead of overflowing when subtractingadc_zero(e.g.,sample-data/mixedsignals). Unset (None)adc_res,adc_zero,baseline,units, andsig_namefields (e.g.,sample-data/n8_evoked_raw_95_F1_R9) no longer raiseTypeError/AttributeError..heaaccuracy & cross-platform paths: clears already-appliedskew, setsblock_sizeto0, setsinit_valuefrom signed decoded samples, recomputeschecksumfor the written output, and usesos.path.basename(os.fspath(record_name))so forward-slash paths work on Windows as well as POSIX.Changes
src/wfdb/io/convert/matlab.py: fix reading, binary serialization, padding, missing-sample preservation, and companion header metadata inwfdb_to_mat.tests/io/test_convert.py: addTestWfdbToMatcovering 16-bit padding and round-trip,channels+sampfromslicing, 8-bit (format 80) offset-binary output, 24/32-bit records with unset header fields, missing-sample preservation and skew handling, and forward-slash paths (verified with bothscipy.io.loadmatandwfdb.rdrecord).changelog.d/wfdb-to-mat-fixes.rst: add towncrier changelog fragment.Verification
uv run ruff format --check --diff .— passeduv run ruff check .— passeduv run towncrier build --draft— passeduv run pytest tests/io/test_convert.py -v— 22 passeduv run pytest -n auto -q -k "not url and not pn_dir"— 360 passed, 4 skipped (2 POSIX permissions, 2 remote PhysioNet 502)