Repository navigation
Do not apply skew twice to rewritten records - #677
Merged
Merged
Conversation
rdrecord aligns skewed signals, but the record keeps its skew field, so Record.wrsamp wrote aligned samples with a header that still gave the skew. Reading the new record shifted those signals a second time. Remember the skew applied when reading, and leave it out of the header when writing the samples. The skew attribute is not changed, a value assigned to it after reading is written, and wrheader on its own still describes the original signal files. wfdb_to_wav had the same problem with write_header=True.
tompollard
commented
Nov 24, 2026
tompollard
left a comment
Member
Author
There was a problem hiding this comment.
Reviewed commit 3612391. I found no issues. The write path suppresses skew already applied to the samples while preserving the in-memory skew value and allowing a newly assigned value to be written. All 125 offline record tests and the focused WAV header test pass. Docs and style checks pass; the test matrix is still running. Ready to merge once CI passes.
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.
rdrecordaligns skewed signals, but the record keeps itsskewfield.Record.wrsampthen wrote the aligned samples with a header that still gave the skew, so reading the new record shifted those signals a second time, with no error:This is the first step towards a reliable read and write round trip (#484, #500). Of the 75 single-segment records in
sample-data, the 4 with skew were written incorrectly. All 4 now read back with the same samples.The record now remembers the skew applied when it was read, and
Record.wrsampleaves it out of the header.record.skewdoes not change, so code that reads it afterrdrecordis not affected.record.skewafter reading is written to the header.ignore_skew=Trueare still written with their skew, and their signal files are byte-identical to the originals.wrheaderon its own still writes the skew, since that header may describe the original signal files.Record.__eq__.wfdb_to_wavwithwrite_header=Truehad the same problem, and now writes no skew.Testing:
TestWriteAppliedSkew, covering full and partial reads, channel selection, physical and digital reads,ignore_skew, an assigned skew,wrheader, equality and multi-segment records, andtest_write_header_skewforwfdb_to_wav. The tests for the bug fail onmain.uv run pytest -m "not network" -W error(582 passed), the network tests intests/test_record.py(14 passed),ruff format --check,ruff checkand the docs build with-Wpass. Changelog entry added inchangelog.d/.Refs #484, #500
@tompollard 🟥 red 🐳 whale · quince