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
Separate header metadata from loaded record values #743
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.
I think the next public model should make two descriptions explicit:
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.
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.
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.
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).
Activity
Pin public I/O behavior before record refactor (#750)
Represent parsed single and multi-segment headers separately (#753)
Keep source headers separate during single-segment reads (#754)
Type parsed record-line metadata (#761)
tompollard commentedon Nov 28, 2026
I think the next public model should make two descriptions explicit:
file_name,fmt,byte_offset,block_size, andskew, 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.Record/MultiRecordattributes 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 futurerecord.metadatacan 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 existingsource_segmentscan 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 keepingrdheader()returningRecord/MultiRecordduring the transition. This would revise the direct-alias suggestion forread_headerin #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_lenderived 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.Preserve source header and selection on loaded reads (#762)
Add immutable read_header API (#763)
tompollard commentedon Nov 29, 2026
The first logical metadata view is proposed in #767.
Record.metadatais a fresh immutable snapshot of the currentRecordattributes, 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.MultiRecordneeds 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 mergedread_headerAPI.Add logical Record metadata snapshot (#767)
Expose source provenance on loaded records (#801)
tompollard commentedon Nov 30, 2026
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 legacyrdheader()remains compatible.Record.metadatais a fresh, immutable description of the returned logical view. The existing mutableRecordfields remain the editable state, so there is no second mutable copy to synchronize.source_header, the channel-definingsource_signal_header, andsource_selectionin source coordinates (Expose source provenance on loaded records #801).source_segmentscontinues 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
MultiRecordcontract (#746), broader metadata encapsulation (#371), and public names (#672).