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
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
img = mpimg.imread('../data/images/example33/cover_example33.png')
plt.figure(figsize=(10, 10))
imgplot = plt.imshow(img)
plt.axis('off')
plt.tight_layout()
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/)
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
.
import warnings
warnings.filterwarnings("ignore")
import gemgis as gg
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.
import geopandas as gpd
import rasterio
file_path = '../data/example33_folded_layers/'
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()
.
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
img = mpimg.imread('../data/images/example33/dem_example33.png')
plt.figure(figsize=(10, 10))
imgplot = plt.imshow(img)
plt.axis('off')
plt.tight_layout()
topo = gpd.read_file(file_path + 'topo33.shp')
# topo['Z'] = topo['Z']*0.425
topo.head()
topo_raster = gg.vector.interpolate_raster(gdf=topo, value='Z', method='rbf', res=5)
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
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]')
plt.xlim(0, 601)
plt.ylim(0, 705)
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 + 'raster33.tif', extent=[0, 601, 0, 705], crs='EPSG:4326', overwrite_file=True)
The previously computed and saved raster can now be opened using rasterio.
topo_raster = rasterio.open(file_path + 'raster33.tif')
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.
img = mpimg.imread('../data/images/example33/interfaces_example33.png')
plt.figure(figsize=(10, 10))
imgplot = plt.imshow(img)
plt.axis('off')
plt.tight_layout()
interfaces = gpd.read_file(file_path + 'interfaces33.shp')
interfaces.head()
interfaces_coords = gg.vector.extract_xyz(gdf=interfaces, dem=topo_raster)
interfaces_coords = interfaces_coords[interfaces_coords['formation'].isin(['Claystone','Sandstone'])]#
interfaces_coords
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)
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.
img = mpimg.imread('../data/images/example33/orientations_example33.png')
plt.figure(figsize=(10, 10))
imgplot = plt.imshow(img)
plt.axis('off')
plt.tight_layout()
orientations_points = gpd.read_file(file_path + 'orientations33.shp')
orientations_points = gg.vector.extract_xyz(gdf=orientations_points, dem=topo_raster)
orientations_points
strikes = gpd.read_file(file_path + 'strikes33.shp')
# strikes['Z'] = strikes['Z']*0.425
strikes
strikes[strikes['formation'] == 'Claystone']
orientations_claystone1 = gg.vector.calculate_orientations_from_strike_lines(gdf=strikes[strikes['formation'] == 'Claystone'].sort_values(by='id', ascending=True).reset_index())
orientations_claystone1['dip'] = orientations_claystone1['dip'] + 180
orientations_claystone1
orientations_claystone2 = gg.vector.calculate_orientations_from_strike_lines(gdf=strikes[strikes['formation'] == 'Claystone2'].sort_values(by='id', ascending=True).reset_index())
orientations_claystone2
orientations_sandstone1 = gg.vector.calculate_orientations_from_strike_lines(gdf=strikes[strikes['formation'] == 'Sandstone'].sort_values(by='id', ascending=True).reset_index())
orientations_sandstone1
import pandas as pd
orientations = pd.concat([orientations_points, orientations_claystone1, orientations_claystone2])#, orientations_sandstone1])#, orientations_sandstone2, ])
orientations['formation'] = ['Claystone', 'Claystone', 'Claystone', 'Claystone','Claystone', 'Claystone', 'Claystone', 'Claystone','Claystone', 'Claystone','Claystone', 'Claystone', 'Claystone', 'Claystone','Claystone', 'Claystone', 'Claystone', 'Claystone', 'Claystone', 'Claystone','Claystone','Claystone', 'Claystone']#, 'Claystone', 'Claystone', 'Claystone']#, 'Sandstone', 'Sandstone', 'Sandstone', 'Sandstone']#, 'Sandstone']
orientations = orientations[orientations['formation'].isin(['Claystone', 'Sandstone'])].reset_index()
orientations.at[4, 'Z'] = 300
orientations.at[5, 'Z'] = 300
orientations.at[6, 'Z'] = 300
orientations.at[7, 'Z'] = 300
orientations.at[8, 'Z'] = 100
orientations.at[9, 'Z'] = 100
orientations.at[10, 'Z'] = 100
orientations.at[11, 'Z'] = 100
orientations.at[12, 'Z'] = 250
orientations.at[13, 'Z'] = 250
orientations.at[14, 'Z'] = 250
orientations.at[15, 'Z'] = 250
orientations.at[16, 'Z'] = 250
orientations.at[17, 'Z'] = 250
orientations
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)
The structural geological model will be constructed using the GemPy
package.
import gempy as gp
geo_model = gp.create_model('Model33')
geo_model
gp.init_data(geo_model, [0, 601, 0, 705, 0, 300], [50,50,50],
surface_points_df=interfaces_coords,
orientations_df=orientations,
default_values=True)
geo_model.surfaces
gp.map_stack_to_surfaces(geo_model,
{'Strata1': ( 'Sandstone', 'Claystone'), #
},
remove_unused_series=True)
geo_model.add_surfaces('Sandstein')
gg.utils.show_number_of_data_points(geo_model=geo_model)
geo_model.set_topography(source='gdal', filepath=file_path + 'raster33.tif')
gp.plot_2d(geo_model, direction='z', show_lith=False, show_boundaries=False)
plt.grid()
gp.plot_3d(geo_model, image=False, plotter_type='basic', notebook=True)
gp.set_interpolator(geo_model,
compile_theano=True,
theano_optimizer='fast_compile',
verbose=[],
update_kriging=False
)
sol = gp.compute_model(geo_model, compute_mesh=True)
gp.plot_2d(geo_model, direction=['x', 'x', 'y', 'y'], cell_number=[25, 40, 25, 40], show_topography=True, show_data=False)
gpv = gp.plot_3d(geo_model, image=False, show_topography=True,
plotter_type='basic', notebook=True, show_lith=False)