TableWriter#
- class ctapipe.io.TableWriter(**kwargs: Any)[source]#
 Bases:
ComponentBase class for writing tabular data stored in
ContainerA single write will add a new row to the output table, where each
Fieldbecomes a column. Subclasses of this implement specific output types.See also
ctapipe.io.HDF5TableWriterImplementation of this base class for writing HDF5 files
Methods Summary
add_column_transform(table_name, col_name, ...)Add a transformation function for a column.
add_column_transform_regexp(table_regexp, ...)Add a transformation function for a set of columns and tables that match the given regular expressions.
close()Close open writer
exclude(table_regexp, 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: ColumnTransform
 function that transforms input into output
- add_column_transform_regexp(table_regexp, col_regexp, transform)[source]#
 Add a transformation function for a set of columns and tables that match the given regular expressions. Each requested transform pattern will be turned into an explicit column transform when the table schema is built.
- Parameters:
 - table_name: regexp
 pattern matching the table name (via re.matchall)
- col_name: regexp
 pattern matching the column name if the table name also matches (via re.matchall)
- transform: ColumnTransform
 function that tranformns input value into output value
- exclude(table_regexp, pattern)[source]#
 Exclude any columns (Fields) matching the pattern from being written. The patterns are matched with re.fullmatch.
- Parameters:
 - table_regexp: str
 regexp matching to match table name to apply exclusion
- pattern: str
 regular expression string to match column name in the table
- 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