Skip to content

Group per-channel header fields into coherent signal metadata #744

Backlog

Description

@tompollard

Problem

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?

Related: #371 (record metadata), #441 (signal metadata on MultiRecord), #672 (readable attributes), and the design review on #417.

Activity

  1. tompollard commented on Nov 30, 2026

    @tompollard
    MemberAuthor

    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.

  2. tompollard commented on Nov 30, 2026

    @tompollard
    MemberAuthor

    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.

  3. tompollard commented on Nov 30, 2026

    @tompollard
    MemberAuthor

    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.

  4. tompollard commented on Dec 3, 2026

    @tompollard
    MemberAuthor

    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, 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.

  5. tompollard commented on Dec 3, 2026

    @tompollard
    MemberAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions