Skip to content

Commit f0e4da2

Browse files
committed
[ENH] Improve ID mapping in 3D plotting with default handling
Enhanced `_vectorize_ids` method to filter invalid IDs and assign a default value (0) when IDs are missing from the mapping. Added a warning for unmatched IDs to improve error visibility.
1 parent aeaf0fa commit f0e4da2

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

gempy_viewer/modules/plot_3d/drawer_input_3d.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ def plot_orientations(
128128
)
129129
gempy_vista.orientations_mesh = arrows
130130

131-
132131
def _vectorize_ids(mapping_ids, ids_to_map):
133132
def _mapping_dict(ids):
134133
unique_values, first_indices = np.unique(ids, return_index=True) # Find the unique elements and their first indices
@@ -139,5 +138,14 @@ def _mapping_dict(ids):
139138
return mapping_dict
140139

141140
mapping_dict = _mapping_dict(mapping_ids)
142-
mapped_array = np.vectorize(mapping_dict.get)(ids_to_map) # Map the original array to the new values
143-
return mapped_array
141+
142+
# Filter out invalid IDs or provide a default value
143+
# Option 1: Filter out IDs that don't exist in mapping_dict
144+
valid_mask = np.isin(ids_to_map, list(mapping_dict.keys()))
145+
if not np.all(valid_mask):
146+
print(f"Warning: Found {np.sum(~valid_mask)} orientation IDs that don't exist in surface points. These will be assigned a default value of 0.")
147+
148+
# Option 2: Use a default value (0) for missing IDs
149+
mapped_array = np.vectorize(lambda x: mapping_dict.get(x, 0))(ids_to_map)
150+
151+
return mapped_array

0 commit comments

Comments
 (0)