Skip to content

Separate header metadata from loaded record values #743

Done

Description

@tompollard

Problem

rdheader() and rdrecord() return the same Record or MultiRecord types. A header-only Record has signal fields such as p_signal and d_signal set to None, while a loaded record combines metadata and values in one object. After a range or channel selection, fields such as sig_len and n_sig describe the returned view rather than the full source header.

Decisions to make

  • What should a metadata-only read return?
  • Should metadata attached to loaded data describe the source file, the returned selection, or both? How should source provenance be exposed?
  • How can existing mutable Record attributes keep working during a transition without maintaining two conflicting copies of metadata?
  • Which fields describe the logical data, and which describe its source header and files? A selected or aligned read may differ from the on-disk layout.

Related: #371 (metadata encapsulation), #442 (multi-segment header reads), #672 (public API names), and the design review on #417.

Activity

  1. tompollard commented on Nov 28, 2026

    @tompollard
    MemberAuthor

    I think the next public model should make two descriptions explicit:

    1. Source header: an immutable, typed description of the WFDB source. A single-segment header contains signal lines; a multi-segment header contains segment lines. It keeps file layout and encoding fields such as file_name, fmt, byte_offset, block_size, and skew, along with the source calibration (adc_gain, baseline, adc_zero). It describes the source, including values inferred when the header omits them, rather than the selected or aligned array.
    2. Returned data: the existing mutable Record/MultiRecord attributes remain authoritative for editing and writing. On a selected read, sig_len, n_sig, signal names, units, and the base time describe the returned view. A future record.metadata can be a fresh, immutable snapshot computed from those attributes each time it is accessed. It would describe the logical signals and their loaded mode (physical/digital, uniform/expanded), without claiming that file layout or source skew applies to the returned array. A single effective gain/baseline should appear there only when it is well defined; variable-layout segments can differ.

    For provenance, I would expose the original source description separately from the selected view: a read-only source_header, the source location, and the selected source frame range and channel indices. The existing source_segments can continue to give segment boundaries in returned frame coordinates. These are different coordinate systems, so I would name them explicitly. PR #762 preserves the header and selection privately for both flattened and segment-preserving reads; it does not add the public properties yet.

    For a metadata-only read, I would add a typed read_header() that returns a single- or multi-segment header object, while keeping rdheader() returning Record/MultiRecord during the transition. This would revise the direct-alias suggestion for read_header in #672, so the return type is worth agreeing on before adding that name. The amount of segment metadata fetched for multi-segment headers remains the separate #442 decision.

    This avoids two mutable copies of the same metadata: old attributes remain the editable state; the logical metadata view is computed; source provenance is an immutable snapshot. Before exposing the source header publicly, I would also make inferred values (such as a missing sig_len derived from a signal file) distinguishable from values actually present in the header. I would test legacy in-place edits, equality and pickle behavior, skew, selected reads, and both multi-segment layouts before changing the public API.

  2. tompollard commented on Nov 29, 2026

    @tompollard
    MemberAuthor

    The first logical metadata view is proposed in #767. Record.metadata is a fresh immutable snapshot of the current Record attributes, so selected frames and channels and later in-place edits are reflected without a second mutable copy. It includes the loaded value kind and layout, while source file names, encoding, and skew remain outside the logical view.

    I kept this first PR to Record, including flattened multi-segment reads. MultiRecord needs its own channel and segment contract (#746), and public source location and provenance still need the decisions in #748. The 5.7.0 release PR (#766) is separate and contains only the merged read_header API.

  3. tompollard commented on Nov 30, 2026

    @tompollard
    MemberAuthor

    The design questions here now have concrete APIs:

    • read_header() returns an immutable description of one source header; read_multi_segment_headers() also identifies the header that defines a multi-segment record's channels. The legacy rdheader() remains compatible.
    • Record.metadata is a fresh, immutable description of the returned logical view. The existing mutable Record fields remain the editable state, so there is no second mutable copy to synchronize.
    • Loaded records expose the original source_header, the channel-defining source_signal_header, and source_selection in source coordinates (Expose source provenance on loaded records #801). source_segments continues to use returned-frame coordinates.

    That settles the separation this issue asked for, so I'm closing it. The remaining work has its own scope: source location and remote paths (#534), the MultiRecord contract (#746), broader metadata encapsulation (#371), and public names (#672).

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