Example 28 - Folded Layers
Contents
Example 28 - 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 3954 m wide (W-E extent) and 2738 m high (N-S extent). The model represents folded layers that dip to the northeast or southwest, respectively.
The map has been georeferenced with QGIS. The stratigraphic boundaries were digitized in QGIS. Strikes lines were digitized in QGIS as well and will be used to calculate orientations for the GemPy
model. The contour lines were also digitized and will be interpolated with GemGIS
to create a topography for the model.
Map Source: An Introduction to Geological Structures and Maps by G.M. Bennison
[1]:
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
img = mpimg.imread('../images/cover_example28.png')
plt.figure(figsize=(10, 10))
imgplot = plt.imshow(img)
plt.axis('off')
plt.tight_layout()
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, 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 form 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/example28/'
gg.download_gemgis_data.download_tutorial_data(filename="example28_folded_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_example28.png')
plt.figure(figsize=(10, 10))
imgplot = plt.imshow(img)
plt.axis('off')
plt.tight_layout()
[6]:
topo = gpd.read_file(file_path + 'topo28.shp')
topo.head()
[6]:
id | Z | geometry | |
---|---|---|---|
0 | None | 350 | LINESTRING (1.385 62.877, 136.138 47.987, 292.... |
1 | None | 300 | LINESTRING (1.571 124.111, 129.996 110.524, 22... |
2 | None | 250 | LINESTRING (0.082 198.374, 59.641 178.273, 118... |
3 | None | 50 | LINESTRING (863.690 271.706, 829.815 271.334, ... |
4 | None | 100 | LINESTRING (864.062 307.070, 828.326 304.092, ... |
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
fix, 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,865,0,867], 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]')
[8]:
Text(67.3456168134622, 0.5, 'Y [m]')
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 as raster is already provided with the example data.
[9]:
gg.raster.save_as_tiff(raster=topo_raster, path=file_path + 'raster28.tif', extent=[0,865,0,867], crs='EPSG:4326', overwrite_file=True)
Raster successfully saved
Opening Raster#
The previously computed and saved raster can now be opened using rasterio.
[10]:
topo_raster = rasterio.open(file_path + 'raster28.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.
[11]:
img = mpimg.imread('../images/interfaces_example28.png')
plt.figure(figsize=(10, 10))
imgplot = plt.imshow(img)
plt.axis('off')
plt.tight_layout()
[12]:
interfaces = gpd.read_file(file_path + 'interfaces28.shp')
interfaces.head()
[12]:
id | formation | Z | geometry | |
---|---|---|---|---|
0 | None | Layer1 | 0 | LINESTRING (750.000 865.441, 764.514 845.629, ... |
1 | None | Layer1 | 50 | LINESTRING (628.941 863.195, 637.925 850.294, ... |
2 | None | Layer1 | 100 | LINESTRING (534.604 865.153, 549.463 845.687, ... |
3 | None | Layer1 | 150 | LINESTRING (458.590 864.955, 473.370 845.597, ... |
4 | None | Layer1 | 100 | LINESTRING (2.577 102.527, 17.435 83.097, 25.0... |
Extracting XY coordinates from Digital Elevation Model#
[13]:
interfaces_coords = gg.vector.extract_xy(gdf=interfaces)
interfaces_coords = interfaces_coords.sort_values(by='formation', ascending=False)
interfaces_coords.head()
[13]:
formation | Z | geometry | X | Y | |
---|---|---|---|---|---|
0 | Layer1 | 0.00 | POINT (750.000 865.441) | 750.00 | 865.44 |
304 | Layer1 | 350.00 | POINT (345.483 629.092) | 345.48 | 629.09 |
332 | Layer1 | 350.00 | POINT (669.435 197.325) | 669.43 | 197.33 |
331 | Layer1 | 350.00 | POINT (653.053 219.421) | 653.05 | 219.42 |
330 | Layer1 | 350.00 | POINT (648.227 227.168) | 648.23 | 227.17 |
Plotting the Interface Points#
[14]:
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]')
[14]:
Text(67.45106220501688, 0.5, 'Y [m]')
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.
[15]:
img = mpimg.imread('../images/orientations_example28.png')
plt.figure(figsize=(10, 10))
imgplot = plt.imshow(img)
plt.axis('off')
plt.tight_layout()
[16]:
strikes = gpd.read_file(file_path + 'strikes28.shp')
strikes
[16]:
id | Z | formation | geometry | |
---|---|---|---|---|
0 | 1 | 100 | Layer1a | LINESTRING (2.577 102.527, 78.137 1.951) |
1 | 2 | 150 | Layer1a | LINESTRING (3.720 276.250, 208.683 2.713) |
2 | 3 | 200 | Layer1a | LINESTRING (1.942 442.607, 335.546 1.697) |
3 | 4 | 250 | Layer1a | LINESTRING (1.307 583.693, 438.662 6.395) |
4 | 5 | 300 | Layer1a | LINESTRING (1.815 721.604, 544.572 2.967) |
5 | 6 | 350 | Layer1a | LINESTRING (1.466 864.659, 648.100 2.014) |
6 | 8 | 350 | Layer1b | LINESTRING (168.585 865.421, 817.632 2.522) |
7 | 7 | 300 | Layer1b | LINESTRING (267.892 865.294, 862.714 70.843) |
8 | 6 | 250 | Layer1b | LINESTRING (346.245 863.643, 862.841 176.372) |
9 | 5 | 200 | Layer1b | LINESTRING (407.708 863.135, 863.857 256.376) |
10 | 4 | 150 | Layer1b | LINESTRING (458.590 864.955, 863.317 326.157) |
11 | 3 | 100 | Layer1b | LINESTRING (534.604 865.153, 859.196 434.936) |
12 | 2 | 50 | Layer1b | LINESTRING (628.941 863.195, 862.767 552.331) |
13 | 1 | 0 | Layer1b | LINESTRING (750.000 865.441, 858.044 718.925) |
Calculate Orientations for each formation#
[17]:
orientations_layer1a = gg.vector.calculate_orientations_from_strike_lines(gdf=strikes[strikes['formation']=='Layer1a'].sort_values(by='Z', ascending=True).reset_index())
orientations_layer1a
[17]:
dip | azimuth | Z | geometry | polarity | formation | X | Y | |
---|---|---|---|---|---|---|---|---|
0 | 25.48 | 233.15 | 125.00 | POINT (73.279 95.860) | 1.00 | Layer1a | 73.28 | 95.86 |
1 | 26.81 | 232.96 | 175.00 | POINT (137.473 180.816) | 1.00 | Layer1a | 137.47 | 180.82 |
2 | 30.56 | 232.87 | 225.00 | POINT (194.364 258.598) | 1.00 | Layer1a | 194.36 | 258.60 |
3 | 31.23 | 232.90 | 275.00 | POINT (246.589 328.665) | 1.00 | Layer1a | 246.59 | 328.66 |
4 | 31.29 | 233.06 | 325.00 | POINT (298.988 397.811) | 1.00 | Layer1a | 298.99 | 397.81 |
[18]:
orientations_layer1b = gg.vector.calculate_orientations_from_strike_lines(gdf=strikes[strikes['formation']=='Layer1b'].sort_values(by='Z', ascending=True).reset_index())
orientations_layer1b
[18]:
dip | azimuth | Z | geometry | polarity | formation | X | Y | |
---|---|---|---|---|---|---|---|---|
0 | 27.42 | 53.15 | 25.00 | POINT (774.938 749.973) | 1.00 | Layer1b | 774.94 | 749.97 |
1 | 34.21 | 52.99 | 75.00 | POINT (721.377 678.904) | 1.00 | Layer1b | 721.38 | 678.90 |
2 | 39.39 | 53.04 | 125.00 | POINT (678.927 622.800) | 1.00 | Layer1b | 678.93 | 622.80 |
3 | 50.31 | 53.07 | 175.00 | POINT (648.368 577.656) | 1.00 | Layer1b | 648.37 | 577.66 |
4 | 45.68 | 53.07 | 225.00 | POINT (620.163 539.881) | 1.00 | Layer1b | 620.16 | 539.88 |
5 | 39.01 | 53.13 | 275.00 | POINT (584.923 494.038) | 1.00 | Layer1b | 584.92 | 494.04 |
6 | 32.97 | 53.11 | 325.00 | POINT (529.206 451.020) | 1.00 | Layer1b | 529.21 | 451.02 |
Merging Orientations#
[19]:
import pandas as pd
orientations = pd.concat([orientations_layer1a, orientations_layer1b]).reset_index()
orientations['formation'] = 'Layer1'
orientations
[19]:
index | dip | azimuth | Z | geometry | polarity | formation | X | Y | |
---|---|---|---|---|---|---|---|---|---|
0 | 0 | 25.48 | 233.15 | 125.00 | POINT (73.279 95.860) | 1.00 | Layer1 | 73.28 | 95.86 |
1 | 1 | 26.81 | 232.96 | 175.00 | POINT (137.473 180.816) | 1.00 | Layer1 | 137.47 | 180.82 |
2 | 2 | 30.56 | 232.87 | 225.00 | POINT (194.364 258.598) | 1.00 | Layer1 | 194.36 | 258.60 |
3 | 3 | 31.23 | 232.90 | 275.00 | POINT (246.589 328.665) | 1.00 | Layer1 | 246.59 | 328.66 |
4 | 4 | 31.29 | 233.06 | 325.00 | POINT (298.988 397.811) | 1.00 | Layer1 | 298.99 | 397.81 |
5 | 0 | 27.42 | 53.15 | 25.00 | POINT (774.938 749.973) | 1.00 | Layer1 | 774.94 | 749.97 |
6 | 1 | 34.21 | 52.99 | 75.00 | POINT (721.377 678.904) | 1.00 | Layer1 | 721.38 | 678.90 |
7 | 2 | 39.39 | 53.04 | 125.00 | POINT (678.927 622.800) | 1.00 | Layer1 | 678.93 | 622.80 |
8 | 3 | 50.31 | 53.07 | 175.00 | POINT (648.368 577.656) | 1.00 | Layer1 | 648.37 | 577.66 |
9 | 4 | 45.68 | 53.07 | 225.00 | POINT (620.163 539.881) | 1.00 | Layer1 | 620.16 | 539.88 |
10 | 5 | 39.01 | 53.13 | 275.00 | POINT (584.923 494.038) | 1.00 | Layer1 | 584.92 | 494.04 |
11 | 6 | 32.97 | 53.11 | 325.00 | POINT (529.206 451.020) | 1.00 | Layer1 | 529.21 | 451.02 |
Plotting the Orientations#
[20]:
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]')
[20]:
Text(67.45106220501688, 0.5, 'Y [m]')
GemPy Model Construction#
The structural geological model will be constructed using the GemPy
package.
[21]:
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#
[22]:
geo_model = gp.create_model('Model28')
geo_model
[22]:
Model28 2022-04-13 08:25
Initiate Data#
[23]:
gp.init_data(geo_model, [0,865,0,867,0,500], [50,50,50],
surface_points_df = interfaces_coords[interfaces_coords['Z']!=0].sample(n=75, random_state=1),
orientations_df = orientations,
default_values=True)
Active grids: ['regular']
[23]:
Model28 2022-04-13 08:25
Model Surfaces#
[24]:
geo_model.surfaces
[24]:
surface | series | order_surfaces | color | id | |
---|---|---|---|---|---|
0 | Layer1 | Default series | 1 | #015482 | 1 |
Mapping the Stack to Surfaces#
[25]:
gp.map_stack_to_surfaces(geo_model,
{
'Strata1': ('Layer1'),
},
remove_unused_series=True)
geo_model.add_surfaces('Basement')
[25]:
surface | series | order_surfaces | color | id | |
---|---|---|---|---|---|
0 | Layer1 | Strata1 | 1 | #015482 | 1 |
1 | Basement | Strata1 | 2 | #9f0052 | 2 |
Showing the Number of Data Points#
[26]:
gg.utils.show_number_of_data_points(geo_model=geo_model)
[26]:
surface | series | order_surfaces | color | id | No. of Interfaces | No. of Orientations | |
---|---|---|---|---|---|---|---|
0 | Layer1 | Strata1 | 1 | #015482 | 1 | 75 | 12 |
1 | Basement | Strata1 | 2 | #9f0052 | 2 | 0 | 0 |
Loading Digital Elevation Model#
[27]:
geo_model.set_topography(
source='gdal', filepath=file_path + 'raster28.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']
[27]:
Grid Object. Values:
array([[ 8.65 , 8.67 , 5. ],
[ 8.65 , 8.67 , 15. ],
[ 8.65 , 8.67 , 25. ],
...,
[862.5 , 854.54310345, 363.79455566],
[862.5 , 859.52586207, 364.32107544],
[862.5 , 864.50862069, 364.75622559]])
Defining Custom Section#
[28]:
custom_section = gpd.read_file(file_path + 'customsections28.shp')
custom_section_dict = gg.utils.to_section_dict(custom_section, section_column='section')
geo_model.set_section_grid(custom_section_dict)
Active grids: ['regular' 'topography' 'sections']
[28]:
start | stop | resolution | dist | |
---|---|---|---|---|
Section1 | [1.593210345965275, 388.4453900184363] | [852.4277356922321, 865.9286460336549] | [100, 80] | 975.66 |
[29]:
gp.plot.plot_section_traces(geo_model)
[29]:
<gempy.plot.visualization_2d.Plot2D at 0x1ebe7a01f10>
Plotting Input Data#
[30]:
gp.plot_2d(geo_model, direction='z', show_lith=False, show_boundaries=False)
plt.grid()
[31]:
gp.plot_3d(geo_model, image=False, plotter_type='basic', notebook=True)
[31]:
<gempy.plot.vista.GemPyToVista at 0x1ebe70f09d0>
Setting the Interpolator#
[32]:
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 1322.84
$C_o$ 41664.62
drift equations [3]
[32]:
<gempy.core.interpolator.InterpolatorModel at 0x1ebe0d78af0>
Computing Model#
[33]:
sol = gp.compute_model(geo_model, compute_mesh=True)
Plotting Cross Sections#
[34]:
gp.plot_2d(geo_model, section_names=['Section1'], show_topography=True, show_data=False)
[34]:
<gempy.plot.visualization_2d.Plot2D at 0x1ebe71ad130>
[35]:
gp.plot_2d(geo_model, direction=['x', 'x', 'y', 'y'], cell_number=[25,40,25,40], show_topography=True, show_data=False)
[35]:
<gempy.plot.visualization_2d.Plot2D at 0x1ebe72b9460>
Plotting 3D Model#
[36]:
gpv = gp.plot_3d(geo_model, image=False, show_topography=False,
plotter_type='basic', notebook=True, show_lith=True)
[ ]: