HDF5 Data File Tree Structure : h5tree

Print the tree structure of any HDF5 file.

Note: The tree subcommand replaces the now-legacy structure subcommand and
also [replaces](https://github.com/prjemian/spec2nexus/issues/70) the h5toText program from the [spec2nexus](https://github.com/prjemian/spec2nexus) project.

How to use h5tree

Print the HDF5 tree of a file:

$ punx tree  path/to/file/hdf5/file.hdf5

the help message:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
  [linux,512]$ punx tree -h
  usage: punx tree [-h] [-a] [-m MAX_ARRAY_ITEMS] infile

  positional arguments:
    infile                HDF5 or NXDL file name

  optional arguments:
    -h, --help            show this help message and exit
    -a                    Do not print attributes of HDF5 file structure
    -m MAX_ARRAY_ITEMS, --max_array_items MAX_ARRAY_ITEMS
                          maximum number of array items to be shown

Example

Here’s an example from a test data file (writer_1_3.h5 from the NeXus documentation [1]):

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
  [linux,512]$ punx tree data/writer_1_3.hdf5
  data/writer_1_3.hdf5 : NeXus data file
    Scan:NXentry
      @NX_class = NXentry
      data:NXdata
        @NX_class = NXdata
        @signal = counts
        @axes = two_theta
        @two_theta_indices = [0]
        counts:NX_INT32[31] = [1037, 1318, 1704, '...', 1321]
          @units = counts
        two_theta:NX_FLOAT64[31] = [17.926079999999999, 17.925909999999998, 17.925750000000001, '...', 17.92108]
          @units = degrees
[1]writer_1_3 from NeXus: http://download.nexusformat.org/doc/html/examples/h5py/writer_1_3.html

source code documentation

Describe the tree structure of any HDF5 file

Hdf5TreeView(filename) Describe the tree structure of any HDF5 file
class punx.h5tree.Hdf5TreeView(filename)[source]

Describe the tree structure of any HDF5 file

Example usage showing default display:

mc = Hdf5TreeView(filename)
mc.array_items_shown = 5
show_attributes = False
txt = mc.report(show_attributes)
report(show_attributes=True)[source]

return the structure of the HDF5 file in a list of strings

The work of parsing the datafile is done in this method.