Skip to content

Commit a8c3ca6

Browse files
committed
[CLN] Small cleaning while reviewing new code
1 parent 4edb718 commit a8c3ca6

File tree

1 file changed

+37
-26
lines changed

1 file changed

+37
-26
lines changed

gempy/modules/mesh_extranction/marching_cubes.py

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ def set_meshes_with_marching_cubes(model: GeoModel) -> None:
2222
If the model solutions do not contain dense grid data.
2323
"""
2424
# Verify that solutions contain dense grid data
25-
if (model.solutions is None or
26-
model.solutions.block_solution_type != RawArraysSolution.BlockSolutionType.DENSE_GRID):
25+
solution_not_having_dense: bool = model.solutions.block_solution_type != RawArraysSolution.BlockSolutionType.DENSE_GRID
26+
if model.solutions is None or solution_not_having_dense:
2727
raise ValueError("Model solutions must contain dense grid data for mesh extraction.")
28-
28+
2929
regular_grid: RegularGrid = model.grid.regular_grid
3030
structural_groups: list[StructuralGroup] = model.structural_frame.structural_groups
3131

3232
if not model.solutions.octrees_output or not model.solutions.octrees_output[0].outputs_centers:
3333
raise ValueError("No interpolation outputs available for mesh extraction.")
34-
34+
3535
output_lvl0: list[InterpOutput] = model.solutions.octrees_output[0].outputs_centers
3636

3737
# TODO: How to get this properly in gempy
@@ -50,26 +50,12 @@ def set_meshes_with_marching_cubes(model: GeoModel) -> None:
5050
scalar_values = model.solutions.raw_arrays.scalar_field_at_surface_points
5151

5252
# TODO: Here I just get my own masks, cause the gempy masks dont work as expected
53-
masks = []
54-
masks.append(np.ones_like(model.solutions.raw_arrays.scalar_field_matrix[0].reshape(model.grid.regular_grid.resolution),
55-
dtype=bool))
56-
for idx in lith_group_indices:
57-
mask = model.solutions.raw_arrays.scalar_field_matrix[idx].reshape(model.grid.regular_grid.resolution) <= \
58-
scalar_values[idx][-1]
59-
60-
masks.append(mask)
53+
masks = _get_masking_arrays(lith_group_indices, model, scalar_values)
6154

6255
# TODO: Attribute of element.scalar_field was None, changed it to scalar field value of that element
6356
# This should probably be done somewhere else and maybe renamed to scalar_field_value?
6457
# This is just the most basic solution to be clear what I did
65-
counter = 0
66-
for e, structural_group in enumerate(structural_groups):
67-
if e >= len(output_lvl0):
68-
continue
69-
70-
for element in structural_group.elements:
71-
element.scalar_field = model.solutions.scalar_field_at_surface_points[counter]
72-
counter += 1
58+
_set_scalar_field_to_element(model, output_lvl0, structural_groups)
7359

7460
# Trying to use the exiting gempy masks
7561
# masks = []
@@ -96,7 +82,7 @@ def set_meshes_with_marching_cubes(model: GeoModel) -> None:
9682
if structural_group.is_fault:
9783
mask = np.ones_like(scalar_field, dtype=bool)
9884
else:
99-
mask = masks[non_fault_counter] # TODO: I need the entry without faults here
85+
mask = masks[non_fault_counter] # TODO: I need the entry without faults here
10086
non_fault_counter += 1
10187

10288
for element in structural_group.elements:
@@ -108,9 +94,34 @@ def set_meshes_with_marching_cubes(model: GeoModel) -> None:
10894
)
10995

11096

111-
def extract_mesh_for_element(structural_element: StructuralElement,
112-
regular_grid: RegularGrid,
113-
scalar_field: np.ndarray,
97+
# TODO: This should be set somewhere else
98+
def _set_scalar_field_to_element(model, output_lvl0, structural_groups):
99+
counter = 0
100+
for e, structural_group in enumerate(structural_groups):
101+
if e >= len(output_lvl0):
102+
continue
103+
104+
for element in structural_group.elements:
105+
element.scalar_field = model.solutions.scalar_field_at_surface_points[counter]
106+
counter += 1
107+
108+
109+
# TODO: This should be set somewhere else
110+
def _get_masking_arrays(lith_group_indices, model, scalar_values):
111+
masks = []
112+
masks.append(np.ones_like(model.solutions.raw_arrays.scalar_field_matrix[0].reshape(model.grid.regular_grid.resolution),
113+
dtype=bool))
114+
for idx in lith_group_indices:
115+
mask = model.solutions.raw_arrays.scalar_field_matrix[idx].reshape(model.grid.regular_grid.resolution) <= \
116+
scalar_values[idx][-1]
117+
118+
masks.append(mask)
119+
return masks
120+
121+
122+
def extract_mesh_for_element(structural_element: StructuralElement,
123+
regular_grid: RegularGrid,
124+
scalar_field: np.ndarray,
114125
mask: Optional[np.ndarray] = None) -> None:
115126
"""Extract a mesh for a single structural element using marching cubes.
116127
@@ -132,12 +143,12 @@ def extract_mesh_for_element(structural_element: StructuralElement,
132143
spacing=(regular_grid.dx, regular_grid.dy, regular_grid.dz),
133144
mask=mask
134145
)
135-
146+
136147
# Adjust vertices to correct coordinates in the model's extent
137148
verts = (verts + [regular_grid.extent[0],
138149
regular_grid.extent[2],
139150
regular_grid.extent[4]])
140151

141152
# Store mesh in the structural element
142153
structural_element.vertices = verts
143-
structural_element.edges = faces
154+
structural_element.edges = faces

0 commit comments

Comments
 (0)