Skip to content

Commit 4684526

Browse files
committed
[CLN] Refactor array type annotations for consistency
Replaced verbose `Annotated` type definitions with `short_array_type` for cleaner and more consistent code. Improved clarity and added error handling for deserialized implicit functions in `FiniteFaultData`.
1 parent ba227b4 commit 4684526

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

gempy_engine/core/data/centered_grid.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
from dataclasses import dataclass, field
2-
from typing import Sequence, Union, Annotated
32

43
import numpy as np
5-
from .encoders.converters import numpy_array_short_validator
4+
5+
from .encoders.converters import short_array_type
6+
67

78
@dataclass
89
class CenteredGrid:
9-
centers: Annotated[np.ndarray, numpy_array_short_validator] #: This is just used to calculate xyz to interpolate. Tz is independent
10-
resolution: Annotated[np.ndarray, numpy_array_short_validator]
11-
radius: float | Annotated[np.ndarray, numpy_array_short_validator]
10+
centers: short_array_type #: This is just used to calculate xyz to interpolate. Tz is independent
11+
resolution: short_array_type
12+
radius: float | short_array_type
1213

1314
kernel_grid_centers: np.ndarray = field(init=False)
1415
left_voxel_edges: np.ndarray = field(init=False)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
from typing import Annotated
2+
13
import numpy as np
24
from pydantic import BeforeValidator
35

46
numpy_array_short_validator = BeforeValidator(lambda v: np.array(v) if v is not None else None)
7+
short_array_type = Annotated[np.ndarray, numpy_array_short_validator]

gempy_engine/core/data/kernel_classes/faults.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,39 @@
11
import dataclasses
2-
from typing import Optional
2+
from typing import Optional, Callable
33

44
import numpy as np
5+
from pydantic import Field
56

6-
from gempy_engine.core.data.transforms import Transform
7+
from ..encoders.converters import short_array_type
8+
from ..transforms import Transform
79

810

911
@dataclasses.dataclass
1012
class FiniteFaultData:
11-
implicit_function: callable
12-
implicit_function_transform: Transform
13-
pivot: np.ndarray
14-
13+
implicit_function: Callable | None = Field(exclude=True, default=None)#, default=None)
14+
implicit_function_transform: Transform = Field()
15+
pivot: short_array_type = Field()
16+
1517
def apply(self, points: np.ndarray) -> np.ndarray:
1618
transformed_points = self.implicit_function_transform.apply_inverse_with_pivot(
1719
points=points,
1820
pivot=self.pivot
1921
)
22+
if self.implicit_function is None:
23+
raise ValueError("No implicit function defined. This can happen after deserializing (loading).")
24+
2025
scalar_block = self.implicit_function(transformed_points)
2126
return scalar_block
2227

2328

2429

2530
@dataclasses.dataclass
2631
class FaultsData:
27-
fault_values_everywhere: np.ndarray = None
28-
fault_values_on_sp: np.ndarray = None
32+
fault_values_everywhere: short_array_type | None = None
33+
fault_values_on_sp: short_array_type | None = None
2934

30-
fault_values_ref: np.ndarray = None
31-
fault_values_rest: np.ndarray = None
35+
fault_values_ref: short_array_type | None = None
36+
fault_values_rest: short_array_type | None = None
3237

3338
# User given data:
3439
thickness: Optional[float] = None

0 commit comments

Comments
 (0)