Skip to content

Conversation

@GuillaumeFavelier
Copy link
Contributor

@GuillaumeFavelier GuillaumeFavelier commented Jul 10, 2019

Fixes the last part of #6518.

This PR adds the missing _set_3d_view() and _set_3d_title() functions to the pyvista 3d backend and switches to BackgroundPlotter.

In order to avoid regression, I need to investigate:

  • 1) _Brain object features (my results are here)
  • 2) interactivity inside a jupyter notebook (paused for now)

State of testing:

Build examples/tutorials with pyvista:

To do next:

  • Use the BackgroundPlotter for testing now that offscreen rendering is available.
  • Port the mne/report.py to use the 3d backend abstraction layer
  • Improve lighting (see this comment)

Known issues:

  • missing window title (fixed by #305)
  • visual artifact at the first frame fixed after interaction/refresh (example below, #315 didn't fix this)
  • hanging windows while building the doc with make html_dev (fixed by #293)
  • camera not updated initially, manually resizing the window can solve it (found here, fixed by #315)
  • offscreen rendering is still experimental (fixed by #309)

@lgtm-com
Copy link

lgtm-com bot commented Jul 10, 2019

This pull request introduces 2 alerts when merging e8d2d8e into 26231ff - view on LGTM.com

new alerts:

  • 2 for Unused local variable

@codecov
Copy link

codecov bot commented Jul 10, 2019

Codecov Report

Merging #6551 into master will increase coverage by <.01%.
The diff coverage is 87.17%.

@@            Coverage Diff            @@
##           master   #6551      +/-   ##
=========================================
+ Coverage    89.4%   89.4%   +<.01%     
=========================================
  Files         415     416       +1     
  Lines       74985   75140     +155     
  Branches    12330   12347      +17     
=========================================
+ Hits        67039   67182     +143     
- Misses       5118    5123       +5     
- Partials     2828    2835       +7

@GuillaumeFavelier
Copy link
Contributor Author

GuillaumeFavelier commented Jul 11, 2019

Starting by 1), these are examples using _Brain and BackgroundPlotter:

Basic Visualization

image

Activation Data Visualization

image

Display ROI Values

image

I have to report 2 bugs for now:

  • missing window title
  • visual artifact at the first frame fixed after interaction/refresh (example below)
    image

@GuillaumeFavelier
Copy link
Contributor Author

GuillaumeFavelier commented Jul 12, 2019

These are the results of the now available snapshot_brain_montage() function used in examples/visualization/plot_3d_to_2d.py:

PyVista Mayavi
image image
image image
image image

I have inconsistency with Mayavi on the second figure and the camera's distance is not correct for PyVista but this can be fixed later.

I have to report one bug:

  • The camera was not updated initially, I had to manually resize the window to obtain a satifying result:
    image

Note: I used the master branch of PyVista, that's why windows have a title now

@larsoner
Copy link
Member

That's great!

Bugs like the no refresh are probably not "our problem" (they are an upstream library bug) but there are often workarounds. We can work around them later. In the meantime if you can file a bug report with some minimal example to pyvista that's great.

@GuillaumeFavelier
Copy link
Contributor Author

After discussing IRC with @larsoner and @agramfort, it seems that building the doc with the experimental version of the offscreen BackgroundPlotter could have some issues cleaning the memory. I will investigate further.

@GuillaumeFavelier
Copy link
Contributor Author

With the last test, tutorials/misc/plot_ecog.py has failed with RuntimeError so I still need to fix this. But Circle was able to upload its results successfully, we can already check the examples and tutorials.

fig = brain._figures[0][0]
mne.viz.set_3d_view(fig, azimuth=0, elevation=0, distance=550,
focalpoint=[0, 0, 0])
mne.viz.set_3d_title(fig, 'MNE-dSPM inverse (RMS)')
Copy link
Member

Choose a reason for hiding this comment

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

Instead just do brain.show_view https://pysurfer.github.io/generated/surfer.Brain.html#surfer.Brain.show_view

And maybe in stc.plot you could use time_label='MNE-dSPM inverse (RMS)' to set the title instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had some trouble to make it work with time_label locally. The window's title wasn't updated for some reason and I obtained the "Mayavi Scene" instead. Maybe I did something wrong, I'll push my changes.

fig = brain._figures[0][0]
mne.viz.set_3d_view(fig, azimuth=0, elevation=0, distance=550,
focalpoint=[0, 0, 0])
mne.viz.set_3d_title(fig, 'DICS power map, approach %d' % approach)
Copy link
Member

Choose a reason for hiding this comment

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

same, hopefully can remove the use_3d_backend

time_label = "MEG %d"
brain_meg = stc_psf_meg.plot(hemi='rh', subjects_dir=subjects_dir,
time_label=time_label,
figure=create_3d_figure(size=(500, 500)))
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand why you need to use use_3d_backend in these examples. stc.plot should use PySurfer which will use mayavi anyway

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's for the create_3d_figure() function which relies on the _Renderer now. Before the port, it was mlab.figure().

Copy link
Member

Choose a reason for hiding this comment

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

You don't need create_3d_figure, use stc.plot(..., size=(500, 500)) instead

Copy link
Member

Choose a reason for hiding this comment

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

Oh wait, that could lead to a problem with it plotting into the same Mayavi figure because it's the same subject name.

In that case, perhaps do figure=1 in the first plot and figure=2 in the second one, and it should spawn separate plots for you.

Copy link
Member

Choose a reason for hiding this comment

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

(one of these two solutions should hopefully work and allow you to avoid the MNE context manager business)

@GuillaumeFavelier
Copy link
Contributor Author

GuillaumeFavelier commented Jul 31, 2019

All CIs are happy with this version. The results are available here.

mne/viz/_3d.py Outdated
hemis = [hemi]

if title is None:
if title is None and isinstance(time_label, str):
Copy link
Member

Choose a reason for hiding this comment

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

Actually instead of using time_label you could just pass title. Sorry I forgot it was an argument at all. Then you don't need to add this conditional.

So for the code in the example you can do title = 'MNE...'; stc.plot(time_label=title, title=title, ...) and it will show up in the title bar and in the image itself. Is that what you want?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that's perfect!

time_label = "MNE %d"
brain_mne = stc_ctf_mne.plot(hemi='rh', subjects_dir=subjects_dir,
time_label=time_label,
figure=create_3d_figure(size=(500, 500)))
Copy link
Member

Choose a reason for hiding this comment

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

You can't use figure=1 here and figure=2 below?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just missed this example, thank you

@larsoner
Copy link
Member

@GuillaumeFavelier can you look through the rendered examples and set this to MRG if it's good to go? +1 for merge from me if so

environment.yml Outdated
- mne
- vtk
- pyvista>=0.20.3
- https://github.com/GuillaumeFavelier/pyvista/zipball/memory_footprint
Copy link
Member

Choose a reason for hiding this comment

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

I would wait for pyvista to merge the PRs so we use master here. Maybe some API we'll change still. wdyt @GuillaumeFavelier ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the discussion about memory optimization is still open. I would recommend waiting until it's merged then I can probably do one last pass to check that everything works as expected.

@massich
Copy link
Contributor

massich commented Aug 2, 2019

I'vee check the examples and apart the fact that the montage look like a "salami brain" everything looks fine. Maybe the lighting of this https://14519-1301584-gh.circle-artifacts.com/0/dev/auto_tutorials/source-modeling/plot_dipole_orientations.html#sphx-glr-auto-tutorials-source-modeling-plot-dipole-orientations-py could be made lighter but I'm +1 to merge like this.

maybe just add the lighting of the example above to the todo list next to reducing the diameter of the location markers.

@agramfort
Copy link
Member

agramfort commented Aug 2, 2019 via email

@massich
Copy link
Contributor

massich commented Aug 2, 2019

@GuillaumeFavelier the travis error is not related. only network.

@GuillaumeFavelier
Copy link
Contributor Author

It should be fixed now (I like salami btw):

example Mayavi PyVista
plot_eeg_on_scalp.py image image
plot_montage.py image image

@massich
Copy link
Contributor

massich commented Aug 2, 2019

NICE!! great job @GuillaumeFavelier, we are almost free of mayavi

@GuillaumeFavelier GuillaumeFavelier changed the title WIP: Pyvista background plotter MRG: Pyvista background plotter Aug 2, 2019
@agramfort agramfort merged commit f64d613 into mne-tools:master Aug 2, 2019
@GuillaumeFavelier GuillaumeFavelier deleted the pyvista_background_plotter branch August 2, 2019 15:06
@massich
Copy link
Contributor

massich commented Aug 2, 2019 via email

alexrockhill pushed a commit to alexrockhill/mne-python that referenced this pull request Oct 1, 2019
* Switch to BackgroundPlotter

* Add _set_3d_view()

* Add _set_3d_title()

* Fix unused variables

* Fix offscreen support

* Update pyvista package

* Catch DeprecationWarning coming from ipywidget

* Fix import ordering

* TST: try with test_plot_alignment as slowtest

* Enable snapshot_brain_montage

* TST: Try to build the doc with pyvista [circle full]

* Revert "TST: Try to build the doc with pyvista"

This reverts commit e4f2b74.

* Refactor _Figure management

* Fix _set_3d_view and _set_3d_title

* Fix set_camera

* TST: Try to build doc [circle full]

* TST: Fix the test [circle full]

* TST: Fix the test again [circle full]

* TST: Try to build doc [circle full]

* TST: Try build doc again [circle full]

* TST: build doc with pyvista [circle full]

* Revert doc testing

* Improve mayavi/pyvista backend switching

* Update backend switching in examples/tutorials

* Catch some deprecation warnings

* Catch some more warnings

* TST: Build doc with pyvista [circle full]

* Revert "TST: Build doc with pyvista"

This reverts commit cbeef23.

* Update backend switching for plot_dics.py

* Fix duplicate figure bug and drastically improve camera settings

* TST: Build doc with pyvista [circle full]

* Revert "TST: Build doc with pyvista"

This reverts commit cac3487.

* TST: Upgrade PyVista to master version

* TST: Upgrade PyVista to version 0.21.2

* TST: Use conda version 4.5.10

* TST: Use conda version 4.7.5

* TST: Build doc with pyvista [circle full]

* TST: Build doc normally [circle full]

This reverts commit 66c6f3d.

* revert last commit [circle full]

* Revert "Disable building of doc for now"

This reverts commit be7cd48.

* Go back to the doc building configuration with pyvista

This reverts commit 20570f8.

* TST: Ignore doc/tutorials/report.rst in doctest [circle front]

* TST: Render all the figures [circle full]

* Revert "TST: Ignore doc/tutorials/report.rst in doctest"

This reverts commit d968917.

* TST: Build doc with pyvista [circle full]

* Fix plot_ecog.py [circle full]

* Clean doc scraper conf

* Avoid use_3d_backend in examples/tutorials

* Fix minor bugs

* Fix figure title

* Avoid use_3d_backend in plot_mne_crosstalk_function.py

* TST: Update PyVista to 0.21.3 [circle full]

* Switch back to mayavi to build the doc by default (compatibility with Pysurfer)

* Fix tube radius
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.

4 participants