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 data validation in structural elements & tests
Refactored `StructuralElement` attributes to use Pydantic's `Field` for improved data validation and added `exclude=True` where necessary. Enhanced serialization test to include model save after computation with validation.
  • Loading branch information
Leguark committed May 25, 2025
commit 69c5b58982d2ce75f28bb27874ed6b47a59d4ba6
7 changes: 4 additions & 3 deletions gempy/core/data/structural_element.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import re
from dataclasses import dataclass, field
from pydantic import Field
from typing import Optional

import numpy as np
Expand Down Expand Up @@ -29,9 +30,9 @@ class StructuralElement:

# Output
# ? Should we extract this to a separate class?
vertices: Optional[np.ndarray] = None #: The vertices of the element in 3D space.
edges: Optional[np.ndarray] = None #: The edges of the element in 3D space.
scalar_field_at_interface: Optional[float] = None #: The scalar field value for the element.
vertices: np.ndarray | None = Field(default=None, exclude=True) #: The vertices of the element in 3D space.
edges: np.ndarray | None = Field(default=None, exclude=True) #: The edges of the element in 3D space.
scalar_field_at_interface: float | None = None #: The scalar field value for the element.

_id: int = -1

Expand Down
13 changes: 9 additions & 4 deletions test/test_modules/test_serialize_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_generate_horizontal_stratigraphic_model():
f.write(model_json)

with loading_model_from_binary(
binary_body=model.structural_frame.input_tables_binary
binary_body=model.structural_frame.input_tables_binary
):
model_deserialized = gp.data.GeoModel.model_validate_json(model_json)

Expand Down Expand Up @@ -50,17 +50,22 @@ def _validate_serialization(original_model, model_deserialized):
def test_save_model_to_disk():
model = gp.generate_example_model(ExampleModel.COMBINATION, compute_model=False)
save_model(model, "temp/test_save_model_to_disk.gempy")

# Load the model from disk
loaded_model = load_model("temp/test_save_model_to_disk.gempy")
_validate_serialization(model, loaded_model)

gp.compute_model(loaded_model)
if True:
import gempy_viewer as gpv
gpv.plot_3d(loaded_model, image=True)


# Test save after compute
save_model(
model=model,
path="temp/test_save_model_to_disk.gempy",
validate_serialization=True
)


def test_interpolation_options():
Expand Down