Skip to content

Commit

Permalink
add data arrays to geoh5py and gocad
Browse files Browse the repository at this point in the history
  • Loading branch information
lachlangrose committed May 9, 2024
1 parent 547c81b commit 0d0e94f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions LoopStructural/datatypes/_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Surface:
normals: np.ndarray
name: str
values: Optional[np.ndarray] = None
properties: Optional[dict] = None

@property
def triangle_area(self):
Expand Down
12 changes: 10 additions & 2 deletions LoopStructural/export/geoh5.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,18 @@ def add_surface_to_geoh5(filename, surface, overwrite=True, groupname="Loop"):
existing_surf[0].allow_delete = True
if overwrite:
workspace.remove_entity(existing_surf[0])
geoh5py.objects.Surface.create(
data = {}
if surface.properties is not None:
for k, v in surface.properties.items():
data[k] = {'association': "VERTEX", "values": v}
surface = geoh5py.objects.Surface.create(
workspace,
name=surface.name,
vertices=surface.vertices,
triangles=surface.triangles,
cells=surface.triangles,
parent=group,
)
surface.add_data(data)


# def add_points_to_geoh5(filename, points, overwrite=True, groupname="Loop"):
15 changes: 14 additions & 1 deletion LoopStructural/export/gocad.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ def _write_feat_surfs_gocad(surf, file_name):
"""
from pathlib import Path

properties_header = None
if surf.properties:

properties_header = f"""PROPERTIES {' '.join(list(surf.properties.keys()))}
NO_DATA_VALUES -99999
PROPERTY_CLASSES {' '.join(list(surf.properties.keys()))}
"""

file_name = Path(file_name).with_suffix(".ts")
with open(f"{file_name}", "w") as fd:
fd.write(
Expand All @@ -45,6 +53,7 @@ def _write_feat_surfs_gocad(surf, file_name):
END_ORIGINAL_COORDINATE_SYSTEM
GEOLOGICAL_FEATURE {surf.name}
GEOLOGICAL_TYPE fault
{properties_header if properties_header else ""}
PROPERTY_CLASS_HEADER X {{
kind: X
unit: m
Expand All @@ -69,7 +78,11 @@ def _write_feat_surfs_gocad(surf, file_name):
v_map = {}
for idx, vert in enumerate(surf.vertices):
if not np.isnan(vert[0]) and not np.isnan(vert[1]) and not np.isnan(vert[2]):
fd.write(f"VRTX {v_idx:} {vert[0]} {vert[1]} {vert[2]} \n")
fd.write(f"VRTX {v_idx:} {vert[0]} {vert[1]} {vert[2]}")
if surf.properties:
for value in surf.properties.values():
fd.write(f" {value[idx]}")
fd.write("\n")
v_map[idx] = v_idx
v_idx += 1
for face in surf.triangles:
Expand Down

0 comments on commit 0d0e94f

Please sign in to comment.