|
| 1 | +import dataclasses |
| 2 | + |
1 | 3 | import warnings
|
2 |
| -from typing import Optional |
| 4 | +from pydantic import Field |
| 5 | +from typing import Optional, Tuple |
3 | 6 |
|
4 | 7 | import numpy as np
|
5 | 8 |
|
6 | 9 | from .grid_types import RegularGrid
|
7 | 10 | from ....modules.grids.create_topography import _LoadDEMArtificial
|
8 | 11 |
|
9 | 12 | from ....optional_dependencies import require_skimage
|
| 13 | +from dataclasses import field, dataclass |
10 | 14 |
|
11 | 15 |
|
| 16 | +@dataclass |
12 | 17 | class Topography:
|
13 |
| - """ |
14 |
| - Object to include topography in the model. |
15 |
| -
|
16 |
| - Notes: |
17 |
| - This always assumes that the topography we pass fits perfectly the extent |
18 | 18 |
|
19 | 19 | """
|
| 20 | + Object to include topography in the model. |
| 21 | + Notes: |
| 22 | + This always assumes that the topography we pass fits perfectly the extent. |
| 23 | + """ |
| 24 | + |
| 25 | + regular_grid: RegularGrid |
| 26 | + values_2d: np.ndarray = Field(exclude=True, default_factory=lambda: np.zeros((0, 0, 3))) |
| 27 | + source: Optional[str] = None |
| 28 | + |
| 29 | + # Fields managed internally |
| 30 | + values: np.ndarray = field(init=False, default_factory=lambda: np.zeros((0, 3))) |
| 31 | + resolution: Tuple[int, int] = field(init=False, default=(0, 0)) |
| 32 | + raster_shape: Tuple[int, ...] = field(init=False, default=()) |
| 33 | + _mask_topo: Optional[np.ndarray] = field(init=False, default=None, repr=False) |
| 34 | + _x: Optional[np.ndarray] = field(init=False, default=None, repr=False) |
| 35 | + _y: Optional[np.ndarray] = field(init=False, default=None, repr=False) |
| 36 | + |
| 37 | + def __post_init__(self): |
| 38 | + # if a non-empty array was provided, initialize the flattened values |
| 39 | + if self.values_2d.size: |
| 40 | + self.set_values(self.values_2d) |
20 | 41 |
|
21 |
| - def __init__(self, regular_grid: RegularGrid, values_2d: Optional[np.ndarray] = None): |
22 |
| - |
23 |
| - self._mask_topo = None |
24 |
| - self._regular_grid = regular_grid |
25 |
| - |
26 |
| - # Values (n, 3) |
27 |
| - self.values = np.zeros((0, 3)) |
28 |
| - |
29 |
| - # Values (n, n, 3) |
30 |
| - self.values_2d = np.zeros((0, 0, 3)) |
31 |
| - |
32 |
| - # Shape original |
33 |
| - self.raster_shape = tuple() |
34 |
| - |
35 |
| - # Topography Resolution |
36 |
| - self.resolution = np.zeros((0, 3)) |
37 |
| - |
38 |
| - # Source for the |
39 |
| - self.source = None |
40 |
| - |
41 |
| - # Coords |
42 |
| - self._x = None |
43 |
| - self._y = None |
44 |
| - |
45 |
| - if values_2d is not None: |
46 |
| - self.set_values(values_2d) |
47 | 42 |
|
48 | 43 | @classmethod
|
49 | 44 | def from_subsurface_structured_data(cls, structured_data: 'subsurface.StructuredData', regular_grid: RegularGrid):
|
|
0 commit comments