Skip to content

Commit 1990bce

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents 298e57b + 250d338 commit 1990bce

21 files changed

+247
-145
lines changed
Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,53 @@
11
# Refactoring grid to add transform
22

33
## TODO:
4-
- [ ] Rotation of pyvista grid
5-
- [ ] Rotation of pyvista meshes
4+
- [x] Rotation of pyvista grid
5+
- [x] Rotation of pyvista meshes
6+
- [ ] Run something with octrees again
7+
- [ ] **We do need settings presets**
8+
69

10+
## Notes:
11+
### Optimizing interpolation June 2024
12+
13+
- Create_grad_kernel is call 27 times
14+
15+
### Wholes issue
16+
- Spremberg with 1.5 std of extra refinement:
17+
Number of voxels marked by stats: 424 of torch.Size([512]).
18+
Number of voxels marked total by corners: 281
19+
Dense Grid would be 512 voxels
20+
Number of voxels marked by stats: 2535 of torch.Size([3568]).
21+
Number of voxels marked total by corners: 1492
22+
Dense Grid would be 4096 voxels
23+
Number of voxels marked by stats: 12148 of torch.Size([21152]).
24+
Number of voxels marked total by corners: 7614
25+
Dense Grid would be 32768 voxels
26+
Number of voxels marked by stats: 69619 of torch.Size([101432]).
27+
Number of voxels marked total by corners: 37423
28+
Dense Grid would be 262144 voxels
29+
Chunking done: 12 chunks
30+
- Spremberg with 1
31+
Number of voxels marked by stats: 408 of torch.Size([512]).
32+
Number of voxels marked total by corners: 281
33+
Dense Grid would be 512 voxels
34+
Number of voxels marked by stats: 1953 of torch.Size([3504]).
35+
Number of voxels marked total by corners: 1492
36+
Dense Grid would be 4096 voxels
37+
Number of voxels marked by stats: 8632 of torch.Size([16856]).
38+
Number of voxels marked total by corners: 7612
39+
Dense Grid would be 32768 voxels
40+
Chunking done: 13 chunks
41+
Number of voxels marked by stats: 47653 of torch.Size([79080]).
42+
Number of voxels marked total by corners: 37408
43+
Dense Grid would be 262144 voxels
44+
Chunking done: 10 chunks
45+
46+
### Other:
47+
{'_cached_pivot': [200, 200, 0],
48+
'_is_default_transform': False,
49+
'position': array([0., 0., 0.]),
50+
'rotation': array([ 0., -0., -45.]),
51+
'scale': array([1., 1., 1.])}
52+
753
## Questions:

