You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Group per-channel header fields into coherent signal metadata #744
Record stores per-channel header fields in parallel lists: sig_name, file_name, fmt, units, samps_per_frame, adc_gain, baseline, and others. Their entries must remain aligned with each other, the signal array columns, and n_sig as records are selected, edited, and written.
Decisions to make
Should logical signal metadata and signal-file layout/encoding metadata be separate objects? Which fields belong to each?
How should the model represent several signals sharing a file, and variable-layout multi-segment records?
Should counts and name lists be derived from channel entries? How would legacy in-place edits such as record.sig_name[0] = "ECG" remain compatible?
Should omitted header defaults, such as one sample per frame, be normalized to explicit values when read? When should type checks and cross-field validation happen?
One concrete case to include when deciding whether counts should be derived: after read_record("sample-data/100", stop=4), assigning record.n_sig = 5 makes record.metadata.n_signals report 5, but record.write(...) writes a two-channel header. Conversely, slicing record.p_signal down to one column leaves both counts at 2, and record.write(...) fails with a NumPy broadcasting error. I reproduced both cases while reviewing #802.
I removed the proposed writable n_signals alias from #802 so the new name does not inherit this ambiguity. A future count API should decide which value is authoritative when several signal arrays are loaded, and make Record.metadata and writing behave consistently with that decision. This fits the count and cross-field validation questions already tracked here.
One remaining writer case for this issue: Record.wrsamp() still raises NumPy's non-broadcastable output operand error after a loaded two-channel p_signal is sliced to one column without updating the per-channel fields. I reproduced it with read_record("sample-data/100", stop=4). PR #803 improves validation and diagnostics for write_record() and Record.write(); the legacy writer's validation path still needs a separate compatibility review.
We have settled the count contract for this part of the work. n_sig is the mutable, declared channel count for the current record view. In #805, n_signals is an alias for that same stored value, and each access to Record.metadata takes a fresh snapshot of it. The count is not inferred from a loaded array: a record may be header-only or hold more than one signal form.
Edits can leave the declaration, arrays, and per-channel lists temporarily inconsistent. #803 and #804 make the single-segment writers reject those inconsistencies before writing. #805 adds a check that a MultiRecord master count agrees with its fixed-layout segments or variable-layout header. The larger question of grouping per-channel fields into a coherent metadata model remains open here.
I would group the private model's per-channel fields into one entry per selected channel, with separate logical information (name, units, calibration) and storage/encoding information (format, file, samples per frame, offsets and related header fields). The selected view and the original source header must remain distinct: a uniform read can contain one value per frame even when the source had several samples per frame, and a flattened multi-segment read can span files with different formats. Source provenance should retain the original header and segment mapping rather than make the selected channel entry pretend there was one source file.
For the modern result, derive channel count and names from those entries. For mutable Record, keep n_sig as the declared count and keep its existing parallel lists authoritative, including in-place edits. Build a fresh model/snapshot from those current fields when writing and validate mismatches before files are created; do not maintain a second mutable copy. This preserves the count contract already recorded here and the compatibility cases checked on #898.
I am deferring removal of _WriteModel's short-lived parallel lists until the private reader model is designed. Grouping the channels for readers and writers together avoids making the writer's internal layout a public design decision by accident. The proposed read-result direction is in #749. The first implementation step should be a private reader-model PR, with no public return-type change; it needs parity checks for channel selection, variable-layout segment mapping, expanded layout, skew, masks and header-only reads.
One refinement to the channel proposal: SignalRead.metadata.channels already exposes frozen ChannelMetadata entries, each with LogicalSignalMetadata and SignalStorageMetadata. The private model should use those classes directly where the meanings match, or have an explicit one-to-one projection to them. It should not introduce a third, independently maintained set of channel fields.
The distinction between the selected view and its source still matters. SignalStorageMetadata describes current declarations; the original header and per-segment file formats belong in source provenance. I would test that the private model and public metadata agree after channel selection, conversion, expanded/uniform reads, and variable-layout flattening. Record's mutable lists remain authoritative only for that compatibility view, and are converted from their current values at the write boundary.
Activity
Group parsed fields by signal line (#755)
tompollard commentedon Nov 30, 2026
One concrete case to include when deciding whether counts should be derived: after
read_record("sample-data/100", stop=4), assigningrecord.n_sig = 5makesrecord.metadata.n_signalsreport 5, butrecord.write(...)writes a two-channel header. Conversely, slicingrecord.p_signaldown to one column leaves both counts at 2, andrecord.write(...)fails with a NumPy broadcasting error. I reproduced both cases while reviewing #802.I removed the proposed writable
n_signalsalias from #802 so the new name does not inherit this ambiguity. A future count API should decide which value is authoritative when several signal arrays are loaded, and makeRecord.metadataand writing behave consistently with that decision. This fits the count and cross-field validation questions already tracked here.Add signal_names alias to Record and MultiRecord (#802)
tompollard commentedon Nov 30, 2026
One remaining writer case for this issue:
Record.wrsamp()still raises NumPy'snon-broadcastable output operanderror after a loaded two-channelp_signalis sliced to one column without updating the per-channel fields. I reproduced it withread_record("sample-data/100", stop=4). PR #803 improves validation and diagnostics forwrite_record()andRecord.write(); the legacy writer's validation path still needs a separate compatibility review.Validate record channel counts before writing (#803)
Validate selected channels before legacy record writes (#804)
tompollard commentedon Nov 30, 2026
We have settled the count contract for this part of the work.
n_sigis the mutable, declared channel count for the current record view. In #805,n_signalsis an alias for that same stored value, and each access toRecord.metadatatakes a fresh snapshot of it. The count is not inferred from a loaded array: a record may be header-only or hold more than one signal form.Edits can leave the declaration, arrays, and per-channel lists temporarily inconsistent. #803 and #804 make the single-segment writers reject those inconsistencies before writing. #805 adds a check that a
MultiRecordmaster count agrees with its fixed-layout segments or variable-layout header. The larger question of grouping per-channel fields into a coherent metadata model remains open here.Add n_signals alias for declared record channel count (#805)
Add n_frames alias for record frame count (#808)
Add samples_per_frame alias to Record (#809)
Use on-demand channel views for record selection (#840)
Separate current storage fields from logical metadata (#841)
Reject new skew when writing aligned signals (#842)
Use a channel snapshot throughout header writes (#845)
Calculate channel defaults from one snapshot (#847)
Use one channel snapshot for header and signal writes (#848)
Expose grouped current channel metadata (#850)
Remove temporary writer parity implementations (#898)
tompollard commentedon Dec 3, 2026
Proposed channel-metadata ownership after #866
I would group the private model's per-channel fields into one entry per selected channel, with separate logical information (name, units, calibration) and storage/encoding information (format, file, samples per frame, offsets and related header fields). The selected view and the original source header must remain distinct: a uniform read can contain one value per frame even when the source had several samples per frame, and a flattened multi-segment read can span files with different formats. Source provenance should retain the original header and segment mapping rather than make the selected channel entry pretend there was one source file.
For the modern result, derive channel count and names from those entries. For mutable
Record, keepn_sigas the declared count and keep its existing parallel lists authoritative, including in-place edits. Build a fresh model/snapshot from those current fields when writing and validate mismatches before files are created; do not maintain a second mutable copy. This preserves the count contract already recorded here and the compatibility cases checked on #898.I am deferring removal of
_WriteModel's short-lived parallel lists until the private reader model is designed. Grouping the channels for readers and writers together avoids making the writer's internal layout a public design decision by accident. The proposed read-result direction is in #749. The first implementation step should be a private reader-model PR, with no public return-type change; it needs parity checks for channel selection, variable-layout segment mapping, expanded layout, skew, masks and header-only reads.tompollard commentedon Dec 3, 2026
One refinement to the channel proposal:
SignalRead.metadata.channelsalready exposes frozenChannelMetadataentries, each withLogicalSignalMetadataandSignalStorageMetadata. The private model should use those classes directly where the meanings match, or have an explicit one-to-one projection to them. It should not introduce a third, independently maintained set of channel fields.The distinction between the selected view and its source still matters.
SignalStorageMetadatadescribes current declarations; the original header and per-segment file formats belong in source provenance. I would test that the private model and public metadata agree after channel selection, conversion, expanded/uniform reads, and variable-layout flattening.Record's mutable lists remain authoritative only for that compatibility view, and are converted from their current values at the write boundary.