Skip to content

Conversation

@GuillaumeFavelier
Copy link
Contributor

@GuillaumeFavelier GuillaumeFavelier commented Jan 23, 2020

This PR enables point picking and display the vertex id as text in the top left. It's the first step to achieve #7235. Shortcut is p to pick under the mouse. This is still a work in progress.

Animation

output

ToDo

#7235 (comment)

Closes #7235
It's an item of #7162

@codecov
Copy link

codecov bot commented Jan 23, 2020

Codecov Report

Merging #7247 into master will increase coverage by 0.02%.
The diff coverage is 97.22%.

@@            Coverage Diff             @@
##           master    #7247      +/-   ##
==========================================
+ Coverage   89.93%   89.96%   +0.02%     
==========================================
  Files         451      451              
  Lines       81795    81846      +51     
  Branches    12977    12982       +5     
==========================================
+ Hits        73564    73630      +66     
+ Misses       5404     5385      -19     
- Partials     2827     2831       +4

@GuillaumeFavelier
Copy link
Contributor Author

The shortcut is o to plot the timecourse of the latest picked point. For now it uses matplotlib for plotting.

@larsoner
Copy link
Member

Mostly throwing out ideas here -- the most relevant VTK examples I could find are:

We could put a time course up right over the 3D scene if you want (charts on 3D scene). But it might be cleaner to have the drawing area be split somehow, e.g. upper 2/3 for 3D lower 1/3 for 2D chart (if and only if show_traces=True, False by default) with the interaction being:

  • click a point, the time course for that vertex is added to the chart, and a dot appears at that point on the surface
  • click on a given the dot, that time course corresponding to that dot disappears from the chart and the point on the surface is removed

This would allow comparing multiple time courses very easily, which is nice. The dots that appear on the surface (probably from a scatter 3D sort of thing) could have the center colored according to the color that is used in the chart.

This would be a killer interactive data browsing feature for me personally...

(Someday, in the distant future, maybe we could also show time-frequency data by displaying a rectilinear grid on axes. But the time-course is much more important.)

@GuillaumeFavelier
Copy link
Contributor Author

  • click a point, the time course for that vertex is added to the chart, and a dot appears at that point on the surface
  • click on a given the dot, that time course corresponding to that dot disappears from the chart and the point on the surface is removed

Wow, really nice UX. I will pin that in the issue as a todo list.

@GuillaumeFavelier
Copy link
Contributor Author

Thank you so much @alexis-cvetkov for the help, the UX has been improved drastically!

@GuillaumeFavelier
Copy link
Contributor Author

Thanks for the feedback @drammock, I'll make a pass to rename those

@GuillaumeFavelier
Copy link
Contributor Author

This is the latest result:

output

@larsoner
Copy link
Member

Awesome! Happy to try and push some fig.subplots_adjust / xlabel / ylabel etc. fixes if you want, or you can do it.

As far as picking goes I would say leave enable it by default if they have show_traces=True turned on, allowing them to hit p to turn it off

@GuillaumeFavelier
Copy link
Contributor Author

Feel free to modify as you wish.

I have a question about show_traces though. Is it a parameter of link_brains() or plot_source_estimates ? Because _TimeViewer is not public.

@larsoner
Copy link
Member

show_traces would be a parameter of plot_source_estimates

@larsoner
Copy link
Member

BTW @GuillaumeFavelier like the volume viewer I think if show_traces=True then by default it should start with the vertex with the max abs value across time shown (as if it had already been clicked on). I can push this with my matplotlib tweaks if you want, but it might be better if you do it since you have a better idea of how to make this work with the _Brain internals.

@GuillaumeFavelier
Copy link
Contributor Author

I'll take care of it 👍
I can't work on it right now but I will edit the todo list in the linked issue.

@larsoner
Copy link
Member

Okay I'll test and push some mpl tweaks in the meantime, then

@larsoner
Copy link
Member

The interaction is weird/not what I expected. Pressing "p" is when it picks a point. I think it should pick whenever you click. And clicking on the sphere that appears should make the point disappear.

@larsoner
Copy link
Member

