@@ -49,39 +49,19 @@ class GeoModelMeta:
49
49
owner : str | None
50
50
51
51
52
- # @dataclass(init=False)
53
52
class GeoModel (BaseModel ):
54
53
"""
55
54
Class representing a geological model.
56
55
57
56
"""
58
57
59
- model_config = ConfigDict (
60
- arbitrary_types_allowed = True ,
61
- use_enum_values = False ,
62
- json_encoders = {
63
- np .ndarray : encode_numpy_array
64
- }
65
- )
66
-
67
58
meta : GeoModelMeta = Field (exclude = False ) #: Meta-information about the geological model, like its name, creation and modification dates, and owner.
68
59
structural_frame : StructuralFrame = Field (exclude = False ) #: The structural information of the geological model.
69
60
grid : Grid = Field (exclude = False , default = None ) #: The general grid used in the geological model.
70
61
71
62
# region GemPy engine data types
72
63
_interpolation_options : InterpolationOptions #: The interpolation options provided by the user.
73
64
74
- @computed_field (alias = "_interpolation_options" )
75
- @property
76
- def interpolation_options (self ) -> InterpolationOptions :
77
- self ._infer_dense_grid_solution ()
78
- self ._interpolation_options .cache_model_name = self .meta .name
79
- return self ._interpolation_options
80
-
81
- @interpolation_options .setter
82
- def interpolation_options (self , value ):
83
- self ._interpolation_options = value
84
-
85
65
geophysics_input : GeophysicsInput = Field (default = None , exclude = True ) #: The geophysics input of the geological model.
86
66
input_transform : Transform = Field (default = None , exclude = False ) #: The transformation used in the geological model for input points.
87
67
@@ -92,78 +72,22 @@ def interpolation_options(self, value):
92
72
# endregion
93
73
_solutions : Solutions = PrivateAttr (init = False , default = None ) #: The computed solutions of the geological model.
94
74
95
- @model_validator (mode = 'wrap' )
96
- @classmethod
97
- def deserialize_properties (cls , data : Union ["GeoModel" , dict ], constructor : ModelWrapValidatorHandler ["GeoModel" ]) -> "GeoModel" :
98
- try :
99
- match data :
100
- case GeoModel ():
101
- return data
102
- case dict ():
103
- instance : GeoModel = constructor (data )
104
- instantiate_if_necessary (
105
- data = data ,
106
- key = "_interpolation_options" ,
107
- type = InterpolationOptions
108
- )
109
- instance ._interpolation_options = data .get ("_interpolation_options" )
110
- return instance
111
- case _:
112
- raise ValidationError
113
- except ValidationError :
114
- raise
115
-
116
- @classmethod
117
- def from_args (cls , name : str , structural_frame : StructuralFrame , grid : Grid , interpolation_options : InterpolationOptions ):
118
- # TODO: Fill the arguments properly
119
- meta = GeoModelMeta (
120
- name = name ,
121
- creation_date = datetime .datetime .now ().isoformat (),
122
- last_modification_date = None ,
123
- owner = None
124
- )
125
-
126
- structural_frame = structural_frame # ? This could be Optional
127
-
128
- grid = grid
129
- _interpolation_options = interpolation_options
130
- input_transform = Transform .from_input_points (
131
- surface_points = structural_frame .surface_points_copy ,
132
- orientations = structural_frame .orientations_copy
133
- )
134
-
135
- model = GeoModel (
136
- meta = meta ,
137
- structural_frame = structural_frame ,
138
- grid = grid ,
139
- input_transform = input_transform ,
140
- _interpolation_options = _interpolation_options
141
- )
142
-
143
- return model
144
-
145
75
def __repr__ (self ):
146
76
# TODO: Improve this
147
77
return pprint .pformat (self .__dict__ )
148
78
149
- def update_transform (self , auto_anisotropy : GlobalAnisotropy = GlobalAnisotropy .NONE , anisotropy_limit : Optional [np .ndarray ] = None ):
150
- """Update the transformation of the geological model.
151
-
152
- This function updates the transformation of the geological model using the provided surface points and orientations.
153
- It also applies anisotropy based on the specified type and limit.
154
-
155
- Args:
156
- auto_anisotropy (GlobalAnisotropy): The type of anisotropy to apply. Defaults to GlobalAnisotropy.NONE.
157
- anisotropy_limit (Optional[np.ndarray]): Anisotropy limit values. If None, no limit is applied.
158
-
159
- """
79
+ # region Properties
160
80
161
- self .input_transform = Transform .from_input_points (
162
- surface_points = self .surface_points_copy ,
163
- orientations = self .orientations_copy
164
- )
81
+ @computed_field (alias = "_interpolation_options" )
82
+ @property
83
+ def interpolation_options (self ) -> InterpolationOptions :
84
+ self ._infer_dense_grid_solution ()
85
+ self ._interpolation_options .cache_model_name = self .meta .name
86
+ return self ._interpolation_options
165
87
166
- self .input_transform .apply_anisotropy (anisotropy_type = auto_anisotropy , anisotropy_limit = anisotropy_limit )
88
+ @interpolation_options .setter
89
+ def interpolation_options (self , value ):
90
+ self ._interpolation_options = value
167
91
168
92
@property
169
93
def solutions (self ) -> Solutions :
@@ -297,10 +221,98 @@ def input_data_descriptor(self) -> InputDataDescriptor:
297
221
# TODO: This should have the exact same dirty logic as interpolation_input
298
222
return self .structural_frame .input_data_descriptor
299
223
224
+ # endregion
225
+ # region Constructors
226
+ @classmethod
227
+ def from_args (cls , name : str , structural_frame : StructuralFrame , grid : Grid , interpolation_options : InterpolationOptions ):
228
+ # TODO: Fill the arguments properly
229
+ meta = GeoModelMeta (
230
+ name = name ,
231
+ creation_date = datetime .datetime .now ().isoformat (),
232
+ last_modification_date = None ,
233
+ owner = None
234
+ )
235
+
236
+ structural_frame = structural_frame # ? This could be Optional
237
+
238
+ grid = grid
239
+ _interpolation_options = interpolation_options
240
+ input_transform = Transform .from_input_points (
241
+ surface_points = structural_frame .surface_points_copy ,
242
+ orientations = structural_frame .orientations_copy
243
+ )
244
+
245
+ model = GeoModel (
246
+ meta = meta ,
247
+ structural_frame = structural_frame ,
248
+ grid = grid ,
249
+ input_transform = input_transform ,
250
+ _interpolation_options = _interpolation_options
251
+ )
252
+
253
+ return model
254
+
255
+ # endregion
256
+
257
+ # region Methods
258
+ def update_transform (self , auto_anisotropy : GlobalAnisotropy = GlobalAnisotropy .NONE , anisotropy_limit : Optional [np .ndarray ] = None ):
259
+ """Update the transformation of the geological model.
260
+
261
+ This function updates the transformation of the geological model using the provided surface points and orientations.
262
+ It also applies anisotropy based on the specified type and limit.
263
+
264
+ Args:
265
+ auto_anisotropy (GlobalAnisotropy): The type of anisotropy to apply. Defaults to GlobalAnisotropy.NONE.
266
+ anisotropy_limit (Optional[np.ndarray]): Anisotropy limit values. If None, no limit is applied.
267
+
268
+ """
269
+
270
+ self .input_transform = Transform .from_input_points (
271
+ surface_points = self .surface_points_copy ,
272
+ orientations = self .orientations_copy
273
+ )
274
+
275
+ self .input_transform .apply_anisotropy (anisotropy_type = auto_anisotropy , anisotropy_limit = anisotropy_limit )
276
+
300
277
def add_surface_points (self , X : Sequence [float ], Y : Sequence [float ], Z : Sequence [float ],
301
278
surface : Sequence [str ], nugget : Optional [Sequence [float ]] = None ) -> None :
302
279
raise NotImplementedError ("This method is deprecated. Use `gp.add_surface_points` instead" )
303
280
281
+ # endregion
282
+
283
+ # region Pydantic serialization
284
+
285
+ model_config = ConfigDict (
286
+ arbitrary_types_allowed = True ,
287
+ use_enum_values = False ,
288
+ json_encoders = {
289
+ np .ndarray : encode_numpy_array
290
+ }
291
+ )
292
+
293
+ @model_validator (mode = 'wrap' )
294
+ @classmethod
295
+ def deserialize_properties (cls , data : Union ["GeoModel" , dict ], constructor : ModelWrapValidatorHandler ["GeoModel" ]) -> "GeoModel" :
296
+ try :
297
+ match data :
298
+ case GeoModel ():
299
+ return data
300
+ case dict ():
301
+ instance : GeoModel = constructor (data )
302
+ instantiate_if_necessary (
303
+ data = data ,
304
+ key = "_interpolation_options" ,
305
+ type = InterpolationOptions
306
+ )
307
+ instance ._interpolation_options = data .get ("_interpolation_options" )
308
+ return instance
309
+ case _:
310
+ raise ValidationError
311
+ except ValidationError :
312
+ raise
313
+
314
+ # endregion
315
+
304
316
def _infer_dense_grid_solution (self ):
305
317
octrees_set : bool = Grid .GridTypes .OCTREE in self .grid .active_grids
306
318
dense_set : bool = Grid .GridTypes .DENSE in self .grid .active_grids
0 commit comments