Skip to content

Commit fe82e2e

Browse files
committed
[WIP] Trying to figure out the mess I have with the transforms
1 parent cb59ff1 commit fe82e2e

File tree

5 files changed

+52
-9
lines changed

5 files changed

+52
-9
lines changed

gempy/core/data/geo_model.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ 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
173173
if self.input_transform is not None:
174-
surface_points_table.model_transform = self.input_transform
174+
transform = self.input_transform + self.grid.dense_grid.transform
175+
surface_points_table.model_transform = transform
175176
return surface_points_table
176177

177178
@property
@@ -188,7 +189,8 @@ def orientations_copy(self) -> OrientationsTable:
188189
"""This is a copy! Returns a OrientationsTable for all orientations across the structural elements"""
189190
orientations_table = self.structural_frame.orientations_copy
190191
if self.input_transform is not None:
191-
orientations_table.model_transform = self.input_transform
192+
transform = self.input_transform + self.grid.dense_grid.transform
193+
orientations_table.model_transform = transform
192194
return orientations_table
193195

194196
@property

gempy/core/data/grid.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ def extent(self):
6868
@extent.setter
6969
def extent(self, value):
7070
self._extent = value
71+
72+
@property
73+
def corner_min(self):
74+
return self.extent[::2]
75+
76+
@property
77+
def corner_max(self):
78+
return self.extent[1::2]
7179

7280
@property
7381
def bounding_box(self):

gempy/core/data/grid_modules/grid_types.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def _create_regular_grid_3d(self):
4141

4242
# Transform the values
4343
if self.transform is not None:
44-
self.values = self.transform.apply_with_pivot(
44+
self.values = self.transform.apply_inverse_with_pivot(
4545
points=values,
4646
pivot=np.array([self.extent[0], self.extent[2], self.extent[4]])
4747
)
@@ -126,18 +126,18 @@ def _calculate_rotated_box_val(v1, v2):
126126
[0, 0, 0, 1]
127127
])
128128

129-
transform = Transform.from_matrix(rotation_matrix)
129+
inverted_rotation_matrix = np.linalg.inv(rotation_matrix)
130+
transform = Transform.from_matrix(inverted_rotation_matrix)
130131

131132
# Calculate the extents in the new coordinate system
132133
extent_x = np.linalg.norm(v1)
133134
extent_y = np.linalg.norm(v2)
134135

135136
# We transform the origin point1 to the new coordinates
136137
# [[ 5.47925650e+06 5.70152895e+06 -2.39200000e+02]]
137-
vector = np.array([[x1, y1, zmin]])
138-
origin_transformed = transform.apply_with_pivot(vector, pivot=vector[0])[0]
138+
origin_ = [x1, y1, zmin]
139139

140-
xmin, ymin, zmin = origin_transformed
140+
xmin, ymin, zmin = origin_
141141
xmax, ymax, zmax = xmin + extent_x, ymin + extent_y, zmin + zmax - zmin
142142

143143
extent = np.array([xmin, xmax, ymin, ymax, zmin, zmax], dtype='float64')

gempy/modules/data_manipulation/engine_factory.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,19 @@ def interpolation_input_from_structural_frame(structural_frame: StructuralFrame,
4848

4949
def _apply_input_transform_to_grids(grid: Grid, input_transform: Transform) -> engine_grid.EngineGrid:
5050
transformed = input_transform.apply(grid.bounding_box) # ! grid already has the grid transform applied
51+
grid.regular_grid.input_transform = input_transform
5152
new_extents = np.array([transformed[:, 0].min(), transformed[:, 0].max(),
5253
transformed[:, 1].min(), transformed[:, 1].max(),
5354
transformed[:, 2].min(), transformed[:, 2].max()])
54-
55+
5556
# Initialize all variables to None
5657
octree_grid: Optional[engine_grid.RegularGrid] = None
5758
regular_grid: Optional[engine_grid.RegularGrid] = None
5859
custom_values: Optional[engine_grid.GenericGrid] = None
5960
topography_values: Optional[engine_grid.GenericGrid] = None
6061
section_values: Optional[engine_grid.GenericGrid] = None
6162
centered_grid: Optional[engine_grid.CenteredGrid] = None
62-
63+
6364
if grid.GridTypes.DENSE in grid.active_grids:
6465
regular_grid = engine_grid.RegularGrid(
6566
orthogonal_extent=new_extents,

test/test_core/test_transfoms.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,35 @@ def test_transform_operations_rotate():
8686
plt.show()
8787

8888
assert np.allclose(original_points, inv_transformed_points)
89+
90+
91+
def test_transformed_data():
92+
if transfromed_data := True: # TODO: Expose this to user
93+
xyz2 = surface_points.model_transform.apply_with_pivot(
94+
points=xyz,
95+
# pivot=np.array([5_478_256.5, 5_698_528.946534388,0]),
96+
pivot=np.array([5.47825650e+06, 5.69852895e+06, -1.48920000e+03])
97+
98+
)
99+
100+
xyz = np.vstack([xyz, xyz2])
101+
102+
103+
agggg = np.concatenate([mapped_array, mapped_array])
104+
105+
if transfromed_data := True:
106+
orientations_xyz2 = orientations.model_transform.apply_with_pivot(
107+
points=orientations_xyz,
108+
pivot=np.array([5.47825650e+06, 5.69852895e+06, -1.48920000e+03])
109+
)
110+
orientations_grads2 = orientations.model_transform.transform_gradient(orientations_grads)
111+
arrows_factor /= orientations.model_transform.isometric_scale
112+
113+
orientations_xyz = np.vstack([orientations_xyz, orientations_xyz2])
114+
115+
116+
input_transform = regular_grid.input_transform
117+
transformed = input_transform.apply(regular_grid.bounding_box) # ! grid already has the grid transform applied
118+
new_extents = np.array([transformed[:, 0].min(), transformed[:, 0].max(),
119+
transformed[:, 1].min(), transformed[:, 1].max(),
120+
transformed[:, 2].min(), transformed[:, 2].max()])

0 commit comments

Comments
 (0)