.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/07_transformations/02_discrete.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_07_transformations_02_discrete.py: Discrete fields --------------- Here we transform a field to a discrete field with values. If we do not give thresholds, the pairwise means of the given values are taken as thresholds. If thresholds are given, arbitrary values can be applied to the field. See :any:`transform.discrete` .. GENERATED FROM PYTHON SOURCE LINES 12-23 .. code-block:: Python import numpy as np import gstools as gs # Structured field with a size of 100x100 and a grid-size of 0.5x0.5 x = y = np.arange(200) * 0.5 model = gs.Gaussian(dim=2, var=1, len_scale=5) srf = gs.SRF(model, seed=20170519) srf.structured([x, y]) .. GENERATED FROM PYTHON SOURCE LINES 24-25 Create 5 equidistanly spaced values, thresholds are the arithmetic means .. GENERATED FROM PYTHON SOURCE LINES 25-30 .. code-block:: Python values1 = np.linspace(np.min(srf.field), np.max(srf.field), 5) srf.transform("discrete", store="f1", values=values1) srf.plot("f1") .. image-sg:: /examples/07_transformations/images/sphx_glr_02_discrete_001.png :alt: Field 2D structured: (200, 200) :srcset: /examples/07_transformations/images/sphx_glr_02_discrete_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 31-33 Calculate thresholds for equal shares but apply different values to the separated classes .. GENERATED FROM PYTHON SOURCE LINES 33-38 .. code-block:: Python values2 = [0, -1, 2, -3, 4] srf.transform("discrete", store="f2", values=values2, thresholds="equal") srf.plot("f2") .. image-sg:: /examples/07_transformations/images/sphx_glr_02_discrete_002.png :alt: Field 2D structured: (200, 200) :srcset: /examples/07_transformations/images/sphx_glr_02_discrete_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 39-41 Create user defined thresholds and apply different values to the separated classes .. GENERATED FROM PYTHON SOURCE LINES 41-46 .. code-block:: Python values3 = [0, 1, 10] thresholds = [-1, 1] srf.transform("discrete", store="f3", values=values3, thresholds=thresholds) srf.plot("f3") .. image-sg:: /examples/07_transformations/images/sphx_glr_02_discrete_003.png :alt: Field 2D structured: (200, 200) :srcset: /examples/07_transformations/images/sphx_glr_02_discrete_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.605 seconds) .. _sphx_glr_download_examples_07_transformations_02_discrete.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 02_discrete.ipynb <02_discrete.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 02_discrete.py <02_discrete.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 02_discrete.zip <02_discrete.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_