Post-processing Lethe with PyVista#
Lethe has a post-processing module written in Python based on Lethe users specific needs. lethe_pyvista_tools was conceived to optimize the reading and post-treatment of Lethe data using Python.
The module is powered by PyVista, a powerful 3D plotting and mesh analysis tool. It is a pythonic interface to deal with Visualization Toolkit (VTK) data. The module also uses the powerful multiprocessing Python library to increase post-processing speed by running tasks in multiple processors.
Warning
For lethe_pyvista_tools to work, along with Python 3, the following libraries are needed: os, NumPy, PyVista, tqdm, matplotlib, SciPy, and scikit-learn. If any of the modules are missing, use pip to install it by running pip3 install $NAME_OF_THE_MODULE
on the terminal. Alternatively, use the requirements.txt
file and install them all at once running pip install -r requirements.txt
located at contrib/postprocessing/
.
Importing lethe_pyvista_tools#
There are two ways to have access to lethe_pyvista_tools
: you can install the module and have it on your machine just like os
, sys
, or other PyPi modules; or, you can use it without installing. Here, we explain how to do both.
Installing#
Installing lethe_pyvista_tools
is very simple. In the contrib/postprocessing of your Lethe version you will find all source files, including setup.py
and requirements.txt
. Those two files take care of configuring your installation and assuring that everything is set correctly. To install it, navigate to contrib/postprocessing on your terminal and run:
pip3 install .
or
pip install .
Note
If you do not have pip
on your machine, run sudo apt install python3-pip
.
Tip
Uninstalling lethe_pyvista_tools
is exactly like doing so with any other library: pip3 uninstall lethe_pyvista_tools
or pip3 uninstall lethe_pyvista_tools
.
Importing without installing#
In this case, we use the sys module to import it directly from Lethe’s directory into a python session:
import sys
path_to_module = '$LETHE_PATH/contrib/postprocessing/'
sys.path.append(path_to_module)
from lethe_pyvista_tools import *
import matplotlib.pyplot as plt
where sys.path is a list of strings that specifies the search path for modules. Another option is to simply copy the lethe_pyvista_tools.py file to the same folder as the Python post-processing script, and import it as follows:
from lethe_pyvista_tools import *
One third and very convenient way to always import the module without copying it or even adding the sys.path.append(path_to_module)
is permanently adding the path to the module (i.e., /contrib/postprocessing/
) to your PYTHONPATH.
The *
means that we want to import all members of lethe_pyvista_tools.
Using lethe_pyvista_tools#
To get quick-started, follow the hand-on Small Scale Rotating Drum Post-processing example. It has a detailed explanation on how to use the module. You can also start with a “raw” template file, check this example file.