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

ENH: Notebook 3d backend improvements (ipyvtklink) #8704

Closed
7 of 11 tasks
GuillaumeFavelier opened this issue Jan 7, 2021 · 10 comments
Closed
7 of 11 tasks

ENH: Notebook 3d backend improvements (ipyvtklink) #8704

GuillaumeFavelier opened this issue Jan 7, 2021 · 10 comments
Assignees

Comments

@GuillaumeFavelier
Copy link
Contributor

GuillaumeFavelier commented Jan 7, 2021

I open this issue following #8503 (comment) to keep track of the missing features or anything that could be improved.

Feature status

Design/UX


Known issues

Resolved

JupyterLab

  • matplotlib is not interactive Javascript Error: IPython is not defined
  • The mesh is translucent
  • A VTK window opens on local instance

Google Colab


A testing notebook is available on gist.github.com.

@GuillaumeFavelier GuillaumeFavelier self-assigned this Jan 7, 2021
@GuillaumeFavelier GuillaumeFavelier changed the title Notebook improvements Notebook 3d backend improvements (ipyvtk) Jan 7, 2021
@GuillaumeFavelier
Copy link
Contributor Author

About Google Colab, I made some research @agramfort.

Considering that ipyvtk_simple's main viewer class, ViewInteractiveWidget, is based on ipycanvas's Canvas widget, I found that it is a known issue. The short answer is (and I quote Martin Renou):

Custom widgets libraries are not supported by Google colab yet

We could track the progress on this matter on https://github.com/martinRenou/ipycanvas/issues/170 or more directly in googlecolab/colabtools#498.

Anyway, I think those need to be resolved before more can be expected from ipyvtk_simple and finally mne-python.

@larsoner
Copy link
Member

larsoner commented Jan 7, 2021

For movie and autoplay I think you basically need a timer, e.g. https://stackoverflow.com/questions/57255394/jupyter-and-timer-functions

For a screenshot it seems like it should be fairly easy since the ipyvtk_simple is sending bitmaps, and/or we should be able to get the Renderer directly and get the image from it

For label time course do you need more than https://ipywidgets.readthedocs.io/en/latest/examples/Widget%20List.html#Dropdown ?

For sizing I think it's https://ipywidgets.readthedocs.io/en/latest/examples/Widget%20Styling.html

@GuillaumeFavelier
Copy link
Contributor Author

Exactly what I was looking for, thank you @larsoner 👍

@GuillaumeFavelier GuillaumeFavelier changed the title Notebook 3d backend improvements (ipyvtk) ENH: Notebook 3d backend improvements (ipyvtk) Feb 3, 2021
@GuillaumeFavelier
Copy link
Contributor Author

The mouse events on Firefox might be fixed by Kitware/ipyvtklink#25. I'll open a PR and give it a try.

@GuillaumeFavelier
Copy link
Contributor Author

It might not be necessary, I don't have those issues anymore on Firefox 87.0

@GuillaumeFavelier
Copy link
Contributor Author

For Jupyter Lab integration it might worth trying again once pyvista/pyvista#1116 is fixed.

@GuillaumeFavelier
Copy link
Contributor Author

Quick update: ipycanvas now works on Google Colab. It's a big milestone for the notebook 3d backend.

https://github.com/martinRenou/ipycanvas/issues/170#issuecomment-1062071346

I'll check ipyvtklink and report back in here.

@agramfort
Copy link
Member

agramfort commented Mar 9, 2022 via email

@GuillaumeFavelier GuillaumeFavelier changed the title ENH: Notebook 3d backend improvements (ipyvtk) ENH: Notebook 3d backend improvements (ipyvtklink) Mar 9, 2022
@GuillaumeFavelier
Copy link
Contributor Author

GuillaumeFavelier commented Mar 9, 2022

Although now ipycanvas is supported on Google Colab, vtk, even on notebook, still requires a running X server.

My testing workflow is: ipycanvas ✔️ -> ipyvtklink ✔️ -> pyvista (ipyvtklink) ✔️ -> mne-python (notebook)

It's a work in progress but I managed to get it working at low resolution, which is already amazing IMO.
Here is a modified version of ipyvtklink's default example:

output.mp4

The important points:

  1. setting the custom widget manager
from google.colab import output
output.enable_custom_widget_manager()
  1. setting up xvfb
!sudo apt update
!sudo apt-get install libgl1-mesa-dev xvfb
!sudo apt install -yqq libxkbcommon-x11-0 libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-randr0 libxcb-render-util0 libxcb-xinerama0 libxcb-xfixes0 libopengl0
  1. start xvfb with the correct DISPLAY variable at the beginning of the cell
!/sbin/start-stop-daemon --start --quiet --background --exec /usr/bin/Xvfb -- :99 -screen 0 800x600x24 -ac +extension GLX +render -noreset

import os
os.environ['DISPLAY'] = ':99'

Note:
I tested on Mozilla Firefox 97.0.2.

Known issues:
I encountered a bug where I have to change the size of the viewer explicitly to re-render.

@larsoner
Copy link
Member

larsoner commented Oct 1, 2023

I think we can close this now that the notebook seems to be working correctly (even nowadays with trame)

@larsoner larsoner closed this as completed Oct 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants