# HDF5TableWriter¶

class ctapipe.io.HDF5TableWriter(filename, group_name='', add_prefix=False, mode='w', root_uep='/', filters=Filters(complevel=5, complib='blosc:zstd', shuffle=True, bitshuffle=False, fletcher32=True, least_significant_digit=None), parent=None, config=None, **kwargs)[source]

A very basic table writer that can take a container (or more than one) and write it to an HDF5 file. It does _not_ recursively write the container. This is intended as a building block to create a more complex I/O system.

It works by creating a HDF5 Table description from the Fields inside a container, where each item becomes a column in the table. The first time HDF5TableWriter.write() is called, the container(s) are registered and the table created in the output file.

Each item in the container can also have an optional transform function that is called before writing to transform the value. For example, unit quantities always have their units removed, or converted to a common unit if specified in the Field.

Any metadata in the Container (stored in Container.meta) will be written to the table’s header on the first call to write()

Multiple tables may be written at once in a single file, as long as you change the table_name attribute to write() to specify which one to write to. Likewise multiple Containers can be merged into a single output table by passing a list of containers to write().

To append to existing files, pass the mode='a' option to the constructor.

Parameters
filename: str

name of hdf5 output file

group_name: str

name of group into which to put all of the tables generated by this Writer (it will be placed under “/” in the file)

if True, add the container prefix before each column name

modestr (‘w’, ‘a’)

‘w’ if you want to overwrite the file ‘a’ if you want to append data to the file

root_uepstr

root location of the group_name

filters: pytables.Filters

A set of filters (compression settings) to be used for all datasets created by this writer.

kwargs:

any other arguments that will be passed through to pytables.open().

Methods Summary

 open(filename, **kwargs) open an output file write(table_name, containers) Write the contents of the given container or containers to a table.

Methods Documentation

close()[source]
open(filename, **kwargs)[source]

open an output file

Parameters
filename: str

output file name

kwargs:

any extra args to pass to the subclass open method

write(table_name, containers)[source]

Write the contents of the given container or containers to a table. The first call to write will create a schema and initialize the table within the file. The shape of data within the container must not change between calls, since variable-length arrays are not supported.

Parameters
table_name: str

name of table to write to

containers: ctapipe.core.Container or Iterable[ctapipe.core.Container]

container to write