-
Notifications
You must be signed in to change notification settings - Fork 70
/
06_pyvista_support.py
58 lines (44 loc) · 2.19 KB
/
06_pyvista_support.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""
Using PyVista meshes
--------------------
`PyVista <https://www.pyvista.org>`__ is a helper module for the
Visualization Toolkit (VTK) that takes a different approach on interfacing with
VTK through NumPy and direct array access.
It provides mesh data structures and filtering methods for spatial datasets,
makes 3D plotting simple and is built for large/complex data geometries.
The :any:`Field.mesh` method enables easy field creation on PyVista meshes
used by the :any:`SRF` or :any:`Krige` class.
"""
# sphinx_gallery_thumbnail_path = 'pics/GS_pyvista_cut.png'
import pyvista as pv
import gstools as gs
###############################################################################
# We create a structured grid with PyVista containing 50 segments on all three
# axes each with a length of 2 (whatever unit).
dims, spacing = (50, 50, 50), (2, 2, 2)
grid = pv.ImageData(dimensions=dims, spacing=spacing)
###############################################################################
# Now we set up the SRF class as always. We'll use an anisotropic model.
model = gs.Gaussian(dim=3, len_scale=[16, 8, 4], angles=(0.8, 0.4, 0.2))
srf = gs.SRF(model, seed=19970221)
###############################################################################
# The PyVista mesh can now be directly passed to the :any:`SRF.mesh` method.
# When dealing with meshes, one can choose if the field should be generated
# on the mesh-points (`"points"`) or the cell-centroids (`"centroids"`).
#
# In addition we can set a name, under which the resulting field is stored
# in the mesh.
srf.mesh(grid, points="points", name="random-field")
###############################################################################
# Now we have access to PyVista's abundancy of methods to explore the field.
#
# .. note::
# PyVista is not working on readthedocs, but you can try it out yourself by
# uncommenting the following line of code.
# grid.contour(isosurfaces=8).plot()
###############################################################################
# The result should look like this:
#
# .. image:: https://github.com/GeoStat-Framework/GeoStat-Framework.github.io/raw/master/img/GS_pyvista_cut.png
# :width: 400px
# :align: center