-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enh browserfig UI events #12819
base: main
Are you sure you want to change the base?
Enh browserfig UI events #12819
Conversation
This needs a unit test. |
Co-authored-by: Marijn van Vliet <w.m.vanvliet@gmail.com>
for more information, see https://pre-commit.ci
Now the following works:
And scrolling through time will update both figures. |
@wmvanvliet I added the |
Where/how would I put a unit test? I also saw there's no unit test for |
Co-authored-by: Marijn van Vliet <w.m.vanvliet@gmail.com>
Co-authored-by: Marijn van Vliet <w.m.vanvliet@gmail.com>
Co-authored-by: Marijn van Vliet <w.m.vanvliet@gmail.com>
Co-authored-by: Marijn van Vliet <w.m.vanvliet@gmail.com>
…itz/mne-python into ENH-browserfig-ui-events
@wmvanvliet the matplotlib and qt browsers (on this branch mne-tools/mne-qt-browser#286 ) are synced in time and channels. It's also working for epochs. |
Mouse and keypresses no longer directly update the plot, but instead generate the appropriate UI events. Figures always listen and respond to their own UI events, which is where the updating of the figure happens. This way, there is a single place in the code where checking of corner cases, etc. happens. In addition, the matplotlib xdata timeline is different from actual times in the Raw object. UI events should always be meaningful outside of the figure. Hence, TimeChange and TimeBrowse should give the selected times in terms of the original Raw object. Various translations therefore need to happen.
for more information, see https://pre-commit.ci
I've overhauled the event code in the matplotlib figure a bit. The biggest improvement is that now the import mne
path = mne.datasets.sample.data_path()
raw = mne.io.read_raw_fif(path / "MEG" / "sample" / "sample_audvis_raw.fif")
events = mne.find_events(raw)
epochs = mne.Epochs(raw, events, preload=True)
mne.viz.set_browser_backend('matplotlib')
fig1 = raw.plot(events=events)
fig2 = epochs.plot()
def on_time_browse_event(event):
print(event)
def on_channel_browse_event(event):
print(event)
def on_time_change_event(event):
print(event)
mne.viz.ui_events.subscribe(fig2, 'time_browse', on_time_browse_event)
mne.viz.ui_events.subscribe(fig2, 'channel_browse', on_channel_browse_event)
mne.viz.ui_events.subscribe(fig2, 'time_change', on_time_change_event)
mne.viz.ui_events.link(fig2, fig1, include_events=['time_browse', 'channel_browse']) |
another improvement is that the figure is no longer updated twice on every keypress. Before, the keypress first updated the figure and then generated the UI event, which caused the event handler to update the figure again. Now, the keypress just generates the UI event and lets the event handler take care of updating the figure. |
Should we do the same for the vertical bar? Currently when the vertical bar appears in epoch mode all epochs at that timepoint are marked with a vertical bar. So raw time doesn't matter here. |
I've updated the |
What does this implement/fix?
Creates hook to use UI-events in the Qt browser. Also implements the
TimeChange
event for the matplotlib-based browser.Additional information