Repository navigation
Make flattened multi-segment records writable - #728
Conversation
tompollard
left a comment
There was a problem hiding this comment.
This fixes #727: every flattened record I wrote read back correctly. Two changes I'd suggest before merging: avoid modifying the caller's record, and detect flattened records explicitly.
Checked:
- Round trips: 99 random windows across
p000878-2137-10-26-16-57,s25047-2704-05-04-10-44,v102sand041s, with physical and digital reads, and with smoothed and expanded frames. Each was written withwrsampand read back, and all matched: physical values within half a digital unit, digital values exactly (with missing markers mapped to the format 32 marker). - The WFDB C tools:
rdsamp -p(10.7.0) reads a writtenp000878window, showing missing samples as-. - Tests:
pytest -m "not network"(756 passed) and ruff pass.
Suggestions:
wrsampchanges the caller's record. After writing a digitalp000878window (sampfrom=3700, sampto=3800), these fields had changed in memory:d_signal,fmt,adc_gain,baseline,units,adc_res,adc_zero,init_value,checksumandblock_size. For example,fmtwent from['80', None, None, None]to['32', '32', '32', '32'], and the missing samples ind_signalwent from-128to-2147483648. Code that keeps using the record afterwards, such asdac()or a comparison with another read, would then see different data from whatrdrecordreturned. Preparing and writing a copy would leave the caller's record unchanged.- Detect flattened records explicitly.
getattr(self, "layout", None) in ("fixed", "variable")depends onmulti_to_singleleaving the multi-segmentlayoutattribute on the flattenedRecord. Once #726 merges,self.source_segments is not Nonewould mark these records explicitly.
Minor: the docstring or changelog could mention that a channel with no samples in the window is written with gain 1 and baseline -2147483648 in format 32. The PR description notes that format 32 can make the output larger than the source, and that would be useful in the user-facing docs too.
473405e to
9dec71b
Compare
|
Thanks for the thorough review. I rebased on
One clarification on the suggested exact baseline: it is not always Validation: 41 multi-record tests, 762 offline tests, Ruff, and the strict Sphinx build pass. |
Summary
RecordwhenRecord.wrsampis called, leaving the caller's object unchanged. Usesource_segmentsto detect records flattened from aMultiRecord.NU.Callers should assign a new
record_nameandfile_namebefore writing a copy, as shown in the issue. Format 32 can make the output larger than the source.Fixes #727.
Validation
pytest tests/test_multi_record.py -q— 41 passedpytest -m 'not network' -q— 762 passed, 4 skipped, 21 deselected-W --keep-going— passed