Repository navigation
Capture channel metadata once for record writes - #838
Conversation
tompollard
left a comment
There was a problem hiding this comment.
Thanks. Output is unchanged: write_record and SignalRead.write produce byte-identical .hea and .dat files to main for uniform and expanded, digital and physical writes of drive02-no-len (multiple samples per frame). A record read with skew writes the same header as before, and MultiRecord.wrsamp and header-only records behave as on main. The samps_per_frame=[None, 2] expanded write now works. The offline suite, Ruff and the strict docs build pass locally.
Two things I'd change:
- Two snapshot builders.
_header._capture_signal_write_snapshotand the end ofrecord._snapshot_record_write_channelsbuild the same_ParsedSignalLinetuple; only the rule for which fields count as present differs. Could the record helper pass itspresent_fieldsto the_headerone, so there's a single place that builds the per-channel view? - Test.
assert "_write_snapshot" not in vars(source)can't fail, since nothing sets that attribute. The middle of the same test drives the private helpers with an edit between capture and preparation, which no public writer can do; the publicsource.write(path)part seems enough.
A side effect worth noting: write_record now accepts per-channel fields given as a NumPy array or tuple (adc_gain=np.array(...) fails on main with "Field adc_gain must be a list"), because the private copy is projected to lists. That's an improvement, but it could go in the changelog with a test so it doesn't regress unnoticed.
|
Thanks, I addressed all three points in 4498018.
The full offline suite passes (1,608 passed, 4 skipped), as do Ruff and the strict docs build. |
tompollard
left a comment
There was a problem hiding this comment.
Thanks, 4498018 covers all three: both write paths now build the per-channel view with _capture_signal_write_snapshot, the test checks two public writes after in-place edits, and NumPy array and tuple fields have a round-trip test and a changelog line. A NumPy gain with an int32 baseline writes a normal header, and SignalRead.write still works. The offline suite, Ruff and the strict docs build pass locally.
Ready to merge once CI is green.
Summary
This starts the write-side work in #749.
write_record()now validates and captures the selected record's per-channel fields once, then projects that captured view onto its private writable copy. The header and data writers use the same checked channel values for file names, formats, offsets, and samples per frame.The snapshot is temporary and is never attached to
Record. In-place edits to legacy field lists remain visible to the next write, while existing equality and serialization behavior remain unchanged.SignalRead.write()uses the same preparation path.Expanded writes now treat an omitted per-channel
samps_per_framevalue as one throughout the write. Previously, validation accepted that default but conversion could fail before writing.Scope
Refs #749. This PR covers the write boundary. The parser's projection into mutable
Recordfields, annotation internals, and structural equality questions in #749 remain separate work.Verification