Component

class ctapipe.core.Component(config=None, parent=None, **kwargs)[source]

Bases: traitlets.config.configurable.Configurable

Base class of all Components.

Components are classes that are configurable via traitlets and setup a logger in the ctapipe logging hierarchy.

traitlets can validate values and provide defaults and descriptions. These will be automatically translated into configuration parameters (command-line, config file, etc). Note that any parameter that should be externally configurable must have its config attribute set to True, e.g. defined like myparam = Integer(0, help='the parameter').tag(config=True).

All components also contain a logger instance in their log attribute, that you must use to output info, debugging data, warnings, etc (do not use print() statements, instead use self.log.info(), self.log.warning(), self.log.debug(), etc).

Components are generally used within ctapipe.core.Tool subclasses, which provide configuration handling and command-line tool generation.

For example:

from ctapipe.core import Component
from traitlets import (Integer, Float)

class MyComponent(Component):
    """ Does something """
    some_option = Integer(default_value=6,
                          help='a value to set').tag(config=True)

comp = MyComponent()
comp.some_option = 6      # ok
comp.some_option = 'test' # will fail validation

Methods Summary

from_name(name[, config, parent])

Obtain an instance of a subclass via its name

get_current_config()

return the current configuration as a dict (e.g.

non_abstract_subclasses()

get dict{name: cls} of non abstract subclasses, subclasses can possibly be definded in plugins

Methods Documentation

classmethod from_name(name, config=None, parent=None, **kwargs)[source]

Obtain an instance of a subclass via its name

Parameters
namestr

Name of the subclass to obtain

configtraitlets.loader.Config

Configuration specified by config file or cmdline arguments. Used to set traitlet values. This argument is typically only specified when using this method from within a Tool.

parentctapipe.core.Tool

Tool executable that is calling this component. Passes the correct logger and configuration to the component. This argument is typically only specified when using this method from within a Tool (config need not be passed if parent is used).

kwargs
Returns
instace

Instance of subclass to this class

get_current_config()[source]

return the current configuration as a dict (e.g. the values of all traits, even if they were not set during configuration)

classmethod non_abstract_subclasses()[source]

get dict{name: cls} of non abstract subclasses, subclasses can possibly be definded in plugins