Add vtki support to make using VTK data objects more Pythonic
- from pr #130
- commits from: @banesullivan
- review from: @lheagy
Add vtki support to make using VTK data objects more Pythonic
@banesullivan recently added a ton of new features to vtki
(the VTK interface Python package) that help make using just about any VTK data objects more intuitive/Pythonic. If vtki
is available in your Python environment then these changes make using VTK data objects way easier. Here's a screenshot of what this currently looks like in a Jupyter notebook (creates static renderings but can also be interactive in a separate pop-up window).
Also check out this notebook to see more ways to use PVGeo
, discretize
, and vtki
. Below is a screenshot of a simple use case:
Simple example
import discretize
import numpy as np
# Create a simple TensorMesh
h1 = np.linspace(.1, .5, 3)
h2 = np.linspace(.1, .5, 5)
h3 = np.linspace(.1, .5, 3)
mesh = discretize.TensorMesh([h1, h2, h3])
# Convert to VTK object and use vtki to render it
mesh.toVTK().plot(notebook=False)
Fancy example
Here we load the Laguna del Maule Bouguer Gravity example from the SimPEG docs.
This data scene was produced from the Laguna del Maule Bouguer Gravity example provided by Craig Miller (Maule volcanic field, Chile. Refer to Miller et al 2016 EPSL for full details.)
Miller, C. A., Williams-Jones, G., Fournier, D., & Witter, J. (2017). 3D gravity inversion and thermodynamic modelling reveal properties of shallow silicic magma reservoir beneath Laguna del Maule, Chile. Earth and Planetary Science Letters, 459, 14–27. https://doi.org/10.1016/j.epsl.2016.11.007
import shelve
import tarfile
import discretize
f = discretize.utils.download(
"https://storage.googleapis.com/simpeg/laguna_del_maule_slicer.tar.gz"
)
tar = tarfile.open(f, "r")
tar.extractall()
tar.close()
with shelve.open('./laguna_del_maule_slicer/laguna_del_maule-result') as db:
mesh = db['mesh']
Lpout = db['Lpout']
mesh = discretize.TensorMesh.copy(mesh)
models = {'Lpout':Lpout}
mesh.toVTK(models).plot()
Usage Notes
Since vtk
and vtki
are not required dependencies you'll need to make sure you install them to your Python environment. Pip install for vtki
should do the trick but Windows folks might need to install vtk
from conda seperately. Also this is Python 3 friendly!
pip installl vtki