示例#1
0
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 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
示例#3
0
def test_kriging_mutation(interpolator, map_sequential_pile):
    geo_model = map_sequential_pile
    geo_model.set_theano_graph(interpolator)

    gp.compute_model(geo_model, compute_mesh=False)
    gp.plot.plot_2d(geo_model, cell_number=25, show_scalar=True, series_n=1, N=15,
                    direction='y', show_data=True)
    print(geo_model.solutions.lith_block, geo_model._additional_data)
    #plt.savefig(os.path.dirname(__file__)+'/figs/test_kriging_mutation')

    geo_model.modify_kriging_parameters('range', 1)
    geo_model.modify_kriging_parameters('drift equations', [0, 3])

    print(geo_model.solutions.lith_block, geo_model._additional_data)
    # copy dataframe before interpolator is calculated
    pre = geo_model._additional_data.kriging_data.df.copy()

    gp.set_interpolator(geo_model, compile_theano=True,
                        theano_optimizer='fast_compile', update_kriging=False)
    gp.compute_model(geo_model, compute_mesh=False)

    gp.plot.plot_2d(geo_model, cell_number=25, series_n=1, N=15, show_boundaries=False,
                    direction='y', show_data=True, show_lith=True)

    print(geo_model.solutions.lith_block, geo_model._additional_data)
    plt.savefig(os.path.dirname(__file__)+'/../figs/test_kriging_mutation2')
    assert geo_model._additional_data.kriging_data.df['range'][0] == pre['range'][0]
示例#4
0
    def vista_obj(self) -> vs.Vista:
        """Return a GemPy Vista instance with basic geomodel attached."""
        from gempy.plot import vista as vs

        geo_model = gp.create_data(
            [0, 2000, 0, 2000, 0, 2000], [50, 50, 50],
            path_o=input_path + '/input_data/tut_chapter1'
            '/simple_fault_model_orientations.csv',
            path_i=input_path + '/input_data/tut_chapter1'
            '/simple_fault_model_points.csv')

        gp.set_series(
            geo_model, {
                "Fault_Series":
                'Main_Fault',
                "Strat_Series":
                ('Sandstone_2', 'Siltstone', 'Shale', 'Sandstone_1')
            })
        geo_model.set_is_fault(['Fault_Series'])
        gp.set_interpolator(geo_model)
        gp.compute_model(geo_model)
        # with open(os.path.dirname(__file__)+"input_data/geomodel_fabian_sol.p", "rb") as f:
        #     geo_model.solutions = load(f)

        return vs.Vista(geo_model)
示例#5
0
def test_magnetics_api():
    # TODO add the check

    geo_model = gp.create_model('test_center_grid_slicing')
    geo_model.set_default_surfaces()
    geo_model.add_surface_points(X=-1, Y=0, Z=0, surface='surface1')
    geo_model.add_surface_points(X=1, Y=0, Z=0, surface='surface1')
    geo_model.add_orientations(X=0,
                               Y=0,
                               Z=0,
                               surface='surface1',
                               pole_vector=(0, 0, 1))
    geo_model.surfaces.add_surfaces_values([0.037289, 0.0297],
                                           ['susceptibility'])

    # needed constants
    mu_0 = 4.0 * np.pi * 10e-7  # magnetic permeability in free space [N/A^2]
    cm = mu_0 / (4.0 * np.pi)  # constant for SI unit
    incl = 77.0653  # NOAA
    decl = 6.8116
    B_ext = 52819.8506939139e-9  # T

    geo_model.set_regular_grid(extent=[-5, 5, -5, 5, -5, 5],
                               resolution=[5, 5, 5])
    geo_model.set_centered_grid(np.array([0, 0, 0]),
                                resolution=[10, 10, 15],
                                radio=5000)

    gp.set_interpolator(geo_model, output=['magnetics'], incl=incl, decl=decl)

    gp.compute_model(geo_model)
    print(geo_model.interpolator.theano_graph.lg0.get_value())
    return geo_model
