Controlling ParaView from Jupyter Notebook

June 30, 2020

We are happy to announce the release of a ParaView kernel for Jupyter notebooks [1] [2]!

Basically, creating a ParaView Notebook launches the ParaView GUI in background. Then, the whole API of ParaView is available from the Notebook. At this point, it is very similar to the standard Python shell. Below is a demonstration video.

Demonstration of our ParaView kernel for Jupyter Notebooks.

API to ease data manipulation

In addition, we created a simple Python API so numpy data can easily be added to the pipeline. The API includes:

  • create an empty grid;
  • create a grid from data;
  • add/remove data to a grid;
  • remove a grid;
  • get the current selection;
  • display screenshots (current View states) in the notebook.

For instance, the following notebook generate data with numpy and initialize a regular grid – see Fig. 1.

Figure 1 – A new source can be created and initialized from numpy array.

The dimensions of the resulting grid are set accordingly to the numpy array shape, and a PointData array is created with the data values – see Fig. 2.

Figure 2 – Resulting information panel

Then the ParaView API can be used to create visualization. Note the Display method to bring back screenshots in the cell output – see Fig. 3.

Figure 3 – Screenshots can be displayed inside the notebook.

Generating Notebooks from the GUI

In ParaView’s GUI, the Python Trace utility can be used to generate a python script. This feature records action from the GUI and creates a Python version of those actions. To ease creation of notebooks, we added a button in the toolbar to create a trace and transfer it to the current notebook – see Fig. 4.

Figure 4 – This last Notebook cell is the ParaView trace for creating a clip retrieved by clicking a button in the UI.

Technical information

This ParaView plugin implements Jupyter kernel based on the Xeus project [4]. It provides a kernel configuration file for Jupyter. In this configuration, the executable to be launch is ParaView, configured to load the plugin at startup. It uses environment environment variables to specify the plugin location and to initialize the Jupyter communication.

Also please note that current version does not work on Windows.

Next steps

Some features from notebook, such as widgets and magics could be useful but are not implemented yet. They may come in the future, stay tuned!

Acknowledgements

This work was supported by Total SA

Developments were done by Kitware SAS, France.

We wanted to thank the 3DSlicer team who worked on a similar project a few months ago [3], and helped us a lot to start the work.

Resources

[1] Kernel repository https://gitlab.kitware.com/paraview/paraviewjupyterkernel
[2] Jupyter main page https://jupyter.org/
[3] Slicer kernel announcement https://discourse.slicer.org/t/jupyter-notebooks-are-now-usable-in-3d-slicer/3438
[4] xeus https://xeus.readthedocs.io/en/latest/

5 comments to Controlling ParaView from Jupyter Notebook

  1. Hi, I have followed the installation step by step on Ubuntu 16.04.
    I installed Xeus with Conda, I compiled Paraview, I then download the Kernel and built it using cmake.

    But then, when I run it in Jupyter notebook, the Kernel connects and it seems to work, but when I run the Example DemoAPI, I am unable to run any command in it.
    When I run “from PVInterface import ” for example, the star [] appears but then do not dissapear. There is no error message whatsoever.
    Any idea what might go wrong and how to check?
    Thank you very much

    Cyprien

  2. Is this project still being developed or is it deprecated at this point? I am giving Python courses for Scientists and am currently planning a lecture on Jupyter – Paraview interoperability

      1. Thank you for the quick reply! Are you working together with the NVidia people for the ipyparaview project or are these basically two competing libraries?

        1. Those are different and independant projects: nvidia code (https://github.com/NVIDIA/ipyparaview) add a jupyter widget containing a ParaView view, in pure python. Our project aimed to be used together with a running ParaView client application, as you can do from the GUI with the embeded python shell.

Leave a Reply