add function to extract path based on label
This commit is contained in:
parent
4e8bd83d4b
commit
491b4e31ec
|
@ -20,21 +20,17 @@ except(NameError):
|
||||||
# Singleton class for converting feature name to H5F path #
|
# Singleton class for converting feature name to H5F path #
|
||||||
# ------------------------------------------------------- #
|
# ------------------------------------------------------- #
|
||||||
# NOTE:
|
# NOTE:
|
||||||
# 1. use simple diction to mimic the singleton class in
|
# use simple function to mimic the singleton class in
|
||||||
# C++/Java
|
# C++/Java
|
||||||
# 2. data structure
|
def lables_to_path(label, dsXMLPath=None):
|
||||||
# {<FEATURE_NAME>: (<TYPE>, <PATH>), ...}
|
|
||||||
# <FEATURE_NAME> ==> the name of the feature, e.g. f, ...
|
|
||||||
# <TYPE> ==> attribute, dataset
|
|
||||||
# <PATH> ==> path_in_HDF5_file, e.g. '/f'
|
|
||||||
def lables_to_path(label, ns="https://damask.mpie.de"):
|
|
||||||
""" read the xml definition file and return the path."""
|
""" read the xml definition file and return the path."""
|
||||||
dsXMLPath = os.path.abspath(__file__).replace("h5table.py",
|
if dsXMLPath is None:
|
||||||
"DS_HDF5.xml")
|
dsXMLPath = os.path.abspath(__file__).replace("h5table.py",
|
||||||
|
"DS_HDF5.xml")
|
||||||
tree = ET.parse(dsXMLPath)
|
tree = ET.parse(dsXMLPath)
|
||||||
root = tree.getroot()
|
dataType = tree.find('{}/type'.format(label)).text
|
||||||
path = 'test'
|
h5path = tree.find('{}/h5path'.format(label)).text
|
||||||
return path
|
return (dataType, h5path)
|
||||||
|
|
||||||
|
|
||||||
# ----------------------- #
|
# ----------------------- #
|
||||||
|
@ -44,12 +40,12 @@ class H5Table(object):
|
||||||
"""
|
"""
|
||||||
DESCRIPTION
|
DESCRIPTION
|
||||||
-----------
|
-----------
|
||||||
Container class for interfacing with HDF5 file format. This
|
Interface class for manipulating data in HDF5 with DAMASK
|
||||||
is a bare-bone interface class that provide simplified getter
|
specialized data structure.
|
||||||
and setter for retrieving and appending data and attributes.
|
|
||||||
PARAMETERS
|
PARAMETERS
|
||||||
----------
|
----------
|
||||||
h5f_path
|
h5f_path: str
|
||||||
|
Absolute path the HDF5 file
|
||||||
METHOD
|
METHOD
|
||||||
------
|
------
|
||||||
get_attr()
|
get_attr()
|
||||||
|
@ -63,7 +59,6 @@ class H5Table(object):
|
||||||
----
|
----
|
||||||
1. As an interface class, it uses the lazy evaluation design
|
1. As an interface class, it uses the lazy evaluation design
|
||||||
that read the data only when its absolutely necessary.
|
that read the data only when its absolutely necessary.
|
||||||
2.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, h5f_path):
|
def __init__(self, h5f_path):
|
||||||
|
@ -71,11 +66,10 @@ class H5Table(object):
|
||||||
"""
|
"""
|
||||||
self.h5f_path = h5f_path
|
self.h5f_path = h5f_path
|
||||||
|
|
||||||
def get_attr(self, feature_name=None):
|
def get_attr(self, attr_name=None):
|
||||||
"""
|
"""
|
||||||
"""
|
"""
|
||||||
h5f = h5py.File(self.h5f_path, 'r')
|
h5f = h5py.File(self.h5f_path, 'r')
|
||||||
pass
|
|
||||||
|
|
||||||
def add_attr(self, ):
|
def add_attr(self, ):
|
||||||
"""
|
"""
|
||||||
|
@ -87,10 +81,12 @@ class H5Table(object):
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def get_data(self, ):
|
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)
|
||||||
pass
|
h5f = h5py.File(self.h5f_path, 'r')
|
||||||
|
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, ):
|
def add_data(self, ):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue