ras-commander 0.44.0__py3-none-any.whl → 0.46.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
ras_commander/HdfUtils.py CHANGED
@@ -17,6 +17,7 @@ from typing import Union, Optional, Dict, List, Tuple, Any
17
17
  from scipy.spatial import KDTree
18
18
  import re
19
19
 
20
+
20
21
  from .Decorators import standardize_input, log_call
21
22
  from .LoggingConfig import setup_logging, get_logger
22
23
 
@@ -465,3 +466,53 @@ class HdfUtils:
465
466
  except Exception as e:
466
467
  logger.error(f"Error reading projection from {hdf_path}: {str(e)}")
467
468
  return None
469
+
470
+ def print_attrs(name, obj):
471
+ """
472
+ Print attributes of an HDF5 object.
473
+ """
474
+ if obj.attrs:
475
+ print("")
476
+ print(f" Attributes for {name}:")
477
+ for key, val in obj.attrs.items():
478
+ print(f" {key}: {val}")
479
+ else:
480
+ print(f" No attributes for {name}.")
481
+
482
+ @staticmethod
483
+ @standardize_input(file_type='plan_hdf')
484
+ def explore_hdf5(file_path: Path, group_path: str = '/') -> None:
485
+ """
486
+ Recursively explore and print the structure of an HDF5 file.
487
+
488
+ :param file_path: Path to the HDF5 file
489
+ :param group_path: Current group path to explore
490
+ """
491
+ def recurse(name, obj, indent=0):
492
+ spacer = " " * indent
493
+ if isinstance(obj, h5py.Group):
494
+ print(f"{spacer}Group: {name}")
495
+ HdfUtils.print_attrs(name, obj)
496
+ for key in obj:
497
+ recurse(f"{name}/{key}", obj[key], indent+1)
498
+ elif isinstance(obj, h5py.Dataset):
499
+ print(f"{spacer}Dataset: {name}")
500
+ print(f"{spacer} Shape: {obj.shape}")
501
+ print(f"{spacer} Dtype: {obj.dtype}")
502
+ HdfUtils.print_attrs(name, obj)
503
+ else:
504
+ print(f"{spacer}Unknown object: {name}")
505
+
506
+ try:
507
+ with h5py.File(file_path, 'r') as hdf_file:
508
+ if group_path in hdf_file:
509
+ print("")
510
+ print(f"Exploring group: {group_path}\n")
511
+ group = hdf_file[group_path]
512
+ for key in group:
513
+ print("")
514
+ recurse(f"{group_path}/{key}", group[key], indent=1)
515
+ else:
516
+ print(f"Group path '{group_path}' not found in the HDF5 file.")
517
+ except Exception as e:
518
+ print(f"Error exploring HDF5 file: {e}")