Skip to content

Commit bdc90fd

Browse files
avoid exception if no crs for grids
1 parent 9f73fb7 commit bdc90fd

3 files changed

Lines changed: 37 additions & 28 deletions

File tree

energyml-utils/example/attic/main_data.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
)
1212
from energyml.utils.data.export import export_obj
1313

14-
from src.energyml.utils.data.helper import (
14+
from energyml.utils.data.helper import (
1515
get_array_reader_function,
1616
read_array,
1717
)
18-
from src.energyml.utils.data.mesh import (
18+
from energyml.utils.data.mesh import (
1919
GeoJsonGeometryType,
2020
MeshFileFormat,
2121
_create_shape,
@@ -24,29 +24,29 @@
2424
export_off,
2525
read_mesh_object,
2626
)
27-
from src.energyml.utils.epc import gen_energyml_object_path
28-
from src.energyml.utils.introspection import (
27+
from energyml.utils.epc import gen_energyml_object_path
28+
from energyml.utils.introspection import (
2929
get_object_attribute,
3030
is_abstract,
3131
get_obj_uuid,
3232
search_attribute_matching_name_with_path,
3333
)
34-
from src.energyml.utils.manager import get_sub_classes
35-
from src.energyml.utils.serialization import (
34+
from energyml.utils.manager import get_sub_classes
35+
from energyml.utils.serialization import (
3636
read_energyml_xml_file,
3737
read_energyml_xml_str,
3838
read_energyml_xml_bytes,
3939
read_energyml_xml_tree,
4040
)
41-
from src.energyml.utils.validation import validate_epc
42-
from src.energyml.utils.xml import get_tree
43-
from src.energyml.utils.data.datasets_io import (
41+
from energyml.utils.validation import validate_epc
42+
from energyml.utils.xml import get_tree
43+
from energyml.utils.data.datasets_io import (
4444
HDF5FileReader,
4545
get_path_in_external_with_path,
4646
get_external_file_path_from_external_path,
4747
)
4848
from energyml.utils.epc import Epc
49-
from src.energyml.utils.data.mesh import (
49+
from energyml.utils.data.mesh import (
5050
read_polyline_representation,
5151
read_point_representation,
5252
read_grid2d_representation,
@@ -165,7 +165,8 @@ def read_h5_polyline():
165165

166166

167167
def read_h5_grid2d_bis():
168-
path = "../rc/obj_Grid2dRepresentation_7c43bad9-4cad-4ab0-bb50-9afb24a4b883.xml"
168+
path = "rc/obj_Grid2dRepresentation_7c43bad9-4cad-4ab0-bb50-9afb24a4b883.xml"
169+
# path = "../rc/obj_Grid2dRepresentation_7c43bad9-4cad-4ab0-bb50-9afb24a4b883.xml"
169170

170171
xml_content = ""
171172
with open(path, "r") as f:
@@ -179,12 +180,12 @@ def read_h5_grid2d_bis():
179180
)
180181
uuid = get_obj_uuid(grid)
181182
print("Exporting")
182-
with open(f"result/grid2d_{uuid}.obj", "wb") as f:
183+
with open(f"rc/result/grid2d_{uuid}.obj", "wb") as f:
183184
export_obj(
184185
mesh_list=grid_list,
185186
out=f,
186187
)
187-
with open(f"result/grid2d_{uuid}_bis.off", "wb") as f:
188+
with open(f"rc/result/grid2d_{uuid}_bis.off", "wb") as f:
188189
export_off(
189190
mesh_list=grid_list,
190191
out=f,
@@ -206,12 +207,12 @@ def read_h5_grid2d_ter():
206207
)
207208
uuid = get_obj_uuid(grid)
208209
print("Exporting")
209-
with open(f"result/grid2d_{uuid}.obj", "wb") as f:
210+
with open(f"rc/result/grid2d_{uuid}.obj", "wb") as f:
210211
export_obj(
211212
mesh_list=grid_list,
212213
out=f,
213214
)
214-
with open(f"result/grid2d_{uuid}_bis.off", "wb") as f:
215+
with open(f"rc/result/grid2d_{uuid}_bis.off", "wb") as f:
215216
export_off(
216217
mesh_list=grid_list,
217218
out=f,
@@ -248,12 +249,12 @@ def read_h5_grid2d():
248249
# keep_holes=False
249250
)
250251
print("Exporting")
251-
with open(f"result/grid2d_{uuid}.obj", "wb") as f:
252+
with open(f"rc/result/grid2d_{uuid}.obj", "wb") as f:
252253
export_obj(
253254
mesh_list=grid_list,
254255
out=f,
255256
)
256-
with open(f"result/grid2d_{uuid}.off", "wb") as f:
257+
with open(f"rc/result/grid2d_{uuid}.off", "wb") as f:
257258
export_off(
258259
mesh_list=grid_list,
259260
out=f,
@@ -272,12 +273,12 @@ def read_meshes():
272273
workspace=epc22,
273274
)
274275
print("Exporting")
275-
with open(f"result/{gen_energyml_object_path(energyml_obj)}.obj", "wb") as f:
276+
with open(f"rc/result/{gen_energyml_object_path(energyml_obj)}.obj", "wb") as f:
276277
export_obj(
277278
mesh_list=mesh_list,
278279
out=f,
279280
)
280-
with open(f"result/{gen_energyml_object_path(energyml_obj)}.off", "wb") as f:
281+
with open(f"rc/result/{gen_energyml_object_path(energyml_obj)}.off", "wb") as f:
281282
export_off(
282283
mesh_list=mesh_list,
283284
out=f,

energyml-utils/src/energyml/utils/data/helper.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,8 @@ def get_crs_obj(
473473
crs = workspace.get_object(get_obj_uri(crs_list[0]))
474474
if crs is None:
475475
# logging.debug(f"CRS {crs_list[0]} not found (or not read correctly)")
476-
crs = workspace.get_object_by_uuid(get_obj_uuid(crs_list[0]))
476+
_crs_list = workspace.get_object_by_uuid(get_obj_uuid(crs_list[0]))
477+
crs = _crs_list[0] if _crs_list is not None and len(_crs_list) > 0 else None
477478
if crs is None:
478479
logging.error(f"CRS {crs_list[0]} not found (or not read correctly)")
479480
raise ObjectNotFoundNotError(get_obj_uri(crs_list[0]))
@@ -883,12 +884,16 @@ def read_external_array(
883884
"""
884885
array = None
885886
if workspace is not None:
886-
crs = get_crs_obj(
887-
context_obj=root_obj,
888-
root_obj=root_obj,
889-
path_in_root=path_in_root,
890-
workspace=workspace,
891-
)
887+
crs = None
888+
try:
889+
get_crs_obj(
890+
context_obj=root_obj,
891+
root_obj=root_obj,
892+
path_in_root=path_in_root,
893+
workspace=workspace,
894+
)
895+
except ObjectNotFoundNotError as e:
896+
logging.debug(f"CRS not found for {get_obj_title(root_obj)}: {e}")
892897

893898
# Search for ExternalDataArrayPart type objects (RESQML v2.2)
894899
external_parts = search_attribute_matching_type(

energyml-utils/src/energyml/utils/data/mesh.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,11 @@ def read_mesh_object(
241241
): # WellboreFrameRep has allready the displacement applied
242242
# TODO: the displacement should be done in each reader function to manage specific cases
243243
for s in surfaces:
244-
logging.debug(f"CRS : {s.crs_object.uuid if s.crs_object is not None else 'None'}")
245-
crs_displacement(s.point_list, s.crs_object)
244+
logging.debug(f"CRS : {s.crs_object}")
245+
crs_displacement(
246+
s.point_list,
247+
s.crs_object[0] if isinstance(s.crs_object, list) and len(s.crs_object) > 0 else s.crs_object,
248+
)
246249
return surfaces
247250
else:
248251
# logging.error(f"Type {array_type_name} is not supported: function read_{snake_case(array_type_name)} not found")

0 commit comments

Comments
 (0)