Skip to content
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

Allow lasso selection sensors in a plot_evoked_topo #12071

Merged
merged 34 commits into from
Jan 23, 2025

Conversation

wmvanvliet
Copy link
Contributor

@wmvanvliet wmvanvliet commented Oct 4, 2023

This adds plot_evoked_topo(select=True) which will allow you to use a lasso selection tool in the same manner as plot_sensors("select"). It currently doesn't do anything with this selection other than publishing an SelectChannels UI-Event. This is a part of the planned XFit-like GUI, but could have other uses as well. For example, we could in the future make plot_evoked_topo open up a figure with the average of the selected sensors when you select them, similar to what happens when you click on a sensor.

The main change this PR makes is to refactor mne.viz.utils.SelectFromCollection a bit to make it more general purpose. Where the names of the variables and such were first tightly coupled to raw.plot_sensors, things are now named from the perspective of a matplotlib figure with a Collection of patches. The translation from "selecting matplotlib patches" to "selecting channels" is now happening though UI-events. You can register a callback function with mne.viz.utils.SelectFromCollection for when a selection is made. Raw and Evoked use this to emit SelectChannels UI-events whenever the user uses the lasso to select channels.

The main unit test for this class has been moved from viz/tests/test_raw.py to viz/tests/test_util.py. Smaller unit tests are now in place for raw.plot_sensors and evoked.plot_topo.

In addition to using CTRL to "add to selection" you can now also use CTRL+SHIFT to "remove from selection".

At the moment, this doesn't work yet when unified=False. If there is a pressing need for it, I can add it, but perhaps this can also be left to a later PR.

@wmvanvliet wmvanvliet force-pushed the sensorselect branch 2 times, most recently from 084bd38 to 4fe2135 Compare October 4, 2023 17:12
@wmvanvliet wmvanvliet added the ENH label Oct 4, 2023
@wmvanvliet wmvanvliet marked this pull request as draft October 4, 2023 17:21
@wmvanvliet wmvanvliet marked this pull request as ready for review October 24, 2024 08:13
@wmvanvliet wmvanvliet requested a review from larsoner as a code owner October 24, 2024 08:13
@wmvanvliet
Copy link
Contributor Author

It's been a while, but this PR is finally ready for review (and at some point, merge).

Copy link
Member

@drammock drammock left a comment

Choose a reason for hiding this comment

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

My only complaint is that I can't remove sensors from the selection because Alt+click+drag is an OS-level "drag this whole window around the screen" shortcut in Linux. Can we use another key?

mne/viz/tests/test_topo.py Outdated Show resolved Hide resolved
mne/viz/topo.py Show resolved Hide resolved
mne/viz/topo.py Outdated Show resolved Hide resolved
mne/viz/utils.py Show resolved Hide resolved
@wmvanvliet wmvanvliet mentioned this pull request Jan 21, 2025
3 tasks
@wmvanvliet
Copy link
Contributor Author

Can we use another key?

I now make it that CTRL adds to the selection, as it was before, and CTRL+SHIFT removes from the selection. Does that work better on OSX?

@drammock
Copy link
Member

failures look like they're probably related:

FAILED mne/viz/tests/test_topo.py::test_plot_topo - TypeError: hasattr expected 2 arguments, got 1
FAILED mne/viz/tests/test_topo.py::test_plot_topo_single_ch - TypeError: hasattr expected 2 arguments, got 1
FAILED mne/viz/tests/test_topo.py::test_plot_topo_image_epochs - TypeError: hasattr expected 2 arguments, got 1
FAILED mne/viz/tests/test_topo.py::test_plot_topo_select - TypeError: hasattr expected 2 arguments, got 1
FAILED mne/viz/tests/test_topo.py::test_plot_tfr_topo - Failed: DID NOT WARN. No warnings of type (<class 'RuntimeWarning'>,) were emitted.
 Emitted warnings: [].

mne/viz/topo.py Outdated Show resolved Hide resolved
mne/viz/tests/test_raw.py Outdated Show resolved Hide resolved
mne/viz/topo.py Outdated Show resolved Hide resolved
wmvanvliet and others added 2 commits January 22, 2025 21:22
Co-authored-by: Daniel McCloy <[email protected]>
Co-authored-by: Daniel McCloy <[email protected]>
@wmvanvliet
Copy link
Contributor Author

done!

@drammock drammock merged commit aca4965 into mne-tools:main Jan 23, 2025
30 checks passed
@drammock
Copy link
Member

thanks @wmvanvliet awesome work

larsoner added a commit to larsoner/mne-python that referenced this pull request Jan 24, 2025
* upstream/main: (57 commits)
  Allow lasso selection sensors in a plot_evoked_topo (mne-tools#12071)
  MAINT: Fix doc build (mne-tools#13076)
  BUG: Improve sklearn compliance (mne-tools#13065)
  [pre-commit.ci] pre-commit autoupdate (mne-tools#13073)
  MAINT: Add Numba to 3.13 test (mne-tools#13075)
  Bump autofix-ci/action from ff86a557419858bb967097bfc916833f5647fa8c to 551dded8c6cc8a1054039c8bc0b8b48c51dfc6ef in the actions group (mne-tools#13071)
  [BUG] Correct annotation onset for exportation to EDF and EEGLAB (mne-tools#12656)
  New feature for removing heart artifacts from EEG or ESG data using a Principal Component Analysis - Optimal Basis Sets (PCA-OBS) algorithm (mne-tools#13037)
  [BUG] Fix taper weighting in computation of TFR multitaper power (mne-tools#13067)
  [FIX] Reading an EDF with preload=False and mixed frequency (mne-tools#13069)
  Fix evoked topomap colorbars, closes mne-tools#13050 (mne-tools#13063)
  [pre-commit.ci] pre-commit autoupdate (mne-tools#13060)
  BUG: Fix bug with interval calculation (mne-tools#13062)
  [DOC] extend documentation for add_channels (mne-tools#13051)
  Add `combine_tfr` to API (mne-tools#13054)
  Add `combine_spectrum()` function and allow `grand_average()` to support `Spectrum` data (mne-tools#13058)
  BUG: Fix bug with helium anon (mne-tools#13056)
  [ENH] Add option to store and return TFR taper weights (mne-tools#12910)
  BUG: viz plot window's 'title' argument showed no effect. (mne-tools#12828)
  MAINT: Ensure limited set of tests are skipped (mne-tools#13053)
  ...
@larsoner
Copy link
Member

@wmvanvliet this main failure looks related can you look?

https://app.circleci.com/pipelines/github/mne-tools/mne-python/26528/workflows/ba13e032-bf8a-4341-b4ee-2de33755c932/jobs/71283?invite=true#step-143-15504_86

maybe just missing an event=None default or something?

@wmvanvliet
Copy link
Contributor Author

looks like it, lets see: #13086

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants