diff --git a/src/hdf5_data_extraction.py b/src/hdf5_data_extraction.py index 76607b1..1ee8182 100644 --- a/src/hdf5_data_extraction.py +++ b/src/hdf5_data_extraction.py @@ -80,6 +80,23 @@ class HDF5DataOpsManager(): 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']) + def append_annotations(self, obj_name, annotation_dict): + """ appends annotations in the form of a dictionary to the obj (group or dataset) spefified by obj_name""" + + obj = self.file_obj[obj_name] + + # Verify if attributes to append are all new + if any(new_attr_key in obj.attrs.keys() for new_attr_key in annotation_dict.keys()): + self.close_file() + raise ValueError("Make sure the provided key, value pairs are not existing metadata elements or attributes. To modify or delete existing attributes use .modify_annotation() or .delete_annotation()") + + for new_attr_key in annotation_dict.keys(): + value = annotation_dict[new_attr_key] + if isinstance(value, dict): + annotation_dict[new_attr_key] = utils.parse_attribute(annotation_dict[new_attr_key]) + obj.attrs.update(annotation_dict) + + def reformat_datetime_column(self, dataset_name, column_name, src_format, desired_format='%Y-%m-%d %H:%M:%S.%f'): # Access the dataset dataset = self.file_obj[dataset_name]