![]() |
Sapphire++
v1.3.0-121-g2682132 |
Often, we need to produce the same plots for multiple datasets or perform additional manipulations on the data, such as calculating the spectral index. A common approach is to use Python for these tasks, often in combination with matplotlib for visualization. Unfortunately, the output of Sapphire++ is not straightforward to manipulate. See the discussion on discontinuous Galerkin on the next page. Therefore, we discourage directly reading the Sapphire++ results in Python. Instead, we recommend using tools like ParaView and VisIt that can handle these subtleties. However, relying on a graphical user interface (GUI) to create repetitive plots or perform detailed analysis can be cumbersome and disrupt existing workflows. Fortunately, ParaView comes with a Python interface that can bridge this gap.
The ParaView Python interface has two main aspects:
Both executables come installed with ParaView. Unfortunately, including other Python packages with these interpreters is not straightforward. (See here for how to use the ParaView Python package outside pvpython.) Using an installation with conda/conda-forge simplifies this by linking ParaView and the Python environment.
To get started with ParaView Python, we provide some scripts as a starting point. These scripts mainly serve to reproduce the plots in the examples but also introduce some advanced concepts. We illustrate their usage using the quick-start example. The script for the quick-start is located at scripts/plot-quick-start.py. This script takes the path to the results, i.e., /path/to/sapphirepp/results/01, either as a command line argument or as prompted input from the user. It loads the data from that folder, reproduces the plots from the ParaView Tutorial, and saves them as .png files in the same folder. This script can be executed in multiple ways:
Execute the script and provide the results path as a command line argument:
Execute the script and provide the results path as a command line argument:
The script creates a 2D plot quick-start-2D.png, as well as an animated time series, quick-start-2D.0000-0200.png. To convert this into an animated .gif, you can use ImageMagick Convert:
The f(x) and f(p) plots created in the ParaView tutorial are saved as quick-start-f-x.png and quick-start-f-p.png, respectively. Additionally, the underlying PlotOverLine data is saved as csv files, quick-start-f-x.csv and quick-start-f-p.csv. This 1D data can be used for further analysis, as ParaView has already interpolated the data and tabulated it in an easy-to-understand format. However, be aware of the quirks of the PlotOverLine feature, as discussed on the next page.
Last, the script also calculates the spectral index \(s\): Spectral Index: s = -4.049119472503662. This section in the plot-quick-start.py script serves as an introduction on how to combine NumPy with ParaView. It utilizes the vtk.util.numpy_support package to facilitate the conversion between VTK and NumPy arrays.
If your plots are similar to those in the quick-start or examples, you can use the provided scripts and adapt them to your needs. However, if you need to create a different kind of plot or a new pipeline, you will likely want to create a new script. Be aware that the ParaView Python package can be a bit unintuitive to use. It is better to think of it as a remote control to manipulate the ParaView GUI rather than an independent scripting language. Therefore, we recommend using the trace feature to create new scripts:
To further familiarize yourself with ParaView Python, we refer to the relevant chapters in the ParaView User's Guide and the ParaView Reference Manual, as well as the following tutorials: Batch Python Scripting and Python & Batch: ParaView & Python. The documentation for the Python interface of the ParaView filters can be found here: paraview.simple documentation.
Since the ParaView Python interface can be quite cumbersome, we develop a Python plotting library to simplify the process, sapphireppplot. Most of the examples use this package to create the plots. For more information refer to the Sapphire++ – Plot webpage and the GitHub repository.