.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/11_plurigaussian/04_3d_pgs.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_11_plurigaussian_04_3d_pgs.py: Creating a Three Dimensional PGS -------------------------------- Let's create a 3d PGS! This will mostly feel very familiar, but the plotting will be a bit more involved. .. GENERATED FROM PYTHON SOURCE LINES 8-22 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np import gstools as gs dim = 3 # no. of cells in all dimensions N = [40] * dim x = np.arange(N[0]) y = np.arange(N[1]) z = np.arange(N[2]) .. GENERATED FROM PYTHON SOURCE LINES 24-27 Because we want to create a 3d PGS, we have to generate 3 SRFs. If we are interested in even higher dimensions, we could solve this code repetition by using a loop... .. GENERATED FROM PYTHON SOURCE LINES 27-38 .. code-block:: Python model1 = gs.Gaussian(dim=dim, var=1, len_scale=[20, 10, 15]) srf1 = gs.SRF(model1) field1 = srf1.structured([x, y, z], seed=20170519) model2 = gs.Exponential(dim=dim, var=1, len_scale=[5, 5, 5]) srf2 = gs.SRF(model2) field2 = srf2.structured([x, y, z], seed=19970221) model3 = gs.Gaussian(dim=dim, var=1, len_scale=[7, 12, 18]) srf3 = gs.SRF(model3) field3 = srf3.structured([x, y, z], seed=20011012) .. GENERATED FROM PYTHON SOURCE LINES 39-41 The 3d lithotypes field will consist of a cube which contains one category and the surrounding is the second category. .. GENERATED FROM PYTHON SOURCE LINES 41-52 .. code-block:: Python # size of cube cube = [18] * dim lithotypes = np.zeros(N) lithotypes[ N[0] // 2 - cube[0] // 2 : N[0] // 2 + cube[0] // 2, N[1] // 2 - cube[1] // 2 : N[1] // 2 + cube[1] // 2, N[2] // 2 - cube[2] // 2 : N[2] // 2 + cube[2] // 2, ] = 1 .. GENERATED FROM PYTHON SOURCE LINES 53-54 With the three SRFs and the lithotypes ready, we can create the 3d PGS. .. GENERATED FROM PYTHON SOURCE LINES 54-71 .. code-block:: Python pgs = gs.PGS(dim, [field1, field2, field3]) P = pgs(lithotypes) # ############################################################################### # For ploting the 3d PGS, we will use [PyVista](https://pyvista.org/) which works # nicely together with GSTools. import pyvista as pv grid = pv.ImageData(dimensions=N) # uncomment, if you want to see lithotypes field, which is just a cube... # grid.point_data['lithotypes'] = np.meshgrid(lithotypes, indexing="ij")[0] # grid.plot(show_edges=True) grid.point_data["PGS"] = P.reshape(-1) .. GENERATED FROM PYTHON SOURCE LINES 72-76 .. note:: PyVista does not work on readthedocs, but you can try it out yourself by running the example yourself. You will get an interactive version of this screenshot. .. GENERATED FROM PYTHON SOURCE LINES 76-79 .. code-block:: Python # grid.contour(isosurfaces=8).plot() .. GENERATED FROM PYTHON SOURCE LINES 80-83 .. image:: ../../pics/3d_pgs.png :width: 400px :align: center .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 5.497 seconds) .. _sphx_glr_download_examples_11_plurigaussian_04_3d_pgs.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 04_3d_pgs.ipynb <04_3d_pgs.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 04_3d_pgs.py <04_3d_pgs.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 04_3d_pgs.zip <04_3d_pgs.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_