Open benk-mira opened 2 months ago
..So I have discovered that if I replace the integer conversion (.astype(np.int32)
) with proper rounding (.round(0)
) the image is much neater. I'm not sure this strategy is perfect though.. Is it expected that the raw_arrays.custom
array is float valued? And if so, what's the recommended solution for this issue?
Hi @benk-mira,
thanks for your question. First of all I was able to reproduce your model. I am not 100% sure how gempy handles custom grids at the moment. I think you are correct, that the geo_model.Solutions.raw_arrays.custom
should be in an integer format (or at least have a lith_block
attribute that is in that format). I think this is just an oversight in gempy version 3. Your rounding solution seems to be the right approach, but I will need to double check that.
Apart from that I have two questions regarding your model: You create the structural frame but I think your elements are not ordered correctly. It still seems to work in this example but best order them correctly to not mess up the algorithm. Second: Your custom grid is a regular grid that you can easily create within gempy. This would allow you too also use the gempy plotting with the right coordinates etc. . I just did:
geo_model = gp.create_geomodel( project_name="test", extent=extents, resolution=[len(x), len(y), len(z)], structural_frame=structural_frame )
With gempy-viewer you then get:
Let me know if this helps or if you have further questions. Cheers, Jan
Thanks for getting back to me - Yes you're right - I have adapted my example here from something I cooked up elsewhere and messed up the order. I used a regular grid to simplify things for the example, but I am interested in the custom grid primarily to be able to pass octree mesh centers in and get models I can use for geophysical simulation with SimPEG.
I do have one more question. While looking into this issue, I couldn't seem to find a straightforward way to access Gempys internal octree cells centers and the computed solution on those centers. Any suggestions for this?
I'll use the round solution for now, but look for an update in the future. My initial results with Gempy have been very positive overall, and I'm looking forward to exploring more!
Cheers, Ben
The octree result is a little hidden: You can find the coordinates in geo_model.solutions.octrees_output[i].grid_centers.values
(i indicating the chosen level) and the computed result in geo_model.solutions.octrees_output[i].outputs_centers[0].final_block
.
The following code (using pyvista, gives you a plot of the centers with their corresponding lith block value:
# Compute model
geo_model = gp.create_geomodel(
project_name="test",
extent=extents,
refinement=7,
structural_frame=structural_frame
)
gp.compute_model(geo_model)
gpv.plot_2d(geo_model, direction="z")
gpv.plot_3d(geo_model)
# Create object containing back transformed octree grids per level
corner_list = []
center_list = []
for i in range(len(geo_model.solutions.octrees_output) - 1):
corner_list.append(
geo_model.input_transform.apply_inverse(geo_model.solutions.octrees_output[i].grid_corners.values))
center_list.append(
geo_model.input_transform.apply_inverse(geo_model.solutions.octrees_output[i].grid_centers.values))
octree_levels = np.array(corner_list, dtype=object)
octree_centers = np.array(center_list, dtype=object)
# Plotting octree level with corresponding lith_block (refinement-1)
level_show = 6
plotter = pv.Plotter()
# Plot each level of octree refinement
for level in range(level_show):
# centers
plotter.add_mesh(pv.PolyData(octree_centers[level]),
render_points_as_spheres=True,
point_size=5,
scalars=geo_model.solutions.octrees_output[level].outputs_centers[0].final_block,
cmap="viridis")
# corners
# plotter.add_mesh(pv.PolyData(octree_levels[level]),
# render_points_as_spheres=True,
# point_size=5,
# scalars=geo_model.solutions.octrees_output[level].outputs_corners[0].final_block,
# cmap="viridis",)
# Set the bounds and grid of the plotter
plotter.show_bounds(bounds=geo_model.grid.extent,
location="furthest",
grid=True)
# Display the interactive plot
plotter.show()
Gives somethin like this for your model:
I have used the
set_custom_grid
method to compute solutions on a pre-existing grid. I am retrieving the solution fromSolutions.raw_arrays.custom
but I find that the solution is all floats and contains values that are not clearly in one of the categories:Many of the floats are close to one of the integer values and converting to integer takes care of most of issues, but I am left with some bad values in the array:
I expected that the solution in the custom array would be integer valued.
Here is my code to reproduce the slice of data pictured above.
I'm running Windows11.