TableWriter

class ctapipe.io.tableio.TableWriter(**kwargs)[source]

Bases: ctapipe.core.component.Component

Base class for writing tabular data stored in Container

A single write will add a new row to the output table, where each Field becomes a column. Subclasses of this implement specific output types.

See also

ctapipe.io.HDF5TableWriter

Implementation of this base class for writing HDF5 files

Methods Summary

add_column_transform(table_name, col_name, …)

Add a transformation function for a column.

close()

exclude(table_name, pattern)

Exclude any columns (Fields) matching the pattern from being written

open(filename, **kwargs)

open an output file

write(table_name, containers, **kwargs)

Write the contents of the given container or containers to a table.

Methods Documentation

add_column_transform(table_name, col_name, transform)[source]

Add a transformation function for a column. This function will be called on the value in the container before it is written to the output file.

Parameters
table_name: str

identifier of table being written

col_name: str

name of column in the table (or item in the Container)

transform: callable

function that take a value and returns a new one

abstract close()[source]
exclude(table_name, pattern)[source]

Exclude any columns (Fields) matching the pattern from being written

Parameters
table_name: str

name of table on which to apply the exclusion

pattern: str

regular expression string to match column name

abstract 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

abstract write(table_name, containers, **kwargs)[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 thereof

container instance(s) to write

**kwargs:

may be passed to a lower level implementation to set options