Repository navigation
Expose grouped current channel metadata - #850
Conversation
tompollard
left a comment
There was a problem hiding this comment.
The grouping works as described. Without edits, metadata.channels[i].storage matches source_header.signals[i] for all 253 single-segment channels in sample-data. Edits are reflected on the next access, and init_value and checksum match the selected values after a range read. The offline suite, Ruff, the strict docs build and CI all pass.
This is the first time these fields become public, and the new class names will be hard to change once released. So I'd settle a few things before merging.
1. storage.skew doesn't say whether the loaded values are already aligned (metadata.py, CurrentStorageMetadata.skew)
On 100skew, an aligned read and an ignore_skew=True read both report [None, 3]:
wfdb.read_record("sample-data/100skew", stop=10).metadata.channels[1].storage.skew # 3
wfdb.read_record("sample-data/100skew", stop=10, ignore_skew=True).metadata.channels[1].storage.skew # 3For the aligned read, the 3 is the source file's skew, not a property of the values held, and the writer will drop it. That is the legacy record.skew ambiguity, copied into a new public type. #841 dropped skew_applied and kept the storage view internal for this reason ("keeps the public naming and semantics open"). I think this needs to be settled before the view is public. Options, roughly in order of preference:
- Report the skew of the loaded values, so 0 or
Noneonce it has been applied, and leave the source skew tosource_header. - Keep
skewand add a per-channelskew_applied. This needs the per-channel comparison raised in #841, not the whole-list one. - Leave
skewout ofCurrentStorageMetadatafor now.
2. The existing docstrings now contradict this view (metadata.py, LogicalSignalMetadata)
LogicalSignalMetadata still says "File names, encoding formats, and source skew belong to the source header instead" and that samples-per-frame "belongs to the loaded arrays". RecordMetadata now carries all of these. A related case: on a uniform read of a record with several samples per frame (03700181 gives [4, 1, 1]), storage.samples_per_frame reports 4 while the only loaded array has one value per frame. That matches "current declarations", but the two docstrings should agree about what the snapshot describes.
3. NumPy integers inside the frozen view
On a flattened multi-segment read (multi-segment/041s), storage.init_value is numpy.int64, although the annotation says int. So json.dumps(dataclasses.asdict(storage)) raises TypeError. Converting the integer fields with int() when building the view would keep the public type honest. Single-segment reads already give plain int.
Smaller points
- Naming:
CurrentStorageMetadatahas exactly the storage fields ofSignalHeader(file_name,format,samples_per_frame,skew,byte_offset,adc_res, ...). The "Current" prefix is unusual for a class name. Something likeSignalStorage, or saying in the docs that it mirrorsSignalHeader's fields, would help readers connect the two. - The PR says this doesn't settle whether channel objects become authoritative later. If that's still open in #744 and #749, shipping two new public class names now commits to their shape. If you prefer to keep that open,
channelscould stay private for one more step. - Tests: a skewed record (aligned and
ignore_skew=True) and a flattened multi-segment read would cover the two cases above.
|
Thanks for checking this across the sample data. I updated #850 in a1d10b2. I removed I renamed I do think the grouped view is ready to be public as an immutable snapshot. It gives callers a stable way to inspect aligned channel fields without making these objects a second mutable owner. If we later change which internal model owns the fields, we can keep this snapshot contract. The larger ownership decision remains open in #744 and #749. The full offline suite passes (1,666 passed, 4 skipped), as do Ruff and the strict docs build. |
tompollard
left a comment
There was a problem hiding this comment.
Thanks, a1d10b2 addresses each point, and the reasoning for keeping the view public as an immutable snapshot makes sense to me. Checked against the new head:
skewis gone fromSignalStorageMetadata, and the docstrings and guide now agree on what the view describes, includingsamples_per_frameon uniform reads.- Across 244 reads of
sample-data(default, digital and expanded), every storage value is a plainintorstr, including on the flattened multi-segment records, andchannelsis neverNonewhilesignalsis available. NumPy integers set by hand (np.int16,np.uint8) also come out asint. - A record built from a physical array, with
set_d_features(do_adc=True)and thenset_defaults(), gets a complete view. - The offline suite (1,666 passed, 4 skipped), Ruff and the strict docs build pass locally.
One small, optional thing: because operator.index rejects floats and the TypeError is caught, a whole-number float hides the whole grouped view. For example, record.init_value = [1.0, 2.0] or samps_per_frame = [1.0, 1.0] gives metadata.channels is None, although write_record still writes those records. That seems a reasonable rule for an integer-typed view, but the docs only mention inconsistent lists as a reason for None. Adding "or a storage field is not an integer" would explain it.
Ready to merge once CI is green.
|
Thanks, I agree the |
Summary
Record.metadata.channels: one immutable entry per current channel, grouping logical fields with current storage declarations.Record.metadata.signalsas the existing logical-only view. The new grouped view isNoneduring an inconsistent per-channel list edit; the logical-only view remains available when its own fields are consistent.source_header.Record.skewdoes not distinguish raw from already aligned loaded values.storage.samples_per_frameis a current record declaration, not a promise about a uniform array's shape.This is a first public grouped view for #744 and #749.
ChannelMetadataandSignalStorageMetadataare read-only snapshots; they do not replace the mutable legacy attributes. A future internal owner can change without changing this view's contract.Validation