Skip to content

Commit 3387aac

Browse files
--
1 parent 32dd3e9 commit 3387aac

7 files changed

Lines changed: 1252 additions & 3681 deletions

File tree

energyml-utils/example/main_stream_sample.py

Lines changed: 77 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,27 @@
22
import sys
33
import logging
44
from energyml.utils.epc_stream import EpcStreamReader, RelsUpdateMode
5-
from energyml.eml.v2_3.commonv2 import Citation
5+
from energyml.eml.v2_3.commonv2 import Citation, ExternalDataArrayPart,
66
from energyml.resqml.v2_2.resqmlv2 import (
77
TriangulatedSetRepresentation,
88
BoundaryFeatureInterpretation,
99
BoundaryFeature,
1010
HorizonInterpretation,
11+
TrianglePatch,
12+
IntegerExternalArray,
13+
ExternalDataArray,
14+
PointGeometry,
15+
Point3DExternalArray,
1116
)
1217
from energyml.utils.introspection import epoch_to_date, epoch
1318
from energyml.utils.epc import as_dor, gen_uuid, get_obj_identifier
14-
from energyml.utils.constants import EPCRelsRelationshipType
19+
from energyml.utils.constants import EPCRelsRelationshipType, MimeType
20+
21+
from energyml.opc.opc import Relationship
22+
23+
24+
CONST_H5_PATH = "wip/external_data.h5"
25+
CONST_CSV_PATH = "wip/external_data.csv"
1526

1627

1728
def sample_objects():
@@ -53,6 +64,7 @@ def sample_objects():
5364
)
5465

5566
# Create a TriangulatedSetRepresentation
67+
trset_uuid = "25773477-ffee-4cc2-867d-000000000004"
5668
trset = TriangulatedSetRepresentation(
5769
citation=Citation(
5870
title="Test TriangulatedSetRepresentation",
@@ -62,6 +74,37 @@ def sample_objects():
6274
uuid="25773477-ffee-4cc2-867d-000000000004",
6375
object_version="1.0",
6476
represented_object=as_dor(horizon_interp),
77+
triangle_patch=[
78+
TrianglePatch(
79+
node_count=3,
80+
triangles=IntegerExternalArray(
81+
values=ExternalDataArray(
82+
external_data_array_part=[
83+
ExternalDataArrayPart(
84+
count=[6],
85+
path_in_external_file=f"/RESQML/{trset_uuid}/triangles",
86+
uri=CONST_H5_PATH,
87+
mime_type=str(MimeType.HDF5),
88+
)
89+
]
90+
)
91+
),
92+
geometry=PointGeometry(
93+
points=Point3DExternalArray(
94+
coordinates=ExternalDataArray(
95+
external_data_array_part=[
96+
ExternalDataArrayPart(
97+
count=[9],
98+
path_in_external_file=f"/RESQML/{trset_uuid}/points",
99+
uri=CONST_CSV_PATH,
100+
mime_type=str(MimeType.CSV),
101+
)
102+
]
103+
)
104+
),
105+
),
106+
)
107+
],
65108
)
66109

67110
return {
@@ -183,10 +226,41 @@ def test_create_epc_v2(path: str):
183226
logging.info(f"Horizon interpretation rels: {hi_rels}")
184227

185228

229+
def test_create_epc_v3_with_different_external_files(path: str):
230+
231+
if os.path.exists(path):
232+
os.remove(path)
233+
logging.info(f"==> Creating new EPC at {path}...")
234+
epc = EpcStreamReader(epc_file_path=path, rels_update_mode=RelsUpdateMode.UPDATE_AT_MODIFICATION)
235+
236+
data = sample_objects()
237+
238+
epc.add_object(data["bf"])
239+
# epc.add_object(data["bfi"])
240+
epc.add_object(data["horizon_interp"])
241+
tr_set_id = epc.add_object(data["trset"])
242+
243+
hi_rels = epc.get_obj_rels(data["horizon_interp"])
244+
245+
logging.info(f"Horizon interpretation rels: {hi_rels}")
246+
247+
# Create an h5 file
248+
h5_file_path = "wip/notARealFile.h5"
249+
epc.add_rels_for_object(
250+
tr_set_id,
251+
relationships=[Relationship(type_value=str(EPCRelsRelationshipType.EXTERNAL_RESOURCE), target=h5_file_path)],
252+
)
253+
254+
epc.write_array()
255+
256+
# Create an
257+
258+
186259
if __name__ == "__main__":
187260
logging.basicConfig(level=logging.DEBUG)
188261

189262
# main((sys.argv[1] if len(sys.argv) > 1 else None) or "wip/80wells_surf.epc")
190263

191264
# test_create_epc("wip/test_create.epc")
192-
test_create_epc_v2("wip/test_create.epc")
265+
# test_create_epc_v2("wip/test_create.epc")
266+
test_create_epc_v3_with_different_external_files("wip/test_create_v3.epc")

0 commit comments

Comments
 (0)