Repository navigation
Preserve uncalibrated gains in modern metadata - #944
tompollard wants to merge 1 commit into
Conversation
tompollard
left a comment
There was a problem hiding this comment.
The behaviour matches the scope agreed on #937. Apart from the specification pin (see #943), this can merge. I have one small point about combined reads, and found an older bug while testing.
What I checked
- On the specification's records, the modern
read_headergives(None, 12)forsigdefaults, and(None, 12), (50.0, 12), (50.0, 12), (50.0, 8)forpartial. Legacyrdheaderis unchanged:(200.0, None)and(200.0, None), (50.0, 0), (50.0, None), (50.0, 8). - Physical values of the uncalibrated signal still use a gain of 200.
- Writing the uncalibrated digital read gives
16 0.0(0)/mV …, and it reads back as uncalibrated. - Against
main(0c1a867), no signal values change, and the legacyRecordvalues are the same. The other differences are in metadata, as intended:- combined multi-segment metadata reports
adc_res=12instead ofNone; - source headers with
adc_res=0report 12; - the private parsed header gains an
uncalibratedfield.
- combined multi-segment metadata reports
Point: "uncalibrated" and "segments disagree" are treated the same when writing
A combined variable-layout read has adc_gain=None when its segments have different gains. That isn't the same as an uncalibrated source. Writing such a read (s25047-2704-05-04-10-44, frames 0–5000, physical) now writes 0.0(1)/NU, where main wrote 1(1)/NU. In every window where I could test this, the values were all missing, so no data changes. Even so, it would be clearer to write a zero gain only when the source signal is actually uncalibrated, which is what the new parser flag records.
Already on main, for a separate issue
Physically writing a combined variable-layout read whose segments have different gains fails on both main and this branch, whenever the window contains values. Examples are s25047, frames 25000–55000, and s00001-2896-10-10-00-31, frames 2225802–2225810. The error is "adc_gain and baseline must be provided together": the combined metadata has no gain but keeps a baseline.
235590c to
40dd5ca
Compare
|
Thanks for catching the distinction between an uncalibrated source and a combined result whose segments disagree. I fixed it in the updated #944 branch: the writer now uses the parsed source's The separate physical-write failure is tracked in #946. This PR remains focused on #937. The stacked tip passes the pinned spec tests, Ruff, the warnings-as-errors docs build, and the parallel offline suite (2,507 passed, 4 skipped). The spec pin will move to a reachable |
Fixes #937. This PR is based on #943; #945 is based on this PR. Its matching spec adapter is wfdb-spec #35, which checks these fields through modern
read_headerrather than the intentionally unchanged legacyrdheader. After the adapter merges, I will pin a commit reachable from specmain.Behavior differences from 6.1.0
read_header,RecordData.metadata, andSegmentedRecordData.metadata.channelsreportadc_gain=Nonewhen a source signal's gain is omitted or zero. Their source-header views reflect the same distinction. Previously modern views reported 200.Noneand an explicit zero remained zero.RecordDatanow writes zero gain rather than 200, so a read of the result remains uncalibrated. An explicit physical write calibration overrides this behavior. A combined record whose segments disagree on gain is not treated as uncalibrated and retains its prior write behavior.Physical conversion still uses an effective gain of 200.
Record,MultiRecord,rdheader,rdrecord, andrdsampkeep their existing gain and ADC-resolution values. The private parser records whether the source gain was uncalibrated while retaining the legacy effective gain. The separate pre-existing physical-write failure is tracked in #946.The
header-partial-signal-fieldsandheader-signal-defaultsknown gaps are removed. Verification on the stacked tip: pinned WFDB spec suite (35 passed), parallel offline suite (2,507 passed, 4 skipped), Ruff, and the warnings-as-errors Sphinx docs build.