Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[ENH] Update GeoModel to include and reset geophysics input
Expose `geophysics_input` and integrate gravity gradient calculation during deserialization. This ensures proper resetting of geophysics-specific fields when grid data is available.
  • Loading branch information
Leguark committed May 25, 2025
commit 3a290f18a902f0675faf48a974f621b31b5c6fa2
13 changes: 10 additions & 3 deletions gempy/core/data/geo_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from gempy_engine.core.data.interpolation_input import InterpolationInput
from gempy_engine.core.data.raw_arrays_solution import RawArraysSolution
from gempy_engine.core.data.transforms import Transform, GlobalAnisotropy
from gempy_engine.modules.geophysics.gravity_gradient import calculate_gravity_gradient
from .encoders.converters import instantiate_if_necessary
from .encoders.json_geomodel_encoder import encode_numpy_array
from .grid import Grid
Expand Down Expand Up @@ -62,7 +63,7 @@ class GeoModel(BaseModel):
# region GemPy engine data types
_interpolation_options: InterpolationOptions #: The interpolation options provided by the user.

geophysics_input: GeophysicsInput = Field(default=None, exclude=True) #: The geophysics input of the geological model.
geophysics_input: GeophysicsInput = Field(default=None, exclude=False) #: The geophysics input of the geological model.
input_transform: Transform = Field(default=None, exclude=False) #: The transformation used in the geological model for input points.

interpolation_grid: EngineGrid = Field(default=None, exclude=True) #: ptional grid used for interpolation. Can be seen as a cache field.
Expand Down Expand Up @@ -303,16 +304,22 @@ def add_surface_points(self, X: Sequence[float], Y: Sequence[float], Z: Sequence
@classmethod
def deserialize_properties(cls, data: Union["GeoModel", dict], constructor: ModelWrapValidatorHandler["GeoModel"]) -> "GeoModel":
match data:
case GeoModel():
case GeoModel():
return data
case dict():
case dict(): #
instance: GeoModel = constructor(data)
instantiate_if_necessary(
data=data,
key="_interpolation_options",
type=InterpolationOptions
)
instance._interpolation_options = data.get("_interpolation_options")

# * Reset geophysics if necessary
centered_grid = instance.grid.centered_grid
if centered_grid is not None and instance.geophysics_input is not None:
instance.geophysics_input.tz = calculate_gravity_gradient(centered_grid)

return instance
case _:
raise ValidationError
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@
"_octree_levels": -1,
"active_grids": 1058
},
"geophysics_input": {
"tz": [],
"densities": [
2.6,
2.4,
3.2
]
},
"input_transform": {
"position": [
-6.0,
Expand Down