Skip to content

Commit

Permalink
logging
Browse files Browse the repository at this point in the history
  • Loading branch information
valentin-gauthier-geosiris committed Jun 14, 2024
1 parent 8efdc32 commit 223bbd0
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 103 deletions.
24 changes: 12 additions & 12 deletions energyml-utils/example/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,17 +465,17 @@ def test_obj_attribs():


if __name__ == "__main__":
# tests_0()
# tests_content_type()
#
# tests_epc()
# tests_dor()
# test_verif()
# test_ast()
# test_introspection()
#
# tests_hdf()
# test_local_depth_crs()
tests_0()
tests_content_type()

tests_epc()
tests_dor()
test_verif()
test_ast()
test_introspection()

tests_hdf()
test_local_depth_crs()
test_wellbore_marker_frame_representation()

# test_obj_attribs()
test_obj_attribs()
7 changes: 4 additions & 3 deletions energyml-utils/src/energyml/utils/data/hdf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) 2023-2024 Geosiris.
# SPDX-License-Identifier: Apache-2.0
import logging
import os
from dataclasses import dataclass
from io import BytesIO
Expand Down Expand Up @@ -167,13 +168,13 @@ def get_hdf5_path_from_external_path(
# resqml 2.0.1
if hdf_proxy_lst is not None and len(hdf_proxy_lst) > 0:
hdf_proxy = hdf_proxy_lst
# print("h5Proxy", hdf_proxy)
# logging.debug("h5Proxy", hdf_proxy)
while isinstance(hdf_proxy, list):
hdf_proxy = hdf_proxy[0]
hdf_proxy_obj = epc.get_object_by_identifier(
get_obj_identifier(hdf_proxy)
)
print("hdf_proxy_obj : ", hdf_proxy_obj, " hdf_proxy : ", hdf_proxy)
logging.debug("hdf_proxy_obj : ", hdf_proxy_obj, " hdf_proxy : ", hdf_proxy)
if hdf_proxy_obj is not None:
for rel in epc.additional_rels.get(
get_obj_identifier(hdf_proxy_obj), []
Expand Down Expand Up @@ -214,7 +215,7 @@ def get_hdf5_path_from_external_path(
if len(result) == 0:
result = [epc.epc_file_path[:-4] + ".h5"]

print(
logging.debug(
external_path_obj,
result,
"\n\t",
Expand Down
26 changes: 13 additions & 13 deletions energyml-utils/src/energyml/utils/data/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def read_external_array(
try:
return h5_reader.read_array(h5_io, path_in_external)
except Exception as e:
print(traceback.format_exc())
logging.error(traceback.format_exc())
pass
return self.read_external_array(
energyml_array=energyml_array,
Expand Down Expand Up @@ -218,7 +218,7 @@ def read_external_array(
f"Failed to read h5 file. Paths tried : {hdf5_paths}"
)

# print(f"\tpath_in_root : {path_in_root}")
# logging.debug(f"\tpath_in_root : {path_in_root}")
# if path_in_root.lower().endswith("points") and len(result_array) > 0 and len(result_array[0]) == 3:
# crs = None
# try:
Expand All @@ -230,7 +230,7 @@ def read_external_array(
# )
# except ObjectNotFoundNotError as e:
# logging.error("No CRS found, not able to check zIncreasingDownward")
# print(f"\tzincreasing_downward : {zincreasing_downward}")
# logging.debug(f"\tzincreasing_downward : {zincreasing_downward}")
# zincreasing_downward = is_z_reversed(crs)

# if zincreasing_downward:
Expand All @@ -254,13 +254,13 @@ def get_crs_obj(
:return:
"""
if workspace is None:
print("@get_crs_obj no Epc file given")
logging.error("@get_crs_obj no Epc file given")
else:
crs_list = search_attribute_matching_name(
context_obj, r"\.*Crs", search_in_sub_obj=True, deep_search=False
)
if crs_list is not None and len(crs_list) > 0:
# print(crs_list[0])
# logging.debug(crs_list[0])
crs = workspace.get_object_by_identifier(
get_obj_identifier(crs_list[0])
)
Expand Down Expand Up @@ -400,7 +400,7 @@ def read_array(
workspace=workspace,
)
else:
print(
logging.error(
f"Type {array_type_name} is not supported: function read_{snake_case(array_type_name)} not found"
)
raise Exception(
Expand All @@ -422,12 +422,12 @@ def read_constant_array(
:param workspace:
:return:
"""
# print(f"Reading constant array\n\t{energyml_array}")
# logging.debug(f"Reading constant array\n\t{energyml_array}")

value = get_object_attribute_no_verif(energyml_array, "value")
count = get_object_attribute_no_verif(energyml_array, "count")

# print(f"\tValue : {[value for i in range(0, count)]}")
# logging.debug(f"\tValue : {[value for i in range(0, count)]}")

return [value for i in range(0, count)]

Expand Down Expand Up @@ -562,7 +562,7 @@ def read_point3d_zvalue_array(
sup_geom_array[i][2] = zvalues_array[i]
except Exception as e:
if count == 0:
print(e, f": {i} is out of bound of {len(zvalues_array)}")
logging.error(e, f": {i} is out of bound of {len(zvalues_array)}")
count = count + 1

return sup_geom_array
Expand Down Expand Up @@ -590,13 +590,13 @@ def read_point3d_from_representation_lattice_array(
energyml_array, "supporting_representation"
)
)
# print(f"energyml_array : {energyml_array}\n\t{supporting_rep_identifier}")
# logging.debug(f"energyml_array : {energyml_array}\n\t{supporting_rep_identifier}")
supporting_rep = workspace.get_object_by_identifier(
supporting_rep_identifier
)

# TODO chercher un pattern \.*patch\.*.[d]+ pour trouver le numero du patch dans le path_in_root puis lire le patch
# print(f"path_in_root {path_in_root}")
# logging.debug(f"path_in_root {path_in_root}")

result = []
if "grid2d" in str(type(supporting_rep)).lower():
Expand Down Expand Up @@ -725,7 +725,7 @@ def read_point3d_lattice_array(
crs_sa_count[0] == fastest_size - 1
and crs_fa_count[0] == slowest_size - 1
):
print("reversing order")
logging.debug("reversing order")
# if offset were given in the wrong order
tmp_table = slowest_table
slowest_table = fastest_table
Expand Down Expand Up @@ -788,4 +788,4 @@ def read_point3d_lattice_array(
# path_in_root: Optional[str] = None,
# workspace: Optional[EnergymlWorkspace] = None
# ):
# print(energyml_array)
# logging.debug(energyml_array)
15 changes: 8 additions & 7 deletions energyml-utils/src/energyml/utils/data/mesh.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright (c) 2023-2024 Geosiris.
# SPDX-License-Identifier: Apache-2.0
import inspect
import logging
import os
import re
import sys
Expand Down Expand Up @@ -147,7 +148,7 @@ def read_mesh_object(
workspace=workspace,
)
else:
print(
logging.error(
f"Type {array_type_name} is not supported: function read_{snake_case(array_type_name)} not found"
)
raise Exception(
Expand Down Expand Up @@ -392,7 +393,7 @@ def read_grid2d_representation(
fa_count = fa_count[0]
sa_count = sa_count[0]

# print(f"sa_count {sa_count} fa_count {fa_count}")
# logging.debug(f"sa_count {sa_count} fa_count {fa_count}")

points_no_nan = []

Expand Down Expand Up @@ -423,13 +424,13 @@ def read_grid2d_representation(
sa_count = sa_count + 1
fa_count = fa_count + 1

# print(f"sa_count {sa_count} fa_count {fa_count} : {sa_count*fa_count} - {len(points)} ")
# logging.debug(f"sa_count {sa_count} fa_count {fa_count} : {sa_count*fa_count} - {len(points)} ")

for sa in range(sa_count - 1):
for fa in range(fa_count - 1):
line = sa * fa_count
# if sa+1 == int(sa_count / 2) and fa == int(fa_count / 2):
# print(
# logging.debug(
# "\n\t", (line + fa), " : ", (line + fa) in indice_to_final_indice,
# "\n\t", (line + fa + 1), " : ", (line + fa + 1) in indice_to_final_indice,
# "\n\t", (line + fa_count + fa + 1), " : ", (line + fa_count + fa + 1) in indice_to_final_indice,
Expand Down Expand Up @@ -458,7 +459,7 @@ def read_grid2d_representation(
indice_to_final_indice[line + fa_count + fa],
]
)
# print(indices)
# logging.debug(indices)
meshes.append(
SurfaceMesh(
identifier=f"{get_obj_identifier(energyml_object)}_patch{patch_idx}",
Expand Down Expand Up @@ -713,7 +714,7 @@ def export_multiple_data(
f".{file_format.value}"
)
file_path = f"{output_folder_path}/{file_name}"
print(f"Exporting : {file_path}")
logging.debug(f"Exporting : {file_path}")
mesh_list = read_mesh_object(
energyml_object=energyml_obj,
workspace=EPCWorkspace(epc=epc),
Expand All @@ -731,4 +732,4 @@ def export_multiple_data(
out=f,
)
else:
print(f"Code is not written for format {file_format}")
logging.error(f"Code is not written for format {file_format}")
26 changes: 13 additions & 13 deletions energyml-utils/src/energyml/utils/epc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""

import datetime
import logging
import re
import traceback
import zipfile
Expand Down Expand Up @@ -429,7 +430,7 @@ def read_stream(cls, epc_file_io: BytesIO): # returns an Epc instance
_read_files.append(content_type_file_name)

if content_type_info is None:
print(f"No {content_type_file_name} file found")
logging.error(f"No {content_type_file_name} file found")
else:
content_type_obj: Types = read_energyml_xml_bytes(
epc_file.read(content_type_file_name)
Expand All @@ -438,7 +439,7 @@ def read_stream(cls, epc_file_io: BytesIO): # returns an Epc instance
for ov in content_type_obj.override:
ov_ct = ov.content_type
ov_path = ov.part_name
# print(ov_ct)
# logging.debug(ov_ct)
while ov_path.startswith("/") or ov_path.startswith(
"\\"
):
Expand All @@ -455,16 +456,15 @@ def read_stream(cls, epc_file_io: BytesIO): # returns an Epc instance
path_to_obj[ov_path] = ov_obj
obj_list.append(ov_obj)
except Exception as e:
print(traceback.format_exc())
print(
logging.error(traceback.format_exc())
logging.error(
f"Epc.@read_stream failed to parse file {ov_path} for content-type: {ov_ct} => {get_class_from_content_type(ov_ct)}\n\n",
get_class_from_content_type(ov_ct),
)
try:
print(epc_file.read(ov_path))
logging.debug(epc_file.read(ov_path))
except:
pass
print(e)
# raise e
elif (
get_class_from_content_type(ov_ct)
Expand All @@ -490,13 +490,13 @@ def read_stream(cls, epc_file_io: BytesIO): # returns an Epc instance
)
)
except IOError as e:
print(traceback.format_exc())
logging.error(traceback.format_exc())
elif (
f_info.filename != "_rels/.rels"
): # CoreProperties rels file
# RELS FILES READING START

# print(f"reading rels {f_info.filename}")
# logging.debug(f"reading rels {f_info.filename}")
(
rels_folder,
rels_file_name,
Expand Down Expand Up @@ -528,7 +528,7 @@ def read_stream(cls, epc_file_io: BytesIO): # returns an Epc instance
)
)
for rel in rels_file.relationship:
# print(f"\t\t{rel.type_value}")
# logging.debug(f"\t\t{rel.type_value}")
if (
rel.type_value
!= EPCRelsRelationshipType.DESTINATION_OBJECT.get_type()
Expand All @@ -548,15 +548,15 @@ def read_stream(cls, epc_file_io: BytesIO): # returns an Epc instance
additional_rels_key
].append(rel)
except AttributeError:
print(traceback.format_exc())
logging.error(traceback.format_exc())
pass # 'CoreProperties' object has no attribute 'object_version'
except Exception as e:
print(
logging.error(
f"Error with obj path {obj_path} {path_to_obj[obj_path]}"
)
raise e
else:
print(
logging.error(
f"xml file '{f_info.filename}' is not associate to any readable object "
f"(or the object type is not supported because"
f" of a lack of a dependency module) "
Expand All @@ -569,7 +569,7 @@ def read_stream(cls, epc_file_io: BytesIO): # returns an Epc instance
additional_rels=additional_rels,
)
except zipfile.BadZipFile as error:
print(error)
logging.error(error)

return None

Expand Down
Loading

0 comments on commit 223bbd0

Please sign in to comment.