Skip to content

Commit d0d3ced

Browse files
authored
Merge pull request #144 from MiraGeoscience/GEOPY-1302
GEOPY-1302: Organize geoapps.utils.testing.setup_inversion_workspace
2 parents 1dbe97d + e62f330 commit d0d3ced

2 files changed

Lines changed: 58 additions & 2 deletions

File tree

geoapps_utils/utils/locations.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,46 @@
1515
import numpy as np
1616
from geoh5py import Workspace
1717
from geoh5py.data import Data
18-
from geoh5py.objects import Grid2D, Points
18+
from geoh5py.objects import CellObject, Grid2D, Points
1919
from geoh5py.objects.grid_object import GridObject
2020
from scipy.interpolate import LinearNDInterpolator
2121
from scipy.spatial import Delaunay, cKDTree
2222

2323

24+
def gaussian(
25+
x: np.ndarray, y: np.ndarray, amplitude: float, width: float
26+
) -> np.ndarray:
27+
"""
28+
Gaussian function for 2D data.
29+
30+
:param x: X-coordinates.
31+
:param y: Y-coordinates.
32+
:param amplitude: Amplitude of the Gaussian.
33+
:param width: Width parameter of the Gaussian.
34+
"""
35+
36+
return amplitude * np.exp(-0.5 * ((x / width) ** 2.0 + (y / width) ** 2.0))
37+
38+
39+
def mask_large_connections(cell_object: CellObject, distance_threshold: float):
40+
"""
41+
Trim connections in cell based objects.
42+
43+
:param cell_object: Cell object containing segments with small vertex spacing
44+
along-line, but large spacing between segments.
45+
46+
:return: Cleaned object without cells exceeding the distance threshold.
47+
"""
48+
49+
dist = np.linalg.norm(
50+
cell_object.vertices[cell_object.cells[:, 0], :]
51+
- cell_object.vertices[cell_object.cells[:, 1], :],
52+
axis=1,
53+
)
54+
55+
return np.where(dist > distance_threshold)[0]
56+
57+
2458
def mask_under_horizon(locations: np.ndarray, horizon: np.ndarray) -> np.ndarray:
2559
"""
2660
Mask locations under a horizon.

tests/locations_test.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,39 @@
1212

1313
import numpy as np
1414
from geoh5py import Workspace
15-
from geoh5py.objects import Grid2D, Points
15+
from geoh5py.objects import Curve, Grid2D, Points
1616

1717
from geoapps_utils.utils.locations import (
18+
gaussian,
1819
get_locations,
1920
get_overlapping_limits,
2021
map_indices_to_coordinates,
22+
mask_large_connections,
2123
mask_under_horizon,
2224
)
2325
from geoapps_utils.utils.transformations import rotate_points, z_rotation_matrix
2426

2527

28+
def test_gaussian():
29+
x = np.linspace(-10, 10, 100)
30+
y = np.linspace(-10, 10, 100)
31+
x_grid, y_grid = np.meshgrid(x, y)
32+
z_grid = gaussian(x_grid, y_grid, 10, 5)
33+
assert np.isclose(z_grid.max(), 10, rtol=1e-3)
34+
35+
36+
def test_mask_large_connections(tmp_path):
37+
with Workspace(tmp_path / "test.geoh5") as ws:
38+
x = np.linspace(0, 100, 11)
39+
y = np.linspace(0, 300, 4)
40+
x_grid, y_grid = np.meshgrid(x, y)
41+
z_grid = np.zeros_like(x_grid)
42+
vertices = np.column_stack([x_grid.ravel(), y_grid.ravel(), z_grid.ravel()])
43+
crv = Curve.create(ws, name="test_curve", vertices=vertices)
44+
mask = mask_large_connections(crv, distance_threshold=50.0)
45+
assert len(mask) == 3
46+
47+
2648
def test_rotate_points():
2749
points = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1], [2, 3, 4]])
2850
validation = rotate_points(

0 commit comments

Comments
 (0)