.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "tutorials/ch1_fundamentals/ch1_3c_topography.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_tutorials_ch1_fundamentals_ch1_3c_topography.py: 1.3c: Adding topography to geological models ============================================ .. GENERATED FROM PYTHON SOURCE LINES 8-13 .. code-block:: python3 import gempy as gp import numpy as np import matplotlib.pyplot as plt import os .. GENERATED FROM PYTHON SOURCE LINES 14-17 1. The common procedure to set up a model: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 19-27 .. code-block:: python3 data_path = 'https://raw.githubusercontent.com/cgre-aachen/gempy_data/master/' geo_model = gp.create_model('Single_layer_topo') gp.init_data(geo_model, extent=[450000, 460000, 70000, 80000, -1000, 500], resolution=[50, 50, 50], path_i=data_path + "/data/input_data/tut-ch1-7/onelayer_interfaces.csv", path_o=data_path + "/data/input_data/tut-ch1-7/onelayer_orient.csv") .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Active grids: ['regular'] Single_layer_topo 2021-04-18 11:28 .. GENERATED FROM PYTHON SOURCE LINES 28-29 use happy spring colors! .. GENERATED FROM PYTHON SOURCE LINES 29-31 .. code-block:: python3 geo_model.surfaces.colors.change_colors({'layer1': '#ff8000', 'basement': '#88cc60'}) .. GENERATED FROM PYTHON SOURCE LINES 32-34 .. code-block:: python3 gp.map_stack_to_surfaces(geo_model, {'series': ('layer1', 'basement')}) .. raw:: html
surface series order_surfaces color id
0 layer1 series 1 #ff8000 1
1 basement series 2 #88cc60 2


.. GENERATED FROM PYTHON SOURCE LINES 35-38 .. code-block:: python3 s = {'s1': ([450000, 75000], [460000, 75500], [100, 100])} geo_model.set_section_grid(s) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Active grids: ['regular' 'sections'] .. raw:: html
start stop resolution dist
s1 [450000, 75000] [460000, 75500] [100, 100] 10012.49


