Controlling ParaView from Jupyter Notebook: A New Version of the Plugin is available !
We are happy to announce the release of a new version of the ParaView kernel for Jupyter notebooks! This new version is intended to replace the previous integration presented in this blog).
This version is now based on IPython so all the features that you are familiar with, such as the concept of “magic commands”, are available (to learn more about magic commands, there is dedicated documentation).
How to launch
The plugin is available here. Once installed (instructions are available on the repository), you can simply launch it in the Jupyter notebook like any other python kernel.
Launching the kernel will automatically start a new ParaView server locally. Note that the server port is randomly chosen by default, but you can also control it thanks to a dedicated environment variable (see the documentation for more details).
Magic commands
In addition to standard IPython magic commands, the IParaView kernel introduces new ones that can be used to facilitate the interaction between the notebook, the GUI client(s) and the ParaView server.
The “%paraview” command
Launching a new ParaView GUI client is not bound to opening the notebook anymore, giving you more flexibility. You can open a new GUI client instance that connects to the ParaView server anytime by typing %paraview
in a cell of the notebook.
It is possible to open multiple clients this way. The magic command prints in the notebook the number (ID) of the GUI client that was created.
By default, the GUI clients do not have the control on the pipeline, because only one client at the time can make changes to it (note that they can however manipulate the camera freely). If you want to edit the pipeline from the GUI, you can use the dedicated button in the toolbar to set the current GUI client as “main client”.
Once all the changes are done, you can give the control back to the notebook by pressing the button again. A python trace showing all the changes made is also displayed. Note that unlike the previous version, the trace is not directly stored inside a notebook cell but in a variable called __pv.trace
instead. It is possible to use this variable in some interesting way through the builtin magic commands such as :
-
%pycat __pv.trace
: display the trace using a syntax-highlighted pager -
%load __pv.trace
: load the trace into the current cell
The “%interact”command
It is now possible to interact with the render view directly in the notebook! To do so, use the %interact
magic command in any cell.
This magic command replaces the Display
method that was used to render non-interactive views in the notebook in the previous version.
The “%sync” command
Use this magic command to synchronize the view between clients. By default, the main client is the Jupyter notebook, meaning that every change made in the Jupyter interactive widget is applied in real time to all opened GUI clients.
You can synchronize the camera of all clients with another using the %sync
magic command, followed by the ID of the “main” client. In the example below, to synchronize the Jupyter interactive view with the (first) GUI client you opened, we type %sync 2
.
Technical information
All of the specific features of the IParaView kernel are contained in an additional layer to the original IPython kernel. This extra layer takes the form of a python script that is executed automatically in the notebook when the kernel starts. This script contains the instructions to instantiate the ParaView server, create a default layout and render view, establish the connection and register the custom magic commands.
Acknowledgments
This work was supported by TotalEnergies SE.
Resources
- New kernel repository: https://gitlab.kitware.com/paraview/iparaview-kernel
- Jupyter main page: https://jupyter.org/
- IPython: https://ipython.readthedocs.io/en/stable/index.html
- ipyvtkklink: https://github.com/Kitware/ipyvtklink