示例#6
0
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)
示例#7
0
def test_gempy_th_op_set_grav():
    path_dir = os.getcwd(
    ) + '/../../examples/tutorials/ch5_probabilistic_modeling'
    geo_model = gp.load_model(r'2-layers', path=path_dir, recompile=False)
    gp.set_interpolator(geo_model, output='grav')

    gto = GemPyThOp(geo_model)
    th_op_grav = gto.set_th_op('gravity')
    i = geo_model.interpolator.get_python_input_block()
    th_f = theano.function([], th_op_grav(*i), on_unused_input='warn')
示例#8
0
    def create_model(resolution=[50, 50, 50]):
        geo_data = gp.create_data(
            'fault',
            extent=[0, 1000, 0, 1000, 0, 1000],
            resolution=resolution,
            path_o=path_to_data + "model5_orientations.csv",
            path_i=path_to_data + "model5_surface_points.csv")

        geo_data.get_data()

        gp.map_stack_to_surfaces(geo_data, {
            "Fault_Series": 'fault',
            "Strat_Series": ('rock2', 'rock1')
        })
        geo_data.set_is_fault(['Fault_Series'])

        interp_data = gp.set_interpolator(geo_data,
                                          theano_optimizer='fast_compile')

        sol = gp.compute_model(geo_data)

        geo = gp.plot_2d(geo_data,
                         direction='y',
                         show_data=True,
                         show_lith=True,
                         show_boundaries=False)
        geo.axes[0].set_title("")
        plt.tight_layout()
        plt.close()
        return geo.axes[0].figure
示例#9
0
def test_axial_anisotropy(model):
    # Location box

    geo_model = model
    geo_model._rescaling.toggle_axial_anisotropy()
    # gp.compute_model(geo_model, compute_mesh_options={'mask_topography': False})

    geo_model.surface_points.df[['X', 'Y',
                                 'Z']] = geo_model.surface_points.df[[
                                     'X_c', 'Y_c', 'Z_c'
                                 ]]
    geo_model.orientations.df[['X', 'Y', 'Z']] = geo_model.orientations.df[[
        'X_c', 'Y_c', 'Z_c'
    ]]

    # This is a hack
    geo_model._grid.topography.extent = geo_model._grid.extent_c

    geo_model.set_regular_grid(geo_model._grid.extent_c, [50, 50, 50])
    geo_model.modify_kriging_parameters('range', 0.1)
    geo_model.modify_kriging_parameters('drift equations', [9, 9, 9, 9, 9])

    geo_model.modify_surface_points(geo_model.surface_points.df.index,
                                    smooth=0.001)

    gp.set_interpolator(geo_model,
                        theano_optimizer='fast_run',
                        dtype='float64')
    gp.compute_model(geo_model,
                     compute_mesh_options={
                         'mask_topography': False,
                         'masked_marching_cubes': False
                     })

    gp.plot_2d(
        geo_model,
        section_names=['topography'],
        show_topography=True,
    )
    plt.show()

    gp.plot_3d(geo_model,
               ve=None,
               show_topography=False,
               image=True,
               show_lith=False,
               kwargs_plot_data={'arrow_size': 10})
示例#10
0
def test_simple_model_gempy_engine():
    import numpy
    numpy.set_printoptions(precision=3, linewidth=200)

    g = gempy.create_data("test_engine",
                          extent=[-4, 4, -4, 4, -4, 4],
                          resolution=[4, 1, 4])
    sp = np.array([[-3, 0, 0], [0, 0, 0], [2, 0, 0.5], [2.5, 0, 1.2],
                   [3, 0, 2], [1, 0, .2], [2.8, 0, 1.5]])

    g.set_default_surfaces()

    for i in sp:
        g.add_surface_points(*i, surface="surface1")

    g.add_orientations(-3, 0, 2, pole_vector=(0, 0, 1), surface="surface1")
    g.add_orientations(2, 0, 3, pole_vector=(-.2, 0, .8), surface="surface1")

    g.modify_orientations([0, 1], smooth=0.000000000001)
    g.modify_surface_points(g._surface_points.df.index, smooth=0.0000000001)

    gempy.set_interpolator(g,
                           verbose=[
                               "n_surface_op_float_sigmoid",
                               "scalar_field_iter", "compare", "sigma"
                           ])

    g.modify_kriging_parameters("range", 50)
    # g.modify_kriging_parameters("$C_o$", 5 ** 2 / 14 / 3)
    g.modify_kriging_parameters("drift equations", [0])

    import theano
    dtype = "float32"

    g._interpolator.theano_graph.i_reescale.set_value(np.cast[dtype](1.))
    g._interpolator.theano_graph.gi_reescale.set_value(np.cast[dtype](1.))

    gempy.compute_model(g)

    print(g.additional_data)
    print(g.solutions.scalar_field_matrix)

    gempy.plot_2d(g)
    print(g.grid.values)

    print(g.solutions.weights_vector)
