Implemented dataset append method in HDF5DatOpsAPI

This commit is contained in:
2024-08-09 15:25:09 +02:00
parent 5fe7fc4b70
commit 18aba8d0d3

View File

@ -3,6 +3,7 @@ import pandas as pd
import numpy as np
import os
import src.hdf5_vis as hdf5_vis
import src.g5505_utils as utils
import logging
class HDF5DataOpsManager():
@ -49,7 +50,7 @@ class HDF5DataOpsManager():
if self.file_obj is None:
self.open_file()
dataset_obj = self.file_obj()[dataset_name]
dataset_obj = self.file_obj[dataset_name]
# Read dataset content from dataset obj
data = dataset_obj[...]
# The above statement can be understood as follows:
@ -62,6 +63,20 @@ class HDF5DataOpsManager():
except ValueError as exp:
logging.error(f"Failed to convert dataset '{dataset_name}' to DataFrame: {exp}")
return data # 'data' is a NumPy array here
def append_dataset(self,dataset_dict, group_name):
# Parse value into HDF5 admissible type
for key in dataset_dict['attributes'].keys():
value = dataset_dict['attributes'][key]
dataset_dict['attributes'][key] = utils.parse_attribute(value)
#name = dataset_dict['name']
#data = dataset_dict['data']
#dtype = dataset_dict['dtype']
self.file_obj[group_name].create_dataset(dataset_dict['name'], data=dataset_dict['data'])
self.file_obj[group_name][dataset_dict['name']].attrs.update(dataset_dict['attributes'])