From 5ca8babe6a13eded2c503c4f05acb30aaa975fa0 Mon Sep 17 00:00:00 2001 From: MigueldelaVarga Date: Thu, 18 Sep 2025 17:26:43 +0200 Subject: [PATCH 1/2] [ENH] Add `name_id_map` support in orientation data manipulation Integrated optional `name_id_map` parameter to the `add_orientation` method for mapping orientation names to IDs. Updated Hecho example with serialization validation and added save/load functionality for models. --- examples/examples/real/Hecho.py | 9 ++++++++- gempy/modules/data_manipulation/manipulate_points.py | 4 +++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/examples/examples/real/Hecho.py b/examples/examples/real/Hecho.py index bdad86b7..ac58fe9d 100644 --- a/examples/examples/real/Hecho.py +++ b/examples/examples/real/Hecho.py @@ -12,6 +12,7 @@ # Aux imports import pandas as pn +from gempy.modules.serialization.save_load import _validate_serialization # Importing gempy import gempy as gp @@ -149,7 +150,8 @@ y=new_orientations.data['Y'], z=new_orientations.data['Z'], pole_vector=new_orientations.grads, - elements_names=fn + elements_names=fn, + name_id_map=element.surface_points.name_id_map ) # %% @@ -216,6 +218,11 @@ # Setting verbose and condition number options for debugging geo_model.interpolation_options.kernel_options.compute_condition_number = True +gp.save_model(geo_model, 'Hecho.gempy') +model_deserialized = gp.load_model('Hecho.gempy') + +_validate_serialization(geo_model, model_deserialized) + # %% gp.compute_model( gempy_model=geo_model, diff --git a/gempy/modules/data_manipulation/manipulate_points.py b/gempy/modules/data_manipulation/manipulate_points.py index edc0df45..9c8a4974 100644 --- a/gempy/modules/data_manipulation/manipulate_points.py +++ b/gempy/modules/data_manipulation/manipulate_points.py @@ -96,7 +96,8 @@ def add_orientations(geo_model: GeoModel, elements_names: Sequence[str], pole_vector: Optional[Union[Sequence[np.ndarray], np.ndarray]] = None, orientation: Optional[Union[Sequence[np.ndarray], np.ndarray]] = None, - nugget: Optional[Sequence[float]] = None + nugget: Optional[Sequence[float]] = None, + name_id_map: Optional[dict[str, int]] = None #: A mapping between orientation names and ids. ) -> StructuralFrame: """Add orientation data to the geological model. @@ -176,6 +177,7 @@ def add_orientations(geo_model: GeoModel, G_z=data['pole_vector'][..., 2], names=[element_name] * len(data['x']), nugget=data['nugget'], + name_id_map=name_id_map ) element: StructuralElement = geo_model.structural_frame.get_element_by_name(element_name) From fd5675f3ebcae84008b17c4795d6c3ba46084381 Mon Sep 17 00:00:00 2001 From: MigueldelaVarga Date: Thu, 18 Sep 2025 17:46:31 +0200 Subject: [PATCH 2/2] [CLN] Simplify Hecho example by removing serialization logic and enhancing validation Removed redundant save/load and serialization validation in the Hecho example. Adjusted section grid to ensure consistent tuple formatting and enabled `validate_serialization` in model computation. --- examples/examples/real/Hecho.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/examples/examples/real/Hecho.py b/examples/examples/real/Hecho.py index ac58fe9d..b2539350 100644 --- a/examples/examples/real/Hecho.py +++ b/examples/examples/real/Hecho.py @@ -127,7 +127,7 @@ gp.set_section_grid( grid=geo_model.grid, section_dict={ - 'section': ([0, 0], [16, 0], [321, 91]) + 'section': ((0., 0.), (16., 0.), (321, 91)) }, ) @@ -218,10 +218,6 @@ # Setting verbose and condition number options for debugging geo_model.interpolation_options.kernel_options.compute_condition_number = True -gp.save_model(geo_model, 'Hecho.gempy') -model_deserialized = gp.load_model('Hecho.gempy') - -_validate_serialization(geo_model, model_deserialized) # %% gp.compute_model( @@ -230,7 +226,7 @@ backend=gp.data.AvailableBackends.PYTORCH, dtype='float64' ), - validate_serialization=False + validate_serialization=True ) # %%