def iMain():
"""
Read an hdf file generated by us to make sure
we can recover its content and structure.
Give the name of an hdf5 file as a command-line argument.
"""
assert sys.argv, __doc__
sFile = sys.argv[1]
assert os.path.isfile(sFile)
oHdfStore = pandas.HDFStore(sFile, mode='r')
print oHdfStore.groups()
# bug - no return value
# oSignals = pandas.read_hdf(oHdfStore, '/servings/signals')
mSignals = oHdfStore.select('/recipe/servings/mSignals', auto_close=False)
print mSignals
print oHdfStore.get_node('/recipe')._v_attrs.metadata[0]['sUrl']
def load_hdf5_data(file_path, **kwargs):
key = kwargs.get('key', None)
pandas_format = kwargs.get('pandas_format', True)
mode = kwargs.get('mode', 'r')
logger.info("Opening HDF5 file {} to read...".format(file_path))
try:
if pandas_format:
data = pd.read_hdf(file_path, key=key, mode=mode)
else:
with h5py.File(file_path, mode) as f:
data = f[key][()]
except KeyError as e:
logger.exception("Dataset {} does not exist".format(dataset))
raise exceptions.FileLoadError("Dataset does not exist")
except Exception as e:
logger.exception("Problem loading dataset: {0}".format(e))
raise exceptions.FileLoadError
logger.info("Successfully loaded HDF5 data")
return data