Skip to content

Commit 55e5c4b

Browse files
authored
Merge pull request #91 from MiraGeoscience/GEOPY-2588
GEOPY-2588: Add strike angle to output metrics
2 parents ebfd9f8 + 8fd6d72 commit 55e5c4b

5 files changed

Lines changed: 42 additions & 10 deletions

File tree

curve_apps/edges/driver.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
from curve_apps.driver import BaseCurveDriver
3232
from curve_apps.edges.options import EdgeDetectionParameters, EdgeParameters
33+
from curve_apps.utils import orientation_from_segments
3334

3435

3536
logger = logging.getLogger(__name__)
@@ -83,14 +84,7 @@ def make_curve(self):
8384
)
8485

8586
# Compute positive angle from North
86-
# TODO: Move to geoapps-utils
87-
delta = np.c_[
88-
vertices[cells[:, 1], 0] - vertices[cells[:, 0], 0],
89-
vertices[cells[:, 1], 1] - vertices[cells[:, 0], 1],
90-
]
91-
delta[delta[:, 0] < 0, :] *= -1
92-
amp = np.linalg.norm(delta, axis=1)
93-
orientation = np.arccos(delta[:, 1] / amp)
87+
length, orientation = orientation_from_segments(vertices, cells)
9488

9589
# TODO: Assign values to vertices until better handling of cell data by GA
9690
vert_azimuth = np.zeros(curve.n_vertices) * np.nan
@@ -102,7 +96,7 @@ def make_curve(self):
10296
)
10397

10498
vert_lengths = np.zeros(curve.n_vertices) * np.nan
105-
vert_lengths[cells.flatten()] = np.repeat(amp, 2)
99+
vert_lengths[cells.flatten()] = np.repeat(length, 2)
106100
curve.add_data(
107101
{
108102
"lengths": {"values": vert_lengths},

curve_apps/peak_finder/driver.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ def run(self): # pylint: disable=too-many-locals, too-many-branches, too-many-s
401401
out_trend = driver.make_curve()
402402

403403
if out_trend is not None:
404+
out_trend.parent = out_group
404405
driver.add_ui_json(out_trend)
405406

406407
except QhullError as e:

curve_apps/trend_lines/driver.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
from curve_apps.driver import BaseCurveDriver
2424
from curve_apps.trend_lines.options import TrendLineParameters
25-
from curve_apps.utils import find_curves
25+
from curve_apps.utils import find_curves, orientation_from_segments
2626

2727

2828
logger = logging.getLogger(__name__)
@@ -60,6 +60,16 @@ def make_curve(self):
6060
)
6161

6262
if curve is not None and self.params.source.data is not None:
63+
_, orientation = orientation_from_segments(curve.vertices, curve.cells)
64+
curve.add_data(
65+
{
66+
"azimuth": {
67+
"values": np.degrees(orientation),
68+
"association": "CELL",
69+
},
70+
}
71+
)
72+
6373
curve.add_data(
6474
{
6575
self.params.source.data.name: {

curve_apps/utils.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,3 +302,25 @@ def filter_segments_orientation(
302302
np.abs(angles) < np.deg2rad(azimuth_tol),
303303
np.abs(angles - np.pi) < np.deg2rad(azimuth_tol),
304304
)
305+
306+
307+
def orientation_from_segments(
308+
vertices: np.ndarray, cells: np.ndarray
309+
) -> tuple[np.ndarray, np.ndarray]:
310+
"""
311+
Compute orientation vectors from segments.
312+
313+
:param vertices: Segment vertices.
314+
:param cells: Segment connectivity.
315+
316+
:return: Lengths and orientations of segments.
317+
"""
318+
delta = np.c_[
319+
vertices[cells[:, 1], 0] - vertices[cells[:, 0], 0],
320+
vertices[cells[:, 1], 1] - vertices[cells[:, 0], 1],
321+
]
322+
delta[delta[:, 0] < 0, :] *= -1
323+
length = np.linalg.norm(delta, axis=1)
324+
orientation = np.arccos(delta[:, 1] / length)
325+
326+
return length, orientation

tests/trend_line_run_test.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ def test_driver_points(tmp_path: Path):
136136
4: "D",
137137
}
138138

139+
orientations = edges.get_data("azimuth")[0]
140+
assert orientations is not None
141+
assert len(orientations.values) == 27
142+
np.testing.assert_almost_equal(np.median(orientations.values), 35.0, decimal=1)
143+
139144

140145
def test_driver_points_no_parts(tmp_path: Path):
141146
workspace = Workspace.create(tmp_path / "test_trend_lines.geoh5")

0 commit comments

Comments
 (0)