Skip to content

Python HDF Object

David Jeske edited this page May 17, 2017 · 5 revisions

class HDF_DATASET:

  def getIntValue(STRING:hdf_var_name,INT:default_value): INT
  def getValue(STRING:hdf_var_name,STRING:default_value): STRING
  def setValue(STRING:hdf_var_name,STRING:value)

These functions are used to read and write individual data elements to and from the HDF dataset. You must provide a default value of the proper type.

  def readFile(STRING:filename)
  def readString(STRING:hdf_string_data)
  def writeFile(STRING:filename)
  def writeString():STRING
  def dump():STRING

These functions are used to read and write chunks of HDF data from strings or files. Remember that since extra HDF information such as comments are not kept in the dataset, using readFile() and then writeFile() will basically result in a nicely formatted output file without comments.

You can generate HDF output in three different formats or styles. They all read in the same way. writeFile() will dump a nicely formatted file with {} nesting and proper indention. writeString() will create the most compact representation by using {} nesting, but eliminates all unnecessary whitespace. This is generally used for rendering HDF for storage into a database or other small data location. dump() writes out the fully qualified HDF path for every element (i.e. A.B.C=1), and is generally used to make certain configuration files or output dumps easy to read and use.

  def getObj(STRING:hdf_name): HDF_DATASET

hdfobj.getObj("Foo") returns a "sub-dataset" within the current dataset located at the given node.

  def top() : HDF_DATASET

This returns the root level of the dataset.

  def copy(STRING:name,HDF_DATASET:src_dataset)

This will copy the source dataset into the named location in the destination dataset. (i.e. the object you're calling copy on)

  def removeTree(STRING:hdf_path)

This deletes and removes an hdf subtree from the current dataset.

  def setSymLink(STRING:hdf_name_src,STRING:hdf_name_dest)

This is something like a UNIX symlink. It points the HDF source node name at the HDF destination node name. For example:

    hdf.setValue("foo","bar")
    hdf.setSymLink("baz","foo")
    print hdf.getValue("baz","")   # ---> "bar"
  def getAttrs(STRING:hdf_var_name): LIST_of_TUPLES
  def setAttr(STRING:hdf_node_name,STRING:attr_name,STRING:attr_value)

These functions allow you to access the attributes which can be attached to any HDF node.

getAttrs returns a list of attributes present on a node in the form [(name1,value1),(name2,value2),...].

setAttr allows you to set an attribute on that node.

See the HDF dataset documentation to get a more thorough description of attributes.

  def child(): HDF_DATASET
  def next(): HDF_DATASET
  def name(): STRING
  def value(): STRING

These functions are used for walking the HDF tree. For example, this function will recursively walk an entire tree (although the printout might not be exactly what you expect, because it only contains the local node names)

    def render_node(a_node):
      print "%s = %s" % (a_node.name(),a_node.value())

    def tree_walk(hdf_node):
      while hdf_node: 
        render_node(hdf_node)
        tree_walk(hdf_node.child())
        hdf_node = hdf_node.next()

Clone this wiki locally