1
1
import enum
2
2
import warnings
3
- from dataclasses import dataclass , asdict , field
3
+
4
+ from pydantic import BaseModel , ConfigDict , Field , model_validator , PrivateAttr
4
5
5
6
import gempy_engine .config
6
7
from .evaluation_options import MeshExtractionMaskingOptions , EvaluationOptions
10
11
from ..raw_arrays_solution import RawArraysSolution
11
12
12
13
13
- @dataclass
14
- class InterpolationOptions :
15
- __slots__ = ['kernel_options' , 'evaluation_options' , 'temp_interpolation_values' , 'debug' ,
16
- 'cache_mode' , 'cache_model_name' , 'block_solutions_type' , 'sigmoid_slope' ]
17
-
14
+ class InterpolationOptions (BaseModel ):
18
15
class CacheMode (enum .Enum ):
19
16
""" Cache mode for the interpolation"""
20
17
NO_CACHE : int = enum .auto () #: No cache at all even during the interpolation computation. This is quite expensive for no good reason.
21
18
CACHE = enum .auto ()
22
19
IN_MEMORY_CACHE = enum .auto ()
23
20
CLEAR_CACHE = enum .auto ()
24
21
22
+ model_config = ConfigDict (
23
+ arbitrary_types_allowed = False ,
24
+ use_enum_values = False ,
25
+ json_encoders = {
26
+ CacheMode : lambda e : e .value
27
+ }
28
+ )
29
+
25
30
# @off
26
- kernel_options : KernelOptions # * This is the compression of the fields above and the way to go in the future
27
- evaluation_options : EvaluationOptions
28
- temp_interpolation_values : TempInterpolationValues
31
+ kernel_options : KernelOptions = Field (init = True ) # * This is the compression of the fields above and the way to go in the future
32
+ evaluation_options : EvaluationOptions = Field (init = True )
29
33
30
34
debug : bool
31
35
cache_mode : CacheMode
32
36
cache_model_name : str # : Model name for the cache
33
-
34
37
block_solutions_type : RawArraysSolution .BlockSolutionType
35
-
36
38
sigmoid_slope : int
37
-
38
39
debug_water_tight : bool = False
39
40
40
- def __init__ (
41
- self ,
41
+ # region Volatile
42
+ _temp_interpolation_values : TempInterpolationValues = PrivateAttr (default_factory = TempInterpolationValues )
43
+
44
+ # endregion
45
+
46
+ @classmethod
47
+ def from_args (
48
+ cls ,
42
49
range : int | float ,
43
50
c_o : float ,
44
51
uni_degree : int = 1 ,
45
- i_res : float = 4 ,
46
- gi_res : float = 2 , # ! This should be DEP
52
+ i_res : float = 4. ,
53
+ gi_res : float = 2. , # ! This should be DEP
47
54
number_dimensions : int = 3 , # ? This probably too
48
55
number_octree_levels : int = 1 ,
49
56
kernel_function : AvailableKernelFunctions = AvailableKernelFunctions .cubic ,
@@ -52,7 +59,7 @@ def __init__(
52
59
compute_condition_number : bool = False ,
53
60
):
54
61
55
- self . kernel_options = KernelOptions (
62
+ kernel_options = KernelOptions (
56
63
range = range ,
57
64
c_o = c_o ,
58
65
uni_degree = uni_degree ,
@@ -63,7 +70,7 @@ def __init__(
63
70
compute_condition_number = compute_condition_number
64
71
)
65
72
66
- self . evaluation_options = EvaluationOptions (
73
+ evaluation_options = EvaluationOptions (
67
74
_number_octree_levels = number_octree_levels ,
68
75
_number_octree_levels_surface = 4 ,
69
76
mesh_extraction = mesh_extraction ,
@@ -73,12 +80,24 @@ def __init__(
73
80
74
81
)
75
82
76
- self .temp_interpolation_values = TempInterpolationValues ()
77
- self .debug = gempy_engine .config .DEBUG_MODE
78
- self .cache_mode = InterpolationOptions .CacheMode .IN_MEMORY_CACHE
79
- self .cache_model_name = ""
80
- self .block_solutions_type = RawArraysSolution .BlockSolutionType .OCTREE
81
- self .sigmoid_slope = 5_000_000
83
+ temp_interpolation_values = TempInterpolationValues ()
84
+ debug = gempy_engine .config .DEBUG_MODE
85
+ cache_mode = InterpolationOptions .CacheMode .IN_MEMORY_CACHE
86
+ cache_model_name = ""
87
+ block_solutions_type = RawArraysSolution .BlockSolutionType .OCTREE
88
+ sigmoid_slope = 5_000_000
89
+
90
+ return InterpolationOptions (
91
+ kernel_options = kernel_options ,
92
+ evaluation_options = evaluation_options ,
93
+ # temp_interpolation_values=temp_interpolation_values,
94
+ debug = debug ,
95
+ cache_mode = cache_mode ,
96
+ cache_model_name = cache_model_name ,
97
+ block_solutions_type = block_solutions_type ,
98
+ sigmoid_slope = sigmoid_slope ,
99
+ debug_water_tight = False ,
100
+ )
82
101
83
102
# @on
84
103
@@ -107,17 +126,17 @@ def probabilistic_options(cls):
107
126
# TODO: This should have the sigmoid slope different
108
127
raise NotImplementedError ("Probabilistic interpolation is not yet implemented." )
109
128
110
- def __repr__ (self ):
111
- return f"InterpolationOptions({ ', ' .join (f'{ k } ={ v } ' for k , v in asdict (self ).items ())} )"
129
+ # def __repr__(self):
130
+ # return f"InterpolationOptions({', '.join(f'{k}={v}' for k, v in asdict(self).items())})"
112
131
113
- def _repr_html_ (self ):
114
- html = f"""
115
- <table>
116
- <tr><td colspan='2' style='text-align:center'><b>InterpolationOptions</b></td></tr>
117
- { '' .join (f'<tr><td>{ k } </td><td>{ v ._repr_html_ () if isinstance (v , KernelOptions ) else v } </td></tr>' for k , v in asdict (self ).items ())}
118
- </table>
119
- """
120
- return html
132
+ # def _repr_html_(self):
133
+ # html = f"""
134
+ # <table>
135
+ # <tr><td colspan='2' style='text-align:center'><b>InterpolationOptions</b></td></tr>
136
+ # {''.join(f'<tr><td>{k}</td><td>{v._repr_html_() if isinstance(v, KernelOptions) else v}</td></tr>' for k, v in asdict(self).items())}
137
+ # </table>
138
+ # """
139
+ # return html
121
140
122
141
def update_options (self , ** kwargs ):
123
142
"""
@@ -147,6 +166,10 @@ def update_options(self, **kwargs):
147
166
else :
148
167
warnings .warn (f"{ key } is not a recognized attribute and will be ignored." )
149
168
169
+ @property
170
+ def temp_interpolation_values (self ):
171
+ return self ._temp_interpolation_values
172
+
150
173
@property
151
174
def number_octree_levels (self ):
152
175
return self .evaluation_options .number_octree_levels
0 commit comments