示例#11
0
    def interpolator(self):
        # Importing the data from csv files and settign extent and resolution
        geo_data = gempy.import_data([0, 10, 0, 10, -10, 0], [50, 50, 50],
                                     path_f="./GeoModeller/test_a/test_a_Foliations.csv",
                                     path_i="./GeoModeller/test_a/test_a_Points.csv")

        data_interp = gempy.set_interpolator(geo_data,
                                             dtype="float64",
                                             verbose=['solve_kriging'])
示例#12
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)
示例#13
0
def geo_model():
    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_series_to_surfaces(
        geo_model, {
            "Flat_Series": 'Flat',
            "Inclined_Series": 'Inclined',
            "Fold_Series": ('Basefold', 'Topfold', 'basement')
        })

    # Create the theano model
    gp.set_interpolator(geo_model, theano_optimizer='fast_compile')

    return geo_model
示例#14
0
def topology_jan_unconf():
    geo_model = gp.create_data(
        [0, 1000, 0, 1000, 0, 1000],
        resolution=[50, 50, 50],
        path_o=data_path / "jan_models/model6_orientations.csv",
        path_i=data_path / "jan_models/model6_surface_points.csv")

    gp.map_series_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)
    gp.set_interpolator(geo_model)
    gp.compute_model(geo_model)

    edges, centroids = tp.compute_topology(geo_model, voxel_threshold=1)
    return edges, centroids
示例#15
0
def create_gempy_model(resolution=[20, 20, 20], type=2):
    if type == 1:
        data_path = 'https://raw.githubusercontent.com/cgre-aachen/gempy_data/master/'
        path_to_data = data_path + "/data/input_data/jan_models/"
        geo_data = gp.create_data(
            'fold',
            extent=[0, 1000, 0, 1000, 0, 1000],
            resolution=resolution,
            path_o=path_to_data + "model2_orientations.csv",
            path_i=path_to_data + "model2_surface_points.csv")
        gp.map_stack_to_surfaces(geo_data, {
            "Strat_Series": ('rock2', 'rock1'),
            "Basement_Series": ('basement')
        })

        interp_data = gp.set_interpolator(geo_data,
                                          theano_optimizer='fast_compile')

        sol = gp.compute_model(geo_data)
    elif type == 2:
        data_path = 'https://raw.githubusercontent.com/cgre-aachen/gempy_data/master/'
        path_to_data = data_path + "/data/input_data/jan_models/"

        geo_data = gp.create_data(
            'unconformity',
            extent=[0, 1000, 0, 1000, 0, 1000],
            resolution=[50, 50, 50],
            path_o=path_to_data + "model6_orientations.csv",
            path_i=path_to_data + "model6_surface_points.csv")
        gp.map_stack_to_surfaces(
            geo_data, {
                "Strat_Series1": ('rock3'),
                "Strat_Series2": ('rock2', 'rock1'),
                "Basement_Series": ('basement')
            })
        interp_data = gp.set_interpolator(geo_data,
                                          theano_optimizer='fast_compile')
        sol = gp.compute_model(geo_data)

    return geo_data
