.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/01_random_field/04_srf_merge.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_04_srf_merge.py: Merging two Fields ------------------ We can even generate the same field realisation on different grids. Let's try to merge two unstructured rectangular fields. .. GENERATED FROM PYTHON SOURCE LINES 9-24 .. code-block:: Python import numpy as np import gstools as gs # creating our own unstructured grid seed = gs.random.MasterRNG(19970221) rng = np.random.RandomState(seed()) x = rng.randint(0, 100, size=10000) y = rng.randint(0, 100, size=10000) model = gs.Exponential(dim=2, var=1, len_scale=[12, 3], angles=np.pi / 8) srf = gs.SRF(model, seed=20170519) field1 = srf((x, y)) srf.plot() .. image-sg:: /examples/01_random_field/images/sphx_glr_04_srf_merge_001.png :alt: Field 2D unstructured: (10000,) :srcset: /examples/01_random_field/images/sphx_glr_04_srf_merge_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 26-29 But now we extend the field on the right hand side by creating a new unstructured grid and calculating a field with the same parameters and the same seed on it: .. GENERATED FROM PYTHON SOURCE LINES 29-41 .. code-block:: Python # new grid seed = gs.random.MasterRNG(20011012) rng = np.random.RandomState(seed()) x2 = rng.randint(99, 150, size=10000) y2 = rng.randint(20, 80, size=10000) field2 = srf((x2, y2)) ax = srf.plot() ax.tricontourf(x, y, field1.T, levels=256) ax.set_aspect("equal") .. image-sg:: /examples/01_random_field/images/sphx_glr_04_srf_merge_002.png :alt: Field 2D unstructured: (10000,) :srcset: /examples/01_random_field/images/sphx_glr_04_srf_merge_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 42-50 The slight mismatch where the two fields were merged is merely due to interpolation problems of the plotting routine. You can convince yourself be increasing the resolution of the grids by a factor of 10. Of course, this merging could also have been done by appending the grid point ``(x2, y2)`` to the original grid ``(x, y)`` before generating the field. But one application scenario would be to generate hugh fields, which would not fit into memory anymore. .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.377 seconds) .. _sphx_glr_download_examples_01_random_field_04_srf_merge.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 04_srf_merge.ipynb <04_srf_merge.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 04_srf_merge.py <04_srf_merge.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 04_srf_merge.zip <04_srf_merge.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_