Skip to content

Commit 3a290f1

Browse files
committed
[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.
1 parent a4126b2 commit 3a290f1

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

gempy/core/data/geo_model.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from gempy_engine.core.data.interpolation_input import InterpolationInput
1616
from gempy_engine.core.data.raw_arrays_solution import RawArraysSolution
1717
from gempy_engine.core.data.transforms import Transform, GlobalAnisotropy
18+
from gempy_engine.modules.geophysics.gravity_gradient import calculate_gravity_gradient
1819
from .encoders.converters import instantiate_if_necessary
1920
from .encoders.json_geomodel_encoder import encode_numpy_array
2021
from .grid import Grid
@@ -62,7 +63,7 @@ class GeoModel(BaseModel):
6263
# region GemPy engine data types
6364
_interpolation_options: InterpolationOptions #: The interpolation options provided by the user.
6465

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

6869
interpolation_grid: EngineGrid = Field(default=None, exclude=True) #: ptional grid used for interpolation. Can be seen as a cache field.
@@ -303,16 +304,22 @@ def add_surface_points(self, X: Sequence[float], Y: Sequence[float], Z: Sequence
303304
@classmethod
304305
def deserialize_properties(cls, data: Union["GeoModel", dict], constructor: ModelWrapValidatorHandler["GeoModel"]) -> "GeoModel":
305306
match data:
306-
case GeoModel():
307+
case GeoModel():
307308
return data
308-
case dict():
309+
case dict(): #
309310
instance: GeoModel = constructor(data)
310311
instantiate_if_necessary(
311312
data=data,
312313
key="_interpolation_options",
313314
type=InterpolationOptions
314315
)
315316
instance._interpolation_options = data.get("_interpolation_options")
317+
318+
# * Reset geophysics if necessary
319+
centered_grid = instance.grid.centered_grid
320+
if centered_grid is not None and instance.geophysics_input is not None:
321+
instance.geophysics_input.tz = calculate_gravity_gradient(centered_grid)
322+
316323
return instance
317324
case _:
318325
raise ValidationError

test/test_modules/_geophysics_TO_UPDATE/test_gravity.test_gravity.verify/2-layers.approved.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,14 @@
103103
"_octree_levels": -1,
104104
"active_grids": 1058
105105
},
106+
"geophysics_input": {
107+
"tz": [],
108+
"densities": [
109+
2.6,
110+
2.4,
111+
3.2
112+
]
113+
},
106114
"input_transform": {
107115
"position": [
108116
-6.0,

0 commit comments

Comments
 (0)