示例#16
0
def topology_fabian():
    """Return a GemPy Vista instance with basic geomodel attached."""
    geo_model = gp.create_data(
        [0, 2000, 0, 2000, 0, 2000], [50, 50, 50],
        path_o=data_path / 'tut_chapter1/simple_fault_model_orientations.csv',
        path_i=data_path / 'tut_chapter1/simple_fault_model_points.csv')

    gp.set_series(
        geo_model, {
            "Fault_Series": 'Main_Fault',
            "Strat_Series":
            ('Sandstone_2', 'Siltstone', 'Shale', 'Sandstone_1')
        })
    geo_model.set_is_fault(['Fault_Series'])
    gp.set_interpolator(geo_model)
    gp.compute_model(geo_model)

    # with open("input_data/geomodel_fabian_sol.p", "rb") as f:
    #     geo_model.solutions = load(f)

    edges, centroids = tp.compute_topology(geo_model, voxel_threshold=1)
    return edges, centroids
示例#17
0
# %%
gp.plot.plot_section_traces(geo_model)

# %%
# Faults
# ''''''
#

# %%
geo_model.set_is_fault(['fault_right', 'fault_left', 'fault_lr'],
                       change_color=True)

# %%
gp.set_interpolator(geo_model,
                    output=['geology'],
                    compile_theano=True,
                    theano_optimizer='fast_run',
                    dtype='float64',
                    verbose=[])

# %%
# Topography
# ~~~~~~~~~~
#

# %%
geo_model.set_topography(source='gdal', filepath=path_dem)

# %%
geo_model.surfaces

# %%
示例#18
0
    ".csv")

gp.map_stack_to_surfaces(
    geo_model, {
        "Fault_1":
        'Fault_1',
        "Fault_2":
        'Fault_2',
        "Strat_Series":
        ('Sandstone', 'Siltstone', 'Shale', 'Sandstone_2', 'Schist', 'Gneiss')
    })

geo_model.set_is_fault(['Fault_1', 'Fault_2'])
geo_model.set_topography()

gp.set_interpolator(geo_model)
gp.compute_model(geo_model, compute_mesh=True)

# %%
# Basic plotting API
# ------------------
#

# %%
# Data plot
# ~~~~~~~~~
#

# %%
gp.plot_3d(geo_model,
           show_surfaces=False,
示例#19
0
文件: Hecho.py 项目: sklgp2016/gempy
# %%
geo_model.modify_order_series(4, 'Default series')

# %%
# Lastly, so far we did not specify which series/faults are actula faults:
#

# %%
geo_model.set_is_fault(['Fault1', 'Fault2', 'Fault3'])

# %%
# Now we are good to go:
#

# %%
gp.set_interpolator(geo_model, theano_optimizer='fast_run', dtype='float64')

# %%
# The default range is always the diagonal of the extent. Since in this
# model data is very close we will need to reduce the range to 5-10% of
# that value:
#

# %%
new_range = geo_model.get_additional_data().loc[('Kriging', 'range'),
                                                'values'] * 0.2
geo_model.modify_kriging_parameters('range', new_range)

# %%
gp.compute_model(geo_model, sort_surfaces=True, compute_mesh=False)
示例#20
0
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()
示例#21
0
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,
               )
示例#22
0
#
# Once we have made sure that we have defined all our primary information
# as desired in our object ``DataManagement.InputData`` (named
# ``geo_data`` in these tutorials), we can continue with the next step
# towards creating our geological model: preparing the input data for
# interpolation.
#
# This is done by generating an ``InterpolatorData`` object (named
# ``interp_data`` in these tutorials) from our ``InputData`` object via
# the following function:
#

# %%
gp.set_interpolator(
    geo_model,
    compile_theano=True,
    theano_optimizer='fast_compile',
)

# %%
# This function rescales the extent and coordinates of the original data
# (and stores it in the attribute ``geo_data_res`` which behaves as a usual
# ``InputData`` object) and adds mathematical parameters that are needed
# for conducting the interpolation. The computation of this step may take
# a while, as it also compiles a theano function which is required for the
# model computation. However, should this not be needed, we can skip it by
# declaring ``compile_theano = False`` in the function.
#
# Furthermore, this preparation process includes an assignment of numbers
# to each formation. Note that GemPy always creates a default basement
# formation as the last formation number. Afterwards, numbers are
示例#23
0
geo_model.set_fault_relation(fr)

# %%
# %matplotlib inline
gp.plot_2d(geo_model, direction=['z'])

# %%
geo_model.set_topography(source='random')

# %%
gp.plot_3d(geo_model)

