Skip to content

Commit 672dde3

Browse files
committed
[WIP] Fixing null references to grid transforms
1 parent fe82e2e commit 672dde3

File tree

7 files changed

+68
-36
lines changed

7 files changed

+68
-36
lines changed

gempy/API/initialization_API.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ def create_geomodel(
4646
if resolution is None:
4747
grid: Grid = Grid(extent=extent)
4848
grid.octree_levels = refinement
49-
grid.set_inactive("regular")
5049
else:
5150
grid = Grid(
5251
extent=extent,

gempy/core/data/geo_model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ 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-
transform = self.input_transform + self.grid.dense_grid.transform
174+
transform = self.input_transform + self.grid.transform
175175
surface_points_table.model_transform = transform
176176
return surface_points_table
177177

@@ -189,7 +189,7 @@ def orientations_copy(self) -> OrientationsTable:
189189
"""This is a copy! Returns a OrientationsTable for all orientations across the structural elements"""
190190
orientations_table = self.structural_frame.orientations_copy
191191
if self.input_transform is not None:
192-
transform = self.input_transform + self.grid.dense_grid.transform
192+
transform = self.input_transform + self.grid.transform
193193
orientations_table.model_transform = transform
194194
return orientations_table
195195

gempy/core/data/grid.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from typing import Optional
77

88
from gempy_engine.core.data.centered_grid import CenteredGrid
9+
from gempy_engine.core.data.transforms import Transform
910
from .grid_modules import RegularGrid, CustomGrid, Sections
1011
from .grid_modules.topography import Topography
1112

@@ -35,6 +36,7 @@ class GridTypes(enum.Flag):
3536
length: np.ndarray = np.empty(0)
3637

3738
_active_grids = GridTypes.NONE
39+
_transform: Optional[Transform] = None
3840

3941
_octree_levels: int = -1
4042

@@ -52,6 +54,23 @@ def __str__(self):
5254
grid_summary_str = "\n".join(grid_summary)
5355
return f"Grid Object:\n{grid_summary_str}"
5456

57+
58+
59+
@property
60+
def transform(self) -> Transform:
61+
if self._transform is None:
62+
if self.dense_grid is not None:
63+
return self.dense_grid.transform
64+
elif self.octree_grid is not None:
65+
return self.octree_grid.transform
66+
else:
67+
return Transform.init_neutral()
68+
return self._transform
69+
70+
@transform.setter
71+
def transform(self, value: Transform):
72+
self._transform = value
73+
5574
@property
5675
def extent(self):
5776
if self._extent is None:

gempy/core/data/grid_modules/grid_types.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ def set_regular_grid(self, extent: Sequence[float], resolution: Sequence[int], t
6969

7070
@property
7171
def transform(self) -> Transform:
72+
if self._transform is None:
73+
return Transform.init_neutral()
7274
return self._transform
7375

7476
@transform.setter
7577
def transform(self, value: Transform):
76-
if value is None:
77-
self._transform = Transform.init_neutral()
7878
self._transform = value
7979

8080
@classmethod

gempy/modules/data_manipulation/engine_factory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def interpolation_input_from_structural_frame(structural_frame: StructuralFrame,
1818
if LEGACY_COORDS := False:
1919
_legacy_factor = 0.5
2020

21-
total_transform: Transform = input_transform + grid.dense_grid.transform
21+
total_transform: Transform = input_transform + grid.transform
2222

2323
surface_points_copy = structural_frame.surface_points_copy
2424
surface_points: SurfacePoints = SurfacePoints(

test/test_core/test_transfoms.py

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -88,33 +88,3 @@ def test_transform_operations_rotate():
8888
assert np.allclose(original_points, inv_transformed_points)
8989

9090

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()])
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import gempy as gp
2+
from gempy.core.data.enumerators import ExampleModel
3+
from gempy.optional_dependencies import require_gempy_viewer
4+
5+
PLOT = True
6+
7+
8+
def test_plot_transformed_data():
9+
model = gp.generate_example_model(ExampleModel.ANTICLINE, compute_model=True)
10+
print(model.structural_frame)
11+
12+
if PLOT:
13+
gpv = require_gempy_viewer()
14+
gpv.plot_3d(model, image=True)
15+
16+
17+
def test_transformed_data():
18+
if transfromed_data := True: # TODO: Expose this to user
19+
xyz2 = surface_points.model_transform.apply_with_pivot(
20+
points=xyz,
21+
# pivot=np.array([5_478_256.5, 5_698_528.946534388,0]),
22+
pivot=np.array([5.47825650e+06, 5.69852895e+06, -1.48920000e+03])
23+
24+
)
25+
26+
xyz = np.vstack([xyz, xyz2])
27+
28+
agggg = np.concatenate([mapped_array, mapped_array])
29+
30+
if transfromed_data := True:
31+
orientations_xyz2 = orientations.model_transform.apply_with_pivot(
32+
points=orientations_xyz,
33+
pivot=np.array([5.47825650e+06, 5.69852895e+06, -1.48920000e+03])
34+
)
35+
orientations_grads2 = orientations.model_transform.transform_gradient(orientations_grads)
36+
arrows_factor /= orientations.model_transform.isometric_scale
37+
38+
orientations_xyz = np.vstack([orientations_xyz, orientations_xyz2])
39+
40+
input_transform = regular_grid.input_transform
41+
transformed = input_transform.apply(regular_grid.bounding_box) # ! grid already has the grid transform applied
42+
new_extents = np.array([transformed[:, 0].min(), transformed[:, 0].max(),
43+
transformed[:, 1].min(), transformed[:, 1].max(),
44+
transformed[:, 2].min(), transformed[:, 2].max()])

0 commit comments

Comments
 (0)