Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattions/431522 to your computer and use it in GitHub Desktop.
Save mattions/431522 to your computer and use it in GitHub Desktop.
def save_node(self, h5file_holder, group_path, section_name, variables,
detail=''):
"""Save a node to the h5file.
h5file_holder: The holder of the h5file
group_path: Where in the hierarchy the leaf has to be saved
section_name: The name of the section which the variables belong to
variables: The dictionary of the variable
"""
found = False
target_group = None
for group in h5file_holder.walkGroups(group_path):
if group._v_name == section_name:
target_group = group
found = True
break
if not found:
target_group = h5file_holder.createGroup(group_path, section_name)
filters = tables.Filters(complevel=5, complib='lzo')
for var, vec in variables.iteritems():
array = np.array(vec.to_python())
atom = tables.Atom.from_dtype(array.dtype)
shape = array.shape
ca = h5file_holder.createCArray(target_group,
var,
atom,
shape,
title = detail,
filters=filters
)
ca[:] = array # filling the array.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment