.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/01_random_field/06_pyvista_support.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_01_random_field_06_pyvista_support.py: Using PyVista meshes -------------------- `PyVista `__ 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. .. GENERATED FROM PYTHON SOURCE LINES 15-20 .. code-block:: Python import pyvista as pv import gstools as gs .. GENERATED FROM PYTHON SOURCE LINES 22-24 We create a structured grid with PyVista containing 50 segments on all three axes each with a length of 2 (whatever unit). .. GENERATED FROM PYTHON SOURCE LINES 24-28 .. code-block:: Python dims, spacing = (50, 50, 50), (2, 2, 2) grid = pv.ImageData(dimensions=dims, spacing=spacing) .. GENERATED FROM PYTHON SOURCE LINES 29-30 Now we set up the SRF class as always. We'll use an anisotropic model. .. GENERATED FROM PYTHON SOURCE LINES 30-34 .. code-block:: Python model = gs.Gaussian(dim=3, len_scale=[16, 8, 4], angles=(0.8, 0.4, 0.2)) srf = gs.SRF(model, seed=19970221) .. GENERATED FROM PYTHON SOURCE LINES 35-41 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. .. GENERATED FROM PYTHON SOURCE LINES 41-44 .. code-block:: Python srf.mesh(grid, points="points", name="random-field") .. GENERATED FROM PYTHON SOURCE LINES 45-50 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. .. GENERATED FROM PYTHON SOURCE LINES 50-53 .. code-block:: Python # grid.contour(isosurfaces=8).plot() .. GENERATED FROM PYTHON SOURCE LINES 54-59 The result should look like this: .. image:: ../../pics/GS_pyvista_cut.png :width: 400px :align: center .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 3.862 seconds) .. _sphx_glr_download_examples_01_random_field_06_pyvista_support.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 06_pyvista_support.ipynb <06_pyvista_support.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 06_pyvista_support.py <06_pyvista_support.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 06_pyvista_support.zip <06_pyvista_support.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_