|
| 1 | +import numpy as np |
| 2 | +import os |
| 3 | + |
| 4 | +import gempy as gp |
| 5 | +import gempy_viewer as gpv |
| 6 | +from gempy.core.data.grid_modules import CustomGrid |
| 7 | +from gempy_engine.core.backend_tensor import BackendTensor |
| 8 | +from gempy_probability.modules.likelihoods import apparent_thickness_likelihood_II |
| 9 | + |
| 10 | + |
| 11 | +def test_gempy_posterior_I(): |
| 12 | + current_dir = os.path.dirname(os.path.abspath(__file__)) |
| 13 | + data_path = os.path.abspath(os.path.join(current_dir, '..', '..', 'examples', 'tutorials', 'data')) |
| 14 | + geo_model = gp.create_geomodel( |
| 15 | + project_name='Wells', |
| 16 | + extent=[0, 12000, -500, 500, 0, 4000], |
| 17 | + refinement=4, |
| 18 | + importer_helper=gp.data.ImporterHelper( |
| 19 | + path_to_orientations=os.path.join(data_path, "2-layers", "2-layers_orientations.csv"), |
| 20 | + path_to_surface_points=os.path.join(data_path, "2-layers", "2-layers_surface_points.csv") |
| 21 | + ) |
| 22 | + ) |
| 23 | + |
| 24 | + BackendTensor.change_backend_gempy(engine_backend=gp.data.AvailableBackends.PYTORCH) |
| 25 | + |
| 26 | + geo_model.interpolation_options.uni_degree = 0 |
| 27 | + geo_model.interpolation_options.mesh_extraction = False |
| 28 | + |
| 29 | + x_loc = 6000 |
| 30 | + y_loc = 0 |
| 31 | + z_loc = np.linspace(0, 4000, 100) |
| 32 | + dz = (4000 - 0)/100 |
| 33 | + xyz_coord = np.array([[x_loc, y_loc, z] for z in z_loc]) |
| 34 | + |
| 35 | + custom_grid = CustomGrid(xyz_coord) |
| 36 | + geo_model.grid.custom_grid = custom_grid |
| 37 | + gp.set_active_grid( |
| 38 | + grid=geo_model.grid, |
| 39 | + grid_type=[gp.data.Grid.GridTypes.CUSTOM] |
| 40 | + ) |
| 41 | + gp.compute_model(gempy_model=geo_model) |
| 42 | + p2d = gpv.plot_2d( |
| 43 | + model=geo_model, |
| 44 | + show_topography=False, |
| 45 | + legend=False, |
| 46 | + show_lith=False, |
| 47 | + show=False |
| 48 | + ) |
| 49 | + |
| 50 | + element_lith_id = 1.5 |
| 51 | + thickness = apparent_thickness_likelihood_II( |
| 52 | + model_solutions=geo_model.solutions, |
| 53 | + distance=dz, |
| 54 | + element_lith_id=element_lith_id |
| 55 | + ) |
| 56 | + |
| 57 | + print(thickness) |
| 58 | + |
| 59 | + p2d = gpv.plot_2d(geo_model, show_topography=False, legend=False, show=False) |
| 60 | + # --- New code: plot all custom grid points with lithology 1 --- |
| 61 | + # |
| 62 | + # Extract the simulated well values from the solution obtained. |
| 63 | + simulated_well = geo_model.solutions.octrees_output[0].last_output_center.custom_grid_values |
| 64 | + # |
| 65 | + # Create a boolean mask for all grid points whose value is between 1 and 2. |
| 66 | + mask = (simulated_well >= element_lith_id) & (simulated_well < (element_lith_id + 1)) |
| 67 | + # |
| 68 | + # Retrieve the custom grid coordinates. |
| 69 | + grid_coords = geo_model.grid.custom_grid.values |
| 70 | + # |
| 71 | + # Use the mask to get only the grid points corresponding to lith id 1. |
| 72 | + # Note: Convert the boolean mask to a NumPy array if necessary. |
| 73 | + coords_lith1 = grid_coords[mask] |
| 74 | + # |
| 75 | + # Plot these points on the figure (using the x and z columns for a 2D image). |
| 76 | + p2d.axes[0].scatter( |
| 77 | + coords_lith1[:, 0], |
| 78 | + coords_lith1[:, 2], |
| 79 | + marker='o', |
| 80 | + s=80, |
| 81 | + c='green', |
| 82 | + label='Lith id = 1', |
| 83 | + zorder=9 |
| 84 | + ) |
| 85 | + p2d.axes[0].legend() |
| 86 | + # -------------------------------------------------------------- |
| 87 | + |
| 88 | + # Plot device location for reference. |
| 89 | + device_loc = np.array([[6e3, 0, 3700]]) |
| 90 | + p2d.axes[0].scatter( |
| 91 | + device_loc[:, 0], |
| 92 | + device_loc[:, 2], |
| 93 | + marker='x', |
| 94 | + s=400, |
| 95 | + c='#DA8886', |
| 96 | + zorder=10 |
| 97 | + ) |
| 98 | + p2d.fig.show() |
0 commit comments