From aae2bcf6f9601651a7eb51bf813e3a58f66dd3ed Mon Sep 17 00:00:00 2001 From: chen Date: Fri, 7 Oct 2016 09:47:15 -0400 Subject: [PATCH] add new interface class to HDF5 --- lib/damask/h5table.py | 101 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 lib/damask/h5table.py diff --git a/lib/damask/h5table.py b/lib/damask/h5table.py new file mode 100644 index 000000000..553d53010 --- /dev/null +++ b/lib/damask/h5table.py @@ -0,0 +1,101 @@ +# -*- coding: UTF-8 no BOM -*- + +import os +import sys +import h5py +import numpy as np + +# ---------------------------------------------------------------- # +# python 3 has no unicode object, this ensures that the code works # +# on Python 2&3 # +# ---------------------------------------------------------------- # +try: + test=isinstance('test', unicode) +except(NameError): + unicode=str + + +# ------------------------------------------------------- # +# Singleton class for converting feature name to H5F path # +# ------------------------------------------------------- # +# NOTE: +# 1. use simple diction to mimic the singleton class in +# C++/Java +# 2. data structure +# {: (, ), ...} +# ==> the name of the feature, e.g. f, ... +# ==> attribute, dataset +# ==> path_in_HDF5_file, e.g. '/f' +# 3. for future HDF5 data structure, this can be convert +# into a function to get more complicated path, this would +# be a great time to integrate XML parser +def lables_to_path(label): + """ read the xml definition file and return the path.""" + path = '/{}'.format(lable) + return path + + +# ----------------------- # +# H5Table interface class # +# ----------------------- # +class H5Table(object): + """ + DESCRIPTION + ----------- + Container class for interfacing with HDF5 file format. This + is a bare-bone interface class that provide simplified getter + and setter for retrieving and appending data and attributes. + PARAMETERS + ---------- + h5f_path + METHOD + ------ + get_attr() + add_attr() + del_attr() + + get_data() + add_data() + del_data() + NOTE + ---- + 1. As an interface class, it uses the lazy evaluation design + that read the data only when its absolutely necessary. + 2. + """ + + def __init__(self, h5f_path): + """ + """ + self.h5f_path = h5f_path + + def get_attr(self, feature_name=None): + """ + """ + h5f = h5py.File(self.h5f_path, 'r') + pass + + def add_attr(self, ): + """ + """ + pass + + def del_attr(self, ): + """ + """ + pass + + def get_data(self, ): + """ + """ + pass + + def add_data(self, ): + """ + """ + pass + + def del_data(self, ): + """ + """ + pass \ No newline at end of file