Skip to content

Commit 8586c7d

Browse files
committed
[WIP] debugging actors
1 parent c7ea098 commit 8586c7d

File tree

5 files changed

+83
-41
lines changed

5 files changed

+83
-41
lines changed

gempy_viewer/API/_plot_3d_API.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def plot_3d(
187187
scalar_data_type=ScalarDataType.SCALAR_FIELD,
188188
active_scalar_field=active_scalar_field,
189189
solution=solutions_raw_arrays,
190-
cmap='viridis',
190+
cmap='magma',
191191
**kwargs_plot_structured_grid
192192
)
193193

gempy_viewer/modules/plot_3d/drawer_input_3d.py

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,22 @@ def plot_data(gempy_vista: GemPyToVista,
2222

2323
plot_surface_points(
2424
gempy_vista=gempy_vista,
25-
surface_points=surface_points_copy,
26-
elements_colors=model.structural_frame.elements_colors,
27-
**kwargs
25+
surface_points=surface_points_copy
2826
)
2927

3028
plot_orientations(
3129
gempy_vista=gempy_vista,
3230
orientations=orientations_copy,
33-
elements_colors=model.structural_frame.elements_colors_orientations,
31+
surface_points=surface_points_copy,
3432
arrows_factor=arrows_factor
3533
)
3634

3735

3836
def plot_surface_points(
3937
gempy_vista: GemPyToVista,
4038
surface_points: SurfacePointsTable,
41-
elements_colors: list[str],
4239
render_points_as_spheres=True,
43-
point_size=10,
44-
**kwargs
40+
point_size=10
4541
):
4642
# Selecting the surfaces to plot
4743
xyz = surface_points.xyz
@@ -54,22 +50,24 @@ def plot_surface_points(
5450
ids = surface_points.ids
5551
if ids.shape[0] == 0:
5652
return
57-
poly['id'] = _vectorize_ids(ids)
53+
vectorize_ids = _vectorize_ids(ids, ids)
54+
poly['id'] = vectorize_ids
5855

5956
gempy_vista.surface_points_mesh = poly
6057
gempy_vista.surface_points_actor = gempy_vista.p.add_mesh(
6158
mesh=poly,
6259
scalars='id',
6360
render_points_as_spheres=render_points_as_spheres,
6461
point_size=point_size,
65-
show_scalar_bar=False
62+
show_scalar_bar=False,
63+
# clim=(0, ids.max())
6664
)
6765

6866

6967
def plot_orientations(
7068
gempy_vista: GemPyToVista,
7169
orientations: OrientationsTable,
72-
elements_colors: list[str],
70+
surface_points: SurfacePointsTable,
7371
arrows_factor: float,
7472
):
7573
orientations_xyz = orientations.xyz
@@ -81,16 +79,11 @@ def plot_orientations(
8179
pv = require_pyvista()
8280
poly = pv.PolyData(orientations_xyz)
8381

84-
ids = orientations.ids
85-
86-
poly['id'] = _vectorize_ids(ids)
87-
poly['vectors'] = orientations_grads
88-
89-
# TODO: I am still trying to figure out colors and ids in orientations and surface points
90-
cmap = get_geo_model_cmap(
91-
elements_colors=np.array(elements_colors),
92-
reverse=False
82+
poly['id'] = _vectorize_ids(
83+
mapping_ids=surface_points.ids,
84+
ids_to_map=orientations.ids
9385
)
86+
poly['vectors'] = orientations_grads
9487

9588
arrows = poly.glyph(
9689
orient='vectors',
@@ -100,17 +93,21 @@ def plot_orientations(
10093

10194
gempy_vista.orientations_actor = gempy_vista.p.add_mesh(
10295
mesh=arrows,
103-
cmap=cmap,
96+
scalars='id',
10497
show_scalar_bar=False
10598
)
10699
gempy_vista.orientations_mesh = arrows
107100

108101

109-
def _vectorize_ids(ids):
110-
unique_values, first_indices = np.unique(ids, return_index=True) # Find the unique elements and their first indices
111-
unique_values_order = unique_values[np.argsort(first_indices)] # Sort the unique values by their first appearance in `a`
112-
# Flip order to please pyvista vertical scalarbar
113-
unique_values_order = unique_values_order[::-1]
114-
mapping_dict = {value: i + 1 for i, value in enumerate(unique_values_order)} # Use a dictionary to map the original numbers to new values
115-
mapped_array = np.vectorize(mapping_dict.get)(ids) # Map the original array to the new values
102+
def _vectorize_ids(mapping_ids, ids_to_map):
103+
def _mapping_dict(ids):
104+
unique_values, first_indices = np.unique(ids, return_index=True) # Find the unique elements and their first indices
105+
unique_values_order = unique_values[np.argsort(first_indices)] # Sort the unique values by their first appearance in `a`
106+
# Flip order to please pyvista vertical scalarbar
107+
unique_values_order = unique_values_order[::-1]
108+
mapping_dict = {value: i + 1 for i, value in enumerate(unique_values_order)} # Use a dictionary to map the original numbers to new values
109+
return mapping_dict
110+
111+
mapping_dict = _mapping_dict(mapping_ids)
112+
mapped_array = np.vectorize(mapping_dict.get)(ids_to_map) # Map the original array to the new values
116113
return mapped_array

gempy_viewer/modules/plot_3d/drawer_structured_grid_3d.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,10 @@ def add_regular_grid_mesh(
6868
_clim = None
6969
gempy_vista.regular_grid_actor = gempy_vista.p.add_mesh(
7070
mesh=structured_grid,
71-
# cmap=cmap,
7271
# ? scalars=main_scalar, if we prepare the structured grid do we need this arg?
7372
show_scalar_bar=False,
74-
# scalar_bar_args=gempy_vista.scalar_bar_arguments,
7573
interpolate_before_map=True,
7674
opacity=opacity,
77-
# flip_scalars=True,
78-
# clim=(4,0),
7975
**kwargs
8076
)
8177

@@ -104,8 +100,9 @@ def set_scalar_data(
104100
# Substitute the madness of the previous if with match
105101
match scalar_data_type:
106102
case ScalarDataType.LITHOLOGY | ScalarDataType.ALL:
107-
max_lith = data.n_surfaces # (for basement)
108-
structured_grid.cell_data['id'] = max_lith - (data.lith_block - 1)
103+
max_lith = data.n_surfaces + 1 # (for basement)
104+
block_ = max_lith - (data.lith_block - 1)
105+
structured_grid.cell_data['id'] = block_
109106
case ScalarDataType.SCALAR_FIELD | ScalarDataType.ALL:
110107
scalar_field_ = 'sf_'
111108
for e in range(data.scalar_field_matrix.shape[0]):

gempy_viewer/modules/plot_3d/plot_3d_utils.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ def select_surfaces_data(data_df: pd.DataFrame, surfaces: Union[str, list[str]]
2626

2727
def set_scalar_bar(gempy_vista: GemPyToVista, elements_names: list[str],
2828
surfaces_ids: np.ndarray, custom_colors: list = None):
29+
"""
30+
31+
LookupTable (0x7f3d1dc62e00)
32+
Table Range: (0.0, 2.0)
33+
N Values: 256
34+
Above Range Color: None
35+
Below Range Color: None
36+
NAN Color: Color(name='darkgray', hex='#a9a9a9ff', opacity=255)
37+
Log Scale: False
38+
Color Map: "viridis"
39+
"""
2940
import pyvista as pv
3041

3142
# Get mapper actor
@@ -60,7 +71,7 @@ def set_scalar_bar(gempy_vista: GemPyToVista, elements_names: list[str],
6071

6172
custom_cmap = ListedColormap(custom_colors)
6273
# Apply the custom colormap to the lookup table
63-
lut.apply_cmap(cmap=custom_cmap, n_values=n_colors)
74+
lut.apply_cmap(cmap=custom_cmap, n_values=n_colors, flip=True)
6475

6576
else:
6677
# Apply a default colormap if no custom colors are provided
@@ -69,7 +80,7 @@ def set_scalar_bar(gempy_vista: GemPyToVista, elements_names: list[str],
6980
# Configure scalar bar arguments
7081
sargs = gempy_vista.scalar_bar_arguments
7182
min_id, max_id = surfaces_ids.min(), surfaces_ids.max()
72-
mapper_actor.mapper.scalar_range = (min_id-.4 , max_id + .5)
83+
mapper_actor.mapper.scalar_range = (min_id - .4, max_id + .5)
7384
sargs["mapper"] = mapper_actor.mapper
7485
sargs["n_labels"] = 0
7586

tests/test_plotting/test_plot_3d.py

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
np.random.seed(1234)
1111

12+
1213
class TestPlot3dInputData:
1314
def test_plot_3d_input_data(self, one_fault_model_no_interp):
1415
gpv.plot_3d(one_fault_model_no_interp, image=True)
@@ -18,19 +19,56 @@ class TestPlot3DSolutions:
1819
def test_plot_3d_solutions_default(self, one_fault_model_topo_solution):
1920
print(one_fault_model_topo_solution.structural_frame)
2021
gpv.plot_3d(one_fault_model_topo_solution, image=True)
21-
22+
2223
def test_plot_3d_solutions(self, one_fault_model_topo_solution):
24+
print(one_fault_model_topo_solution.structural_frame)
25+
gpv.plot_3d(
26+
model=one_fault_model_topo_solution,
27+
show_topography=True,
28+
show_scalar=False,
29+
show_lith=True,
30+
show_data=True,
31+
show_boundaries=True,
32+
image=True
33+
)
34+
35+
def test_plot_3d_solutions_volume_and_input(self, one_fault_model_topo_solution):
36+
print(one_fault_model_topo_solution.structural_frame)
37+
gpv.plot_3d(
38+
model=one_fault_model_topo_solution,
39+
show_topography=False,
40+
show_scalar=False,
41+
show_lith=True,
42+
show_data=True,
43+
show_boundaries=True,
44+
image=True,
45+
kwargs_plot_structured_grid = {'opacity': 0.5}
46+
)
47+
48+
def test_plot_3d_solutions_only_volume(self, one_fault_model_topo_solution):
2349
print(one_fault_model_topo_solution.structural_frame)
2450
gpv.plot_3d(
2551
model=one_fault_model_topo_solution,
2652
show_topography=False,
2753
show_scalar=False,
2854
show_lith=True,
2955
show_data=False,
56+
show_boundaries=False,
57+
image=True
58+
)
59+
60+
def test_plot_3d_solutions_only_input(self, one_fault_model_topo_solution):
61+
print(one_fault_model_topo_solution.structural_frame)
62+
gpv.plot_3d(
63+
model=one_fault_model_topo_solution,
64+
show_topography=False,
65+
show_scalar=False,
66+
show_lith=False,
67+
show_data=True,
3068
show_boundaries=True,
3169
image=True
3270
)
33-
71+
3472
def test_plot_3d_scalar_field(self, one_fault_model_topo_solution):
3573
gpv.plot_3d(
3674
model=one_fault_model_topo_solution,
@@ -39,15 +77,15 @@ def test_plot_3d_scalar_field(self, one_fault_model_topo_solution):
3977
show_lith=False,
4078
image=True
4179
)
42-
80+
4381
def test_plot_3d_solutions_topography(self, one_fault_model_topo_solution):
4482
gpv.plot_3d(
4583
model=one_fault_model_topo_solution,
4684
show_topography=True,
4785
topography_scalar_type=TopographyDataType.TOPOGRAPHY,
4886
image=True
4987
)
50-
88+
5189
def test_plot_3d_solutions_topography_geological_map(self, one_fault_model_topo_solution):
5290
gpv.plot_3d(
5391
model=one_fault_model_topo_solution,
@@ -83,6 +121,5 @@ def one_fault_model_topo_solution_octrees(self) -> GeoModel:
83121
gp.compute_model(one_fault_model)
84122
return one_fault_model
85123

86-
87124
def test_plot_3d_solutions_default(self, one_fault_model_topo_solution_octrees):
88125
gpv.plot_3d(one_fault_model_topo_solution_octrees, image=True)

0 commit comments

Comments
 (0)