Skip to content

Commit 501f04e

Browse files
committed
[TEST] Fixed grid test
1 parent 7cb90c3 commit 501f04e

File tree

4 files changed

+49
-14
lines changed

4 files changed

+49
-14
lines changed

gempy/core/data/core_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55

66
def calculate_line_coordinates_2points(p1, p2, res):
7-
if isinstance(p1, list):
7+
if isinstance(p1, list) or isinstance(p1, tuple):
88
p1 = np.array(p1)
9-
if isinstance(p2, list):
9+
if isinstance(p2, list) or isinstance(p2, tuple):
1010
p2 = np.array(p2)
1111
v = p2 - p1 # vector pointing from p1 to p2
1212
u = v / np.linalg.norm(v) # normalize it

gempy/core/data/grid_modules/topography.py

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Topography:
2929

3030
# Fields managed internally
3131
values: short_array_type = field(init=False, default=np.zeros((0, 3)))
32-
resolution: Tuple[int, int] = field(init=False, default=(0, 0))
32+
resolution: Tuple[int, int] = Field(init=True, default=(0, 0))
3333
raster_shape: Tuple[int, ...] = field(init=False, default=())
3434
_mask_topo: Optional[np.ndarray] = field(init=False, default=None, repr=False)
3535
_x: Optional[np.ndarray] = field(init=False, default=None, repr=False)
@@ -95,7 +95,7 @@ def from_unstructured_mesh(cls, regular_grid, xyz_vertices):
9595
# Reshape the grid for compatibility with existing structure
9696
values_2d = np.stack((x_regular, y_regular, z_regular), axis=-1)
9797

98-
return cls(regular_grid=regular_grid, values_2d=values_2d)
98+
return cls(_regular_grid=regular_grid, values_2d=values_2d)
9999

100100

101101
@classmethod
@@ -107,7 +107,7 @@ def from_arrays(cls, regular_grid, x_coordinates, y_coordinates, height_values,)
107107
topography_vals = height_values.values[:, :, np.newaxis] # shape (73, 34, 1)
108108
# Stack along the last dimension
109109
result = np.concatenate([x_vals, y_vals, topography_vals], axis=2) # shape (73, 34, 3)
110-
return cls(regular_grid=regular_grid, values_2d=result)
110+
return cls(_regular_grid=regular_grid, values_2d=result)
111111

112112
@property
113113
def extent(self):
@@ -154,9 +154,34 @@ def set_values(self, values_2d: np.ndarray):
154154
# n,3 array
155155
self.values = values_2d.reshape((-1, 3), order='C')
156156
return self
157-
158-
def set_values2d(self, values: np.ndarray):
159-
self.values_2d = values.reshape(self.resolution)
157+
158+
def set_values2d(self, values: np.ndarray) -> "Topography":
159+
"""
160+
Reconstruct the 2D topography (shape = resolution + [3]) from
161+
a flat Nx3 array (or from self.values if none is provided).
162+
"""
163+
# default to the already-flattened XYZ array
164+
165+
# compute expected size
166+
nx, ny = self.resolution
167+
expected = nx * ny * 3
168+
if values.size != expected:
169+
raise ValueError(
170+
f"Cannot reshape array of size {values.size} into shape {(nx, ny, 3)}."
171+
)
172+
173+
# reshape in C-order to (nx, ny, 3)
174+
self.set_values(
175+
values_2d=values.reshape(nx, ny, 3, order="C")
176+
)
177+
178+
# invalidate any cached mask
179+
self._mask_topo = None
180+
return self
181+
182+
def set_values2d_(self, values: np.ndarray):
183+
resolution = (60, 60)
184+
self.values_2d = values.reshape(*resolution, 3)
160185

161186
@property
162187
def topography_mask(self):

test/test_modules/test_grids/test_grids_sections.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ def test_section_grids():
2424
gp.set_section_grid(
2525
grid=geo_model.grid,
2626
section_dict={
27-
'section_SW-NE': ([250, 250], [1750, 1750], [100, 100]),
28-
'section_NW-SE': ([250, 1750], [1750, 250], [100, 100])
27+
'section_SW-NE': ((250., 250.), (1750., 1750.), (100, 100)),
28+
'section_NW-SE': ((250., 1750.), (1750., 250.), (100, 100))
2929
}
3030
)
3131

@@ -41,7 +41,8 @@ def test_section_grids():
4141
verify_moment="after",
4242
file_name=f"verify/{geo_model.meta.name}"
4343
)
44-
gp.compute_model(geo_model, validate_serialization=False)
44+
45+
gp.compute_model(geo_model, validate_serialization=True)
4546
gpv.plot_2d(
4647
model=geo_model,
4748
section_names=['section_SW-NE', 'section_NW-SE', 'topography'],

test/test_modules/test_grids/test_grids_sections.test_section_grids.verify/fold.approved.txt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,11 @@
6161
],
6262
"is_dirty": true,
6363
"basement_color": "#ffbe00",
64+
"_input_binary_size": 233,
6465
"binary_meta_data": {
65-
"sp_binary_length": 1296
66+
"sp_binary_length": 1296,
67+
"ori_binary_length": 120,
68+
"input_binary_size": 233
6669
}
6770
},
6871
"grid": {
@@ -104,8 +107,8 @@
104107
"source": null,
105108
"values": [],
106109
"resolution": [
107-
0,
108-
0
110+
60,
111+
60
109112
],
110113
"raster_shape": [],
111114
"_mask_topo": null,
@@ -151,6 +154,12 @@
151154
"_centered_grid": null,
152155
"_transform": null,
153156
"_octree_levels": -1,
157+
"_grid_binary_size": 37758,
158+
"binary_meta_data": {
159+
"custom_grid_binary_length": 0,
160+
"topography_binary_length": 86400,
161+
"grid_binary_size": 37758
162+
},
154163
"active_grids": 1049
155164
},
156165
"geophysics_input": null,

0 commit comments

Comments
 (0)