Skip to content

Commit a905a7b

Browse files
committed
[WIP] Move transformation logic to GeoModel properties
1 parent 4cbe235 commit a905a7b

File tree

3 files changed

+42
-35
lines changed

3 files changed

+42
-35
lines changed

gempy/core/data/geo_model.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from gempy_engine.core.data.transforms import Transform, GlobalAnisotropy
1616

1717
from .orientations import OrientationsTable
18+
from .surface_points import SurfacePointsTable
1819
from .structural_frame import StructuralFrame
1920
from .grid import Grid
2021
from ...modules.data_manipulation.engine_factory import interpolation_input_from_structural_frame
@@ -153,10 +154,10 @@ def solutions(self, value):
153154
dc_mesh = self._solutions.dc_meshes[e]
154155
if dc_mesh is None:
155156
continue
156-
157+
157158
# TODO: These meshes are in the order of the scalar field
158159
world_coord_vertices = self.input_transform.apply_inverse(dc_mesh.vertices)
159-
160+
160161
element.vertices = world_coord_vertices
161162
element.edges = (dc_mesh.edges if dc_mesh is not None else None)
162163

@@ -171,14 +172,14 @@ def surface_points_copy(self):
171172
"""This is a copy! Returns a SurfacePointsTable for all surface points across the structural elements"""
172173
surface_points_table = self.structural_frame.surface_points_copy
173174
return surface_points_table
174-
175+
175176
@property
176-
def surface_points_copy_transformed(self):
177+
def surface_points_copy_transformed(self) -> SurfacePointsTable:
177178
og_sp = self.surface_points_copy
178179
total_transform: Transform = self.input_transform + self.grid.transform
179180
og_sp.xyz_view = total_transform.apply(og_sp.xyz)
180181
return og_sp
181-
182+
182183
@property
183184
def surface_points(self):
184185
raise AttributeError("This property can only be set, not read. You can access the copy with `surface_points_copy` or"
@@ -192,17 +193,15 @@ def surface_points(self, value):
192193
def orientations_copy(self) -> OrientationsTable:
193194
"""This is a copy! Returns a OrientationsTable for all orientations across the structural elements"""
194195
orientations_table = self.structural_frame.orientations_copy
195-
if self.input_transform is not None:
196-
transform = self.input_transform + self.grid.transform
197-
orientations_table.model_transform = transform
198196
return orientations_table
199-
197+
200198
@property
201-
def orientations_copy_transformed(self):
199+
def orientations_copy_transformed(self) -> OrientationsTable:
202200
# ! This is not done
203201
og_or = self.orientations_copy
204202
total_transform: Transform = self.input_transform + self.grid.transform
205203
og_or.xyz_view = total_transform.apply(og_or.xyz)
204+
og_or.grads_view = total_transform.transform_gradient(og_or.grads)
206205
return og_or
207206

208207
@property
@@ -217,28 +216,29 @@ def orientations(self, value):
217216
@property
218217
def project_bounds(self) -> np.ndarray:
219218
return self.grid.bounding_box
220-
219+
221220
@property
222221
def extent_transformed(self) -> np.ndarray:
223222
transformed = self.input_transform.apply(self.project_bounds) # ! grid already has the grid transform applied
224223
new_extents = np.array([transformed[:, 0].min(), transformed[:, 0].max(),
225224
transformed[:, 1].min(), transformed[:, 1].max(),
226225
transformed[:, 2].min(), transformed[:, 2].max()])
227226
return new_extents
228-
227+
229228
@property
230229
def extent(self) -> np.ndarray:
231230
return self.grid.extent
232231

233232
@property
234233
def interpolation_input_copy(self):
234+
warnings.warn("This property is deprecated. Use directly "
235+
"`interpolation_input_from_structural_frame` instead.", DeprecationWarning)
236+
235237
if self.structural_frame.is_dirty is False:
236238
return self._interpolationInput
237239

238240
self._interpolationInput = interpolation_input_from_structural_frame(
239-
structural_frame=self.structural_frame,
240-
grid=self.grid,
241-
input_transform=self.input_transform
241+
geo_model=self
242242
)
243243

244244
return self._interpolationInput

gempy/core/data/orientations.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ def xyz_view(self, value: np.ndarray):
7373
def grads(self) -> np.ndarray:
7474
return np.array([self.data['G_x'], self.data['G_y'], self.data['G_z']]).T
7575

76+
@property
77+
def grads_view(self) -> np.ndarray:
78+
return self.data[['G_x', 'G_y', 'G_z']]
79+
80+
@grads_view.setter
81+
def grads_view(self, value: np.ndarray):
82+
self.data['G_x'], self.data['G_y'], self.data['G_z'] = value.T
83+
7684
@property
7785
def nugget(self) -> np.ndarray:
7886
return self.data['nugget']

gempy/modules/data_manipulation/engine_factory.py

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,33 @@
1111
from gempy_engine.core.data.transforms import Transform
1212

1313

14-
def interpolation_input_from_structural_frame(structural_frame: StructuralFrame, grid: Grid,
15-
input_transform: Transform) -> InterpolationInput:
14+
def interpolation_input_from_structural_frame(geo_model: "GeoModel") -> InterpolationInput:
1615
_legacy_factor = 0
17-
18-
if LEGACY_COORDS := False:
19-
_legacy_factor = 0.5
16+
17+
structural_frame: StructuralFrame = geo_model.structural_frame
18+
input_transform: Transform = geo_model.input_transform
19+
grid: Grid = geo_model.grid
2020

2121
total_transform: Transform = input_transform + grid.transform
2222

23-
surface_points_copy = structural_frame.surface_points_copy
23+
surface_points_copy_transformed = geo_model.surface_points_copy_transformed
2424
surface_points: SurfacePoints = SurfacePoints(
25-
sp_coords=total_transform.apply(surface_points_copy.xyz) + _legacy_factor,
26-
nugget_effect_scalar=surface_points_copy.nugget
25+
sp_coords=geo_model.surface_points_copy_transformed.xyz,
26+
nugget_effect_scalar=surface_points_copy_transformed.nugget
2727
)
2828

29-
orientations_copy = structural_frame.orientations_copy
29+
orientations_copy_transformed = geo_model.orientations_copy_transformed
3030
orientations: Orientations = Orientations(
31-
dip_positions=total_transform.apply(orientations_copy.xyz) + _legacy_factor,
32-
dip_gradients=total_transform.transform_gradient(orientations_copy.grads),
33-
nugget_effect_grad=orientations_copy.nugget
31+
dip_positions=orientations_copy_transformed.xyz,
32+
dip_gradients=orientations_copy_transformed.grads,
33+
nugget_effect_grad=orientations_copy_transformed.nugget
3434
)
3535

36-
grid: engine_grid.EngineGrid = _apply_input_transform_to_grids(grid, input_transform)
37-
36+
grid: engine_grid.EngineGrid = _apply_input_transform_to_grids(
37+
grid=grid,
38+
input_transform=input_transform,
39+
extent_transformed=geo_model.extent_transformed
40+
)
3841

3942
interpolation_input: InterpolationInput = InterpolationInput(
4043
surface_points=surface_points,
@@ -46,12 +49,8 @@ def interpolation_input_from_structural_frame(structural_frame: StructuralFrame,
4649
return interpolation_input
4750

4851

49-
def _apply_input_transform_to_grids(grid: Grid, input_transform: Transform) -> engine_grid.EngineGrid:
50-
transformed = input_transform.apply(grid.bounding_box) # ! grid already has the grid transform applied
51-
new_extents = np.array([transformed[:, 0].min(), transformed[:, 0].max(),
52-
transformed[:, 1].min(), transformed[:, 1].max(),
53-
transformed[:, 2].min(), transformed[:, 2].max()])
54-
52+
def _apply_input_transform_to_grids(grid: Grid, input_transform: Transform, extent_transformed: np.ndarray) -> engine_grid.EngineGrid:
53+
new_extents = extent_transformed
5554
# Initialize all variables to None
5655
octree_grid: Optional[engine_grid.RegularGrid] = None
5756
regular_grid: Optional[engine_grid.RegularGrid] = None

0 commit comments

Comments
 (0)