Skip to content

Commit cb59ff1

Browse files
committed
[CLN] Refactor GeoModel.transform to input_transform
[CLN] Refactor extent to orthogonal_extent [WIP] Trying to figure out how to apply the grid rotation
1 parent 84b77d7 commit cb59ff1

File tree

7 files changed

+48
-52
lines changed

7 files changed

+48
-52
lines changed

examples/tutorials/ch1_fundamentals/ch1_4_onlap_relations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
geo_model.structural_frame
4848

4949
# %%
50-
geo_model.transform.apply_anisotropy(gp.data.GlobalAnisotropy.NONE)
50+
geo_model.input_transform.apply_anisotropy(gp.data.GlobalAnisotropy.NONE)
5151
gp.add_structural_group(
5252
model=geo_model,
5353
group_index=0,

examples/tutorials/ch1_fundamentals/ch1_5_fault_relations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363

6464
# %%
6565

66-
geo_model.transform.apply_anisotropy(gp.data.GlobalAnisotropy.NONE)
66+
geo_model.input_transform.apply_anisotropy(gp.data.GlobalAnisotropy.NONE)
6767
if False:
6868
gp.compute_model(geo_model)
6969
# %%

examples/tutorials/ch3-Interpolations/ch3_1_kriging_interpolation_and_simulation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
# creating a domain object from the gempy solution, a defined domain conditioning data
9494
domain = kriging.Domain(
9595
model_solutions=sol,
96-
transform=geo_data.transform,
96+
transform=geo_data.input_transform,
9797
domain=[2],
9898
data=cond_data
9999
)

gempy/core/data/geo_model.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class GeoModel:
6060
_interpolation_options: InterpolationOptions #: The interpolation options provided by the user.
6161
geophysics_input: GeophysicsInput = None #: The geophysics input of the geological model.
6262

63-
transform: Transform = None #: The transformation used in the geological model for input points.
63+
input_transform: Transform = None #: The transformation used in the geological model for input points.
6464

6565
interpolation_grid: EngineGrid = None #: Optional grid used for interpolation. Can be seen as a cache field.
6666
_interpolationInput: InterpolationInput = None #: Input data for interpolation. Fed by the structural frame and can be seen as a cache field.
@@ -84,7 +84,7 @@ def __init__(self, name: str, structural_frame: StructuralFrame, grid: Grid, int
8484

8585
self.grid = grid
8686
self._interpolation_options = interpolation_options
87-
self.transform = Transform.from_input_points(
87+
self.input_transform = Transform.from_input_points(
8888
surface_points=self.surface_points_copy,
8989
orientations=self.orientations_copy
9090
)
@@ -94,12 +94,12 @@ def __repr__(self):
9494
return pprint.pformat(self.__dict__)
9595

9696
def update_transform(self, auto_anisotropy: GlobalAnisotropy = GlobalAnisotropy.NONE, anisotropy_limit: Optional[np.ndarray] = None):
97-
self.transform = Transform.from_input_points(
97+
self.input_transform = Transform.from_input_points(
9898
surface_points=self.surface_points_copy,
9999
orientations=self.orientations_copy
100100
)
101101

102-
self.transform.apply_anisotropy(anisotropy_type=auto_anisotropy, anisotropy_limit=anisotropy_limit)
102+
self.input_transform.apply_anisotropy(anisotropy_type=auto_anisotropy, anisotropy_limit=anisotropy_limit)
103103

104104
@property
105105
def interpolation_options(self) -> InterpolationOptions:
@@ -155,7 +155,7 @@ def solutions(self, value):
155155
continue
156156

157157
# TODO: These meshes are in the order of the scalar field
158-
world_coord_vertices = self.transform.apply_inverse(dc_mesh.vertices)
158+
world_coord_vertices = self.input_transform.apply_inverse(dc_mesh.vertices)
159159

160160
element.vertices = world_coord_vertices
161161
element.edges = (dc_mesh.edges if dc_mesh is not None else None)
@@ -170,8 +170,8 @@ def solutions(self, value):
170170
def surface_points_copy(self):
171171
"""This is a copy! Returns a SurfacePointsTable for all surface points across the structural elements"""
172172
surface_points_table = self.structural_frame.surface_points_copy
173-
if self.transform is not None:
174-
surface_points_table.model_transform = self.transform
173+
if self.input_transform is not None:
174+
surface_points_table.model_transform = self.input_transform
175175
return surface_points_table
176176

177177
@property
@@ -187,8 +187,8 @@ def surface_points(self, value):
187187
def orientations_copy(self) -> OrientationsTable:
188188
"""This is a copy! Returns a OrientationsTable for all orientations across the structural elements"""
189189
orientations_table = self.structural_frame.orientations_copy
190-
if self.transform is not None:
191-
orientations_table.model_transform = self.transform
190+
if self.input_transform is not None:
191+
orientations_table.model_transform = self.input_transform
192192
return orientations_table
193193

194194
@property
@@ -208,7 +208,7 @@ def interpolation_input_copy(self):
208208
self._interpolationInput = interpolation_input_from_structural_frame(
209209
structural_frame=self.structural_frame,
210210
grid=self.grid,
211-
transform=self.transform
211+
input_transform=self.input_transform
212212
)
213213

214214
return self._interpolationInput

gempy/modules/data_manipulation/engine_factory.py

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,69 +12,75 @@
1212

1313

1414
def interpolation_input_from_structural_frame(structural_frame: StructuralFrame, grid: Grid,
15-
transform: Transform) -> InterpolationInput:
15+
input_transform: Transform) -> InterpolationInput:
1616
_legacy_factor = 0
1717

1818
if LEGACY_COORDS := False:
1919
_legacy_factor = 0.5
2020

21+
total_transform: Transform = input_transform + grid.dense_grid.transform
22+
2123
surface_points_copy = structural_frame.surface_points_copy
2224
surface_points: SurfacePoints = SurfacePoints(
23-
sp_coords=transform.apply(surface_points_copy.xyz) + _legacy_factor,
25+
sp_coords=total_transform.apply(surface_points_copy.xyz) + _legacy_factor,
2426
nugget_effect_scalar=surface_points_copy.nugget
2527
)
2628

2729
orientations_copy = structural_frame.orientations_copy
2830
orientations: Orientations = Orientations(
29-
dip_positions=transform.apply(orientations_copy.xyz) + _legacy_factor,
30-
dip_gradients=transform.transform_gradient(orientations_copy.grads),
31+
dip_positions=total_transform.apply(orientations_copy.xyz) + _legacy_factor,
32+
dip_gradients=total_transform.transform_gradient(orientations_copy.grads),
3133
nugget_effect_grad=orientations_copy.nugget
3234
)
3335

34-
# region Transforming the grid
36+
grid: engine_grid.EngineGrid = _apply_input_transform_to_grids(grid, input_transform)
37+
3538

36-
transformed = transform.apply(grid.bounding_box) # ? isn't this making the regular grid not optional?
39+
interpolation_input: InterpolationInput = InterpolationInput(
40+
surface_points=surface_points,
41+
orientations=orientations,
42+
grid=grid,
43+
unit_values=structural_frame.elements_ids # TODO: Here we will need to pass densities etc.
44+
)
45+
46+
return interpolation_input
47+
48+
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
3751
new_extents = np.array([transformed[:, 0].min(), transformed[:, 0].max(),
3852
transformed[:, 1].min(), transformed[:, 1].max(),
3953
transformed[:, 2].min(), transformed[:, 2].max()])
40-
54+
4155
# Initialize all variables to None
4256
octree_grid: Optional[engine_grid.RegularGrid] = None
4357
regular_grid: Optional[engine_grid.RegularGrid] = None
4458
custom_values: Optional[engine_grid.GenericGrid] = None
4559
topography_values: Optional[engine_grid.GenericGrid] = None
4660
section_values: Optional[engine_grid.GenericGrid] = None
4761
centered_grid: Optional[engine_grid.CenteredGrid] = None
48-
62+
4963
if grid.GridTypes.DENSE in grid.active_grids:
5064
regular_grid = engine_grid.RegularGrid(
51-
extent=new_extents,
65+
orthogonal_extent=new_extents,
5266
regular_grid_shape=grid.dense_grid.resolution,
53-
transform=grid.dense_grid.transform
5467
)
55-
5668
if grid.GridTypes.CUSTOM in grid.active_grids and grid.custom_grid is not None:
57-
custom_values = engine_grid.GenericGrid(values=transform.apply(grid.custom_grid.values))
58-
69+
custom_values = engine_grid.GenericGrid(values=input_transform.apply(grid.custom_grid.values))
5970
if grid.GridTypes.TOPOGRAPHY in grid.active_grids and grid.topography is not None:
60-
topography_values = engine_grid.GenericGrid(values=transform.apply(grid.topography.values))
61-
71+
topography_values = engine_grid.GenericGrid(values=input_transform.apply(grid.topography.values))
6272
if grid.GridTypes.SECTIONS in grid.active_grids and grid.sections is not None:
63-
section_values = engine_grid.GenericGrid(values=transform.apply(grid.sections.values))
64-
73+
section_values = engine_grid.GenericGrid(values=input_transform.apply(grid.sections.values))
6574
if grid.GridTypes.CENTERED in grid.active_grids and grid.centered_grid is not None:
6675
centered_grid = engine_grid.CenteredGrid(
67-
centers=transform.apply(grid.centered_grid.centers),
68-
radius=transform.scale_points(np.atleast_2d(grid.centered_grid.radius))[0],
76+
centers=input_transform.apply(grid.centered_grid.centers),
77+
radius=input_transform.scale_points(np.atleast_2d(grid.centered_grid.radius))[0],
6978
resolution=grid.centered_grid.resolution
7079
)
71-
7280
octree_grid = engine_grid.RegularGrid(
73-
extent=new_extents,
74-
regular_grid_shape=np.array([2, 2, 2]),
75-
transform=grid.dense_grid.transform # ! That here we need to grab the dense grid smells
81+
orthogonal_extent=new_extents,
82+
regular_grid_shape=np.array([2, 2, 2])
7683
)
77-
7884
grid: engine_grid.EngineGrid = engine_grid.EngineGrid( # * Here we convert the GemPy grid to the
7985
octree_grid=octree_grid, # BUG: Adapt the engine to deal with this
8086
dense_grid=regular_grid,
@@ -83,14 +89,4 @@ def interpolation_input_from_structural_frame(structural_frame: StructuralFrame,
8389
custom_grid=custom_values,
8490
geophysics_grid=centered_grid
8591
)
86-
87-
# endregion
88-
89-
interpolation_input: InterpolationInput = InterpolationInput(
90-
surface_points=surface_points,
91-
orientations=orientations,
92-
grid=grid,
93-
unit_values=structural_frame.elements_ids # TODO: Here we will need to pass densities etc.
94-
)
95-
96-
return interpolation_input
92+
return grid

test/test_core/test_transfoms.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
def test_transform_1():
99
geo_data: GeoModel = _create_data()
10-
print(geo_data.transform)
11-
transformed_xyz = geo_data.transform.apply(geo_data.surface_points_copy.xyz)
10+
print(geo_data.input_transform)
11+
transformed_xyz = geo_data.input_transform.apply(geo_data.surface_points_copy.xyz)
1212
print(transformed_xyz)
1313
return
1414

test/test_modules/test_faults/test_finite_faults.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ def test_finite_fault_scalar_field_on_fault():
2525
regular_grid = geo_model.grid.regular_grid
2626

2727
# TODO: Extract grid from the model
28-
scaled_center = geo_model.transform.apply(center.reshape(1, -1))[0]
29-
scaled_radius = geo_model.transform.scale_points(radius.reshape(1, -1))[0]
28+
scaled_center = geo_model.input_transform.apply(center.reshape(1, -1))[0]
29+
scaled_radius = geo_model.input_transform.scale_points(radius.reshape(1, -1))[0]
3030
scalar_funtion: callable = gp.implicit_functions.ellipsoid_3d_factory( # * This paints the 3d regular grid
3131
center=scaled_center,
3232
radius=scaled_radius,

0 commit comments

Comments
 (0)