Repository navigation
Add a common header-only channel metadata reader - #827
Conversation
tompollard
left a comment
There was a problem hiding this comment.
Thanks. One function that gives the channel-defining header for both record forms is a good fit for the header-only case in #441, and not adding more mutable per-channel lists to MultiRecord matches the direction in #744. It returns the right header for 100, 041s (041s01), p000878 (3269321_layout) and a physionet:// URI, reads no signal files, and the shared helper avoids parsing the master header twice. The offline suite, Ruff and the strict docs build pass locally.
Two things before the name is public:
- Name.
wfdb.SignalHeaderis already the per-signal type (each entry inheader.signals), soread_signal_header()returning a wholeSingleSegmentHeaderis easy to misread. Could it be renamed, for example toread_channel_header(path)? Alternatively,read_signal_headers(path) -> tuple[SignalHeader, ...](empty when all segments are gaps) would match the type name, at the cost of the source record name andfs. pn_dir. This is a new function, but it accepts the just-deprecatedpn_dir, andread_signal_header("100", pn_dir="mitdb/1.0.0")immediately emits theFutureWarning. Could it accept only a path or URI, so the new API never takespn_dir?
|
Thanks, both points make sense. I renamed the function to |
There was a problem hiding this comment.
Thanks, 6048925 covers both points: the function is now read_channel_header(path), and passing pn_dir raises the usual unexpected-keyword TypeError. The full offline suite, Ruff and the strict docs build pass locally.
One small fix: removing the pn_dir parameter also removed the blank line before Returns in the docstring, so numpydoc renders it inside the path description. The built page shows "...or local .wfdb archive path. Returns ——- SingleSegmentHeader or None ..." as part of the parameter text. The strict build doesn't catch it, but adding the blank line back fixes it. The changelog also still says "returns an immutable signal header"; "channel-defining header" would match the new name.
|
Fixed the missing blank line before |
tompollard
left a comment
There was a problem hiding this comment.
Thanks, c439b44 fixes both: the Returns section renders properly now and the changelog wording matches. Leaving the property name for a possible follow-up makes sense. The full offline suite, Ruff and the strict docs build pass locally.
One optional wording tweak to the new docs sentence: source_signal_header returns the whole header the read used, not only the selected channels, and for fixed layout it can be a later segment. For example, after read_record("…/041s", start=1500, stop=1600, channels=[1]) it is 041s02 with all 7 signals, while read_channel_header returns 041s01. Moving the sentence to the end of the paragraph and saying something like "On a loaded record, source_signal_header gives the header that read used, which for fixed layout may be a later segment" would avoid it reading as if the following "For variable layout…" sentence described the property.
Ready to merge once CI is green.
|
Good catch. I moved the sentence to the end of the paragraph and clarified that |
## Summary Add `MultiRecord.segment_views`, a read-only snapshot of the current segment names, roles, and frame ranges. Each entry is a `SegmentView(index, name, start, stop, kind)` with `n_frames` available as a property. The roles are `layout`, `gap`, and `data`. This lets callers inspect gap lengths and variable-layout headers without interpreting `None` entries in `MultiRecord.segments`. A non-gap segment stays `data` even when no selected channels caused its `Record` to be loaded. The existing mutable lists and segment objects remain unchanged. Combined `Record.source_segments` also gains `kind` and `n_frames` properties, so both return forms expose the same distinction. This addresses the segment representation and provenance questions in #746. The separate header-only channel view is in #827. ## Checks - `uv run pytest tests/test_segment_views.py tests/test_read_record.py tests/test_source_provenance.py -q -m 'not network'` (79 passed) - `uv run pytest -m 'not network' -q` (1578 passed, 4 skipped, 23 deselected) - `uv run ruff check .` - `uv run ruff format --check .` - `uv run --only-group docs make -C docs html SPHINXOPTS='-W --keep-going'`
Summary
Add
read_channel_header(path)so header-only callers can inspect signal names, units, and samples per frame through the same immutableSingleSegmentHeadertype for ordinary and multi-segment records. The new function accepts one explicit path or URI; it does not take the deprecatedpn_dirargument.None.The function reads no samples and does not add mutable channel fields to
MultiRecord. Calibration and file layout remain explicitly tied to the returned source header, which may differ from later segments. This addresses the header-only use case in #441 and advances #746.Checks
uv run pytest tests/test_read_header.py tests/test_source_provenance.py -q -m 'not network'(38 passed)uv run pytest -m 'not network' -q(1569 passed, 4 skipped, 23 deselected)uv run ruff check .uv run ruff format --check .uv run --only-group docs make -C docs html SPHINXOPTS='-W --keep-going'