diff --git a/lib/damask/h5table.py b/lib/damask/h5table.py index eaef5d1c7..65c98d605 100644 --- a/lib/damask/h5table.py +++ b/lib/damask/h5table.py @@ -50,11 +50,9 @@ class H5Table(object): ------ get_attr() add_attr() - del_attr() get_data() add_data() - del_data() NOTE ---- 1. As an interface class, it uses the lazy evaluation design @@ -66,6 +64,11 @@ class H5Table(object): """ self.h5f_path = h5f_path + def __del__(self, feature_name=None): + dataType, h5f_path = lables_to_path(feature_name) + h5f = h5py.File(self.h5f_path, 'a') + del h5f[h5f_path] + def get_attr(self, attr_name=None): """ """ @@ -76,11 +79,6 @@ class H5Table(object): """ pass - def del_attr(self, ): - """ - """ - pass - def get_data(self, feature_name=None): """ extract dataset from HDF5 table and return it in a numpy array """ dataType, h5f_path = lables_to_path(feature_name) @@ -88,12 +86,11 @@ class H5Table(object): h5f_dst = h5f[h5f_path] # get the handle for target dataset(table) return h5f_dst.read_direct(np.zeros(h5f_dst.shape)) - def add_data(self, ): - """ - """ - pass - - def del_data(self, ): - """ - """ - pass \ No newline at end of file + def add_data(self, feature_name, dataset=None): + """ adding new feature into existing HDF5 file """ + dataType, h5f_path = lables_to_path(feature_name) + if dataType is not "attr": + h5f = h5py.File(self.h5f_path, 'a') + h5f.create_dataset(h5f_path, data=dataset) + else: + raise ValueError("feature {} isn't valid".format(feature_name))