Rescale the waveform view when the waveforms type changes - #1407
Merged
rossant merged 2 commits intoAug 9, 2026
Conversation
The waveform view computed its y axis bounds on the first plot and kept them for the lifetime of the view, so switching between raw waveforms, mean waveforms and templates reused the scale of whichever type happened to be shown first. Templates then appeared as flat lines, and raw waveforms overflowed their box. Discard the cached bounds whenever the waveforms type actually changes, through the property setter, the next and previous actions, and the mean waveforms toggle. Bounds are still shared across cluster selections of the same type, so the scale stays comparable while curating. Fixes cortex-lab#1045
# Conflicts: # docs/changelog.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Toggling the Waveform View between raw waveforms, mean waveforms, and templates does not rescale the y axis. Because templates and raw traces differ in amplitude by orders of magnitude, whichever type is not the one the view first drew is unreadable, either as flat lines or as traces overflowing their box. Reset scaling does not help because it only touches box and probe scaling, and the only workaround reported in the issue is restarting the GUI with the desired type already selected.
The cause is in
WaveformView.plot, which doesself.data_bounds = self.data_bounds or self._get_data_bounds(bunchs).data_boundsis set toNoneonly in__init__, so the bounds are computed once on the first plot and then reused for the whole life of the view, including across waveforms type switches. The four entry points that change the type, thewaveforms_typesetter,next_waveforms_type,previous_waveforms_type, andtoggle_mean_waveforms, all callplotwithout invalidating those bounds.The fix adds
_rescale_if_waveforms_type_changed, which clearsdata_boundsonly when the current type actually differs from the previous one, and routes all four entry points through it.toggle_mean_waveformsnow assigns through the property setter rather than callingRotatingProperty.setdirectly, so there is a single place where the invalidation happens. Bounds are still shared across cluster selections of the same type, so the scale stays comparable while stepping through clusters, which is the existing behavior users rely on.Tested headlessly with a view holding two waveform types whose amplitudes differ by a factor of 1000. On master, after switching to the smaller type the upper bound stays at 80.126 instead of 0.080126, a relative error of 999, which is the flat-line symptom. With the fix it tracks the displayed type through all four entry points. The new test in
phy/cluster/views/tests/test_waveform.pyfails on master and passes here.make lint,make format-check,pytest phy/cluster(112 passed), andpytest phy/apps(139 passed) are all green.Fixes #1045