.. GENERATED FROM PYTHON SOURCE LINES 39-42 2. Adding topography ~~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 45-48 2 a. Load from raster file ^^^^^^^^^^^^^^^^^^^^^^^^^^ .. GENERATED FROM PYTHON SOURCE LINES 50-51 This is to make it work in sphinx gallery .. GENERATED FROM PYTHON SOURCE LINES 51-59 .. code-block:: python3 cwd = os.getcwd() if not 'examples' in cwd: path_dir = os.getcwd() + '/examples/tutorials/ch5_probabilistic_modeling' else: path_dir = cwd fp = path_dir + "/../../data/input_data/tut-ch1-7/bogota.tif" .. GENERATED FROM PYTHON SOURCE LINES 60-67 .. code-block:: python3 geo_model.set_topography(source='gdal', filepath=fp) gp.plot_2d(geo_model, show_topography=True, section_names=['topography'], show_lith=False, show_boundaries=False, kwargs_topography={'cmap': 'gray', 'norm': None} ) plt.show() .. image:: /tutorials/ch1_fundamentals/images/sphx_glr_ch1_3c_topography_001.png :alt: Geological map :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Cropped raster to geo_model.grid.extent. depending on the size of the raster, this can take a while... storing converted file... Active grids: ['regular' 'topography' 'sections'] .. GENERATED FROM PYTHON SOURCE LINES 68-71 2 b. create fun topography ^^^^^^^^^^^^^^^^^^^^^^^^^^ .. GENERATED FROM PYTHON SOURCE LINES 74-79 If there is no topography file, but you think that your model with topography would look significantly cooler, you can use gempys :meth:`set_topography ` function to generate a random topography based on a fractal grid: .. GENERATED FROM PYTHON SOURCE LINES 81-82 sphinx_gallery_thumbnail_number = 2 .. GENERATED FROM PYTHON SOURCE LINES 82-86 .. code-block:: python3 geo_model.set_topography(source='random') gp.plot_2d(geo_model, show_topography=True, section_names=['topography']) plt.show() .. image:: /tutorials/ch1_fundamentals/images/sphx_glr_ch1_3c_topography_002.png :alt: Geological map :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out Out: .. code-block:: none [200. 500.] Active grids: ['regular' 'topography' 'sections'] .. GENERATED FROM PYTHON SOURCE LINES 87-107 It has additional keywords to play around with: * fd: fractal dimension: defaults to 2.0. The higher (try 2.9), the rougher the landscape will be. * d\_z: height difference: If none, last 20% of the model in z direction. * extent: extent in xy direction. If none, ``geo_model.grid.extent`` is used. * resolution: resolution of the topography array. If none, ``geo_model.grid.resoution`` is used. Increasing the resolution leads to much nicer geological maps! .. GENERATED FROM PYTHON SOURCE LINES 109-112 .. code-block:: python3 geo_model.set_topography(source='random', fd=1.9, d_z=np.array([0, 250]), resolution=np.array([200, 200])) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Active grids: ['regular' 'topography' 'sections'] Grid Object. Values: array([[450100. , 70100. , -985. ], [450100. , 70100. , -955. ], [450100. , 70100. , -925. ], ..., [460000. , 75500. , 469.6969697 ], [460000. , 75500. , 484.84848485], [460000. , 75500. , 500. ]]) .. GENERATED FROM PYTHON SOURCE LINES 113-118 Note that each time this function is called, a new random topography is created. If you particularly like the generated topography or if you have loaded a large file with gdal, you can save the topography object and load it again later: .. GENERATED FROM PYTHON SOURCE LINES 120-121 save: .. GENERATED FROM PYTHON SOURCE LINES 121-123 .. code-block:: python3 geo_model._grid.topography.save('test_topo') .. GENERATED FROM PYTHON SOURCE LINES 124-125 load: .. GENERATED FROM PYTHON SOURCE LINES 125-127 .. code-block:: python3 geo_model.set_topography(source='saved', filepath='test_topo.npy') .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Active grids: ['regular' 'topography' 'sections'] Grid Object. Values: array([[450100. , 70100. , -985. ], [450100. , 70100. , -955. ], [450100. , 70100. , -925. ], ..., [460000. , 75500. , 469.6969697 ], [460000. , 75500. , 484.84848485], [460000. , 75500. , 500. ]]) .. GENERATED FROM PYTHON SOURCE LINES 128-131 Compute model ~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 133-135 .. code-block:: python3 gp.set_interpolator(geo_model) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Setting kriging parameters to their default values. Compiling theano function... Level of Optimization: fast_compile Device: cpu Precision: float64 Number of faults: 0 Compilation Done! Kriging values: values range 14221.46 $C_o$ 4815476.19 drift equations [3] .. GENERATED FROM PYTHON SOURCE LINES 136-138 .. code-block:: python3 gp.compute_model(geo_model, compute_mesh=False, set_solutions=True) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Lithology ids [2. 2. 2. ... 1. 1. 1.] .. GENERATED FROM PYTHON SOURCE LINES 139-145 Visualize: ^^^^^^^^^^ Now, the solutions object does also contain the computed geological map. It can be visualized using the 2D and 3D plotting functionality: .. GENERATED FROM PYTHON SOURCE LINES 147-151 .. code-block:: python3 gp.plot_2d(geo_model, show_topography=True, section_names=['topography'], show_boundaries=False, show_data=True) plt.show() .. image:: /tutorials/ch1_fundamentals/images/sphx_glr_ch1_3c_topography_003.png :alt: Geological map :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 152-155 .. code-block:: python3 gp.plot_2d(geo_model, show_topography=True, section_names=['s1']) plt.show() .. image:: /tutorials/ch1_fundamentals/images/sphx_glr_ch1_3c_topography_004.png :alt: s1 :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 156-163 .. code-block:: python3 g3d = gp.plot_3d(geo_model, show_topography=True, show_lith=False, show_surfaces=False, show_results=False, ve=5) .. image:: /tutorials/ch1_fundamentals/images/sphx_glr_ch1_3c_topography_005.png :alt: ch1 3c topography :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 164-165 sphinx_gallery_thumbnail_number = 3 .. GENERATED FROM PYTHON SOURCE LINES 165-169 .. code-block:: python3 g3d = gp.plot_3d(geo_model, show_topography=True, show_lith=True, show_surfaces=True, ve=5) .. image:: /tutorials/ch1_fundamentals/images/sphx_glr_ch1_3c_topography_006.png :alt: ch1 3c topography :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 13.109 seconds) .. _sphx_glr_download_tutorials_ch1_fundamentals_ch1_3c_topography.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: ch1_3c_topography.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: ch1_3c_topography.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_