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
[WIP] Making topography a data class
  • Loading branch information
Leguark committed May 25, 2025
commit 5bbf54bc10efb26bcd87e0159b272e17d42bf626
59 changes: 27 additions & 32 deletions gempy/core/data/grid_modules/topography.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,44 @@
import dataclasses

import warnings
from typing import Optional
from pydantic import Field
from typing import Optional, Tuple

import numpy as np

from .grid_types import RegularGrid
from ....modules.grids.create_topography import _LoadDEMArtificial

from ....optional_dependencies import require_skimage
from dataclasses import field, dataclass


@dataclass
class Topography:
"""
Object to include topography in the model.

Notes:
This always assumes that the topography we pass fits perfectly the extent

"""
Object to include topography in the model.
Notes:
This always assumes that the topography we pass fits perfectly the extent.
"""

regular_grid: RegularGrid
values_2d: np.ndarray = Field(exclude=True, default_factory=lambda: np.zeros((0, 0, 3)))
source: Optional[str] = None

# Fields managed internally
values: np.ndarray = field(init=False, default_factory=lambda: np.zeros((0, 3)))
resolution: Tuple[int, int] = field(init=False, default=(0, 0))
raster_shape: Tuple[int, ...] = field(init=False, default=())
_mask_topo: Optional[np.ndarray] = field(init=False, default=None, repr=False)
_x: Optional[np.ndarray] = field(init=False, default=None, repr=False)
_y: Optional[np.ndarray] = field(init=False, default=None, repr=False)

def __post_init__(self):
# if a non-empty array was provided, initialize the flattened values
if self.values_2d.size:
self.set_values(self.values_2d)

def __init__(self, regular_grid: RegularGrid, values_2d: Optional[np.ndarray] = None):

self._mask_topo = None
self._regular_grid = regular_grid

# Values (n, 3)
self.values = np.zeros((0, 3))

# Values (n, n, 3)
self.values_2d = np.zeros((0, 0, 3))

# Shape original
self.raster_shape = tuple()

# Topography Resolution
self.resolution = np.zeros((0, 3))

# Source for the
self.source = None

# Coords
self._x = None
self._y = None

if values_2d is not None:
self.set_values(values_2d)

@classmethod
def from_subsurface_structured_data(cls, structured_data: 'subsurface.StructuredData', regular_grid: RegularGrid):
Expand Down
4 changes: 4 additions & 0 deletions test/test_modules/test_grids/test_grids_sections.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ def test_section_grids():
evaluation_options=geo_model.interpolation_options.evaluation_options
)

model = geo_model
model_json = model.model_dump_json(by_alias=True, indent=4)
gp.set_section_grid(
grid=geo_model.grid,
section_dict={
Expand All @@ -28,13 +30,15 @@ def test_section_grids():
}
)

model_json = model.model_dump_json(by_alias=True, indent=4)
gp.set_topography_from_random(
grid=geo_model.grid,
fractal_dimension=1.2,
d_z=np.array([200, 1000]),
topography_resolution=np.array([60, 60])
)

model_json = model.model_dump_json(by_alias=True, indent=4)
gp.compute_model(geo_model)
gpv.plot_2d(
model=geo_model,
Expand Down