examples/tutorials/z_other_tutorials/a1_fold.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
geo_model = gp.create_geomodel(
3232
project_name='tutorial_model',
3333
extent=[0, 2500, 0, 1000, 0, 1110],
34-
refinement=6,
34+
refinement=4,
3535
importer_helper=gp.data.ImporterHelper(
3636
path_to_orientations=path_to_data + "tutorial_model_orientations.csv",
3737
path_to_surface_points=path_to_data + "tutorial_model_surface_points.csv"
@@ -62,17 +62,23 @@
6262

6363
interpolation_options: gp.data.InterpolationOptions = geo_model.interpolation_options
6464

65-
6665
interpolation_options.kernel_options.range = 1.7
6766
interpolation_options.evaluation_options.number_octree_levels_surface = 4
68-
interpolation_options.evaluation_options.curvature_threshold = 0.1
67+
interpolation_options.evaluation_options.compute_scalar_gradient = False
68+
interpolation_options.evaluation_options.curvature_threshold = 1
69+
interpolation_options.evaluation_options.min_octree_level = 1
70+
71+
interpolation_options.evaluation_options.verbose = True
6972

7073
# %%
7174
# Compute the geological model
7275
# We use the specified backend (in this case, PyTorch) to compute the model.
7376
gp.compute_model(
7477
gempy_model=geo_model,
75-
engine_config=gp.data.GemPyEngineConfig(backend=gp.data.AvailableBackends.PYTORCH)
78+
engine_config=gp.data.GemPyEngineConfig(
79+
backend=gp.data.AvailableBackends.numpy,
80+
dtype="float64"
81+
)
7682
)
7783

7884
# %%

gempy/API/compute_API.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from .grid_API import set_custom_grid
1111
from ..core.data.gempy_engine_config import GemPyEngineConfig
1212
from ..core.data.geo_model import GeoModel
13+
from ..modules.data_manipulation.engine_factory import interpolation_input_from_structural_frame
1314
from ..optional_dependencies import require_gempy_legacy
1415

1516

@@ -39,7 +40,7 @@ def compute_model(gempy_model: GeoModel, engine_config: Optional[GemPyEngineConf
3940
)
4041

4142
# TODO: To decide what to do with this.
42-
interpolation_input = gempy_model.interpolation_input_copy
43+
interpolation_input = interpolation_input_from_structural_frame(gempy_model)
4344
gempy_model.taped_interpolation_input = interpolation_input # * This is used for gradient tape
4445

4546
gempy_model.solutions = gempy_engine.compute_model(

gempy/API/grid_API.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@
1212
def set_section_grid(grid: Grid, section_dict: dict):
1313
if grid.sections is None:
1414
grid.sections = Sections(regular_grid=grid.regular_grid, section_dict=section_dict)
15-
grid.sections
1615
else:
1716
grid.sections.set_sections(section_dict,
1817
regular_grid=grid.regular_grid)
1918

20-
set_active_grid(grid, [GridTypes.SECTIONS])
19+
set_active_grid(grid, [Grid.GridTypes.SECTIONS])
2120
return grid.sections
2221

2322

@@ -38,19 +37,19 @@ def set_topography_from_random(grid: Grid, fractal_dimension: float = 2.0, d_z:
3837
values_2d=random_topography
3938
)
4039

41-
set_active_grid(grid, [GridTypes.TOPOGRAPHY])
40+
set_active_grid(grid, [Grid.GridTypes.TOPOGRAPHY])
4241
return grid.topography
4342

4443

4544
def set_topography_from_subsurface_structured_grid(grid: Grid, struct: "subsurface.StructuredData"):
4645
grid.topography = Topography.from_subsurface_structured_data(struct, grid.regular_grid)
47-
set_active_grid(grid, [GridTypes.TOPOGRAPHY])
46+
set_active_grid(grid, [Grid.GridTypes.TOPOGRAPHY])
4847
return grid.topography
4948

5049

5150
def set_topography_from_arrays(grid: Grid, xyz_vertices: np.ndarray):
5251
grid.topography = Topography.from_unstructured_mesh(grid.regular_grid, xyz_vertices)
53-
set_active_grid(grid, [GridTypes.TOPOGRAPHY])
52+
set_active_grid(grid, [Grid.GridTypes.TOPOGRAPHY])
5453
return grid.topography
5554

5655

@@ -67,7 +66,7 @@ def set_custom_grid(grid: Grid, xyz_coord: np.ndarray):
6766
custom_grid = CustomGrid(xyx_coords=xyz_coord)
6867
grid.custom_grid = custom_grid
6968

70-
set_active_grid(grid, [GridTypes.CUSTOM])
69+
set_active_grid(grid, [Grid.GridTypes.CUSTOM])
7170
return grid.custom_grid
7271

7372

@@ -79,7 +78,7 @@ def set_centered_grid(grid: Grid, centers: np.ndarray, resolution: Sequence[floa
7978
radius=radius
8079
)
8180
grid.centered_grid = centered_grid
82-
set_active_grid(grid, [GridTypes.CENTERED])
81+
set_active_grid(grid, [Grid.GridTypes.CENTERED])
8382
return grid.centered_grid
8483

8584

@@ -93,7 +92,7 @@ def set_topography_from_array():
9392

9493
def set_active_grid(grid: Grid, grid_type: list[Grid.GridTypes], reset: bool = False):
9594
if reset is True:
96-
grid.active_grids = GridTypes.NONE
95+
grid.active_grids = Grid.GridTypes.NONE
9796
for grid_type in grid_type:
9897
grid.active_grids |= grid_type
9998

gempy/API/initialization_API.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from gempy.API.io_API import read_surface_points, read_orientations
88
from gempy_engine.core.data import InterpolationOptions
9+
from ..core.data.grid_modules import RegularGrid
910
from ..optional_dependencies import require_subsurface
1011
from ..core.data import StructuralElement
1112
from ..core.data.geo_model import GeoModel
@@ -44,10 +45,12 @@ def create_geomodel(
4445
"""
4546
# init resolutions well
4647
if resolution is None:
47-
grid: Grid = Grid(extent=extent)
48-
grid.octree_levels = refinement
48+
grid: Grid = Grid.init_octree_grid(
49+
extent=extent,
50+
octree_levels=refinement
51+
)
4952
else:
50-
grid = Grid(
53+
grid: Grid = Grid.init_dense_grid(
5154
extent=extent,
5255
resolution=resolution
5356
)
@@ -92,18 +95,18 @@ def structural_elements_from_borehole_set(
9295
Returns:
9396
list[StructuralElement]: A list of StructuralElement instances.
9497
"""
95-
98+
9699
ss = require_subsurface()
97100
borehole_set: ss.core.geological_formats.BoreholeSet
98-
101+
99102
elements = []
100103
component_lith: dict[Hashable, np.ndarray] = borehole_set.get_bottom_coords_for_each_lith()
101-
104+
102105
for name, properties in elements_dict.items():
103106
top_coordinates = component_lith.get(properties['id'])
104107
if top_coordinates is None:
105108
raise ValueError(f"Top lithology {properties['id']} not found in borehole set.")
106-
109+
107110
element = StructuralElement(
108111
name=name,
109112
id=properties['id'],
@@ -119,7 +122,7 @@ def structural_elements_from_borehole_set(
119122
)
120123
elements.append(element)
121124
# Reverse the list to have the oldest rocks at the bottom
122-
125+
123126
return elements
124127

125128

gempy/core/data/geo_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def project_bounds(self) -> np.ndarray:
233233
return self.grid.bounding_box
234234

235235
@property
236-
def extent_transformed(self) -> np.ndarray:
236+
def extent_transformed_transformed_by_input(self) -> np.ndarray:
237237
transformed = self.input_transform.apply(self.project_bounds) # ! grid already has the grid transform applied
238238
new_extents = np.array([transformed[:, 0].min(), transformed[:, 0].max(),
239239
transformed[:, 1].min(), transformed[:, 1].max(),

0 commit comments

Comments
 (0)