Repository navigation
Plot segmented records in one figure - #928
Conversation
tompollard
left a comment
There was a problem hiding this comment.
The segmented plot draws exactly the data read_segments loaded, in the right place on the master timeline. It can merge. I found one small labelling bug. The offline suite (2,380 passed, 4 skipped) and Ruff pass.
What I checked
- The plotted data matches the combined read. I covered the five multi-segment sample records and my fixed-layout
~gap records, in both kinds and both layouts. I used windows across the first four segment boundaries plus a window from the start, with default and reversed channel order. For each figure, I placed every plotted point at its master-record position, taking samples per frame into account for expanded layout, and compared it withread_recordfor the same window. All 196 figures match point for point. Every position without a plotted point is a missing sample in the combined read: a~gap, a channel absent from that segment, or a masked digital sample. - It plots what
read_recordcan't combine. A variable-layout digital window ons00001-2896-10-10-00-31(frames 2225802–2225810), whichread_recordrejects for conflicting calibration, plots without error. - Gaps and boundaries are drawn. The
~segment ins25047, and in my gap record, is shaded, and a boundary line marks each segment start after the first.
To fix: a digital plot falls back to physical units when no segment has the channel
_plot_segmented_record works out the kind only from segments with at least one selected channel. If none of the loaded segments contains a requested channel, the set is empty and kind defaults to "physical". For example, read_segments(s25047, kind="digital", stop=60000, channel_names=["ABP"]) loads 16 zero-channel segments, all digital, and none containing ABP, but the axis is labelled ABP/mmHg instead of ABP/adu.
The zero-channel RecordData entries still carry signals.kind, so dropping the n_signals condition from that set comprehension would fix it. Please add this window as a test.
|
Fixed in bcd1fd2. The plot now takes the signal kind from zero-channel data segments too, so a digital selection with no present channel is labelled |
|
The review fix is in the merged PR. I also found that the minimum-dependency job failed on a test assertion: older Matplotlib uses a |
## Summary Fix the minimum-dependency CI failure from #928. Older Matplotlib versions represent `axvspan` shading as a `Polygon`, while newer versions use a `Rectangle`. The test asserted the rectangle-specific `get_x()` method. Removing that assertion keeps the test focused on the masked digital values; another plotting test still checks that a gap is shaded. ## Verification - `tests/test_plot.py`: 27 passed locally. - Ruff check passed.
## Summary Prepare wfdb 6.1.0, the first minor release after 6.0.0. This release adds the modern segmented-record workflow: - Plot a `SegmentedRecordData` on one timeline with boundaries and gaps (#928). - Inspect selected master metadata and edit a segment or shift times (#930). - Write fixed- and variable-layout segmented records, including selected windows, gaps, and explicit target formats (#931). This PR bumps the version in `pyproject.toml` and collects the three changelog fragments into `docs/changes.rst`. ## Verification - `uv build --offline` produced `wfdb-6.1.0.tar.gz` and `wfdb-6.1.0-py3-none-any.whl`. - Sphinx HTML build passed with `-W --keep-going`. - The release diff contains only the version and changelog changes. After this PR is merged, publish GitHub release `v6.1.0`. The release workflow will build and upload to PyPI through Trusted Publishing.
Summary
Add
SegmentedRecordData.plot()soread_segments(...).plot()shows the selected segment sequence in one figure. Signals use positions in the master record; segment boundaries are marked and~gaps are shaded. The plot uses the data already loaded byread_segments, including variable-layout channel absence, expanded sample positions, and masked digital gaps.Document the method in the README and plotting and I/O guides, with a changelog entry.
Verification