def test_pile_geomodel_2(): ve = 3 extent = [451e3, 456e3, 6.7820e6, 6.7840e6, -2309 * ve, -1651 * ve] geo_model = gp.create_model('Topology-Gullfaks') gp.init_data(geo_model, extent, [30, 30, 30], path_o=input_path + "/filtered_orientations.csv", path_i=input_path + "/filtered_surface_points.csv", default_values=True) series_distribution = { "fault3": "fault3", "fault4": "fault4", "unconformity": "BCU", "sediments": ("tarbert", "ness", "etive"), } gp.map_series_to_surfaces(geo_model, series_distribution, remove_unused_series=True) geo_model.reorder_series( ["unconformity", "fault3", "fault4", "sediments", "Basement"]) geo_model.set_is_fault(["fault3"]) geo_model.set_is_fault(["fault4"]) rel_matrix = np.array([[0, 0, 0, 0, 0], [0, 0, 0, 1, 1], [0, 0, 0, 1, 1], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]) geo_model.set_fault_relation(rel_matrix) surf_groups = pd.read_csv(input_path + "/filtered_surface_points.csv").group geo_model.surface_points.df["group"] = surf_groups orient_groups = pd.read_csv(input_path + "/filtered_orientations.csv").group geo_model.orientations.df["group"] = orient_groups geo_model.surface_points.df.reset_index(inplace=True, drop=True) geo_model.orientations.df.reset_index(inplace=True, drop=True) gp.set_interpolator(geo_model, verbose=['mask_matrix_loop', 'mask_e', 'nsle']) gp.compute_model(geo_model) gp.plot.plot_section(geo_model, cell_number=25, direction='y', show_data=True) from gempy.plot.plot_api import plot_2d p = plot_2d(geo_model, cell_number=[25]) plt.savefig(os.path.dirname(__file__) + '/../figs/test_pile_lith_block') return geo_model
def model(): geo_model = gp.create_model('test_map2Loop') gp.init_data( geo_model, extent=[bbox[0], bbox[2], bbox[1], bbox[3], model_base, model_top], resolution=[50, 50, 80], path_o=orientations_file, path_i=contacts_file) # Load Topology geo_model.set_topography(source='gdal', filepath=fp) # Stack Processing contents = np.genfromtxt(series_file, delimiter=',', dtype='U100')[1:, 4:-1] map_series_to_surfaces = {} for pair in contents: map_series_to_surfaces.setdefault(pair[1], []).append(pair[0]) gp.map_stack_to_surfaces(geo_model, map_series_to_surfaces, remove_unused_series=False) gp.plot_3d(geo_model, ve=None, show_topography=False, image=True, show_lith=False, kwargs_plot_data={'arrow_size': 300}) return geo_model
def test_gravity(interpolator_gravity): geo_model = gp.create_model('2-layers') gp.init_data(geo_model, extent=[0, 12, -2, 2, 0, 4], resolution=[500, 1, 500]) geo_model.add_surfaces('surface 1') geo_model.add_surfaces('surface 2') geo_model.add_surfaces('basement') dz = geo_model._grid.regular_grid.dz geo_model._surfaces.add_surfaces_values([dz, 0, 0], ['dz']) geo_model._surfaces.add_surfaces_values([2.6, 2.4, 3.2], ['density']) geo_model.add_surface_points(3, 0, 3.05, 'surface 1') geo_model.add_surface_points(9, 0, 3.05, 'surface 1') geo_model.add_surface_points(3, 0, 1.02, 'surface 2') geo_model.add_surface_points(9, 0, 1.02, 'surface 2') geo_model.add_orientations(6, 0, 4, 'surface 1', [0, 0, 1]) device_loc = np.array([[6, 0, 4]]) geo_model.set_centered_grid(device_loc, resolution=[10, 10, 100], radius=16000) geo_model.set_theano_function(interpolator_gravity) geo_model._interpolator.set_theano_shared_gravity(pos_density=2) print(geo_model._additional_data) gp.compute_model(geo_model, set_solutions=True, compute_mesh=False) print(geo_model.solutions.fw_gravity) np.testing.assert_almost_equal(geo_model.solutions.fw_gravity, np.array([-1624.1714]), decimal=4)
def test_gravity(): geo_model = gp.create_model('2-layers') gp.init_data(geo_model, extent=[0, 12, -2, 2, 0, 4], resolution=[500, 1, 500]) geo_model.add_surfaces('surface 1') geo_model.add_surfaces('surface 2') geo_model.add_surfaces('basement') dz = geo_model.grid.regular_grid.dz geo_model.surfaces.add_surfaces_values([dz, 0, 0], ['dz']) geo_model.surfaces.add_surfaces_values([2.6, 2.4, 3.2], ['density']) geo_model.add_surface_points(3, 0, 3.05, 'surface 1') geo_model.add_surface_points(9, 0, 3.05, 'surface 1') geo_model.add_surface_points(3, 0, 1.02, 'surface 2') geo_model.add_surface_points(9, 0, 1.02, 'surface 2') geo_model.add_orientations(6, 0, 4, 'surface 1', [0, 0, 1]) device_loc = np.array([[6, 0, 4]]) geo_model.set_centered_grid(device_loc, resolution=[10, 10, 100], radius=16000) gp.set_interpolator(geo_model, output=['gravity'], pos_density=2, gradient=True, theano_optimizer='fast_compile') gp.compute_model(geo_model, set_solutions=True, compute_mesh=False) print(geo_model.solutions.fw_gravity) np.testing.assert_almost_equal(geo_model.solutions.fw_gravity, np.array([-9291.8003]), decimal=4)
def interpolator_islith_isfault(): geo_model = gp.create_model('interpolator_islith_isfault') # Importing the data from CSV-files and setting extent and resolution gp.init_data(geo_model, path_o=input_path + "/simple_fault_model_orientations.csv", path_i=input_path + "/simple_fault_model_points.csv", default_values=True) gp.map_series_to_surfaces(geo_model, { "Fault_Series": 'Main_Fault', "Strat_Series": ('Sandstone_2', 'Siltstone', 'Shale', 'Sandstone_1', 'basement') }, remove_unused_series=True) geo_model.set_is_fault(['Fault_Series']) gp.set_interpolation_data(geo_model, compile_theano=True, theano_optimizer='fast_compile', verbose=[]) return geo_model.interpolator
def test_issue_569(data_path): surface_points_df = df = pd.read_csv(data_path + "/coordinates_mwe.csv") orientations_df = pd.read_csv(data_path + "/orientations_mwe.csv") geo_model = gp.create_model("Deltatest") gp.init_data(geo_model, [ df.X.min() - 50, df.X.max() + 50, df.Y.min() - 50, df.Y.max() + 50, df.Z.min() - 50, df.Z.max() + 50, ], [50, 50, 50], surface_points_df=surface_points_df, orientations_df=orientations_df, default_values=True) fault_list = [] series = { "Strat_Series": surface_points_df.loc[ ~surface_points_df["formation"].str.contains("fault"), "formation"].unique().tolist() } for fault in surface_points_df.loc[ surface_points_df["formation"].str.contains("fault"), "formation"].unique(): series[fault] = fault fault_list.append(fault) gp.map_stack_to_surfaces(geo_model, series, remove_unused_series=True) geo_model.set_is_fault(fault_list) geo_model.reorder_features(['fault_a', 'fault_b', 'Strat_Series']) geo_model.add_surfaces("basement") plot = gp.plot_2d(geo_model, show_lith=False, show_boundaries=True, direction=['z']) plt.show(block=False) gp.set_interpolator( geo_model, compile_theano=True, theano_optimizer='fast_compile', ) gp.get_data(geo_model, 'kriging') sol = gp.compute_model(geo_model, sort_surfaces=True) gp.plot_2d(geo_model, show_scalar=True, series_n=0) gp.plot_2d(geo_model, series_n=0) gp.plot_3d(geo_model, image=True)
def load_model(): geo_model = gp.create_model('Model_Tuto1-1') # Importing the data from CSV-files and setting extent and resolution gp.init_data(geo_model, [0, 2000., 0, 2000., 0, 2000.], [50 ,50 ,50], path_o = input_path+"/simple_fault_model_orientations.csv", path_i = input_path+"/simple_fault_model_points.csv", default_values=True) gp.get_data(geo_model, 'surface_points').head() return geo_model
def interpolator_islith_nofault(): geo_model = gp.create_model('interpolator_islith_isfault') # Importing the data from csv files and settign extent and resolution gp.init_data(geo_model, #[0, 10, 0, 10, -10, 0], [50, 50, 50], path_o=input_path + "/GeoModeller/test_a/test_a_Foliations.csv", path_i=input_path + "/GeoModeller/test_a/test_a_Points.csv") interpolator = gempy.set_interpolation_data(geo_model, grid=None, compile_theano=True) return interpolator
def model_horizontal_two_layers(interpolator): geo_model = gp.create_model('interpolator') # Importing the data from csv files and settign extent and resolution gp.init_data(geo_model, [0, 10, 0, 10, -10, 0], [50, 50, 50], path_o=input_path + "/GeoModeller/test_a/test_a_Foliations.csv", path_i=input_path + "/GeoModeller/test_a/test_a_Points.csv") geo_model.set_theano_function(interpolator) return geo_model
def load_model(name=None, path=None, recompile=False): """ Loading model saved with model.save_model function. Args: name: name of folder with saved files path (str): path to folder directory or the zip file recompile (bool): if true, theano functions will be recompiled Returns: :class:`Project` """ # TODO: Divide each dataframe in its own function and move them as # method of the class # TODO: Include try except in case some of the datafiles is missing # # Default path is_compressed = False if path is None: path = f'./{name}' p = pathlib.Path(path) # If the path includes .zip if p.suffix == '.zip': is_compressed, path = _unpack_model_if_compressed_includes_zip( is_compressed, path) # if the path does not include .zip but exist elif os.path.isfile(f'{path}.zip'): is_compressed = _unpack_model_if_compressed_no_zip(is_compressed, path) # create model with extent and resolution from csv - check geo_model = create_model() init_data(geo_model, np.load(f'{path}/{name}_extent.npy'), np.load(f'{path}/{name}_resolution.npy')) _load_files_into_geo_model(geo_model, name, path) if recompile is True: from gempy.api_modules.setters import set_interpolator set_interpolator(geo_model, verbose=[0]) # Cleaning temp files if is_compressed: shutil.rmtree(path) return geo_model
def test_load_model_df(): verbose = True df_i = pn.DataFrame(np.random.randn(6,3), columns='X Y Z'.split()) df_i['formation'] = ['surface_1' for _ in range(3)] + ['surface_2' for _ in range(3)] df_o = pn.DataFrame(np.random.randn(6,6), columns='X Y Z azimuth dip polarity'.split()) df_o['formation'] = ['surface_1' for _ in range(3)] + ['surface_2' for _ in range(3)] geo_model = gp.create_model('test') # Importing the data directly from the dataframes gp.init_data(geo_model, [0, 2000., 0, 2000., 0, 2000.], [50, 50, 50], surface_points_df=df_i, orientations_df=df_o, default_values=True) df_cmp_i = gp.get_data(geo_model, 'surface_points') df_cmp_o = gp.get_data(geo_model, 'orientations') if verbose: print(df_cmp_i.head()) print(df_cmp_o.head()) assert not df_cmp_i.empty, 'data was not set to dataframe' assert not df_cmp_o.empty, 'data was not set to dataframe' assert df_cmp_i.shape[0] == 6, 'data was not set to dataframe' assert df_cmp_o.shape[0] == 6, 'data was not set to dataframe' # try without the default_values command geo_model = gp.create_model('test') # Importing the data directly from the dataframes gp.init_data(geo_model, [0, 2000., 0, 2000., 0, 2000.], [50 ,50 ,50], surface_points_df=df_i, orientations_df=df_o) df_cmp_i2 = gp.get_data(geo_model, 'surface_points') df_cmp_o2 = gp.get_data(geo_model, 'orientations') if verbose: print(df_cmp_i2.head()) print(df_cmp_o2.head()) assert not df_cmp_i2.empty, 'data was not set to dataframe' assert not df_cmp_o2.empty, 'data was not set to dataframe' assert df_cmp_i2.shape[0] == 6, 'data was not set to dataframe' assert df_cmp_o2.shape[0] == 6, 'data was not set to dataframe' return geo_model
def test_add_point(): extend = [0.0, 1.0, 0.0, 1.0, 0.0, 1.1] discretization = [5, 20, 20] x, y, z, f = 0.0, 0.0, 0.5, 'surface2' # %% geo_model = gp.create_model('test') gp.init_data(geo_model, extend, discretization) geo_model.set_default_surfaces() geo_model.set_default_orientation() strats = ['surface1', 'surface2', 'basement'] gp.map_stack_to_surfaces(geo_model, {'Strat_Series': strats}) geo_model.add_surface_points(x, y, z, f) geo_model.add_orientations(x, y, z, f, pole_vector=(1,0,0))
def test_issue_564(data_path): geo_model = gp.create_model('SBPM') gp.init_data(geo_model, [550, 730, -200, 1000, 20, 55], [50, 50, 50], path_i=data_path + "/564_Points.csv", path_o=data_path + "/564_Orientations_.csv", default_values=True) gp.map_stack_to_surfaces(geo_model, { "Q": 'Quartaer', "vK": 'verwKeuper', "Sa": 'Sandstein', "Sc": 'Schluffstein', "b": 'basement' }, remove_unused_series=True) gp.set_interpolator(geo_model, compile_theano=True, theano_optimizer='fast_compile') sol = gp.compute_model(geo_model) gp.plot_2d(geo_model) gpv = gp.plot_3d(geo_model, image=True, plotter_type='basic', ve=5, show_lith=False) geo_model.set_bottom_relation( ["Q", "vK", "Sa", "Sc", "b"], ["Onlap", "Onlap", "Onlap", "Onlap", "Onlap"]) sol = gp.compute_model(geo_model) gp.plot_2d(geo_model) gpv = gp.plot_3d(geo_model, image=True, plotter_type='basic', ve=5, show_lith=True)
def test_issue_566(): from pyvista import set_plot_theme set_plot_theme('document') geo_model = gp.create_model('Model1') geo_model = gp.init_data(geo_model, extent=[0, 791, 0, 200, -582, 0], resolution=[100, 10, 100]) geo_model.set_default_surfaces() geo_model.add_surface_points(X=223, Y=0.01, Z=-94, surface='surface1')
def test_map2loop_model_import_data(): geo_model = gp.create_model('test_map2Loop') gp.init_data( geo_model, extent=[bbox[0], bbox[2], bbox[1], bbox[3], model_base, model_top], resolution=[50, 50, 50], path_o=orientations_file, path_i=contacts_file ) # Load Topology geo_model.set_topography(source='gdal', filepath=fp) gp.plot_2d(geo_model, ve=10, show_topography=True) plt.show() # Plot in 3D gp.plot_3d(geo_model, ve=None, show_topography=False, image=True, kwargs_plot_data={'arrow_size': 400} ) print(geo_model.orientations)
def test_map2loop_model_import_aus(): geo_model = gp.create_model('test_map2Loop') gp.init_data( geo_model, extent=extent_g, resolution=[50, 50, 50], path_o=orientations_file2, path_i=contacts_file2 ) # Load Topology geo_model.set_topography(source='gdal', array=fp2) gp.plot_2d(geo_model, ve=10, show_topography=True) plt.show() # Plot in 3D gp.plot_3d(geo_model, ve=None, show_topography=False, image=False, kwargs_plot_data={'arrow_size': 40} ) print(geo_model.orientations)
def geo_model(interpolator): geo_model = gp.create_model('Test_uncomformities') # Importing the data from CSV-files and setting extent and resolution gp.init_data( geo_model, [0, 10., 0, 2., 0, 5.], [100, 3, 100], path_o=input_path + '/05_toy_fold_unconformity_orientations.csv', path_i=input_path + '/05_toy_fold_unconformity_interfaces.csv', default_values=True) gp.map_stack_to_surfaces( geo_model, { "Flat_Series": 'Flat', "Inclined_Series": 'Inclined', "Fold_Series": ('Basefold', 'Topfold', 'basement') }) # Create the theano model geo_model.set_theano_function(interpolator) return geo_model
def load_model(): verbose = False geo_model = gp.create_model('Model_Tuto1-1') # Importing the data from CSV-files and setting extent and resolution gp.init_data(geo_model, [0, 2000., 0, 2000., 0, 2000.], [50 ,50 ,50], path_o=input_path+"/simple_fault_model_orientations.csv", path_i=input_path+"/simple_fault_model_points.csv", default_values=True) df_cmp_i = gp.get_data(geo_model, 'surface_points') df_cmp_o = gp.get_data(geo_model, 'orientations') df_o = pn.read_csv(input_path + "/simple_fault_model_orientations.csv") df_i = pn.read_csv(input_path + "/simple_fault_model_points.csv") assert not df_cmp_i.empty, 'data was not set to dataframe' assert not df_cmp_o.empty, 'data was not set to dataframe' assert df_cmp_i.shape[0] == df_i.shape[0], 'data was not set to dataframe' assert df_cmp_o.shape[0] == df_o.shape[0], 'data was not set to dataframe' if verbose: gp.get_data(geo_model, 'surface_points').head() return geo_model
def test_reorder_series(): geo_model = gp.create_model('Geological_Model1') geo_model = gp.init_data(geo_model, extent=[0, 4000, 0, 2775, 200, 1200], resolution=[100, 10, 100]) # Adding a fault geo_model.rename_features(['Cycle1']) geo_model.add_features(['Fault1']) geo_model.set_is_fault(['Fault1']) geo_model.reorder_features(['Fault1', 'Cycle1']) assert (geo_model._stack.df['BottomRelation'] == ['Fault', 'Erosion']).all() assert (geo_model._stack.df.index == ['Fault1', 'Cycle1']).all() print(geo_model._stack.df)
def test_map2loop_model_no_faults(): # Location box bbox = (500000, 7490000, 545000, 7520000) model_base = -3200 # Original 3200 model_top = 800 # Input files geo_model = gp.create_model('test_map2Loop') gp.init_data( geo_model, extent=[bbox[0], bbox[2], bbox[1], bbox[3], model_base, model_top], resolution=[50, 50, 80], path_o=orientations_file, path_i=contacts_file ) gp.set_interpolator(geo_model) # Load Topology geo_model.set_topography(source='gdal', filepath=fp) # Stack Processing contents = np.genfromtxt(series_file, delimiter=',', dtype='U100')[1:, 4:-1] map_series_to_surfaces = {} for pair in contents: map_series_to_surfaces.setdefault(pair[1], []).append(pair[0]) gp.map_stack_to_surfaces(geo_model, map_series_to_surfaces, remove_unused_series=False) gp.plot_2d(geo_model, ve=10, show_topography=False) plt.show() # Plot in 3D gp.plot_3d(geo_model, ve=10, show_topography=False, image=True) # Stack Processing contents = np.genfromtxt(series_file, delimiter=',', dtype='U100')[1:, 4:-1] map_series_to_surfaces = {} for pair in contents: map_series_to_surfaces.setdefault(pair[1], []).append(pair[0]) gp.map_stack_to_surfaces(geo_model, map_series_to_surfaces, remove_unused_series=False) # Adding axial rescale #geo_model._rescaling.toggle_axial_anisotropy() # Increasing nugget effect geo_model.modify_surface_points( geo_model.surface_points.df.index, smooth=0.001 ) geo_model.modify_kriging_parameters('drift equations', [9, 9, 9, 9, 9]) gp.compute_model(geo_model) gp.plot_2d(geo_model, section_names=['topography'], show_topography=True, ) plt.show() gp.plot_3d(geo_model, ve=10, show_topography=True, image=True, show_lith=False, )
# %% # Setup the model # --------------- # # %% geo_model = gp.create_model('Tutorial_ch1-1_Basics') # Importing the data from CSV-files and setting extent and resolution data_path = 'https://raw.githubusercontent.com/cgre-aachen/gempy_data/master/' gp.init_data( geo_model, [0, 2000., 0, 2000., 0, 2000.], [5, 5, 5], path_o=data_path + "/data/input_data/tut_chapter1/simple_fault_model_orientations.csv", path_i=data_path + "/data/input_data/tut_chapter1/simple_fault_model_points.csv", default_values=True) gp.map_stack_to_surfaces(geo_model, { "Fault_Series": 'Main_Fault', "Strat_Series": ('Sandstone_2', 'Siltstone', 'Shale', 'Sandstone_1', 'basement') }, remove_unused_series=True) geo_model.set_is_fault(['Fault_Series']) # %% # Add sections # ~~~~~~~~~~~~
# representative space. As our model voxels are not cubes, but prisms, the # resolution can take a different shape than the extent. We don't # recommend going much higher than 100 cells in every direction (1,000,000 # voxels), as higher resolutions will become increasingly expensive to # compute. # # %% geo_model = gp.create_model('Tutorial_ch1_1_Basics') # %% data_path = 'https://raw.githubusercontent.com/cgre-aachen/gempy_data/master/' # Importing the data from CSV-files and setting extent and resolution gp.init_data(geo_model, [0, 2000., 0, 2000., 0, 750.], [50, 50, 50], path_o=data_path + "/data/input_data/getting_started/" "simple_fault_model_orientations.csv", path_i=data_path + "/data/input_data/getting_started/" "simple_fault_model_points.csv", default_values=True) # %% geo_model.surfaces # %% # The input data can then be listed using the command ``get_data``. Note # that the order of formations and respective allocation to series is # still completely arbitrary. We will fix this in the following. # # %% gp.get_data(geo_model, 'surface_points').head()
# Importing auxiliary libraries import matplotlib matplotlib.rcParams['figure.figsize'] = (20.0, 10.0) os.environ["THEANO_FLAGS"] = "mode=FAST_RUN,device=cuda" # %% data_path = 'https://raw.githubusercontent.com/cgre-aachen/gempy_data/master/' geo_model = gp.create_model('Perth_Basin') # %% gp.init_data( geo_model, extent=[337000, 400000, 6640000, 6710000, -18000, 1000], resolution=[100, 100, 100], path_i=data_path + "/data/input_data/Perth_basin/Paper_GU2F_sc_faults_topo_Points.csv", path_o=data_path + "/data/input_data/Perth_basin/Paper_GU2F_sc_faults_topo_Foliations.csv") # %% geo_model.surfaces # %% del_surfaces = ['Cadda', 'Woodada_Kockatea', 'Cattamarra'] # %% geo_model.delete_surfaces(del_surfaces, remove_data=True) # %% # %debug
# below but for this lets treat is a simple spatial interpolation in order # to keep the focus on the constraction of the probabilistic model. # # %% path_dir = os.getcwd() + '/examples/tutorials/ch5_probabilistic_modeling' # %% geo_model = gp.load_model(r'2-layers', path=path_dir, recompile=True) # %% # %% geo_model = gp.create_model('2-layers') gp.init_data(geo_model, extent=[0, 12e3, -2e3, 2e3, 0, 4e3], resolution=[500, 1, 500]) # %% geo_model.add_surfaces('surface 1') geo_model.add_surfaces('surface 2') geo_model.add_surfaces('basement') dz = geo_model.grid.regular_grid.dz geo_model.surfaces.add_surfaces_values([dz, 0, 0], ['dz']) geo_model.surfaces.add_surfaces_values(np.array([2.6, 2.4, 3.2]), ['density']) # %% geo_model.add_surface_points(3e3, 0, 3.05e3, 'surface 1') geo_model.add_surface_points(9e3, 0, 3.05e3, 'surface 1') geo_model.add_surface_points(3e3, 0, 1.02e3, 'surface 2')
if 'examples' not in cwd: data_path = os.getcwd() + '/examples' else: data_path = cwd + '/../..' path_interf = data_path + "/data/input_data/AlesModel/2018_interf.csv" path_orient = data_path + "/data/input_data/AlesModel/2018_orient_clust_n_init5_0.csv" path_dem = data_path + "/data/input_data/AlesModel/_cropped_DEM_coarse.tif" # %% resolution = [100, 100, 100] extent = np.array([729550.0, 751500.0, 1913500.0, 1923650.0, -1800.0, 800.0]) geo_model = gp.create_model('Alesmodel') gp.init_data(geo_model, extent=extent, resolution=resolution, path_i=path_interf, path_o=path_orient) # %% sdict = {'section1': ([732000, 1916000], [745000, 1916000], [200, 150])} geo_model.set_section_grid(sdict) # %% # sorting of lithologies gp.map_stack_to_surfaces(geo_model, { 'fault_left': ('fault_left'), 'fault_right': ('fault_right'), 'fault_lr': ('fault_lr'), 'Trias_Series': ('TRIAS', 'LIAS'), 'Carbon_Series': ('CARBO'),
def test_complex_model(): geo_model = gp.create_model('Geological_Model1') geo_model = gp.init_data(geo_model, extent=[0, 4000, 0, 2775, 200, 1500], resolution=[100, 10, 100]) gp.set_interpolator(geo_model, theano_optimizer='fast_run', verbose=[]) geo_model.add_features(['Fault2', 'Cycle2', 'Fault1', 'Cycle1']) geo_model.delete_features('Default series') geo_model.add_surfaces(['F2', 'H', 'G', 'F1', 'D', 'C', 'B', 'A']) gp.map_stack_to_surfaces(geo_model, { 'Fault1': 'F1', 'Fault2': 'F2', 'Cycle2': ['G', 'H'] }) geo_model.set_is_fault(['Fault1', 'Fault2']) ###Cycle 1 # surface B - before F1 geo_model.add_surface_points(X=584, Y=285, Z=500, surface='B') geo_model.add_surface_points(X=494, Y=696, Z=500, surface='B') geo_model.add_surface_points(X=197, Y=1898, Z=500, surface='B') geo_model.add_surface_points(X=473, Y=2180, Z=400, surface='B') geo_model.add_surface_points(X=435, Y=2453, Z=400, surface='B') # surface C - before F1 geo_model.add_surface_points(X=946, Y=188, Z=600, surface='C') geo_model.add_surface_points(X=853, Y=661, Z=600, surface='C') geo_model.add_surface_points(X=570, Y=1845, Z=600, surface='C') geo_model.add_surface_points(X=832, Y=2132, Z=500, surface='C') geo_model.add_surface_points(X=767, Y=2495, Z=500, surface='C') # Surface D - Before F1 geo_model.add_surface_points(X=967, Y=1638, Z=800, surface='D') geo_model.add_surface_points(X=1095, Y=996, Z=800, surface='D') # Adding orientation to Cycle 1 geo_model.add_orientations(X=832, Y=2132, Z=500, surface='C', orientation=[76, 17.88, 1]) # surface B - After F1 geo_model.add_surface_points(X=1447, Y=2554, Z=500, surface='B') geo_model.add_surface_points(X=1511, Y=2200, Z=500, surface='B') geo_model.add_surface_points(X=1549, Y=629, Z=600, surface='B') geo_model.add_surface_points(X=1630, Y=287, Z=600, surface='B') # surface C - After F1 geo_model.add_surface_points(X=1891, Y=2063, Z=600, surface='C') geo_model.add_surface_points(X=1605, Y=1846, Z=700, surface='C') geo_model.add_surface_points(X=1306, Y=1641, Z=800, surface='C') geo_model.add_surface_points(X=1476, Y=979, Z=800, surface='C') geo_model.add_surface_points(X=1839, Y=962, Z=700, surface='C') geo_model.add_surface_points(X=2185, Y=893, Z=600, surface='C') geo_model.add_surface_points(X=2245, Y=547, Z=600, surface='C') # Surface D - After F1 geo_model.add_surface_points(X=2809, Y=2567, Z=600, surface='D') geo_model.add_surface_points(X=2843, Y=2448, Z=600, surface='D') geo_model.add_surface_points(X=2873, Y=876, Z=700, surface='D') # Surface D - After F2 geo_model.add_surface_points(X=3056, Y=2439, Z=650, surface='D') geo_model.add_surface_points(X=3151, Y=1292, Z=700, surface='D') ### Fault 1 # Surface F1 geo_model.add_surface_points(X=1203, Y=138, Z=600, surface='F1') geo_model.add_surface_points(X=1250, Y=1653, Z=800, surface='F1') # orientation to Fault 1 geo_model.add_orientations(X=1280, Y=2525, Z=500, surface='F1', orientation=[272, 90, 1]) ### Cycle 2 # Surface G - Before F2 geo_model.add_surface_points(X=1012, Y=1493, Z=900, surface='G') geo_model.add_surface_points(X=1002, Y=1224, Z=900, surface='G') geo_model.add_surface_points(X=1579, Y=1376, Z=850, surface='G') geo_model.add_surface_points(X=2489, Y=336, Z=750, surface='G') geo_model.add_surface_points(X=2814, Y=1848, Z=750, surface='G') # Surface H - Before F2 geo_model.add_surface_points(X=2567, Y=129, Z=850, surface='H') geo_model.add_surface_points(X=3012, Y=726, Z=800, surface='H') # Orientation to cycle 2 geo_model.add_orientations(X=1996, Y=47, Z=800, surface='G', orientation=[92, 5.54, 1]) # Surface G - After F2 geo_model.add_surface_points(X=3031, Y=2725, Z=800, surface='G') geo_model.add_surface_points(X=3281, Y=2314, Z=750, surface='G') geo_model.add_surface_points(X=3311, Y=1357, Z=750, surface='G') geo_model.add_surface_points(X=3336, Y=898, Z=750, surface='G') # Surface H - After F2 geo_model.add_surface_points(X=3218, Y=1818, Z=890, surface='H') geo_model.add_surface_points(X=3934, Y=1207, Z=810, surface='H') geo_model.add_surface_points(X=3336, Y=704, Z=850, surface='H') ### Fault 2 geo_model.add_surface_points(X=3232, Y=178, Z=1000, surface='F2') geo_model.add_surface_points(X=2912, Y=2653, Z=700, surface='F2') # Add orientation to Fault 2 geo_model.add_orientations(X=3132, Y=951, Z=700, surface='F2', orientation=[85, 90, 1]) gp.compute_model(geo_model, sort_surfaces=False) module = GemPyModule(geo_model=geo_model, extent=extent, box=[1000, 800], load_examples=False) module.show_boundary = True module.show_lith = True module.show_hillshades = True module.show_contour = True module.show_fill_contour = False sb_params = module.update(pytest.sb_params) sb_params['fig'].show()
# %% # Data initialization: # ~~~~~~~~~~~~~~~~~~~~ # # Suggested size of the axis-aligned modeling box: Origin: 0 -0.5 0 # Maximum: 16 0.5 4.5 # # Suggested resolution: 0.05m (grid size 321 x 21 x 91) # # %% geo_model = gp.create_model('Moureze') geo_model = gp.init_data(geo_model, extent=[0, 16, -0.5, 0.5, 0, 4.5], resolution=[321, 21, 91], surface_points_df=surface_points, orientations_df=orientations, surface_name='surface', add_basement=True) # %% geo_model.orientations.df.at[5, 'surface'] # %% geo_model.orientations.df # %% # We need an orientation per series/fault. The faults does not have # orientation so the easiest is to create an orientation from the surface # points availablle: #
def extract_borehole(geo_model: gp.core.model.Project, geo_data: gemgis.GemPyData, loc: List[Union[int, float]], **kwargs): """ Extracting a borehole at a provided location from a recalculated GemPy Model Args: geo_model: gp.core.model.Project - previously calculated GemPy Model geo_data: gemgis.GemPyData - GemGIS GemPy Data class used to calculate the previous model loc: list of x and y point pair representing the well location Kwargs: zmax: int/float indicating the maximum depth of the well, default is minz of the previous model res: int indicating the resolution of the model in z-direction Returns: """ # Checking if geo_model is a GemPy geo_model if not isinstance(geo_model, gp.core.model.Project): raise TypeError('geo_model must be a GemPy geo_model') # Checking if geo_data is a GemGIS GemPy Data Class if not isinstance(geo_data, gemgis.GemPyData): raise TypeError('geo_data must be a GemPy Data object') # Checking if loc is of type list if not isinstance(loc, list): raise TypeError( 'Borehole location must be provided as a list of a x- and y- coordinate' ) # Checking if elements of loc are of type int or float if not all(isinstance(n, (int, float)) for n in loc): raise TypeError( 'Location values must be provided as integers or floats') # Selecting DataFrame columns and create deep copy of DataFrame orientations_df = geo_model.orientations.df[[ 'X', 'Y', 'Z', 'surface', 'dip', 'azimuth', 'polarity' ]].copy(deep=True) interfaces_df = geo_model.surface_points.df[['X', 'Y', 'Z', 'surface']].copy(deep=True) # Creating formation column orientations_df['formation'] = orientations_df['surface'] interfaces_df['formation'] = interfaces_df['surface'] # Deleting surface column del orientations_df['surface'] del interfaces_df['surface'] # Getting maximum depth and resolution zmax = kwargs.get('zmax', geo_model.grid.regular_grid.extent[5]) res = kwargs.get('res', geo_model.grid.regular_grid.resolution[2]) # Checking if zmax is of type int or float if not isinstance(zmax, (int, float)): raise TypeError('Maximum depth must be of type int or float') # Checking if res is of type int if not isinstance(res, (int, float, np.int32)): raise TypeError('Resolution must be of type int') # Creating variable for maximum depth z = geo_model.grid.regular_grid.extent[5] - zmax # Prevent printing # sys.stdout = open(os.devnull, 'w') # Create GemPy Model well_model = gp.create_model('Well_Model') # Initiate Data for GemPy Model gp.init_data(well_model, extent=[ loc[0] - 5, loc[0] + 5, loc[1] - 5, loc[1] + 5, geo_model.grid.regular_grid.extent[4], geo_model.grid.regular_grid.extent[5] - z ], resolution=[5, 5, res], orientations_df=orientations_df.dropna(), surface_points_df=interfaces_df.dropna(), default_values=False) # Map Stack to surfaces gp.map_stack_to_surfaces(well_model, geo_data.stack, remove_unused_series=True) # Add Basement surface well_model.add_surfaces('basement') # Change colors of surfaces well_model.surfaces.colors.change_colors(geo_data.surface_colors) # Set Interpolator gp.set_interpolator(well_model, compile_theano=True, theano_optimizer='fast_run', dtype='float64', update_kriging=False, verbose=[]) # Set faults active for i in geo_model.surfaces.df[geo_model.surfaces.df['isFault'] == True]['surface'].values.tolist(): well_model.set_is_fault([i]) # Compute Model sol = gp.compute_model(well_model, compute_mesh=False) # Reshape lith_block well = sol.lith_block.reshape(well_model.grid.regular_grid.resolution[0], well_model.grid.regular_grid.resolution[1], well_model.grid.regular_grid.resolution[2]) # Select colors for plotting color_dict = well_model.surfaces.colors.colordict surface = well_model.surfaces.df.copy(deep=True) surfaces = surface[~surface['id'].isin(np.unique(np.round(sol.lith_block)) )] for key in surfaces['surface'].values.tolist(): color_dict.pop(key) cols = list(color_dict.values()) # Calculate boundaries boundaries = np.where( np.round(well.T[:, 1])[:-1] != np.round(well.T[:, 1])[1:] )[0][::well_model.grid.regular_grid.resolution[0]] # Create Plot plt.figure(figsize=(3, 10)) plt.imshow( np.rot90(np.round(well.T[:, 1]), 2), cmap=ListedColormap(cols), extent=(0, (well_model.grid.regular_grid.extent[5] - well_model.grid.regular_grid.extent[4]) / 8, well_model.grid.regular_grid.extent[4], well_model.grid.regular_grid.extent[5]), ) list_values = np.unique(np.round(well.T[:, 1])[:, 0]).tolist() # Display depths of layer boundaries for i in boundaries: plt.text((well_model.grid.regular_grid.extent[5] - well_model.grid.regular_grid.extent[4]) / 7, i * geo_model.grid.regular_grid.dz + geo_model.grid.regular_grid.extent[4] + geo_model.grid.regular_grid.dz, '%d m' % (i * geo_model.grid.regular_grid.dz + geo_model.grid.regular_grid.extent[4]), fontsize=14) del list_values[list_values.index(np.round(well.T[:, 1])[:, 0][i + 1])] # Plot last depth plt.text( (well_model.grid.regular_grid.extent[5] - well_model.grid.regular_grid.extent[4]) / 7, geo_model.grid.regular_grid.extent[4] + geo_model.grid.regular_grid.dz, '%d m' % (geo_model.grid.regular_grid.extent[4]), fontsize=14) list_values = np.unique(np.round(well.T[:, 1])[:, 0]).tolist() # Display lithology IDs for i in boundaries: plt.text((well_model.grid.regular_grid.extent[5] - well_model.grid.regular_grid.extent[4]) / 24, i * geo_model.grid.regular_grid.dz + geo_model.grid.regular_grid.extent[4] + 2 * geo_model.grid.regular_grid.dz, 'ID: %d' % (np.round(well.T[:, 1])[:, 0][i + 1]), fontsize=14) del list_values[list_values.index(np.round(well.T[:, 1])[:, 0][i + 1])] # Plot last ID plt.text((well_model.grid.regular_grid.extent[5] - well_model.grid.regular_grid.extent[4]) / 24, geo_model.grid.regular_grid.extent[4] + 1 * geo_model.grid.regular_grid.dz, 'ID: %d' % (list_values[0]), fontsize=14) # Set legend handles patches = [ mpatches.Patch( color=cols[i], label="{formation}".format(formation=surface[surface['id'].isin( np.unique(np.round(sol.lith_block)))].surface.to_list()[i])) for i in range( len(surface[surface['id'].isin(np.unique(np.round( sol.lith_block)))].surface.to_list())) ] # Remove xticks plt.tick_params(axis='x', labelsize=0, length=0) # Set ylabel plt.ylabel('Depth [m]') # Set legend plt.legend(handles=patches, bbox_to_anchor=(3, 1)) # Create depth dict depth_dict = { int(np.round(well.T[:, 1])[:, 0][i + 1]): i * geo_model.grid.regular_grid.dz + geo_model.grid.regular_grid.extent[4] for i in boundaries } depth_dict[int(list_values[0])] = geo_model.grid.regular_grid.extent[4] depth_dict = dict(sorted(depth_dict.items())) return sol, well_model, depth_dict
# # Suggested size of the axis-aligned modeling box: Origin: 548800 7816600 # -8400 Maximum: 552500 7822000 -11010 # # Suggested resolution: 100m x 100m x -90m (grid size 38 x 55 x 30) # # %% # Number of voxels: np.array([38, 55, 30]).prod() # %% geo_model = gp.create_model('Claudius') # Importing the data from csv files and settign extent and resolution geo_model = gp.init_data(geo_model, extent=[548800, 552500, 7816600, 7822000, -11010, -8400], resolution=[38, 55, 30], surface_points_df=surface_points[::5], orientations_df=orientations, surface_name='surface', add_basement=True) # %% # We are going to increase the smoothness (nugget) of the data to increase # the conditional number of the matrix: # # %% geo_model.modify_surface_points(geo_model.surface_points.df.index, smooth=0.1).df.tail() # %% # Also the original poles are pointing downwards. We can change the # direction by calling the following: #
# # The first step to create a GemPy model is create a gempy.Model object # that will contain all the other data structures and necessary # functionality. # # In addition for this example we will define a regular grid since the # beginning. This is the grid where we will interpolate the 3D geological # model. GemPy comes with an array of different grids for different # pourposes as we will see below. For visualization usually a regular grid # is the one that makes more sense. # # %% geo_model = gp.create_model('Model1') geo_model = gp.init_data(geo_model, extent=[0, 791, 0, 200, -582, 0], resolution=[100, 10, 100]) # %% # GemPy core code is written in Python. However for efficiency (and other # reasons) most of heavy computations happend in optimize compile code, # either C or CUDA for GPU. To do so, GemPy rely on the library theano. To # guarantee maximum optimization theano requires to compile the code for # every Python kernel. The compilation is done by calling the following # line at any point (before computing the model): # # %% gp.set_interpolator(geo_model, theano_optimizer='fast_compile', verbose=[]) # %%