Skip to content

Rescale the waveform view when the waveforms type changes - #1407

Merged
rossant merged 2 commits into
cortex-lab:masterfrom
adityasingh2400:fix/1045-waveform-rescale
Aug 9, 2026
Merged

Rescale the waveform view when the waveforms type changes#1407
rossant merged 2 commits into
cortex-lab:masterfrom
adityasingh2400:fix/1045-waveform-rescale

Conversation

@adityasingh2400

Copy link
Copy Markdown
Contributor

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 does self.data_bounds = self.data_bounds or self._get_data_bounds(bunchs). data_bounds is set to None only 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, the waveforms_type setter, next_waveforms_type, previous_waveforms_type, and toggle_mean_waveforms, all call plot without invalidating those bounds.

The fix adds _rescale_if_waveforms_type_changed, which clears data_bounds only when the current type actually differs from the previous one, and routes all four entry points through it. toggle_mean_waveforms now assigns through the property setter rather than calling RotatingProperty.set directly, 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.py fails on master and passes here. make lint, make format-check, pytest phy/cluster (112 passed), and pytest phy/apps (139 passed) are all green.

Fixes #1045

adityasingh2400 and others added 2 commits August 5, 2026 06:05
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
@rossant
rossant merged commit 92f0800 into cortex-lab:master Aug 9, 2026
12 checks passed
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.

Waveform view does not rescale when i toggle between waveform types

2 participants