(Also a MPL figure window opens in addition to there being an embedded one, I'll try to fix this)

@GuillaumeFavelier
Copy link
Contributor Author

GuillaumeFavelier commented Feb 20, 2020

P and R are not used at all for picking anymore, the left click with the mouse should be enough

okay so let's get rid of this? I think any unused options should go away

Sorry, maybe I didn't understand correctly. Get rid of what exactly? It shouldn't even be possible to use p or r at this state of the PR.

In general, I agree with you that we should focus on what's necessary 👍

@agramfort
Copy link
Member

agramfort commented Feb 20, 2020 via email

@mmagnuski
Copy link
Member

I agree with @agramfort - using the interface (dragging the time slider) I would expect to travel through time samples without any interpolation. However I understand it is important for movie playback. Is the movie playback bad without this time interpolation?

@jasmainak
Copy link
Member

It shouldn't even be possible to use p or r at this state of the PR.

ummm ... I was getting a large text at the top of the scene saying I could use P or R. I think it appeared after I selected an option from the menu. Happy to take a look again once the PR is closer to being merged.

@larsoner
Copy link
Member

Okay let's make nearest the default @GuillaumeFavelier . At some point we can make the interpolation mode easily publicly settable.

But I would suggest that people try the spacebar playback with linear mode and nearest mode so that you can fully judge the situation. People have seemed pleased about "smoothness" and if such comments had to do with the playback, nearest interpolation mode will be less smooth.

@larsoner
Copy link
Member

... which you can do by setting brain.interp_kind = 'nearest' before starting playback (I think)

@hoechenberger
Copy link
Member

Thinking about it a bit more, too -- any time-plot that we do in MNE that uses ax.plot instead of ax.step (and that's all of them AFAIK, including the time traces shown here) is doing linear interpolation in time rather than zero-order-hold / nearest interpolation in its depiction of the trace. So it's probably a more common practice than people realize

I think the main difference between the trace of a signal produced via ax.plot() and the activation displayed by _TimeViewer is that for the former, the user can typically see all values across all time points at once, while that's not the case for the source visualizations.

@GuillaumeFavelier
Copy link
Contributor Author

Okay let's make nearest the default

It's noted on #7162 , I'll work on FakeVTKPicker now

I think it appeared after I selected an option from the menu.

I understand better now: the option for cell picking in the menu is not compatible with what we have when show_traces is enabled. It corresponds to PyVista default picking. I'll disable it to avoid the confusion.

@larsoner
Copy link
Member

@GuillaumeFavelier I pushed a commit to more fully and cleanly parametrize one of the tests, and in adding 'rh' I found a bug:

mne/viz/_brain/tests/test_brain.py:166: in test_brain_timeviewer_traces
    time_viewer = _TimeViewer(brain_data, show_traces=True)
mne/viz/_brain/_timeviewer.py:283: in __init__
    self.plotter.subplot(ri, ci)
../pyvista/pyvista/plotting/plotting.py:272: in subplot
    raise IndexError('Column index is out of range ({})'.format(self.shape[1]))
E   IndexError: Column index is out of range (1)

@GuillaumeFavelier
Copy link
Contributor Author

I encountered this one locally too, I will fix in this PR

@GuillaumeFavelier GuillaumeFavelier changed the title WIP: Enable point picking in _TimeViewer MRG: Enable point picking in _TimeViewer Feb 27, 2020
@larsoner larsoner merged commit 1a36309 into mne-tools:master Feb 27, 2020
@larsoner
Copy link
Member

Thanks @GuillaumeFavelier !!!

AdoNunes pushed a commit to AdoNunes/mne-python that referenced this pull request Apr 6, 2020
* Enable basic point picking

* Pick & plot time course

* Use only one action to pick & plot

* Improve UX drastically

* Rename polydata to avoid confusion with pandas

* Fix unpacking of mesh data

* Change string formatting

* Use MPL_canvas

* Improve docstring

* FIX: mpl tweaks

* Add show_traces parameter to plot_source_estimates

* Increase the glyph radius to 10

* Update the 3d backend overview table

* Refactor pick_point()

* Initialize the defautl point

* Update picking experience

* Use cell picking

* Modify default size for glyph

* Update legend

* ENH: Add auto mode by default

* FIX: Fix to logic

* FIX: Flake

* Refactor color cycle

* Enable interactive widgets in test_3d.py

* Update the tests

* TST: Put time_viewer=False and show_traces=False by default

* Refactor PyQt5 import

* Use composition for MplCanvas

* Revert "Refactor color cycle"

This reverts commit a76a0ae.

* Disable interactivity in plot_sparse_source_estimates

* Add support for hemi=both

* Add support for hemi=split

* Push hotfix for both/split

* Display MNI coordinates

* Add support for show_traces=separate

* FIX: Legend

* Add support for views

* ENH: Add idx=

* Refactor time_viewer testing

* Add tests for traces

* Improve testing

* FIX: Parametrize

* Fix view indexing logic

* Test remove_point

* Add TstVTKPicker

* Fix style

Co-authored-by: Eric Larson <larson.eric.d@gmail.com>
AdoNunes pushed a commit to AdoNunes/mne-python that referenced this pull request Apr 6, 2020
* Enable basic point picking

* Pick & plot time course

* Use only one action to pick & plot

* Improve UX drastically

* Rename polydata to avoid confusion with pandas

* Fix unpacking of mesh data

* Change string formatting

* Use MPL_canvas

* Improve docstring

* FIX: mpl tweaks

* Add show_traces parameter to plot_source_estimates

* Increase the glyph radius to 10

* Update the 3d backend overview table

* Refactor pick_point()

* Initialize the defautl point

* Update picking experience

* Use cell picking

* Modify default size for glyph

* Update legend

* ENH: Add auto mode by default

* FIX: Fix to logic

* FIX: Flake

* Refactor color cycle

* Enable interactive widgets in test_3d.py

* Update the tests

* TST: Put time_viewer=False and show_traces=False by default

* Refactor PyQt5 import

* Use composition for MplCanvas

* Revert "Refactor color cycle"

This reverts commit a76a0ae.

* Disable interactivity in plot_sparse_source_estimates

* Add support for hemi=both

* Add support for hemi=split

* Push hotfix for both/split

* Display MNI coordinates

* Add support for show_traces=separate

* FIX: Legend

* Add support for views

* ENH: Add idx=

* Refactor time_viewer testing

* Add tests for traces

* Improve testing

* FIX: Parametrize

* Fix view indexing logic

* Test remove_point

* Add TstVTKPicker

* Fix style

Co-authored-by: Eric Larson <larson.eric.d@gmail.com>
@GuillaumeFavelier GuillaumeFavelier deleted the time_viewer_vertex_picking branch June 11, 2020 09:40
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.

picking vertex in brain object to see time course