-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdriver.py
More file actions
77 lines (63 loc) · 2.84 KB
/
driver.py
File metadata and controls
77 lines (63 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
# Copyright (c) 2024-2025 Mira Geoscience Ltd. '
# '
# This file is part of surface-apps package. '
# '
# surface-apps is distributed under the terms and conditions of the MIT License
# (see LICENSE file at the root of this source code package). '
# ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
import logging
import sys
from pathlib import Path
from geoapps_utils.driver.driver import BaseDriver
from geoapps_utils.utils.transformations import (
compute_normals,
)
from geoh5py.groups.property_group_type import GroupTypeEnum
from geoh5py.shared.conversion.base import CellObjectConversion
from geoh5py.shared.merging.points import PointsMerger
from geoh5py.shared.utils import fetch_active_workspace
from surface_apps.surface_normals.options import SurfaceNormalsOptions
logger = logging.getLogger(__name__)
class Driver(BaseDriver):
"""
Driver for computing surface normals.
:param options: Application options
"""
_params_class = SurfaceNormalsOptions
def run(self):
with fetch_active_workspace(self.params.geoh5, mode="r+") as geoh5:
points = []
for surface in self.params.surfaces:
normals = compute_normals(surface)
pts = CellObjectConversion.to_points(
surface, name=f"{surface.name} {self.params.out_name}"
)
pts.add_data(
{
"Nx": {"values": normals[:, 0], "association": "VERTEX"},
"Ny": {"values": normals[:, 1], "association": "VERTEX"},
"Nz": {"values": normals[:, 2], "association": "VERTEX"},
}
)
points.append(pts)
merge_points = self.params.merge_points and len(points) > 1
if merge_points:
points = [
PointsMerger.merge_objects(
geoh5,
points, # type: ignore
add_data=True,
name=f"merged {self.params.out_name}",
)
]
for pts in points:
pts.create_property_group(
properties=[pts.get_data(k)[0] for k in ["Nx", "Ny", "Nz"]],
name="Normals",
property_group_type=GroupTypeEnum.VECTOR,
)
self.update_monitoring_directory(pts)
if __name__ == "__main__":
file = Path(sys.argv[1]).resolve()
driver = Driver.start(file)