Skip to content

Commit c057137

Browse files
bugfix for crs
1 parent ab6b000 commit c057137

5 files changed

Lines changed: 38 additions & 12 deletions

File tree

energyml-utils/D

1.38 KB
Binary file not shown.

energyml-utils/example/attic/arrays_test.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
get_object_attribute,
2424
search_attribute_matching_name_with_path,
2525
)
26-
from energyml.resqml.v2_2.resqmlv2 import VerticalCRS
27-
from energyml.resqml.v2_0_1.resqmlv2 import DiscreteProperty as DiscreteProperty201, ContinuousProperty as ContinuousProperty201
28-
from energyml.eml.v2_3.commonv2 import TimeSeries, ColumnBasedTable
29-
from energyml.eml.v2_1.commonv2 import TimeSeries as TimeSeries21
26+
# from energyml.resqml.v2_2.resqmlv2 import VerticalCRS
27+
# from energyml.resqml.v2_0_1.resqmlv2 import DiscreteProperty as DiscreteProperty201, ContinuousProperty as ContinuousProperty201
28+
# from energyml.eml.v2_3.commonv2 import TimeSeries, ColumnBasedTable
29+
# from energyml.eml.v2_1.commonv2 import TimeSeries as TimeSeries21
3030

3131
from energyml.utils.serialization import read_energyml_xml_str, serialize_json
3232

@@ -271,10 +271,14 @@ def read_props_and_cbt(
271271

272272
epcs = []
273273
for path in epc_path:
274-
epc = EpcStreamReader(
274+
epc = Epc.read_file(
275275
epc_file_path=path,
276-
rels_update_mode=RelsUpdateMode.MANUAL,
276+
# rels_update_mode=RelsUpdateMode.MANUAL,
277277
)
278+
# epc = EpcStreamReader(
279+
# epc_file_path=path,
280+
# rels_update_mode=RelsUpdateMode.MANUAL,
281+
# )
278282
# epc = Epc.read_file(f"{path}", read_rels_from_files=False, recompute_rels=False)
279283
epcs.append(epc)
280284

@@ -464,6 +468,7 @@ def test_read_write_array(h5_path):
464468

465469

466470
if __name__ == "__main__":
471+
# Run $env:PYTHONPATH="src" if it fails to be executed from the project root.
467472
logging.basicConfig(level=logging.DEBUG)
468473
meshes = []
469474
# meshes = read_grid()
@@ -472,7 +477,7 @@ def test_read_write_array(h5_path):
472477
# meshes = read_representation_set_representation()
473478
# meshes = read_trset()
474479
# meshes = read_pointset()
475-
meshes = read_wellbore_frame_repr_demo_jfr_02_26()
480+
# meshes = read_wellbore_frame_repr_demo_jfr_02_26()
476481

477482
print(f"Number of meshes read: {len(meshes)}")
478483

@@ -495,4 +500,6 @@ def test_read_write_array(h5_path):
495500
raise e
496501

497502
# read_props_and_cbt()
503+
read_props_and_cbt(epc_path=["D:/Geosiris/Gitlab/clients/brgm/csv-to-energyml/rc/output/result.epc"],
504+
p_or_cbt_uuids=["deaa96db-9cd0-456c-beb1-dc19607fcfb9", "399678cf-6fe6-4522-9fba-710115c546cf"])
498505
# test_read_write_array("test_array_rw.h5")

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,9 @@ def extract_crs_info(
889889
"""
890890
if crs_obj is None:
891891
return CrsInfo()
892+
893+
if isinstance(crs_obj, CrsInfo):
894+
return crs_obj
892895

893896
# Transparently resolve DataObjectReference inputs (e.g. from get_datum_information)
894897
# so callers do not have to resolve DORs before calling this function.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def _point_as_array(point: Any) -> List:
8383
]
8484

8585

86-
def is_z_reversed(crs: Optional[Any]) -> bool:
86+
def is_z_reversed(crs: Optional[Any], workspace: Optional[EnergymlStorageInterface] = None) -> bool:
8787
"""
8888
Returns True if the Z axis increases downward
8989
(``ZIncreasingDownward==True`` or ``VerticalAxis.Direction=='down'``).
@@ -93,12 +93,12 @@ def is_z_reversed(crs: Optional[Any]) -> bool:
9393
:param crs: a CRS object
9494
:return: By default, ``False`` is returned when *crs* is ``None``.
9595
"""
96-
result = extract_crs_info(crs).z_increasing_downward
96+
result = extract_crs_info(crs, workspace).z_increasing_downward
9797
# logging.debug(f"is_z_reversed: {result}")
9898
return result
9999

100100

101-
def get_vertical_epsg_code(crs_object: Any) -> Optional[int]:
101+
def get_vertical_epsg_code(crs_object: Any, workspace: Optional[EnergymlStorageInterface] = None) -> Optional[int]:
102102
"""Return the EPSG code of the vertical CRS. Delegates to :func:`extract_crs_info`."""
103103
return extract_crs_info(crs_object).vertical_epsg_code
104104

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,8 +1126,24 @@ def read_property_interpreted_with_cbt(
11261126
else None
11271127
)
11281128
elif isinstance(category_lookup_data, dict):
1129-
# Transpose so that each index corresponds to a category (column), not a row
1130-
category_lookup_matrice = np.array(list(category_lookup_data.values())).T
1129+
# Transpose so that each index corresponds to a category (column), not a row.
1130+
logging.debug(f"category_lookup_data dict : {category_lookup_data}")
1131+
1132+
# Guard against inhomogeneous column lengths (e.g. one column is
1133+
# empty while another is not). Pad all columns with None up to
1134+
# the maximum column length so that np.array() can build a
1135+
# rectangular (n_columns, max_rows) matrix before transposing.
1136+
col_values = [
1137+
list(v) if not isinstance(v, list) else v
1138+
for v in category_lookup_data.values()
1139+
]
1140+
max_len = max((len(c) for c in col_values), default=0)
1141+
if max_len == 0:
1142+
# All columns empty — nothing to look up.
1143+
return prop_arrays if not _return_none_if_no_category_lookup else None
1144+
1145+
padded = [c + [None] * (max_len - len(c)) for c in col_values]
1146+
category_lookup_matrice = np.array(padded, dtype=object).T
11311147
# logging.debug(f"category_lookup_matrice : {category_lookup_matrice}")
11321148
# return a matrice with the same shape as prop_arrays but with the values from the category lookup array using the prop value as key in the category lookup array
11331149
result = (

0 commit comments

Comments
 (0)