def one_fault_model_no_interp(): """This only makes sense for running small test fast""" model = gp.create_data('one_fault_model', [0, 2000, 0, 2000, 0, 2000], [50, 50, 50], path_o=input_path2 + 'tut_chapter1/simple_fault_model_orientations.csv', path_i=input_path2 + 'tut_chapter1/simple_fault_model_points.csv') # Assigning series to surface as well as their order (timewise) gp.map_stack_to_surfaces(model, {"Fault_Series": 'Main_Fault', "Strat_Series": ('Sandstone_2', 'Siltstone', 'Shale', 'Sandstone_1')}, ) model.set_is_fault(['Fault_Series']) return model
def model_complex(): model = gempy.create_data(extent=[0, 2500, 0, 1000, 0, 1000], resolution = [50, 20, 20], path_o=input_path2 + "jan_models/fixture_model_orientations.csv", path_i=input_path2 + "jan_models/fixture_model_surfaces.csv") # Assigning series to surface as well as their order (timewise) gp.map_stack_to_surfaces(model, {"Fault_Series": ('fault'), "Strat_Series1": ('rock3'), "Strat_Series2": ('rock2', 'rock1'), "Basement_Series": ('basement')}) model.set_is_fault(['Fault_Series']) return model
def map_sequential_pile(load_model): geo_model = load_model # TODO decide what I do with the layer order 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']) return geo_model
def unconformity_model(): geo_model = gp.create_data('unconformity_model', [0, 1000, 0, 1000, 0, 1000], resolution=[50, 42, 33], path_o=input_path2 + "jan_models/model6_orientations.csv", path_i=input_path2 + "jan_models/model6_surface_points.csv" ) gp.map_stack_to_surfaces( geo_model, {"Strat_Series1": ('rock3'), "Strat_Series2": ('rock2', 'rock1'), "Basement_Series": ('basement')} ) return geo_model
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_stack_to_surfaces(geo_model, series_distribution, remove_unused_series=True) geo_model.reorder_features( ["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) return geo_model
def unconformity_model_topo(): geo_model = gp.create_data('unconformity_model', [0, 1000, 0, 1000, 0, 1000], resolution=[50, 42, 38], path_o=input_path2 + "jan_models/model6_orientations.csv", path_i=input_path2 + "jan_models/model6_surface_points.csv" ) geo_model.set_topography('random', d_z=(200, 920)) gp.map_stack_to_surfaces( geo_model, {"Strat_Series1": ('rock3'), "Strat_Series2": ('rock2', 'rock1'), "Basement_Series": ('basement')} ) # with open("input_data/geomodel_jan_sol.p", "rb") as f: # geo_model.solutions = load(f) 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_complete_model(tmpdir): # ### Initializing the model: compute = True 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]) geo_model.add_surfaces(['D', 'C', 'B', 'A']) # surface B 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 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 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') geo_model.add_orientations(X=832, Y=2132, Z=500, surface='C', orientation=[98, 17.88, 1]) # ----------- # Adding a fault geo_model.rename_features(['Cycle1']) geo_model.add_features(['Fault1']) geo_model.set_is_fault(['Fault1']) geo_model.modify_order_features(1, 'Fault1') geo_model.add_surfaces(['F1']) gp.map_stack_to_surfaces(geo_model, {'Fault1': 'F1'}) # Add input data of the fault 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') # Add orientation geo_model.add_orientations(X=1280, Y=2525, Z=500, surface='F1', orientation=[272, 90, -1]) # surface B 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 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 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') # ---------------- # Second cycle geo_model.add_features(['Cycle2']) geo_model.add_surfaces(['G', 'H']) gp.map_stack_to_surfaces(geo_model, {'Cycle2': ['G', 'H']}) geo_model.reorder_features(['Cycle2', 'Fault1', 'Cycle1']) # Surface G 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=1996, Y=47, Z=800, surface='G') geo_model.add_surface_points(X=300, Y=907, Z=700, surface='G') # Surface H geo_model.add_surface_points(X=3053, Y=727, Z=800, surface='G') # Orientation geo_model.add_orientations(X=1996, Y=47, Z=800, surface='G', orientation=[272, 5.54, 1]) # ---------------- # Second Fault geo_model.add_features('Fault2') geo_model.set_is_fault('Fault2') geo_model.add_surfaces('F2') geo_model.reorder_features(['Cycle2', 'Fault1', 'Fault2', 'Cycle1']) gp.map_stack_to_surfaces(geo_model, {'Fault2': 'F2'}) geo_model.add_surface_points(X=3232, Y=178, Z=1000, surface='F2') geo_model.add_surface_points(X=3132, Y=951, Z=700, surface='F2') # geo_model.add_surface_points(X=2962, Y=2184, Z=700, surface='F2') geo_model.add_orientations(X=3132, Y=951, Z=700, surface='F2', orientation=[95, 90, 1]) geo_model.add_surface_points(X=3135, Y=1300, Z=700, surface='D') geo_model.add_surface_points(X=3190, Y=969, Z=700, surface='D') geo_model.add_surface_points(X=3031, Y=2725, Z=800, surface='G') geo_model.add_surface_points(X=3018, Y=1990, Z=800, surface='G') geo_model.add_surface_points(X=3194, Y=965, Z=700, surface='G') 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')
def loop2gempy( contacts_file: str, orientations_file: str, bbox: Iterable, groups_file: str, model_base: float, model_top: float, dtm_reproj_file: str = None, faults_contact: str = None, faults_orientations: str = None, faults_faults_rel: str = None, faults_groups_rel: str = None, faults_rel_matrix = None, model_name: str = None, compute: bool = True, vtk: bool = False, vtk_path: str = None, image_2d: bool = False, plot_3d_kwargs=None ): """ Calculate the model using gempy_lite as backend. At the moment there is not support for finite faults since gempy_lite does not accept passing the ellipsoid parameters directly. :param contacts_file (str): path of contacts file :param orientations_file: path of orientations file :param bbox: model bounding box :param groups_file: path of groups file :param model_base: z value of base of model :param model_top: z value of top of model :param dtm_reproj_file: path of dtm file :param faults_contact: path of contacts file with fault data :param faults_orientations: path of orientations file with fault data :param faults_rel_matrix: bool matrix describing the interaction between groups. Rows offset columns :param faults_groups_rel: bool matrix describing the interaction between faults and features :param faults_faults_rel: bool matrix describing the interaction between faults and faults :param model_name: name of the model :param compute (bool): Default True. Whether or not compute the model :param vtk (bool): Default False. Whether or not visualize the model :param vtk_path (str): Default None. Path of vtk output directory :param plot_3d_kwargs (dict): kwargs for `gempy_lite.plot_3d` :return: gempy_lite.Project """ if plot_3d_kwargs is None: plot_3d_kwargs = {} contacts = [] orientations = [] contacts.append( pd.read_csv( contacts_file, sep=',', names=['X', 'Y', 'Z', 'formation'], header=1 ) ) if faults_contact is not None: contacts.append( pd.read_csv( faults_contact, sep=',', names=['X', 'Y', 'Z', 'formation'], header=1 ) ) orientations.append( pd.read_csv( orientations_file, sep=',', names=['X', 'Y', 'Z', 'azimuth', 'dip', 'polarity', 'formation'], header=1 ) ) if faults_orientations is not None: orientations.append( pd.read_csv( faults_orientations, sep=',', names=['X', 'Y', 'Z', 'azimuth', 'dip', 'polarity', 'formation'], header=1 ) ) if faults_faults_rel is not None and faults_groups_rel is not None: ff_ = pd.read_csv(faults_faults_rel).set_index('fault_id') fg_ = pd.read_csv(faults_groups_rel).set_index('group') p_ = pd.concat((ff_, fg_), axis=0, sort=True) faults_rel_matrix = pd.concat((p_, fg_.T), axis=1, sort=True).fillna(0).values surface_points_ready = pd.concat(contacts, sort=True) surface_points_ready.reset_index(inplace=True, drop=False) orientation_ready = pd.concat(orientations, sort=True) orientation_ready.reset_index(inplace=True, drop=False) if model_name is None: model_name = 'loop2gempy' geo_model = gp.create_model(model_name) gp.init_data( geo_model, extent=[bbox[0], bbox[2], bbox[1], bbox[3], model_base, model_top], resolution=[50, 50, 50], orientations_df=orientation_ready, surface_points_df=surface_points_ready ) # Load Topology if dtm_reproj_file is not None: if type(dtm_reproj_file) is str: source = 'gdal' topo_kwarg = {'filepath': dtm_reproj_file} elif type(dtm_reproj_file) is np.ndarray: source = 'numpy' topo_kwarg = {'array': dtm_reproj_file} else: raise AttributeError('dtm_proj_file must be either a path to gdal or a' 'numpy array with values') geo_model.set_topography(source=source, **topo_kwarg) # Stack Processing contents = np.genfromtxt(groups_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) order_formations = geo_model.stack.df.index.drop('Default series') # Get the unassigned series as faults if faults_contact is not None and faults_orientations is not None: faults_pair = geo_model._surfaces.df.groupby('series').get_group('Default series')[[ 'surface']].values[:, 0] faults_pair_dict = dict(zip(faults_pair, faults_pair)) gp.map_stack_to_surfaces(geo_model, faults_pair_dict, remove_unused_series=True) # Grabbing the order of faults and Formations ordered_features = np.append(faults_pair, order_formations) # Sorting series geo_model.reorder_features(ordered_features) geo_model.set_is_fault(faults_pair) # Faults relation geo_model.set_fault_relation(faults_rel_matrix) geo_model.add_surfaces('basement') # Check if there is features without data and delete it try: f_ = geo_model.surfaces.df.groupby('isActive').get_group(False) features_without_data = f_['series'] geo_model.delete_features(features_without_data, remove_surfaces=True, remove_data=True) except KeyError: pass if faults_contact is not None and faults_orientations is not None: get_fault_names = geo_model.stack.df.groupby(['isActive', 'isFault']).get_group( (True, True)).index geo_model._surfaces.colors.make_faults_black(get_fault_names) try: colours = pd.read_csv(groups_file).set_index('code')['colour'] # Drop formations that do not exist in surfaces colours = colours.loc[colours.index.isin(geo_model.surfaces.df['surface'])].to_dict() geo_model._surfaces.colors.change_colors(colours) except KeyError: pass if compute is True: gp.set_interpolator(geo_model, dtype='float64', # verbose=['solve_kriging'] ) # Increasing nugget effect geo_model.modify_surface_points( geo_model.surface_points.df.index, smooth=0.1 ) geo_model.modify_orientations( geo_model.orientations.df.index, smooth=0.01 ) new_range = geo_model.get_additional_data().loc[('Kriging', 'range'), 'values'] * 0.5 geo_model.modify_kriging_parameters('range', new_range) gp.compute_model(geo_model) if vtk is True: gp.plot_3d(geo_model, show_topography=True, image=image_2d, show_lith=True, **plot_3d_kwargs ) if vtk_path is not None: gp._plot.export_to_vtk(geo_model, path=vtk_path, name=model_name + '.vtk', voxels=False, block=None, surfaces=True) return geo_model