Skip to content

Commit 7ea945f

Browse files
committed
[TEST] Fixed tests that did not refactor properly
[ENH] Improved way to set octree grids in a robust manner
1 parent 3ea808f commit 7ea945f

File tree

4 files changed

+34
-14
lines changed

4 files changed

+34
-14
lines changed

gempy/API/grid_API.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,19 @@ def set_topography_from_random(grid: Grid, fractal_dimension: float = 2.0, d_z:
3737
values_2d=random_topography
3838
)
3939

40-
set_active_grid(grid, [GridTypes.TOPOGRAPHY])
40+
set_active_grid(grid, [Grid.GridTypes.TOPOGRAPHY])
4141
return grid.topography
4242

4343

4444
def set_topography_from_subsurface_structured_grid(grid: Grid, struct: "subsurface.StructuredData"):
4545
grid.topography = Topography.from_subsurface_structured_data(struct, grid.regular_grid)
46-
set_active_grid(grid, [GridTypes.TOPOGRAPHY])
46+
set_active_grid(grid, [Grid.GridTypes.TOPOGRAPHY])
4747
return grid.topography
4848

4949

5050
def set_topography_from_arrays(grid: Grid, xyz_vertices: np.ndarray):
5151
grid.topography = Topography.from_unstructured_mesh(grid.regular_grid, xyz_vertices)
52-
set_active_grid(grid, [GridTypes.TOPOGRAPHY])
52+
set_active_grid(grid, [Grid.GridTypes.TOPOGRAPHY])
5353
return grid.topography
5454

5555

@@ -66,7 +66,7 @@ def set_custom_grid(grid: Grid, xyz_coord: np.ndarray):
6666
custom_grid = CustomGrid(xyx_coords=xyz_coord)
6767
grid.custom_grid = custom_grid
6868

69-
set_active_grid(grid, [GridTypes.CUSTOM])
69+
set_active_grid(grid, [Grid.GridTypes.CUSTOM])
7070
return grid.custom_grid
7171

7272

@@ -78,7 +78,7 @@ def set_centered_grid(grid: Grid, centers: np.ndarray, resolution: Sequence[floa
7878
radius=radius
7979
)
8080
grid.centered_grid = centered_grid
81-
set_active_grid(grid, [GridTypes.CENTERED])
81+
set_active_grid(grid, [Grid.GridTypes.CENTERED])
8282
return grid.centered_grid
8383

8484

@@ -92,7 +92,7 @@ def set_topography_from_array():
9292

9393
def set_active_grid(grid: Grid, grid_type: list[Grid.GridTypes], reset: bool = False):
9494
if reset is True:
95-
grid.active_grids = GridTypes.NONE
95+
grid.active_grids = Grid.GridTypes.NONE
9696
for grid_type in grid_type:
9797
grid.active_grids |= grid_type
9898

gempy/core/data/grid.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ def octree_grid(self):
139139
def octree_grid(self, value):
140140
raise AttributeError('Octree grid is not allowed to be set directly. Use init_octree_grid instead')
141141

142-
def set_octree_grid(self, value: RegularGrid, evaluation_options: EvaluationOptions):
143-
regular_grid_resolution = value.resolution
142+
def set_octree_grid(self, regular_grid: RegularGrid, evaluation_options: EvaluationOptions):
143+
regular_grid_resolution = regular_grid.resolution
144144
# Check all directions has the same res
145145
if not np.all(regular_grid_resolution == regular_grid_resolution[0]):
146146
raise AttributeError('Octree resolution must be isotropic')
@@ -149,9 +149,29 @@ def set_octree_grid(self, value: RegularGrid, evaluation_options: EvaluationOpti
149149
if octree_levels != evaluation_options.number_octree_levels:
150150
raise AttributeError('Regular grid resolution does not match octree levels. Resolution must be 2^n')
151151

152-
self._octree_grid = value
152+
self._octree_grid = regular_grid
153153
self.active_grids |= self.GridTypes.OCTREE
154154
self._update_values()
155+
156+
def set_octree_grid_by_levels(self, octree_levels: int, evaluation_options: EvaluationOptions, extent: Optional[np.ndarray] = None):
157+
if extent is None:
158+
extent = self.extent
159+
160+
self._octree_grid = RegularGrid(
161+
extent=extent,
162+
resolution=np.array([2 ** octree_levels] * 3),
163+
)
164+
evaluation_options.number_octree_levels = octree_levels
165+
self.active_grids |= self.GridTypes.OCTREE
166+
self._update_values()
167+
168+
@property
169+
def octree_levels(self):
170+
return self._octree_levels
171+
172+
@octree_levels.setter
173+
def octree_levels(self, value):
174+
raise AttributeError('Octree levels are not allowed to be set directly. Use set_octree_grid instead')
155175

156176
@property
157177
def custom_grid(self):

test/test_modules/_geophysics_TO_UPDATE/test_gravity.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# These two lines are necessary only if GemPy is not installed
2-
# sys.path.append("../..")
3-
41
# Importing GemPy
52
import gempy as gp
63

test/test_modules/test_grids/test_grids_sections.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ def test_section_grids():
1414
example_model=ExampleModel.ANTICLINE,
1515
compute_model=False
1616
)
17-
geo_model.grid.octree_levels = 2
18-
geo_model.interpolation_options.number_octree_levels = 2
17+
18+
geo_model.grid.set_octree_grid_by_levels(
19+
octree_levels=2,
20+
evaluation_options=geo_model.interpolation_options.evaluation_options
21+
)
1922

2023
gp.set_section_grid(
2124
grid=geo_model.grid,

0 commit comments

Comments
 (0)