Search code examples
pythondatasethdf5pytables

HDF5 and PyTables: How to read data when the table or group name includes blank characters


How can I read a hdf5 table datablock as:

domains = h5.root.'a name with blanks'

If this is not possible, but maybe with special signs?


Solution

  • Your question is specific to PyTables. You can also read HDF5 with h5py. Both packages support objects with spaces in dataset (table) and group names.
    Here are the ways to access a HDF5 object (table, dataset, or group) using each package. The example assumes 'name with blank' is a dataset. The code still works to get a group object, but you can't create an array from a group.

    PyTables method:
    Note that when defining where with a name, PyTables requires the full path, including the a '/'.

    domains_ds = h5.get_node('/name with blank') # returns table or array object as appropriate 
    domains_arr = h5.get_node('/name with blank').read() # returns numpy array object 
    

    h5py method:

    domains_ds = h5['name with blank'] # returns dataset object
    domains_arr = h5['name with blank'][()] # returns numpy array object