Skip to content

Commit b66bc88

Browse files
bugfix fo h5 file path when uri of file is given as object uri (occurs for etp support)
1 parent 836edbc commit b66bc88

4 files changed

Lines changed: 46 additions & 31 deletions

File tree

energyml-utils/example/attic/arrays_test.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,8 @@ def read_wellbore_frame_repr_demo_jfr_02_26(
383383
epc_path: str = r"rc/epc/out-galaxy-12-pts.epc",
384384
well_uuid: str = "cfad9cb6-99fe-4172-b560-d2feca75dd9f",
385385
) -> List[AbstractMesh]:
386-
epc = Epc.read_file(f"{epc_path}", read_rels_from_files=False, recompute_rels=False)
386+
# epc = Epc.read_file(f"{epc_path}", read_rels_from_files=False, recompute_rels=False)
387+
epc = EpcStreamReader(f"{epc_path}", rels_update_mode=RelsUpdateMode.MANUAL)
387388

388389
frame_repr = epc.get_object_by_uuid(well_uuid)[0]
389390
# print(frame_repr)
@@ -471,7 +472,7 @@ def test_read_write_array(h5_path):
471472
# meshes = read_representation_set_representation()
472473
# meshes = read_trset()
473474
# meshes = read_pointset()
474-
# meshes = read_wellbore_frame_repr_demo_jfr_02_26()
475+
meshes = read_wellbore_frame_repr_demo_jfr_02_26()
475476

476477
print(f"Number of meshes read: {len(meshes)}")
477478

@@ -494,4 +495,4 @@ def test_read_write_array(h5_path):
494495
raise e
495496

496497
# read_props_and_cbt()
497-
test_read_write_array("test_array_rw.h5")
498+
# test_read_write_array("test_array_rw.h5")

energyml-utils/example/attic/test_list_object.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,25 @@
44

55
def list_epc_classical(epc_file):
66
"""List contents of an EPC file."""
7-
epc = EpcStreamReader(epc_file, rels_update_mode=RelsUpdateMode.MANUAL)
87

9-
time_start = datetime.now()
10-
# for obj in epc.list_objects():
11-
# print(f"Object: {obj}")
12-
print(len(epc.list_objects(object_type="eml23.DataobjectCollection")))
8+
if not isinstance(epc_file, list):
9+
epc_file = [epc_file]
1310

14-
for obj in epc.list_objects(object_type="eml23.DataobjectCollection"):
15-
print(f"DataobjectCollection: {obj}")
16-
time_end = datetime.now()
17-
print(f"Time taken: {time_end - time_start}")
11+
for f in epc_file:
12+
print(f"Processing EPC file: {f}")
13+
epc = EpcStreamReader(f, rels_update_mode=RelsUpdateMode.MANUAL)
14+
15+
time_start = datetime.now()
16+
# for obj in epc.list_objects():
17+
# print(f"Object: {obj}")
18+
print(len(epc.list_objects(object_type="resqml22.BoundaryFeature")))
19+
20+
for obj in sorted(epc.list_objects(object_type="resqml22.BoundaryFeature"), key=lambda o: o.title):
21+
print(f"BoundaryFeature: {obj}")
22+
for obj in sorted(epc.list_objects(object_type="resqml22.RockVolumeFeature"), key=lambda o: o.title):
23+
print(f"RockVolumeFeature: {obj}")
24+
time_end = datetime.now()
25+
print(f"Time taken: {time_end - time_start}")
1826

1927

2028
# def list_epc_fast(epc_file):
@@ -48,12 +56,16 @@ def list_epc_classical(epc_file):
4856

4957

5058
if __name__ == "__main__":
51-
epc_file = "D:/Geosiris/Clients/BRGM/git/pointset-extraction/rc/output/full-local/full-local.epc"
59+
epc_file = [
60+
"D:/Geosiris/Clients/BRGM/git/pointset-extraction/rc/output/full-local/full-local.epc",
61+
"D:/Geosiris/Clients/BRGM/git/csv-to-energyml/rc/output/full-local/result-out-local-egis-full.epc",
62+
]
63+
# epc_file = "D:/Geosiris/Clients/BRGM/git/pointset-extraction/rc/output/full-local/full-local.epc"
5264
print("Listing EPC contents (classical method):")
5365
list_epc_classical(epc_file)
5466

