Skip to content

Plot segmented records in one figure - #928

Merged
tompollard merged 2 commits into
mainfrom
plot-segmented-record
Dec 4, 2026
Merged

tompollard merged 2 commits into
mainfrom
plot-segmented-record

Conversation

@tompollard

Copy link
Copy Markdown
Member

Summary

Add SegmentedRecordData.plot() so read_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 by read_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

  • Offline suite: 2,380 passed, 4 skipped, 23 network tests deselected.
  • Ruff check and format passed.
  • Sphinx HTML build passed with warnings treated as errors.

@tompollard tompollard left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 with read_record for 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_record can't combine. A variable-layout digital window on s00001-2896-10-10-00-31 (frames 2225802–2225810), which read_record rejects for conflicting calibration, plots without error.
  • Gaps and boundaries are drawn. The ~ segment in s25047, 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.

@tompollard

Copy link
Copy Markdown
Member Author

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 adu. I added the s25047 window from the review as a regression test. The plotting tests and Ruff pass locally.

@tompollard
tompollard merged commit 9cdf011 into main Dec 4, 2026
18 of 19 checks passed
@tompollard
tompollard deleted the plot-segmented-record branch December 4, 2026 21:58
@tompollard

Copy link
Copy Markdown
Member Author

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 Polygon for gap shading, while the test expected a Rectangle. I opened #929 with the one-line test correction.

tompollard added a commit that referenced this pull request Dec 4, 2026
## 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.
tompollard added a commit that referenced this pull request Dec 4, 2026
## 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant