88from gempy_viewer .optional_dependencies import require_pyvista
99
1010
11- def plot_data (gempy_vista : GemPyToVista ,
11+ def plot_data (gempy_vista : GemPyToVista ,
1212 model : GeoModel ,
1313 arrows_factor : float ,
1414 transformed_data : bool = False ,
@@ -19,7 +19,7 @@ def plot_data(gempy_vista: GemPyToVista,
1919 else :
2020 surface_points_copy = model .surface_points_copy
2121 orientations_copy = model .orientations_copy
22-
22+
2323 plot_surface_points (
2424 gempy_vista = gempy_vista ,
2525 surface_points = surface_points_copy ,
@@ -40,27 +40,21 @@ def plot_surface_points(
4040 surface_points : SurfacePointsTable ,
4141 elements_colors : list [str ],
4242 render_points_as_spheres = True ,
43- point_size = 10 ,
43+ point_size = 10 ,
4444 ** kwargs
4545):
46- ids = surface_points .ids
47- if ids .shape [0 ] == 0 :
48- return
49- unique_values , first_indices = np .unique (ids , return_index = True ) # Find the unique elements and their first indices
50- unique_values_order = unique_values [np .argsort (first_indices )] # Sort the unique values by their first appearance in `a`
51-
52- mapping_dict = {value : i for i , value in enumerate (unique_values_order )} # Use a dictionary to map the original numbers to new values
53- mapped_array = np .vectorize (mapping_dict .get )(ids ) # Map the original array to the new values
54-
5546 # Selecting the surfaces to plot
5647 xyz = surface_points .xyz
5748 if transfromed_data := False : # TODO: Expose this to user
5849 xyz = surface_points .model_transform .apply (xyz )
5950
6051 pv = require_pyvista ()
6152 poly = pv .PolyData (xyz )
62- poly ['id' ] = mapped_array
6353
54+ ids = surface_points .ids
55+ if ids .shape [0 ] == 0 :
56+ return
57+ poly ['id' ] = _vectorize_ids (ids )
6458
6559 gempy_vista .surface_points_mesh = poly
6660 gempy_vista .surface_points_actor = gempy_vista .p .add_mesh (
@@ -80,23 +74,16 @@ def plot_orientations(
8074):
8175 orientations_xyz = orientations .xyz
8276 orientations_grads = orientations .grads
83-
77+
8478 if orientations_xyz .shape [0 ] == 0 :
8579 return
8680
8781 pv = require_pyvista ()
8882 poly = pv .PolyData (orientations_xyz )
89-
83+
9084 ids = orientations .ids
91- if ids .shape [0 ] == 0 :
92- return
93- unique_values , first_indices = np .unique (ids , return_index = True ) # Find the unique elements and their first indices
94- unique_values_order = unique_values [np .argsort (first_indices )] # Sort the unique values by their first appearance in `a`
9585
96- mapping_dict = {value : i for i , value in enumerate (unique_values_order )} # Use a dictionary to map the original numbers to new values
97- mapped_array = np .vectorize (mapping_dict .get )(ids ) # Map the original array to the new values
98-
99- poly ['id' ] = mapped_array
86+ poly ['id' ] = _vectorize_ids (ids )
10087 poly ['vectors' ] = orientations_grads
10188
10289 # TODO: I am still trying to figure out colors and ids in orientations and surface points
@@ -117,3 +104,13 @@ def plot_orientations(
117104 show_scalar_bar = False
118105 )
119106 gempy_vista .orientations_mesh = arrows
107+
108+
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
116+ return mapped_array
0 commit comments