# %%
interp_data = gp.set_interpolator(geo_model,
                                  compile_theano=True,
                                  theano_optimizer='fast_run',
                                  gradient=False,
                                  dtype='float32')

# %%
gp.compute_model(geo_model)

# %%
gp.plot_2d(geo_model, cell_number=[25])

# %%
gp.plot_2d(geo_model, cell_number=[25], series_n=-1, show_scalar=True)

# %%
gp.plot_2d(geo_model,
           cell_number=[12],
示例#24
0
# as well as the lithologies. In addition we need either to pass the density
# block (see below). Or the position of density on the surface(in the
# future the name) to compute the density block at running time.
#

# %%
geo_model.surfaces

# %%
# In this case the densities of each layer are at the loc 1 (0 is the id)
#

# New way
gp.set_interpolator(geo_model,
                    output=['gravity'],
                    pos_density=1,
                    gradient=False,
                    theano_optimizer='fast_run')

# %%
# Once we have created a gravity interpolator we can call it from compute
# model as follows:
#

# %%
sol = gp.compute_model(geo_model)
grav = sol.fw_gravity

# %%
gp.plot_2d(geo_model,
           direction=['z'],
def create_example_model(name,
                         extent=[0, 1000, 0, 1000, 0, 1800],
                         do_sections=False,
                         change_color=False,
                         data_path=path_to_data,
                         resolution=[20, 20, 20],
                         theano_optimizer='fast_compile'):
    # _test_data['gempy_data'], theano_optimizer='fast_compile'):
    """
    Create all the example models
    Args:
        name: Name of the model to create
        extent: extent of the model in model units
        do_sections: False
        change_color: False
        data_path: Path to the .csv files storing the information
        theano_optimizer: 'fast_compile'
    Returns:
        geo_model

    """
    assert name in all_models, 'possible model names are ' + str(all_models)
    if name == 'Horizontal_layers':
        geo_model = gp.create_data(
            name,
            extent=extent,
            resolution=resolution,
            path_o=data_path + "model1_orientations.csv",
            path_i=data_path + "model1_surface_points.csv")

        gp.map_stack_to_surfaces(geo_model, {
            "Strat_Series": ('rock2', 'rock1'),
            "Basement_Series": ('basement')
        })
        if change_color:
            geo_model.surfaces.colors.change_colors({
                "rock2": '#9f0052',
                'rock1': '#e36746',
                'basement': '#f9f871'
            })

    elif name == 'Anticline':
        geo_model = gp.create_data(
            name,
            extent=extent,
            resolution=resolution,
            path_o=data_path + "model2_orientations.csv",
            path_i=data_path + "model2_surface_points.csv")
        gp.map_stack_to_surfaces(geo_model, {
            "Strat_Series": ('rock2', 'rock1'),
            "Basement_Series": ('basement')
        })

    elif name == 'Recumbent_fold':
        geo_model = gp.create_data(
            name,
            extent=extent,
            resolution=resolution,
            path_o=data_path + "model3_orientations.csv",
            path_i=data_path + "model3_surface_points.csv")
        gp.map_stack_to_surfaces(geo_model, {
            "Strat_Series": ('rock2', 'rock1'),
            "Basement_Series": ('basement')
        })
        if change_color:
            geo_model.surfaces.colors.change_colors({
                "rock2": '#e36746',
                'rock1': '#c0539f',
                'basement': '#006fa8'
            })

    elif name == 'Pinchout':
        geo_model = gp.create_data(
            name,
            extent=extent,
            resolution=resolution,
            path_o=data_path + "model4_orientations.csv",
            path_i=data_path + "model4_surface_points.csv")
        gp.map_stack_to_surfaces(geo_model, {
            "Strat_Series": ('rock2', 'rock1'),
            "Basement_Series": ('basement')
        })
        if change_color:
            geo_model.surfaces.colors.change_colors({
                "rock2": '#a1b455',
                'rock1': '#ffbe00',
                'basement': '#006471'
            })

    elif name == 'Fault':
        geo_model = gp.create_data(
            name,
            extent=extent,
            resolution=resolution,
            path_o=data_path + "model5_orientations.csv",
            path_i=data_path + "model5_surface_points.csv")
        gp.map_stack_to_surfaces(geo_model, {
            "Fault_Series": 'fault',
            "Strat_Series": ('rock2', 'rock1')
        })
        geo_model.set_is_fault(['Fault_Series'], change_color=False)
        if change_color:
            geo_model.surfaces.colors.change_colors({
                "rock2": '#00c2d0',
                'rock1': '#a43d00',
                'basement': '#76a237',
                'fault': '#000000'
            })
    elif name == 'Unconformity':
        geo_model = gp.create_data(
            name,
            extent=extent,
            resolution=resolution,
            path_o=data_path + "model6_orientations.csv",
            path_i=data_path + "model6_surface_points.csv")

        gp.map_stack_to_surfaces(
            geo_model, {
                "Strat_Series1": ('rock3'),
                "Strat_Series2": ('rock2', 'rock1'),
                "Basement_Series": ('basement')
            })
    else:
        raise NotImplementedError(name, "Not available in example models")

    if do_sections:
        geo_model.set_section_grid(
            {'section' + ' ' + name: ([0, 500], [1000, 500], [30, 30])})

    interp_data = gp.set_interpolator(
        geo_model,  # compile_theano=True,
        theano_optimizer=theano_optimizer)

    sol = gp.compute_model(geo_model, compute_mesh=False)

    if do_sections:
        gp.plot_2d(geo_model,
                   section_names=['section' + ' ' + name],
                   show_data=False)

    return geo_model
示例#26
0
imageio.mimsave('./hard1.mov', image_list2, fps=9)

# %%
# Plot 3D
# -------
#

# %%
geo_model.set_regular_grid(geo_model.grid.regular_grid.extent, [40, 20, 40])

# %%
geo_model.set_active_grid('regular', reset=True)

# %%
gp.set_interpolator(geo_model,
                    output=['geology'],
                    gradient=False,
                    theano_optimizer='fast_run')

# %%
gp.compute_model(geo_model)

# %%
import pyvista
pyvista.set_plot_theme('doc')

# %%
pv = gp._plot.plot_3d(geo_model,
                      plotter_type='background',
                      render_surfaces=False)

# %%
示例#27
0
# 

# %% 
gp.map_stack_to_surfaces(geo_data,
                         {"Strat_Series": ('rock2', 'rock1'),
                          "Basement_Series": ('basement')})

# %%
gp.plot_2d(geo_data, direction=['y'])

# %%
# Calculating the model:
# 

# %% 
interp_data = gp.set_interpolator(geo_data, theano_optimizer='fast_compile')

# %% 
sol = gp.compute_model(geo_data)

# %%
# Displaying the result in x and y direction:
# 

# %%
gp.plot_2d(geo_data, cell_number=[25],
           direction=['x'], show_data=True)

# %%
# sphinx_gallery_thumbnail_number = 3
gp.plot_2d(geo_data, cell_number=[25],
示例#28
0
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
示例#29
0

# %%
# Check which series/faults are affected by other faults (rows offset
# columns):
# 

# %% 
geo_model.faults.faults_relations_df

# %%
# Now we are good to go:
# 

# %% 
gp.set_interpolator(geo_model, theano_optimizer='fast_run',
                    compile_theano=True)

# %% 
gp.compute_model(geo_model)

# %% 
sect = [35]

gp.plot_2d(geo_model, cell_number=sect, series_n=1, show_scalar=True, direction='x')


# %% 
gp.plot_2d(geo_model, cell_number=sect, show_data=True, direction='x')

# %% 
gp.plot_2d(geo_model, cell_number=[28], series_n=0, direction='y', show_scalar=True)
示例#30
0
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=[])

# %%
# Creating figure:
# ~~~~~~~~~~~~~~~~
#
# GemPy uses matplotlib and pyvista-vtk libraries for 2d and 3d
# visualization of the model respectively. One of the design decisions of
# GemPy is to allow real time construction of the model. What this means
# is that you can start adding input data and see in real time how the 3D
# surfaces evolve. Lets initialize the visualization windows.
#
# The first one is the 2d figure. Just place the window where you can see
# it (maybe move the jupyter notebook to half screen and use the other
# half for the renderers).
#