Skip to content

Commit 1133246

Browse files
committed
[ENH] Getting the first serialization seemingly completed
1 parent 4bb28ae commit 1133246

File tree

2 files changed

+11
-63
lines changed

2 files changed

+11
-63
lines changed

gempy/core/data/geo_model.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,8 @@ class GeoModel(BaseModel):
6464
}
6565
)
6666

67-
meta: GeoModelMeta | None = Field(exclude=False) #: Meta-information about the geological model, like its name, creation and modification dates, and owner.
68-
69-
# BUG: Remove None option for structural frame and meta
70-
structural_frame: Optional[StructuralFrame] | None = Field(exclude=False, default=None) #: The structural information of the geological model.
67+
meta: GeoModelMeta = Field(exclude=False) #: Meta-information about the geological model, like its name, creation and modification dates, and owner.
68+
structural_frame: StructuralFrame = Field(exclude=False) #: The structural information of the geological model.
7169
grid: Grid = Field(exclude=False, default=None) #: The general grid used in the geological model.
7270

7371
# region GemPy engine data types
@@ -85,7 +83,7 @@ def interpolation_options(self, value):
8583
self._interpolation_options = value
8684

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

9088
interpolation_grid: EngineGrid = Field(default=None, exclude=True) #: ptional grid used for interpolation. Can be seen as a cache field.
9189
_interpolationInput: InterpolationInput = PrivateAttr(default=None) #: Input data for interpolation. Fed by the structural frame and can be seen as a cache field.

test/test_modules/test_serialize_model.py

Lines changed: 8 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
import numpy as np
21
import os
3-
import pandas as pd
42
import pprint
5-
import tempfile
63

74
import gempy as gp
8-
from gempy.core.data import SurfacePointsTable
95
from gempy.core.data.encoders.converters import loading_model_injection
106
from gempy.core.data.enumerators import ExampleModel
117
from gempy_engine.core.data import InterpolationOptions
@@ -16,7 +12,7 @@ def test_generate_horizontal_stratigraphic_model():
1612
model: gp.data.GeoModel = gp.generate_example_model(ExampleModel.HORIZONTAL_STRAT, compute_model=False)
1713

1814
model_json = model.model_dump_json(by_alias=True)
19-
15+
2016
# Pretty print JSON
2117
pprint.pp(model_json)
2218

@@ -28,73 +24,27 @@ def test_generate_horizontal_stratigraphic_model():
2824
with open(file_path, "w") as f:
2925
f.write(model_json)
3026

31-
if False: # * Use this to debug which fields are giving problems
32-
# model_deserialized = gp.data.GeoModel.model_validate(from_json(model_json, allow_partial=True))
33-
pass
34-
else:
35-
with loading_model_injection(
36-
surface_points_binary = model.structural_frame.surface_points_copy.data,# TODO: Here we need to pass the binary array
37-
orientations_binary = model.structural_frame.orientations_copy.data
38-
):
39-
model_deserialized = gp.data.GeoModel.model_validate_json(model_json)
27+
with loading_model_injection(
28+
surface_points_binary=model.structural_frame.surface_points_copy.data, # TODO: Here we need to pass the binary array
29+
orientations_binary=model.structural_frame.orientations_copy.data
30+
):
31+
model_deserialized = gp.data.GeoModel.model_validate_json(model_json)
4032

4133
a = hash(model.structural_frame.structural_elements[1].surface_points.data.tobytes())
4234
b = hash(model_deserialized.structural_frame.structural_elements[1].surface_points.data.tobytes())
43-
35+
4436
o_a = hash(model.structural_frame.structural_elements[1].orientations.data.tobytes())
4537
o_b = hash(model_deserialized.structural_frame.structural_elements[1].orientations.data.tobytes())
46-
38+
4739
assert a == b, "Hashes for surface points are not equal"
4840
assert o_a == o_b, "Hashes for orientations are not equal"
49-
50-
# TODO: [ ] Structural frame?
51-
# TODO: [ ] Input transform?
5241
assert model_deserialized.__str__() == model.__str__()
5342

5443
# # Validate json against schema
5544
if False:
5645
verify_json(model_json, name="verify/Horizontal Stratigraphic Model serialization")
5746

5847

59-
60-
61-
def test_generate_horizontal_stratigraphic_model_binary():
62-
model: gp.data.GeoModel = gp.generate_example_model(ExampleModel.HORIZONTAL_STRAT, compute_model=False)
63-
sp = model.surface_points_copy
64-
element_id_map: dict[int, str] = model.structural_frame.element_id_name_map
65-
66-
# * So basically we have 12 elements of a very complex type
67-
data = sp.data
68-
assert data.shape[0] == 12
69-
assert data.dtype == np.dtype([('X', 'f8'), ('Y', 'f8'), ('Z', 'f8'), ('id', 'i4'), ('nugget', 'f8')]) #: The custom data type for the data array.
70-
71-
df = pd.DataFrame(data)
72-
ds = df.to_xarray()
73-
pass
74-
75-
76-
def test_split_input_data_tables():
77-
model: gp.data.GeoModel = gp.generate_example_model(ExampleModel.HORIZONTAL_STRAT, compute_model=False)
78-
sp: gp.data.SurfacePointsTable = model.surface_points_copy
79-
# Temp save sp numpy array
80-
81-
with tempfile.NamedTemporaryFile(delete=False, suffix='.npy') as temp:
82-
np.save(
83-
file=temp,
84-
arr=sp.data
85-
)
86-
temp_path = temp.name
87-
88-
# Load
89-
loaded_array = np.load(temp_path)
90-
loaded_table = SurfacePointsTable(
91-
data=loaded_array,
92-
name_id_map=sp.name_id_map
93-
)
94-
95-
model.structural_frame.surface_points = loaded_table
96-
97-
9848
def test_interpolation_options():
9949
options = InterpolationOptions.from_args(
10050
range=1.7,

0 commit comments

Comments
 (0)