Repository navigation
Expose segment roles and frame ranges on MultiRecord - #828
Conversation
tompollard
left a comment
There was a problem hiding this comment.
Thanks. segment_views reads clearly and fixes a real ambiguity: on s25047 it labels the layout header, gaps and data correctly from both rdheader and a selected read_record, an unloaded data segment stays "data", and the offsets match the combined record's source_segments. The offline suite, Ruff and the strict docs build pass locally.
Two suggestions:
- Use
layoutwhen it's known.kindis"layout"for any first zero-length segment, soMultiRecord(seg_name=["a", "b"], seg_len=[0, 5], layout="fixed").segment_viewsgives["layout", "data"]. Records read from files carrylayout("variable"fors25047), so checkingself.layout == "variable"when set, and falling back to the position rule only when it'sNone, would be exact. - A clear error instead of
Nonefor mismatched lists. Withseg_name=["a", "b"]andseg_len=[2],segment_viewsisNone, andfor view in multi.segment_viewsthen fails withTypeError: 'NoneType' object is not iterable. RaisingValueErrornaming the mismatch would match the recent direction on clear errors.Nonecould still mean "no segment lists at all".
Not for this PR: with SegmentReference (headers), SourceSegment (combined records) and now SegmentView (preserved records), it might be worth noting on #746 whether these should converge.
|
Thanks. I changed I kept I agree the three descriptor types merit a separate look and will note that on #746. The focused tests (11 passed), Ruff and the strict docs build pass. |
Summary
Add
MultiRecord.segment_views, a read-only snapshot of the current segment names, roles, and frame ranges. Each entry is aSegmentView(index, name, start, stop, kind)withn_framesavailable as a property. The roles arelayout,gap, anddata.This lets callers inspect gap lengths and variable-layout headers without interpreting
Noneentries inMultiRecord.segments. A non-gap segment staysdataeven when no selected channels caused itsRecordto be loaded. The existing mutable lists and segment objects remain unchanged. CombinedRecord.source_segmentsalso gainskindandn_framesproperties, 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'