Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[ENH] Refactor interpolation options with enum-based types
Replaces hardcoded interpolation initialization with an enum-based system (`InterpolationOptionsType`) for flexibility. Removes unused tests and updates dependencies to `gempy_engine~=2025.1`.
  • Loading branch information
Leguark committed May 2, 2025
commit 55094c2b7e778c3fb2bc080772bfa60ae6101c64
50 changes: 34 additions & 16 deletions gempy/API/initialization_API.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@

from gempy.API.io_API import read_surface_points, read_orientations
from gempy_engine.core.data import InterpolationOptions
from ..core.data.grid_modules import RegularGrid
from ..optional_dependencies import require_subsurface
from ..core.data import StructuralElement
from ..core.data.geo_model import GeoModel
from ..core.data.grid import Grid
from ..core.data.importer_helper import ImporterHelper
from ..core.data.options import InterpolationOptionsType
from ..core.data.orientations import OrientationsTable
from ..core.data.structural_frame import StructuralFrame
from ..core.data.surface_points import SurfacePointsTable
from ..optional_dependencies import require_pooch
from ..optional_dependencies import require_subsurface


def create_geomodel(
Expand All @@ -26,23 +26,40 @@ def create_geomodel(
refinement: int = 1,
structural_frame: StructuralFrame = None,
importer_helper: ImporterHelper = None,
intpolation_options_tye: InterpolationOptionsType = InterpolationOptionsType.OCTREE,
) -> GeoModel: # ? Do I need to pass pandas read kwargs?
"""
Initializes and returns a GeoModel instance with specified parameters.
Creates a geological model based on input parameters, spatial configuration, and interpolation options.

This function initializes a geological model by defining the grid (dense grid or
octree-based), selecting interpolation options based on the desired type, and
configuring the structural frame using either a provided structural frame or an
importer helper instance. The geological model is tailored for specific project-based
requirements and can be either dense or with variable resolution depending on the
refinement level.

Args:
project_name (str, optional): The name of the project. Defaults to 'default_project'.
extent (Union[List, np.ndarray], optional): The 3D extent of the grid. Must be provided if resolution is specified. Defaults to None.
resolution (Union[List, np.ndarray], optional): The resolution of the grid. If None, an octree grid will be initialized. Defaults to None.
refinement (int, optional): The level of refinement for the octree grid. Defaults to 1.
structural_frame (StructuralFrame, optional): The structural frame of the GeoModel. Either this or importer_helper must be provided. Defaults to None.
importer_helper (ImporterHelper, optional): Helper object for importing structural elements. Either this or structural_frame must be provided. Defaults to None.
project_name (str): Name of the geological model project. Defaults to 'default_project'.
extent (list, ndarray): Spatial extent of the geological model in the form of
[min_x, max_x, min_y, max_y, min_z, max_z].
resolution (list, ndarray): Resolution of the model grid in the form [x_res, y_res, z_res].
If not provided, the function will default to octree initialization.
refinement (int): Refinement level for the octree grid. Ignored if resolution is provided.
Defaults to 1.
structural_frame (StructuralFrame): Pre-configured instance of StructuralFrame
for the geological model. If not provided, an importer_helper must be supplied.
importer_helper (ImporterHelper): Helper object for initializing a structural frame if none
is explicitly provided.
intpolation_options_tye (InterpolationOptionsType): Enum representing the desired type of
interpolation options. Defaults to InterpolationOptionsType.OCTREE.

Returns:
GeoModel: The initialized GeoModel object.
GeoModel: An initialized geological model with specified spatial configuration
and interpolation properties.

Raises:
ValueError: If neither structural_frame nor importer_helper is provided.
ValueError: If the interpolation options type is unrecognized.
"""

# init resolutions well
Expand All @@ -57,12 +74,13 @@ def create_geomodel(
resolution=resolution
)

interpolation_options: InterpolationOptions = InterpolationOptions(
range=1.7,
c_o=10,
mesh_extraction=True,
number_octree_levels=refinement,
)
match intpolation_options_tye:
case InterpolationOptionsType.DENSE_GRID:
interpolation_options: InterpolationOptions = InterpolationOptions.init_dense_grid_options()
case InterpolationOptionsType.OCTREE:
interpolation_options: InterpolationOptions = InterpolationOptions.init_octree_options(refinement=refinement)
case _:
raise ValueError(f"Interpolation options type {intpolation_options_tye} not recognized. Use InterpolationOptionsType.DENSE_GRID or InterpolationOptionsType.OCTREE.")

match (structural_frame, importer_helper):
case (None, None):
Expand Down
5 changes: 5 additions & 0 deletions gempy/core/data/options.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import enum
class InterpolationOptionsType(enum.Enum):

DENSE_GRID = enum.auto()
OCTREE = enum.auto()
2 changes: 1 addition & 1 deletion requirements/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# This install also numpy
gempy_engine~=2024.2.0
gempy_engine~=2025.1
Empty file removed test/test_QA/__init__.py
Empty file.
Empty file removed test/test_QA/test_chuncking.py
Empty file.
41 changes: 0 additions & 41 deletions test/test_core/test_options_presets.py

This file was deleted.

3 changes: 1 addition & 2 deletions test/test_modules/test_marching_cubes.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ def test_marching_cubes_implementation():
reset=True
)

model.interpolation_options.evaluation_options.number_octree_levels = 1
model.interpolation_options.evaluation_options.mesh_extraction = False # * Not extracting the mesh with dual contouring
model.interpolation_options = gp.data.InterpolationOptions.init_dense_grid_options()
gp.compute_model(model)

# Assert
Expand Down