Container¶
-
class
ctapipe.core.
Container
(prefix=None, **fields)[source]¶ Bases:
object
- Generic class that can hold and accumulate data to be passed
between Components.
The purpose of this class is to provide a flexible data structure that works a bit like a dict or blank Python class, but prevents the user from accessing members that have not been defined a priori (more like a C struct), and also keeps metadata information such as a description, defaults, and units for each item in the container.
Containers can transform the data into a
dict
using theas_dict
method. This allows them to be written to an output table for example, where each Field defines a column. Thedict
conversion can be made recursively and even flattened so that a nested set of Containers can be translated into a set of columns in a flat table without naming conflicts (the name of the parent Field is pre-pended).Only members of instance
Field
will be used as output. For hierarchical data structures, Field can useContainer
subclasses or aMap
as the default value.>>> import astropy.units as u >>> class MyContainer(Container): ... x = Field(100, "The X value") ... energy = Field(-1, "Energy measurement", unit=u.TeV) ... >>> cont = MyContainer() >>> print(cont.x) 100 >>> # metadata will become header keywords in an output file: >>> cont.meta["KEY"] = "value"
Fields inside Containers can contain instances of other containers, to allow for a hierarchy of containers, and can also contain a
Map
for the case where one wants e.g. a set of sub-classes indexed by a value like thetelescope_id
. Examples of this can be found inctapipe.containers
Container
works by shadowing all class variables (which must be instances ofField
) with instance variables of the same name that hold the actual data. Ifreset
is called, all instance variables are reset to their default values as defined in the class.Finally, a Container can have associated metadata via its
meta
attribute, which is adict
of keywords to values.
- Attributes
- metadict
dict of attached metadata
- prefixstr
Prefix attached to column names when saved to a table or file
Attributes Summary
Attributes Documentation
-
meta
¶
-
prefix
¶