Repository navigation
Accept RecordData in write_record - #917
Merged
Merged
Conversation
tompollard
added a commit
that referenced
this pull request
Dec 4, 2026
## Summary - Add `RecordData.with_calibration(adc_gain=..., baseline=..., mode=...)` for digital reads. - `mode="reinterpret"` keeps the stored integers and changes their physical interpretation. `mode="rescale"` adjusts the integers to preserve physical values as closely as the new calibration permits. - Require one gain and baseline per loaded channel. Reject missing current calibration for rescaling, invalid gains or baselines, reserved marker collisions, values outside known target formats, and values that would widen the loaded integer dtype when the edit is made. - Copy values and masks, retain source provenance, and clear sample-dependent declarations after rescaling. Physical reads direct callers to write options instead. This is based on main after #917 merged. The physical write-option change is in the stacked #919 PR. ## Rounding detail The existing ADC implementation uses NumPy rounding, so exact halves go to the even integer. This PR uses that same rule. The proposed “half up” wording does not match the current code. WFDB's existing writer requires positive gains, so this edit uses positive finite gains rather than allowing negative ones. ## Verification - 2,279 offline tests passed; 4 skipped and 23 network tests deselected. - Ruff check and format passed; Sphinx docs built with warnings treated as errors. - New tests cover masked and expanded values, both calibration meanings, round-trip writes, format limits, unknown source gain, input validation, and a 5.17.0 pickle.
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.
Summary
RecordDatainwrite_record(path, data)by using the same write path asdata.write(path).signal_alignmentandformatsoptions. Keepkindandlayoutfor mutableRecordonly.Recordwrite path is unchanged.This enables the planned 6.0
read_record/write_recordpair without changing whatread_recordreturns in 5.x.Verification