55-
# print("\nListing EPC contents (fast method):")
67+
# print("Listing EPC contents (fast method):")
5668
# list_epc_fast(epc_file)
5769

58-
# print("\nListing EPC contents (sequential method):")
70+
# print("Listing EPC contents (sequential method):")
5971
# list_epc_seq(epc_file)

energyml-utils/src/energyml/utils/epc.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,13 +1305,13 @@ def get_h5_file_paths(self, obj_or_id: Optional[Any] = None) -> List[str]:
13051305

13061306
h5_paths = set(make_path_relative_to_filepath_list(list(h5_paths), self.epc_file_path))
13071307

1308-
if len(h5_paths) == 0:
1309-
# Collect all .h5 files in the EPC file's folder
1310-
epc_folder = self.get_epc_file_folder()
1311-
if epc_folder is not None and os.path.isdir(epc_folder):
1312-
for fname in os.listdir(epc_folder):
1313-
if fname.lower().endswith(".h5"):
1314-
h5_paths.add(os.path.join(epc_folder, fname))
1308+
# if len(h5_paths) == 0:
1309+
# Collect all .h5 files in the EPC file's folder
1310+
epc_folder = self.get_epc_file_folder()
1311+
if epc_folder is not None and os.path.isdir(epc_folder):
1312+
for fname in os.listdir(epc_folder):
1313+
if fname.lower().endswith(".h5"):
1314+
h5_paths.add(os.path.join(epc_folder, fname))
13151315

13161316
return list(h5_paths)
13171317

energyml-utils/src/energyml/utils/epc_stream.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,7 +1332,9 @@ def get_statistics(self) -> EpcStreamingStats:
13321332
"""Get current statistics about the EPC streaming operations."""
13331333
return self.stats
13341334

1335-
def get_h5_file_paths(self, obj: Union[str, Uri, Any], make_path_absolute_from_epc_path: bool = True) -> List[str]:
1335+
def get_h5_file_paths(
1336+
self, obj_or_id: Union[str, Uri, Any] = None, make_path_absolute_from_epc_path: bool = True
1337+
) -> List[str]:
13361338
"""
13371339
Get all HDF5 file paths referenced in the EPC file (from rels to external resources).
13381340
Optimized to avoid loading the object when identifier/URI is provided.
@@ -1347,7 +1349,7 @@ def get_h5_file_paths(self, obj: Union[str, Uri, Any], make_path_absolute_from_e
13471349

13481350
rels_path = None
13491351

1350-
_id = self._id_from_uri_or_identifier(identifier=obj, get_first_if_simple_uuid=True)
1352+
_id = self._id_from_uri_or_identifier(identifier=obj_or_id, get_first_if_simple_uuid=True)
13511353
if _id is not None:
13521354
rels_path = self._metadata_mgr.gen_rels_path_from_identifier(_id)
13531355

@@ -1372,13 +1374,13 @@ def get_h5_file_paths(self, obj: Union[str, Uri, Any], make_path_absolute_from_e
13721374
if make_path_absolute_from_epc_path:
13731375
h5_paths = set(make_path_relative_to_filepath_list(list(h5_paths), self.epc_file_path))
13741376

1375-
if len(h5_paths) == 0:
1376-
# Collect all .h5 files in the EPC file's folder
1377-
epc_folder = get_file_folder(self.epc_file_path)
1378-
if epc_folder is not None and os.path.isdir(epc_folder):
1379-
for fname in os.listdir(epc_folder):
1380-
if fname.lower().endswith(".h5"):
1381-
h5_paths.add(os.path.join(epc_folder, fname))
1377+
# if len(h5_paths) == 0:
1378+
# Collect all .h5 files in the EPC file's folder
1379+
epc_folder = get_file_folder(self.epc_file_path)
1380+
if epc_folder is not None and os.path.isdir(epc_folder):
1381+
for fname in os.listdir(epc_folder):
1382+
if fname.lower().endswith(".h5"):
1383+
h5_paths.add(os.path.join(epc_folder, fname))
13821384

13831385
return list(h5_paths)
13841386

0 commit comments

Comments
 (0)