Created
June 9, 2010 14:12
-
-
Save mattions/431522 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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