Example 32 - Folded 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 601 m wide (W-E extent) and 705 m high (N-S extent). The vertical model extents varies between 0 m and 300 m. The model represents two folded stratigraphic units (blue and red) 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_example32.png')
plt.figure(figsize=(10, 10))
imgplot = plt.imshow(img)
plt.axis('off')
plt.tight_layout()
../../_images/getting_started_example_example32_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/example32/'
gg.download_gemgis_data.download_tutorial_data(filename="example32_folded_layers.zip", dirpath=file_path)
Downloading file 'example32_folded_layers.zip' from 'https://rwth-aachen.sciebo.de/s/AfXRsZywYDbUF34/download?path=%2Fexample32_folded_layers.zip' to 'C:\Users\ale93371\Documents\gemgis\docs\getting_started\example\data\example32'.

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_example32.png')
plt.figure(figsize=(10, 10))
imgplot = plt.imshow(img)
plt.axis('off')
plt.tight_layout()
../../_images/getting_started_example_example32_10_0.png
[6]:
topo = gpd.read_file(file_path + 'topo32.shp')
topo['Z'] = topo['Z']*0.425
topo.head()
[6]:
id Z geometry
0 None 170.00 LINESTRING (0.994 52.851, 36.954 48.266, 68.32...
1 None 148.75 LINESTRING (1.235 98.706, 42.022 94.603, 80.39...
2 None 127.50 LINESTRING (1.477 157.955, 44.435 147.818, 81....
3 None 127.50 LINESTRING (1.597 320.738, 11.492 310.722, 22....
4 None 106.25 LINESTRING (553.299 3.497, 534.233 30.527, 513...

Interpolating the contour lines#

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

Plotting the raster#

[8]:
import matplotlib.pyplot as plt

from mpl_toolkits.axes_grid1 import make_axes_locatable

fig, ax = plt.subplots(1, figsize=(10, 10))
topo.plot(ax=ax, aspect='equal', column='Z', cmap='gist_earth')
im = ax.imshow(topo_raster, origin='lower', extent=[0, 601, 0, 705], cmap='gist_earth')
divider = make_axes_locatable(ax)
cax = divider.append_axes("right", size="5%", pad=0.05)
cbar = plt.colorbar(im, cax=cax)
cbar.set_label('Altitude [m]')
ax.set_xlabel('X [m]')
ax.set_ylabel('Y [m]')
ax.set_xlim(0, 601)
ax.set_ylim(0, 705)
[8]:
(0.0, 705.0)
../../_images/getting_started_example_example32_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 + 'raster32.tif', extent=[0, 601, 0, 705], 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 + 'raster32.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_example32.png')
plt.figure(figsize=(10, 10))
imgplot = plt.imshow(img)
plt.axis('off')
plt.tight_layout()
../../_images/getting_started_example_example32_21_0.png
[11]:
interfaces = gpd.read_file(file_path + 'interfaces32.shp')
interfaces.head()
[11]:
id formation geometry
0 None Schluffstein LINESTRING (256.467 1.534, 255.813 23.321, 262...
1 None Tonstein LINESTRING (217.032 1.534, 216.378 56.656, 215...
2 None Tonstein LINESTRING (228.797 703.524, 221.389 657.117, ...
3 None Schluffstein LINESTRING (303.746 703.307, 287.405 688.273, ...

Extracting Z coordinate from Digital Elevation Model#

[12]:
interfaces_coords = gg.vector.extract_xyz(gdf=interfaces, dem=topo_raster)
interfaces_coords = interfaces_coords[interfaces_coords['formation'].isin(['Tonstein', 'Schluffstein'])]
interfaces_coords
[12]:
formation geometry X Y Z
0 Schluffstein POINT (256.467 1.534) 256.47 1.53 178.38
1 Schluffstein POINT (255.813 23.321) 255.81 23.32 170.99
2 Schluffstein POINT (262.785 44.891) 262.79 44.89 160.10
3 Schluffstein POINT (266.489 61.885) 266.49 61.89 148.84
4 Schluffstein POINT (271.500 76.047) 271.50 76.05 141.98
... ... ... ... ... ...
101 Schluffstein POINT (484.145 638.598) 484.15 638.60 202.71
102 Schluffstein POINT (476.084 658.860) 476.08 658.86 198.10
103 Schluffstein POINT (465.408 676.944) 465.41 676.94 191.75
104 Schluffstein POINT (450.157 691.977) 450.16 691.98 185.69
105 Schluffstein POINT (432.945 703.307) 432.94 703.31 180.41

106 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, 601)
plt.ylim(0, 705)
[13]:
(0.0, 705.0)
../../_images/getting_started_example_example32_26_1.png

Orientations from Strike Lines and Map#

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.

In addition, orientations were provided on the map which were digitized as points and can be used right away.

[14]:
img = mpimg.imread('../images/orientations_example32.png')
plt.figure(figsize=(10, 10))
imgplot = plt.imshow(img)
plt.axis('off')
plt.tight_layout()
../../_images/getting_started_example_example32_28_0.png

Orientations from Map#

[15]:
orientations_points = gpd.read_file(file_path + 'orientations32.shp')
orientations_points = gg.vector.extract_xyz(gdf=orientations_points, dem=topo_raster)
orientations_points
[15]:
formation dip azimuth polarity geometry X Y Z
0 Tonstein 89.00 90.00 1.00 POINT (194.155 534.236) 194.15 534.24 203.22
1 Tonstein 45.00 270.00 1.00 POINT (489.592 406.562) 489.59 406.56 140.53
2 Tonstein 50.00 90.00 1.00 POINT (231.629 212.654) 231.63 212.65 80.31
3 Tonstein 89.00 90.00 1.00 POINT (199.384 48.813) 199.38 48.81 162.43
4 Tonstein 45.00 270.00 1.00 POINT (433.381 87.158) 433.38 87.16 116.59

Orientations from Strike Lines#

[16]:
strikes = gpd.read_file(file_path + 'strikes32.shp')
strikes['Z'] = strikes['Z']*0.425
strikes
[16]:
id formation Z geometry
0 5 Tonstein1 170.00 LINESTRING (546.457 583.476, 546.022 704.178)
1 4 Tonstein1 148.75 LINESTRING (494.168 436.411, 492.425 705.050)
2 3 Tonstein1 127.50 LINESTRING (447.543 371.266, 443.621 703.742)
3 2 Tonstein1 106.25 LINESTRING (401.353 319.848, 400.482 705.050)
4 1 Tonstein1 106.25 LINESTRING (228.797 259.715, 227.054 704.178)
5 1 Tonstein2 106.25 LINESTRING (230.976 163.414, 230.104 261.022)
6 2 Tonstein2 106.25 LINESTRING (401.789 321.155, 396.560 126.376)
7 3 Tonstein2 127.50 LINESTRING (447.978 372.138, 438.828 57.528)
8 4 Tonstein2 148.75 LINESTRING (494.168 436.629, 491.117 1.316)
9 5 Tonstein2 170.00 LINESTRING (547.329 586.090, 545.586 -0.863)
10 1 Tonstein3 106.25 LINESTRING (231.847 162.107, 231.847 -0.427)
11 2 Tonstein3 106.25 LINESTRING (396.996 125.940, 399.610 0.445)
12 3 Tonstein3 127.50 LINESTRING (438.828 57.963, 438.828 0.880)
13 2 Schluffstein1 106.25 LINESTRING (268.014 63.628, 269.321 0.880)
14 1 Schluffstein1 106.25 LINESTRING (373.901 34.869, 375.644 0.009)
15 3 Schluffstein1 127.50 LINESTRING (256.685 23.103, 257.556 0.880)
16 4 Schluffstein2 191.25 LINESTRING (466.715 675.854, 467.587 527.700)
17 3 Schluffstein2 170.00 LINESTRING (423.576 453.623, 424.012 702.871)
18 1 Schluffstein2 148.75 LINESTRING (373.030 393.054, 373.465 703.307)
19 2 Schluffstein2 148.75 LINESTRING (265.400 352.965, 266.707 702.871)

Calculating Orientations for each formation#

[17]:
orientations_claystone1 = gg.vector.calculate_orientations_from_strike_lines(gdf=strikes[strikes['formation'] == 'Tonstein1'].sort_values(by='id', ascending=True).reset_index())
orientations_claystone1
[17]:
dip azimuth Z geometry polarity formation X Y
0 0.00 0.00 106.25 POINT (314.421 497.198) 1.00 Tonstein1 314.42 497.20
1 26.23 269.64 116.88 POINT (423.250 524.977) 1.00 Tonstein1 423.25 524.98
2 24.15 269.44 138.12 POINT (469.439 554.117) 1.00 Tonstein1 469.44 554.12
3 21.76 269.66 159.38 POINT (519.768 607.278) 1.00 Tonstein1 519.77 607.28
[18]:
orientations_claystone2 = gg.vector.calculate_orientations_from_strike_lines(gdf=strikes[strikes['formation'] == 'Tonstein2'].sort_values(by='id', ascending=True).reset_index())
orientations_claystone2
[18]:
dip azimuth Z geometry polarity formation X Y
0 0.00 0.00 106.25 POINT (314.857 217.992) 1.00 Tonstein2 314.86 217.99
1 25.65 271.63 116.88 POINT (421.289 219.299) 1.00 Tonstein2 421.29 219.30
2 24.92 270.84 138.12 POINT (468.023 216.902) 1.00 Tonstein2 468.02 216.90
3 21.95 270.25 159.38 POINT (519.550 255.793) 1.00 Tonstein2 519.55 255.79
[19]:
orientations_claystone3 = gg.vector.calculate_orientations_from_strike_lines(gdf=strikes[strikes['formation'] == 'Tonstein3'].sort_values(by='id', ascending=True).reset_index())
orientations_claystone3
[19]:
dip azimuth Z geometry polarity formation X Y
0 0.00 0.00 106.25 POINT (315.075 72.016) 1.00 Tonstein3 315.08 72.02
1 28.45 269.01 116.88 POINT (418.565 46.307) 1.00 Tonstein3 418.57 46.31
[20]:
orientations_siltstone1 = gg.vector.calculate_orientations_from_strike_lines(gdf=strikes[strikes['formation'] == 'Schluffstein1'].sort_values(by='id', ascending=True).reset_index())
orientations_siltstone1
[20]:
dip azimuth Z geometry polarity formation X Y
0 0.00 0.00 106.25 POINT (321.720 24.846) 1.00 Schluffstein1 321.72 24.85
1 61.03 88.69 116.88 POINT (262.894 22.123) 1.00 Schluffstein1 262.89 22.12
[21]:
orientations_siltstone2 = gg.vector.calculate_orientations_from_strike_lines(gdf=strikes[strikes['formation'] == 'Schluffstein2'].sort_values(by='id', ascending=True).reset_index())
orientations_siltstone2
[21]:
dip azimuth Z geometry polarity formation X Y
0 0.00 0.00 148.75 POINT (319.650 538.049) 1.00 Schluffstein2 319.65 538.05
1 7.69 270.18 159.38 POINT (344.924 553.082) 1.00 Schluffstein2 344.92 553.08
2 26.43 269.99 180.62 POINT (445.473 590.012) 1.00 Schluffstein2 445.47 590.01

Merging Orientations#

[22]:
import pandas as pd
orientations = pd.concat([orientations_points, orientations_claystone1, orientations_claystone2, orientations_claystone3, orientations_siltstone1, orientations_siltstone2])
orientations['formation'] = ['Tonstein', 'Tonstein', 'Tonstein', 'Tonstein', 'Tonstein', 'Tonstein', 'Tonstein', 'Tonstein', 'Tonstein', 'Tonstein','Tonstein', 'Tonstein', 'Tonstein', 'Tonstein', 'Tonstein', 'Schluffstein', 'Schluffstein', 'Schluffstein', 'Schluffstein', 'Schluffstein']
orientations = orientations[orientations['formation'].isin(['Tonstein', 'Schluffstein'])].reset_index()
orientations
[22]:
index formation dip azimuth polarity geometry X Y Z
0 0 Tonstein 89.00 90.00 1.00 POINT (194.155 534.236) 194.15 534.24 203.22
1 1 Tonstein 45.00 270.00 1.00 POINT (489.592 406.562) 489.59 406.56 140.53
2 2 Tonstein 50.00 90.00 1.00 POINT (231.629 212.654) 231.63 212.65 80.31
3 3 Tonstein 89.00 90.00 1.00 POINT (199.384 48.813) 199.38 48.81 162.43
4 4 Tonstein 45.00 270.00 1.00 POINT (433.381 87.158) 433.38 87.16 116.59
5 0 Tonstein 0.00 0.00 1.00 POINT (314.421 497.198) 314.42 497.20 106.25
6 1 Tonstein 26.23 269.64 1.00 POINT (423.250 524.977) 423.25 524.98 116.88
7 2 Tonstein 24.15 269.44 1.00 POINT (469.439 554.117) 469.44 554.12 138.12
8 3 Tonstein 21.76 269.66 1.00 POINT (519.768 607.278) 519.77 607.28 159.38
9 0 Tonstein 0.00 0.00 1.00 POINT (314.857 217.992) 314.86 217.99 106.25
10 1 Tonstein 25.65 271.63 1.00 POINT (421.289 219.299) 421.29 219.30 116.88
11 2 Tonstein 24.92 270.84 1.00 POINT (468.023 216.902) 468.02 216.90 138.12
12 3 Tonstein 21.95 270.25 1.00 POINT (519.550 255.793) 519.55 255.79 159.38
13 0 Tonstein 0.00 0.00 1.00 POINT (315.075 72.016) 315.08 72.02 106.25
14 1 Tonstein 28.45 269.01 1.00 POINT (418.565 46.307) 418.57 46.31 116.88
15 0 Schluffstein 0.00 0.00 1.00 POINT (321.720 24.846) 321.72 24.85 106.25
16 1 Schluffstein 61.03 88.69 1.00 POINT (262.894 22.123) 262.89 22.12 116.88
17 0 Schluffstein 0.00 0.00 1.00 POINT (319.650 538.049) 319.65 538.05 148.75
18 1 Schluffstein 7.69 270.18 1.00 POINT (344.924 553.082) 344.92 553.08 159.38
19 2 Schluffstein 26.43 269.99 1.00 POINT (445.473 590.012) 445.47 590.01 180.62

Plotting the Orientations#

[23]:
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, 601)
plt.ylim(0, 705)
[23]:
(0.0, 705.0)
../../_images/getting_started_example_example32_42_1.png

GemPy Model Construction#

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

[24]:
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#

[25]:
geo_model = gp.create_model('Model32')
geo_model
[25]:
Model32  2022-04-17 15:06

Initiate Data#

[26]:
gp.init_data(geo_model, [0, 601, 0, 705, 0, 300], [100, 100, 100],
             surface_points_df=interfaces_coords,
             orientations_df=orientations,
             default_values=True)
Active grids: ['regular']
[26]:
Model32  2022-04-17 15:06

Model Surfaces#

[27]:
geo_model.surfaces
[27]:
surface series order_surfaces color id
0 Schluffstein Default series 1 #015482 1
1 Tonstein Default series 2 #9f0052 2

Mapping the Stack to Surfaces#

[28]:
gp.map_stack_to_surfaces(geo_model,
                         {'Strata1': ('Schluffstein', 'Tonstein'),
                          },
                         remove_unused_series=True)
geo_model.add_surfaces('Sandstein')
[28]:
surface series order_surfaces color id
0 Schluffstein Strata1 1 #015482 1
1 Tonstein Strata1 2 #9f0052 2
2 Sandstein Strata1 3 #ffbe00 3

Showing the Number of Data Points#

[29]:
gg.utils.show_number_of_data_points(geo_model=geo_model)
[29]:
surface series order_surfaces color id No. of Interfaces No. of Orientations
0 Schluffstein Strata1 1 #015482 1 48 5
1 Tonstein Strata1 2 #9f0052 2 58 15
2 Sandstein Strata1 3 #ffbe00 3 0 0

Loading Digital Elevation Model#

[30]:
geo_model.set_topography(source='gdal', filepath=file_path + 'raster32.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']
[30]:
Grid Object. Values:
array([[  3.005     ,   3.525     ,   1.5       ],
       [  3.005     ,   3.525     ,   4.5       ],
       [  3.005     ,   3.525     ,   7.5       ],
       ...,
       [598.49583333, 692.5       , 175.96000671],
       [598.49583333, 697.5       , 176.22775269],
       [598.49583333, 702.5       , 176.43305969]])

Plotting Input Data#

[31]:
gp.plot_2d(geo_model, direction='z', show_lith=False, show_boundaries=False)
plt.grid()
../../_images/getting_started_example_example32_58_0.png
[32]:
gp.plot_3d(geo_model, image=False, plotter_type='basic', notebook=True)
../../_images/getting_started_example_example32_59_0.png
[32]:
<gempy.plot.vista.GemPyToVista at 0x23712e34eb0>

Setting the Interpolator#

[33]:
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             973.77
$C_o$           22576.81
drift equations      [3]
[33]:
<gempy.core.interpolator.InterpolatorModel at 0x2370bce2610>

Computing Model#

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

Plotting Cross Sections#

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