nipy / PySurfer

Cortical neuroimaging visualization in Python
https://pysurfer.github.io/
BSD 3-Clause "New" or "Revised" License
239 stars 98 forks source link

Integrate better with Jupyter notebook #268

Closed wmvanvliet closed 5 years ago

wmvanvliet commented 5 years ago

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

codecov-io commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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

larsoner commented 5 years ago

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 commented 5 years ago

You could also achieve this with PyVista. Cross-post from https://github.com/pyvista/pyvista/issues/146#issuecomment-494406647

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 commented 5 years ago

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

larsoner commented 5 years ago

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 commented 5 years ago

neat @wmvanvliet !

wmvanvliet commented 5 years ago

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 commented 5 years ago

You could also achieve this with PyVista

Time to rewrite pysurfer in pyvista? ;)

larsoner commented 5 years ago

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 commented 5 years ago

In the meantime this is great, thanks @wmvanvliet

mwaskom commented 5 years ago

Thanks @wmvanvliet!