From 44073e381634774ff1744265d5d129bdb2fd1472 Mon Sep 17 00:00:00 2001 From: Florez Ospina Juan Felipe Date: Thu, 17 Oct 2024 10:46:19 +0200 Subject: [PATCH] Replaced read_dataset_from_hdf5file(hdf5_file_path, dataset_path) with HDF5DataOpsManager.extract_dataset_as_dataframe(self,dataset_name) --- src/hdf5_ops.py | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/src/hdf5_ops.py b/src/hdf5_ops.py index 61b43e0..9de37e8 100644 --- a/src/hdf5_ops.py +++ b/src/hdf5_ops.py @@ -22,9 +22,11 @@ import copy class HDF5DataOpsManager(): """ - A class to handle HDF5 file operations. + A class to handle HDF5 fundamental middle level file operations to power data updates, metadata revision, and data analysis + with hdf5 files encoding multi-instrument experimental campaign data. Parameters: + ----------- path_to_file : str path/to/hdf5file. mode : str @@ -80,8 +82,7 @@ class HDF5DataOpsManager(): except Exception as e: self.unload_file_obj() - print(f"An unexpected error occurred: {e}. File object will be unloaded.") - + print(f"An unexpected error occurred: {e}. File object will be unloaded.") @@ -423,29 +424,6 @@ class HDF5DataOpsManager(): - - - - - - -def read_dataset_from_hdf5file(hdf5_file_path, dataset_path): - # Open the HDF5 file - with h5py.File(hdf5_file_path, 'r') as hdf: - # Load the dataset - dataset = hdf[dataset_path] - data = np.empty(dataset.shape, dtype=dataset.dtype) - dataset.read_direct(data) - df = pd.DataFrame(data) - - for col_name in df.select_dtypes(exclude='number'): - df[col_name] = df[col_name].str.decode('utf-8') #apply(lambda x: x.decode('utf-8') if isinstance(x,bytes) else x) - ## Extract metadata (attributes) and convert to a dictionary - #metadata = hdf5_vis.construct_attributes_dict(hdf[dataset_name].attrs) - ## Create a one-row DataFrame with the metadata - #metadata_df = pd.DataFrame.from_dict(data, orient='columns') - return df - def get_parent_child_relationships(file: h5py.File): nodes = ['/']