Skip to content

Integrate better with Jupyter notebook #268

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

Merged
merged 3 commits into from
May 22, 2019
Merged

Conversation

wmvanvliet
Copy link
Contributor

@wmvanvliet wmvanvliet commented May 21, 2019

Mayavi can render things inside a jupyter notebook as either PNG or X3D.
This functionality can be enabled with mlab.init_notebook().

This PR adds an _ipython_display_ hook to the Brain class that
renders the brain accordgin to the Mayavi notebook integration settings.

This means interactive PySurfer brains in Binder are now possible!
https://mybinder.org/v2/gh/wmvanvliet/SNL_workshop_2019/master?filepath=pysurfer_demo.ipynb

Mayavi can render things inside a jupyter notebook as either PNG or X3D.
This functionality can be enabled with `mlab.init_notebook()`.

This PR adds an `_ipython_display_` hook to the `Brain` class that
renders the brain accordgin to the Mayavi notebook integration settings.
@codecov-io
Copy link

codecov-io commented May 21, 2019

Codecov Report

Merging #268 into master will decrease coverage by 0.18%.
The diff coverage is 22.22%.

@@            Coverage Diff             @@
##           master     #268      +/-   ##
==========================================
- Coverage      75%   74.82%   -0.19%     
==========================================
  Files           7        7              
  Lines        2517     2526       +9     
  Branches      506      509       +3     
==========================================
+ Hits         1888     1890       +2     
- Misses        454      461       +7     
  Partials      175      175

@larsoner
Copy link
Contributor

This means interactive PySurfer brains in Binder are now possible!

This would be through the X3D backend? It's mature enough that you can for example rotate the brain with the mouse?

@larsoner
Copy link
Contributor

Oh that's a mybinder link, trying now...

@larsoner
Copy link
Contributor

It interacts but has some bugs:

Screenshot from 2019-05-21 10-02-26

We can probably try to fix this at the mayavi end, this looks like a hopefully easy bytes vs str issue.

In any case, +1 for merge from me!

@banesullivan
Copy link

banesullivan commented May 21, 2019

You could also achieve this with PyVista. Cross-post from pyvista/pyvista#146 (comment)

Check out all the PyVista examples on http://playground.pyvista.org

Or this one: https://mybinder.org/v2/gh/OpenGeoVis/omfvista/master?filepath=Example.ipynb

omfvtk

This is enabled by default if panel is installed

@mwaskom
Copy link
Member

mwaskom commented May 21, 2019

It would be good to have this mentioned in the documentation. Maybe at the bottom of this page?

@larsoner
Copy link
Contributor

BTW @wmvanvliet I don't hit the bytes/str bug locally, so if you update your mayavi on MyBinder to latest master it will probably go away

@jasmainak
Copy link

neat @wmvanvliet !

@wmvanvliet
Copy link
Contributor Author

The str vs bytes bug is actually an empty string bug. Sometimes VTK is too slow to render the brain and the X3D string becomes empty. I also hit it locally sometimes. It's a mayavi/VTK bug and generally the X3D is kind of unstable. However, it's better than nothing when in a pinch :)

@wmvanvliet
Copy link
Contributor Author

wmvanvliet commented May 21, 2019

You could also achieve this with PyVista

Time to rewrite pysurfer in pyvista? ;)

@wmvanvliet wmvanvliet changed the title Integrate better with Jupyuter notebook Integrate better with Jupyter notebook May 22, 2019
@larsoner
Copy link
Contributor

Time to rewrite pysurfer in pyvista? ;)

I know you were joking, but just in case you're curious -- we've had long discussions about this in #106 and #134. IIRC the consensus was basically that we should start some new neuro-3D-viz package that is more general, and less bound to Freesurfer conventions (but still provides what we need for working with FS).

To make some progress in MNE, @GuillaumeFavelier has made some progress implementing Mayavi alternatives (PyVista, ipyvolume, VisPy) for our basic 3D functionality such as plot_alignment working. One of the next big targets will be source estimate plotting (currently we use PySurfer for this). Once things actually work to some extent, it will probably make sense to spin this off into its own package.

@larsoner
Copy link
Contributor

In the meantime this is great, thanks @wmvanvliet

@larsoner larsoner merged commit 8b0d631 into nipy:master May 22, 2019
@mwaskom
Copy link
Member

mwaskom commented May 22, 2019

Thanks @wmvanvliet!

Tal-Golan added a commit to Tal-Golan/PySurfer that referenced this pull request Jun 24, 2019
Integrate better with Jupyter notebook (nipy#268)
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.

6 participants