Example 27 - Planar Dipping Layers#

This example will show how to convert the geological map below using GemGIS to a GemPy model. This example is based on digitized data. The area is 1187 m wide (W-E extent) and 1400 m high (N-S extent). The vertical model extents varies between 0 m and 600 m. The model represents two planar stratigraphic units (blue and red) dipping towards the western and southwestern directions above an unspecified basement (yellow). The map has been georeferenced with QGIS. The stratigraphic boundaries were digitized in QGIS. Strikes lines were digitized in QGIS as well and were used to calculate orientations for the GemPy model. These will be loaded into the model directly. The contour lines were also digitized and will be interpolated with GemGIS to create a topography for the model.

Map Source: Unknown

[1]:
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
img = mpimg.imread('../images/cover_example27.png')
plt.figure(figsize=(10, 10))
imgplot = plt.imshow(img)
plt.axis('off')
plt.tight_layout()
../../_images/getting_started_example_example27_2_0.png

Licensing#

Computational Geosciences and Reservoir Engineering, RWTH Aachen University, Authors: Alexander Juestel. For more information contact: alexander.juestel(at)rwth-aachen.de

This work is licensed under a Creative Commons Attribution 4.0 International License (http://creativecommons.org/licenses/by/4.0/)

Import GemGIS#

If you have installed GemGIS via pip or conda, you can import GemGIS like any other package. If you have downloaded the repository, append the path to the directory where the GemGIS repository is stored and then import GemGIS.

[2]:
import warnings
warnings.filterwarnings("ignore")
import gemgis as gg

Importing Libraries and loading Data#

All remaining packages can be loaded in order to prepare the data and to construct the model. The example data is downloaded from an external server using pooch. It will be stored in a data folder in the same directory where this notebook is stored.

[3]:
import geopandas as gpd
import rasterio
[4]:
file_path = 'data/example27/'
gg.download_gemgis_data.download_tutorial_data(filename="example27_planar_dipping_layers.zip", dirpath=file_path)

Creating Digital Elevation Model from Contour Lines#

The digital elevation model (DEM) will be created by interpolating contour lines digitized from the georeferenced map using the SciPy Radial Basis Function interpolation wrapped in GemGIS. The respective function used for that is gg.vector.interpolate_raster().

[5]:
img = mpimg.imread('../images/dem_example27.png')
plt.figure(figsize=(10, 10))
imgplot = plt.imshow(img)
plt.axis('off')
plt.tight_layout()
../../_images/getting_started_example_example27_10_0.png
[6]:
topo = gpd.read_file(file_path + 'topo27.shp')
topo.head()
[6]:
id Z geometry
0 None 300 LINESTRING (2.817 1234.197, 25.768 1257.148, 5...
1 None 350 LINESTRING (4.116 1001.226, 21.004 1029.373, 5...
2 None 350 LINESTRING (4.116 730.148, 47.852 706.764, 92....
3 None 300 LINESTRING (2.817 617.992, 45.687 591.144, 85....
4 None 500 LINESTRING (292.732 981.956, 305.723 995.271, ...

Interpolating the contour lines#

[7]:
topo_raster = gg.vector.interpolate_raster(gdf=topo, value='Z', method='rbf', res=10)

Plotting the raster#

[8]:
import matplotlib.pyplot as plt

fix, ax = plt.subplots(1, figsize=(10, 10))
topo.plot(ax=ax, aspect='equal', column='Z', cmap='gist_earth')
im = plt.imshow(topo_raster, origin='lower', extent=[0, 1187, 0, 1400], cmap='gist_earth')
cbar = plt.colorbar(im)
cbar.set_label('Altitude [m]')
plt.xlabel('X [m]')
plt.ylabel('Y [m]')
plt.xlim(0, 1187)
plt.ylim(0, 1400)
[8]:
(0.0, 1400.0)
../../_images/getting_started_example_example27_15_1.png

Saving the raster to disc#

After the interpolation of the contour lines, the raster is saved to disc using gg.raster.save_as_tiff(). The function will not be executed as a raster is already provided with the example data.

gg.raster.save_as_tiff(raster=topo_raster, path=file_path + 'raster27.tif', extent=[0, 1187, 0, 1400], crs='EPSG:4326', overwrite_file=True)

Opening Raster#

The previously computed and saved raster can now be opened using rasterio.

[9]:
topo_raster = rasterio.open(file_path + 'raster27.tif')

Interface Points of stratigraphic boundaries#

The interface points will be extracted from LineStrings digitized from the georeferenced map using QGIS. It is important to provide a formation name for each layer boundary. The vertical position of the interface point will be extracted from the digital elevation model using the GemGIS function gg.vector.extract_xyz(). The resulting GeoDataFrame now contains single points including the information about the respective formation.

[10]:
img = mpimg.imread('../images/interfaces_example27.png')
plt.figure(figsize=(10, 10))
imgplot = plt.imshow(img)
plt.axis('off')
plt.tight_layout()
../../_images/getting_started_example_example27_21_0.png
[11]:
interfaces = gpd.read_file(file_path + 'interfaces27.shp')
interfaces.head()
[11]:
id formation geometry
0 None S LINESTRING (4.008 1189.324, 55.403 1194.683, 9...
1 None R LINESTRING (2.059 1215.631, 74.890 1221.964, 1...

Extracting Z coordinate from Digital Elevation Model#

[12]:
interfaces_coords = gg.vector.extract_xyz(gdf=interfaces, dem=topo_raster)
interfaces_coords
[12]:
formation geometry X Y Z
0 S POINT (4.008 1189.324) 4.01 1189.32 312.04
1 S POINT (55.403 1194.683) 55.40 1194.68 324.30
2 S POINT (98.273 1194.926) 98.27 1194.93 339.27
3 S POINT (154.784 1192.491) 154.78 1192.49 359.42
4 S POINT (209.833 1185.427) 209.83 1185.43 377.76
... ... ... ... ... ...
148 R POINT (738.890 160.683) 738.89 160.68 302.06
149 R POINT (762.031 119.275) 762.03 119.27 324.07
150 R POINT (774.453 67.148) 774.45 67.15 343.90
151 R POINT (777.620 26.470) 777.62 26.47 358.34
152 R POINT (778.107 1.382) 778.11 1.38 361.61

153 rows × 5 columns

Plotting the Interface Points#

[13]:
fig, ax = plt.subplots(1, figsize=(10, 10))

interfaces.plot(ax=ax, column='formation', legend=True, aspect='equal')
interfaces_coords.plot(ax=ax, column='formation', legend=True, aspect='equal')
plt.grid()
plt.xlabel('X [m]')
plt.ylabel('Y [m]')
plt.xlim(0, 1187)
plt.ylim(0, 1400)
[13]:
(0.0, 1400.0)
../../_images/getting_started_example_example27_26_1.png

Orientations from Strike Lines#

Strike lines connect outcropping stratigraphic boundaries (interfaces) of the same altitude. In other words: the intersections between topographic contours and stratigraphic boundaries at the surface. The height difference and the horizontal difference between two digitized lines is used to calculate the dip and azimuth and hence an orientation that is necessary for GemPy. In order to calculate the orientations, each set of strikes lines/LineStrings for one formation must be given an id number next to the altitude of the strike line. The id field is already predefined in QGIS. The strike line with the lowest altitude gets the id number 1, the strike line with the highest altitude the the number according to the number of digitized strike lines. It is currently recommended to use one set of strike lines for each structural element of one formation as illustrated.

[14]:
img = mpimg.imread('../images/orientations_example27.png')
plt.figure(figsize=(10, 10))
imgplot = plt.imshow(img)
plt.axis('off')
plt.tight_layout()
../../_images/getting_started_example_example27_28_0.png
[15]:
strikes = gpd.read_file(file_path + 'strikes27.shp')
strikes
[15]:
id formation Z geometry
0 1 S1 250 LINESTRING (163.553 475.146, 133.349 358.227)
1 2 S1 300 LINESTRING (320.906 542.374, 246.858 248.129)
2 3 S1 350 LINESTRING (512.848 689.497, 378.391 133.159)
3 1 R1 200 LINESTRING (663.380 498.529, 613.203 359.201)
4 2 R1 250 LINESTRING (810.503 639.319, 687.738 272.000)
5 3 R1 300 LINESTRING (938.139 735.777, 738.403 167.747)
6 4 R1 350 LINESTRING (1089.159 979.358, 777.376 39.137)
7 4 S2 500 LINESTRING (707.225 1180.068, 842.656 1093.353)
8 3 S2 450 LINESTRING (576.666 1159.607, 816.349 957.922)
9 2 S2 400 LINESTRING (338.931 1169.350, 687.738 852.696)
10 1 S2 350 LINESTRING (122.632 1193.708, 511.386 689.009)
11 3 R2 400 LINESTRING (705.276 1323.293, 1127.158 1232.681)
12 2 R2 350 LINESTRING (522.104 1273.603, 1094.031 995.921)
13 1 R2 300 LINESTRING (174.271 1230.733, 941.062 738.700)

Calculating Orientations for each formation#

[16]:
orientations_r1 = gg.vector.calculate_orientations_from_strike_lines(gdf=strikes[strikes['formation'] == 'R1'].sort_values(by='id', ascending=True).reset_index())
orientations_r1
[16]:
dip azimuth Z geometry polarity formation X Y
0 27.78 288.65 225.00 POINT (693.706 442.262) 1.00 R1 693.71 442.26
1 31.26 289.11 275.00 POINT (793.696 453.711) 1.00 R1 793.70 453.71
2 36.87 288.62 325.00 POINT (885.769 480.505) 1.00 R1 885.77 480.50
[17]:
orientations_r2 = gg.vector.calculate_orientations_from_strike_lines(gdf=strikes[strikes['formation'] == 'R2'].sort_values(by='id', ascending=True).reset_index())
orientations_r2
[17]:
dip azimuth Z geometry polarity formation X Y
0 12.59 210.56 325.00 POINT (682.867 1059.739) 1.00 R2 682.87 1059.74
1 21.85 201.78 375.00 POINT (862.142 1206.375) 1.00 R2 862.14 1206.37
[18]:
orientations_s1 = gg.vector.calculate_orientations_from_strike_lines(gdf=strikes[strikes['formation'] == 'S1'].sort_values(by='id', ascending=True).reset_index())
orientations_s1
[18]:
dip azimuth Z geometry polarity formation X Y
0 20.16 284.17 275.00 POINT (216.166 405.969) 1.00 S1 216.17 405.97
1 18.21 283.70 325.00 POINT (364.751 403.289) 1.00 S1 364.75 403.29
[19]:
orientations_s2 = gg.vector.calculate_orientations_from_strike_lines(gdf=strikes[strikes['formation'] == 'S2'].sort_values(by='id', ascending=True).reset_index())
orientations_s2
[19]:
dip azimuth Z geometry polarity formation X Y
0 17.72 228.97 375.00 POINT (415.172 976.191) 1.00 S2 415.17 976.19
1 18.14 221.58 425.00 POINT (604.921 1034.894) 1.00 S2 604.92 1034.89
2 26.63 218.55 475.00 POINT (735.724 1097.738) 1.00 S2 735.72 1097.74

Merging Orientations#

[20]:
import pandas as pd
orientations = pd.concat([orientations_r1, orientations_r2, orientations_s1, orientations_s2])
orientations['formation'] = ['R', 'R', 'R', 'R', 'R', 'S', 'S', 'S', 'S', 'S', ]
orientations = orientations[orientations['formation'].isin(['R', 'S'])].reset_index()
orientations
[20]:
index dip azimuth Z geometry polarity formation X Y
0 0 27.78 288.65 225.00 POINT (693.706 442.262) 1.00 R 693.71 442.26
1 1 31.26 289.11 275.00 POINT (793.696 453.711) 1.00 R 793.70 453.71
2 2 36.87 288.62 325.00 POINT (885.769 480.505) 1.00 R 885.77 480.50
3 0 12.59 210.56 325.00 POINT (682.867 1059.739) 1.00 R 682.87 1059.74
4 1 21.85 201.78 375.00 POINT (862.142 1206.375) 1.00 R 862.14 1206.37
5 0 20.16 284.17 275.00 POINT (216.166 405.969) 1.00 S 216.17 405.97
6 1 18.21 283.70 325.00 POINT (364.751 403.289) 1.00 S 364.75 403.29
7 0 17.72 228.97 375.00 POINT (415.172 976.191) 1.00 S 415.17 976.19
8 1 18.14 221.58 425.00 POINT (604.921 1034.894) 1.00 S 604.92 1034.89
9 2 26.63 218.55 475.00 POINT (735.724 1097.738) 1.00 S 735.72 1097.74

Plotting the Orientations#

[21]:
fig, ax = plt.subplots(1, figsize=(10, 10))

interfaces.plot(ax=ax, column='formation', legend=True, aspect='equal')
interfaces_coords.plot(ax=ax, column='formation', legend=True, aspect='equal')
orientations.plot(ax=ax, color='red', aspect='equal')
plt.grid()
plt.xlabel('X [m]')
plt.ylabel('Y [m]')
plt.xlim(0, 1187)
plt.ylim(0, 1400)
[21]:
(0.0, 1400.0)
../../_images/getting_started_example_example27_38_1.png

GemPy Model Construction#

The structural geological model will be constructed using the GemPy package.

[22]:
import gempy as gp
WARNING (theano.configdefaults): g++ not available, if using conda: `conda install m2w64-toolchain`
WARNING (theano.configdefaults): g++ not detected ! Theano will be unable to execute optimized C-implementations (for both CPU and GPU) and will default to Python implementations. Performance will be severely degraded. To remove this warning, set Theano flags cxx to an empty string.
WARNING (theano.tensor.blas): Using NumPy C-API based implementation for BLAS functions.

Creating new Model#

[23]:
geo_model = gp.create_model('Model27')
geo_model
[23]:
Model27  2022-04-12 08:07

Initiate Data#

[24]:
gp.init_data(geo_model, [0, 1187, 0, 1400, 0, 600], [100, 100, 100],
             surface_points_df=interfaces_coords,
             orientations_df=orientations,
             default_values=True)
Active grids: ['regular']
[24]:
Model27  2022-04-12 08:07

Model Surfaces#

[25]:
geo_model.surfaces
[25]:
surface series order_surfaces color id
0 S Default series 1 #015482 1
1 R Default series 2 #9f0052 2

Mapping the Stack to Surfaces#

[26]:
gp.map_stack_to_surfaces(geo_model,
                         {'Strata1': ('S'),
                          'Strata2': ('R')},
                         remove_unused_series=True)
geo_model.add_surfaces('C')
[26]:
surface series order_surfaces color id
0 S Strata1 1 #015482 1
1 R Strata2 1 #9f0052 2
2 C Strata2 2 #ffbe00 3

Showing the Number of Data Points#

[27]:
gg.utils.show_number_of_data_points(geo_model=geo_model)
[27]:
surface series order_surfaces color id No. of Interfaces No. of Orientations
0 S Strata1 1 #015482 1 78 5
1 R Strata2 1 #9f0052 2 75 5
2 C Strata2 2 #ffbe00 3 0 0

Loading Digital Elevation Model#

[28]:
geo_model.set_topography(source='gdal', filepath=file_path + 'raster27.tif')
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']
[28]:
Grid Object. Values:
array([[   5.935     ,    7.        ,    3.        ],
       [   5.935     ,    7.        ,    9.        ],
       [   5.935     ,    7.        ,   15.        ],
       ...,
       [1182.01260504, 1375.        ,  413.17556763],
       [1182.01260504, 1385.        ,  413.9055481 ],
       [1182.01260504, 1395.        ,  414.4772644 ]])

Plotting Input Data#

[29]:
gp.plot_2d(geo_model, direction='z', show_lith=False, show_boundaries=False)
plt.grid()
../../_images/getting_started_example_example27_54_0.png
[30]:
gp.plot_3d(geo_model, image=False, plotter_type='basic', notebook=True)
../../_images/getting_started_example_example27_55_0.png
[30]:
<gempy.plot.vista.GemPyToVista at 0x145e8c08490>

Setting the Interpolator#

[31]:
gp.set_interpolator(geo_model,
                    compile_theano=True,
                    theano_optimizer='fast_compile',
                    verbose=[],
                    update_kriging=False
                    )
Compiling theano function...
Level of Optimization:  fast_compile
Device:  cpu
Precision:  float64
Number of faults:  0
Compilation Done!
Kriging values:
                   values
range            1931.05
$C_o$           88784.98
drift equations   [3, 3]
[31]:
<gempy.core.interpolator.InterpolatorModel at 0x145e1456c70>

Computing Model#

[32]:
sol = gp.compute_model(geo_model, compute_mesh=True)

Plotting Cross Sections#

[33]:
gp.plot_2d(geo_model, direction=['x', 'x', 'y', 'y'], cell_number=[25, 75, 25, 75], show_topography=True, show_data=False)
[33]:
<gempy.plot.visualization_2d.Plot2D at 0x1458f9bab20>
../../_images/getting_started_example_example27_61_1.png
[34]:
gpv = gp.plot_3d(geo_model, image=False, show_topography=True,
                 plotter_type='basic', notebook=True, show_lith=True)
../../_images/getting_started_example_example27_62_0.png
[ ]: