Skip to content

Commit 50bd141

Browse files
Dev (#9)
* moving part to extras + adding poetry scripts * jsonify validation errors
1 parent 15ada53 commit 50bd141

37 files changed

+65014
-843
lines changed

.github/actions/prepare-poetry/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
---
66

77
name: Prepare Python and Poetry
8-
Description: Install Python, Poetry and dev dependencies, cached for speed
8+
description: Install Python, Poetry and dev dependencies, cached for speed
99

1010
inputs:
1111
python-version:

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# energyml-utils
2+
3+
4+
This project contains multiple projects to use RESQML/WITSML/PRODML with python.
5+
6+
## Supported versions:
7+
8+
- Resqml
9+
- [2.0.1](https://github.com/geosiris-technologies/energyml-python/tree/main/energyml-resqml2-0-1) : **energyml-resqml2-0-1**
10+
- [2.2dev3](https://github.com/geosiris-technologies/energyml-python/tree/main/energyml-resqml2-2-dev3) : **energyml-resqml2-2-dev3**
11+
- [2.2](https://github.com/geosiris-technologies/energyml-python/tree/main/energyml-resqml2-0-1) : **energyml-resqml2-2**
12+
13+
- Witsml
14+
- [2.0](https://github.com/geosiris-technologies/energyml-python/tree/main/energyml-witsml2-0) : **energyml-witsml2-0**
15+
- [2.1](https://github.com/geosiris-technologies/energyml-python/tree/main/energyml-witsml2-1) : **energyml-witsml2-1**
16+
17+
- Prodml
18+
- [2.0](https://github.com/geosiris-technologies/energyml-python/tree/main/energyml-prodml2-0) : **energyml-prodml2-0**
19+
- [2.1](https://github.com/geosiris-technologies/energyml-python/tree/main/energyml-prodml2-2) : **energyml-prodml2-2**
20+
21+
- Common (eml)
22+
- [2.0](https://github.com/geosiris-technologies/energyml-python/tree/main/energyml-common2-0) : **energyml-common2-0**
23+
- [2.1](https://github.com/geosiris-technologies/energyml-python/tree/main/energyml-common2-1) : **energyml-common2-1**
24+
- [2.2](https://github.com/geosiris-technologies/energyml-python/tree/main/energyml-common2-2) : **energyml-common2-2**
25+
- [2.3](https://github.com/geosiris-technologies/energyml-python/tree/main/energyml-common2-3) : **energyml-common2-3**
26+
27+
28+
## Utility package (EPC + h5 support):
29+
30+
To ease the use of the energyml data, we provided a module called **energyml-utils**.
31+
For more information, check the sub project : https://github.com/geosiris-technologies/energyml-python/tree/main/energyml-utils.

energyml-utils/.gitignore

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ dask-worker-space
3333

3434
# Example for local test
3535
example-local/
36+
wip
37+
src/energyml/utils/converter/
3638
# utils/
3739

3840
# Other files
@@ -45,4 +47,10 @@ manip*
4547
*.off
4648
*.obj
4749
*.log
48-
*.geojson
50+
*.geojson
51+
*.json
52+
*.csv
53+
*.zip
54+
55+
*.xml
56+
*.json

energyml-utils/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,12 @@ energyml-prodml2-2 = "^1.12.0"
7676
- The "EnergymlWorkspace" class allows to abstract the access of numerical data like "ExternalArrays". This class can thus be extended to interact with ETP "GetDataArray" request etc...
7777
- ETP URI support : the "Uri" class allows to parse/write an etp uri.
7878

79+
80+
# Poetry scripts :
81+
82+
- extract_3d : extract a representation into an 3D file (obj/off)
83+
- csv_to_dataset : translate csv data into h5 dataset
84+
- generate_data : generate a random data from a qualified_type
85+
- xml_to_json : translate an energyml xml file into json.
86+
- json_to_xml : translate an energyml json file into an xml file
87+
- describe_as_csv : create a csv description of an EPC content

energyml-utils/example/main.py

Lines changed: 29 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
correct_dor,
2828
)
2929
from src.energyml.utils.xml import *
30+
from utils.data.datasets_io import HDF5FileReader
3031

3132
fi_cit = Citation(
3233
title="An interpretation",
@@ -130,11 +131,7 @@ def file_test():
130131
print(find_schema_version_in_element(get_tree(xml_content)))
131132
print(get_class_name_from_xml(get_tree(xml_content)))
132133

133-
print(
134-
get_class_from_name(
135-
"energyml.resqml.v2_2.resqmlv2.TriangulatedSetRepresentation"
136-
)
137-
)
134+
print(get_class_from_name("energyml.resqml.v2_2.resqmlv2.TriangulatedSetRepresentation"))
138135

139136
print(read_energyml_xml_str(xml_content))
140137
print(read_energyml_xml_file(path))
@@ -143,53 +140,27 @@ def file_test():
143140
def tests_content_type():
144141
print(RGX_CONTENT_TYPE)
145142

146-
print(
147-
parse_content_type(
148-
"application/x-resqml+xml;version=2.2;type=TriangulatedSetRepresentation"
149-
)
150-
)
151-
print(
152-
parse_content_type(
153-
"application/vnd.openxmlformats-package.core-properties+xml"
154-
).group("domain")
155-
)
143+
print(parse_content_type("application/x-resqml+xml;version=2.2;type=TriangulatedSetRepresentation"))
144+
print(parse_content_type("application/vnd.openxmlformats-package.core-properties+xml").group("domain"))
156145

157-
print(
158-
get_class_from_content_type(
159-
"application/x-resqml+xml;version=2.2;type=TriangulatedSetRepresentation"
160-
)
161-
)
146+
print(get_class_from_content_type("application/x-resqml+xml;version=2.2;type=TriangulatedSetRepresentation"))
162147
print(
163148
"CT 201 : ",
164-
get_class_from_content_type(
165-
"application/x-resqml+xml;version=2.0;type=obj_HorizonInterpretation"
166-
),
167-
)
168-
print(
169-
parse_content_type(
170-
"application/x-resqml+xml;version=2.0;type=obj_HorizonInterpretation"
171-
)
149+
get_class_from_content_type("application/x-resqml+xml;version=2.0;type=obj_HorizonInterpretation"),
172150
)
151+
print(parse_content_type("application/x-resqml+xml;version=2.0;type=obj_HorizonInterpretation"))
173152

174-
print(
175-
get_class_from_content_type(
176-
"application/vnd.openxmlformats-package.core-properties+xml"
177-
)
178-
)
153+
print(get_class_from_content_type("application/vnd.openxmlformats-package.core-properties+xml"))
179154

180155
print(get_content_type_from_class(tr))
181156
print(get_qualified_type_from_class(tr))
182157
print(
183158
get_qualified_type_from_class(DoubleHdf5Array()),
184-
get_class_from_qualified_type(
185-
get_qualified_type_from_class(DoubleHdf5Array())
186-
),
159+
get_class_from_qualified_type(get_qualified_type_from_class(DoubleHdf5Array())),
187160
)
188161
print(
189162
get_qualified_type_from_class(dor_correct),
190-
get_class_from_qualified_type(
191-
get_qualified_type_from_class(dor_correct)
192-
),
163+
get_class_from_qualified_type(get_qualified_type_from_class(dor_correct)),
193164
)
194165

195166
print(gen_energyml_object_path(tr, EpcExportVersion.EXPANDED))
@@ -204,17 +175,11 @@ def tests_epc():
204175
print(epc)
205176
epc.export_file("D:/Geosiris/Github/energyml/energyml-python/test.epc")
206177
epc.export_version = EpcExportVersion.EXPANDED
207-
epc.export_file(
208-
"D:/Geosiris/Github/energyml/energyml-python/test_EXPANDED.epc"
209-
)
178+
epc.export_file("D:/Geosiris/Github/energyml/energyml-python/test_EXPANDED.epc")
210179
epc.core_props = None
211-
epc.export_file(
212-
"D:/Geosiris/Github/energyml/energyml-python/test_no_core.epc"
213-
)
180+
epc.export_file("D:/Geosiris/Github/energyml/energyml-python/test_no_core.epc")
214181

215-
epc201 = Epc.read_file(
216-
"D:/Geosiris/OSDU/manifestTranslation/#Data/VOLVE_STRUCT.epc"
217-
)
182+
epc201 = Epc.read_file("D:/Geosiris/OSDU/manifestTranslation/#Data/VOLVE_STRUCT.epc")
218183
print(epc201)
219184

220185
print(f"NB errors {len(validate_epc(epc201))}")
@@ -239,10 +204,7 @@ def tests_dor():
239204

240205
print(
241206
json.dumps(
242-
{
243-
k: [get_obj_uuid(x) for x in v]
244-
for k, v in get_reverse_dor_list(epc.energyml_objects).items()
245-
},
207+
{k: [get_obj_uuid(x) for x in v] for k, v in get_reverse_dor_list(epc.energyml_objects).items()},
246208
indent=4,
247209
)
248210
)
@@ -301,16 +263,8 @@ def test_introspection():
301263
print(search_attribute_matching_type(tr, "Citation"))
302264
print(search_attribute_matching_type(tr, "DataObjectreference"))
303265
print(search_attribute_matching_type_with_path(tr, "DataObjectreference"))
304-
print(
305-
class_match_rgx(
306-
ContactElement, "DataObjectreference", super_class_search=False
307-
)
308-
)
309-
print(
310-
class_match_rgx(
311-
ContactElement, "DataObjectreference", super_class_search=True
312-
)
313-
)
266+
print(class_match_rgx(ContactElement, "DataObjectreference", super_class_search=False))
267+
print(class_match_rgx(ContactElement, "DataObjectreference", super_class_search=True))
314268
print(Enum in ExistenceKind.__bases__)
315269
print(Enum in TriangulatedSetRepresentation.__bases__)
316270
print(is_primitive(int))
@@ -331,9 +285,7 @@ def test_introspection():
331285
print(TriangulatedSetRepresentation.__dataclass_params__)
332286

333287
# print(random_value_from_class(int))
334-
print(
335-
serialize_xml(random_value_from_class(TriangulatedSetRepresentation))
336-
)
288+
print(serialize_xml(random_value_from_class(TriangulatedSetRepresentation)))
337289
# print(serialize_json(random_value_from_class(TriangulatedSetRepresentation)))
338290

339291
print(search_attribute_matching_name_with_path(tr, "[tT]it.*"))
@@ -342,13 +294,7 @@ def test_introspection():
342294
print(AbstractPoint3DArray.__dict__)
343295
print(TriangulatedSetRepresentation.__dict__)
344296
print(get_sub_classes(AbstractObject))
345-
print(
346-
list(
347-
filter(
348-
lambda _c: not is_abstract(_c), get_sub_classes(AbstractObject)
349-
)
350-
)
351-
)
297+
print(list(filter(lambda _c: not is_abstract(_c), get_sub_classes(AbstractObject))))
352298
print(AbstractColorMap.__name__.startswith("Abstract"))
353299
print(is_abstract(AbstractColorMap))
354300

@@ -366,17 +312,13 @@ def test_introspection():
366312

367313
print(f"object: {is_abstract(object)}")
368314
print(f"HDF5FileReader: {is_abstract(HDF5FileReader)}")
369-
print(
370-
f"TriangulatedSetRepresentation: {is_abstract(TriangulatedSetRepresentation)}"
371-
)
315+
print(f"TriangulatedSetRepresentation: {is_abstract(TriangulatedSetRepresentation)}")
372316

373317
# print("HDF5FileReader")
374318
# for func in dir(HDF5FileReader):
375319
# if callable(getattr(HDF5FileReader, func)) and not func.startswith("__"):
376320
# print(f"\t{func} {type(getattr(HDF5FileReader, func))}")
377-
print(
378-
get_classes_matching_name(TriangulatedSetRepresentation, "Abstract.*")
379-
)
321+
print(get_classes_matching_name(TriangulatedSetRepresentation, "Abstract.*"))
380322
# print(get_matching_class_attribute_name(ExternalDataArrayPart, "(PathInHdfFile|PathInExternalFile)"))
381323
# print(object.__module__)
382324
# print(serialize_xml(random_value_from_class(PointSetRepresentation)))
@@ -390,21 +332,15 @@ def test_introspection():
390332
# print(serialize_xml(poly))
391333

392334
print("=====] ", r"ClosedPolylines.\d+")
393-
for array_path, array_value in search_attribute_matching_name_with_path(
394-
poly, r"ClosedPolylines.\d+"
395-
):
335+
for array_path, array_value in search_attribute_matching_name_with_path(poly, r"ClosedPolylines.\d+"):
396336
print(f"{array_path}\n\t{array_value}")
397337

398338
print("=====] ", r"ClosedPolylines.values.\d+")
399-
for array_path, array_value in search_attribute_matching_name_with_path(
400-
poly, r"ClosedPolylines.values.\d+"
401-
):
339+
for array_path, array_value in search_attribute_matching_name_with_path(poly, r"ClosedPolylines.values.\d+"):
402340
print(f"{array_path}\n\t{array_value}")
403341

404342
print("=====] ", r"LinePatch.\d+")
405-
for array_path, array_value in search_attribute_matching_name_with_path(
406-
poly, r"LinePatch.\d+"
407-
):
343+
for array_path, array_value in search_attribute_matching_name_with_path(poly, r"LinePatch.\d+"):
408344
print(f"{array_path}\n\t{array_value}")
409345

410346

@@ -424,17 +360,15 @@ def tests_hdf():
424360

425361
for o in tr_list:
426362
print(o.__class__)
427-
print(get_hdf_reference_with_path(o))
363+
print(get_path_in_external_with_path(o))
428364
exit(0)
429365

430366

431367
def test_local_depth_crs():
432368
# Fails because the xsi:type="VerticalCrsEpsgCode" doesn't
433369
# contain the namespace : xsi:type="eml:VerticalCrsEpsgCode"
434370
try:
435-
depth3d = read_energyml_xml_file(
436-
"../rc/obj_LocalDepth3dCrs_716f6472-18a3-4f19-a57c-d4f5642ccc53.xml"
437-
)
371+
depth3d = read_energyml_xml_file("../rc/obj_LocalDepth3dCrs_716f6472-18a3-4f19-a57c-d4f5642ccc53.xml")
438372
print(serialize_json(depth3d, JSON_VERSION.XSDATA))
439373
print(serialize_xml(depth3d))
440374
except Exception as e:
@@ -445,9 +379,7 @@ def test_get_projected_uom():
445379
# Fails because the xsi:type="VerticalCrsEpsgCode" doesn't
446380
# contain the namespace : xsi:type="eml:VerticalCrsEpsgCode"
447381
try:
448-
depth3d = read_energyml_xml_file(
449-
"../rc/obj_LocalDepth3dCrs_716f6472-18a3-4f19-a57c-d4f5642ccc53.xml"
450-
)
382+
depth3d = read_energyml_xml_file("../rc/obj_LocalDepth3dCrs_716f6472-18a3-4f19-a57c-d4f5642ccc53.xml")
451383
print(get_projected_uom(depth3d).value)
452384
except Exception as e:
453385
print(e)
@@ -502,28 +434,18 @@ def class_field():
502434
print(get_class_fields(tr)["citation"])
503435
print(get_class_pkg_version(tr))
504436
print(create_energyml_object("resqml22.TriangulatedSetRepresentation"))
505-
ext_20 = create_energyml_object(
506-
"application/x-eml+xml;version=2.0;type=obj_EpcExternalPartReference"
507-
)
437+
ext_20 = create_energyml_object("application/x-eml+xml;version=2.0;type=obj_EpcExternalPartReference")
508438
print(ext_20)
509439
print(gen_energyml_object_path(ext_20))
510440
print(create_external_part_reference("2.0", "my_h5"))
511441

512-
print(
513-
parse_content_or_qualified_type(
514-
"application/x-eml+xml;version=2.0;type=obj_EpcExternalPartReference"
515-
)
516-
)
442+
print(parse_content_or_qualified_type("application/x-eml+xml;version=2.0;type=obj_EpcExternalPartReference"))
517443
print(
518444
get_domain_version_from_content_or_qualified_type(
519445
"application/x-eml+xml;version=2.0;type=obj_EpcExternalPartReference"
520446
)
521447
)
522-
print(
523-
get_domain_version_from_content_or_qualified_type(
524-
"resqml20.obj_EpcExternalPartReference"
525-
)
526-
)
448+
print(get_domain_version_from_content_or_qualified_type("resqml20.obj_EpcExternalPartReference"))
527449

528450
# print(create_external_part_reference("2.2", "myfile.h5"))
529451
# print(create_external_part_reference("2.0", "myfile.h5"))

energyml-utils/example/main201.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ def import_modules():
99
# import energyml.opc.opc
1010
# import energyml.resqml.v2_0_1.resqmlv2
1111
# import_modules()
12-
epc201 = Epc.read_file(
13-
"D:/Geosiris/OSDU/manifestTranslation/#Data/VOLVE_STRUCT.epc"
14-
)
12+
epc201 = Epc.read_file("D:/Geosiris/OSDU/manifestTranslation/#Data/VOLVE_STRUCT.epc")
1513
print(epc201)
1614

1715

0 commit comments

Comments
 (0)