1 from collections
import namedtuple
7 from .pluginsBase
import BasePlugin, BasePluginConfig
8 from .pluginRegistry
import PluginRegistry, PluginMap
9 from .
import FatalAlgorithmError, MeasurementError
12 FATAL_EXCEPTIONS = (MemoryError, FatalAlgorithmError)
14 __all__ = (
"CatalogCalculationPluginConfig",
"CatalogCalculationPlugin",
"CatalogCalculationConfig",
15 "CatalogCalculationTask")
20 Default configuration class for catalogCalcuation plugins 27 Base class for after CatalogCalculation plugin 30 ConfigClass = CatalogCalculationPluginConfig
38 def __init__(self, config, name, schema, metadata):
40 Initialize the catalogCalculation plugin 42 @param[in] config An instance of catalogCalculation config class. 43 @param[in] name The string the plugin was registered with. 44 @param[in,out] schema The source schema, New fields should be added here to 45 hold output produced by this plugin. 46 @param[in] metadata Plugin metadata that will be attached to the output catalog 48 BasePlugin.__init__(self, config, name)
52 ''' Sets the relative order of plugins (smaller numbers run first). 54 CatalogCalculation plugins must run with BasePlugin.DEFAULT_CATALOGCALCULATION or higher 56 All plugins must implement this method with an appropriate run level 58 raise NotImplementedError()
62 Process either a single catalog enter or the whole catalog and produce output defined by the plugin 64 @param[in,out] cat Either a lsst source catalog or a catalog entery depending on the plug type 65 specified in the classes configuration. Results may be added to new columns, 66 or existing entries altered. 67 @param[in] kwargs Any additional kwargs that may be passed through the CatalogCalculationPlugin. 69 raise NotImplementedError()
74 Context manager to handle catching errors that may have been thrown in a catalogCalculation plugin 75 @param[in] plugin The plugin that is to be run 76 @param[in] cat Either a catalog or a source record entry of a catalog, depending of the plugin type, 77 i.e. either working on a whole catalog, or a single record. 78 @param[in] log The log which to write to, most likely will always be the log (self.log) of the object 79 in which the context manager is used. 90 def __exit__(self, exc_type, exc_value, traceback):
93 if exc_type
in FATAL_EXCEPTIONS:
95 elif exc_type
is MeasurementError:
96 self.plugin.fail(self.cat, exc_value)
98 self.log.warn(
"Error in {}.calculate: {}".format(self.plugin.name, exc_value))
104 Config class for catalog calculation driver task. 106 Specifies which plugins will execute when CatalogCalculationTask 107 associated with this configuration is run. 109 plugins = CatalogCalculationPlugin.registry.makeField(
111 default=[
"base_ClassificationExtendedness",
112 "base_FootprintArea"],
113 doc=
"Plugins to be run and their configuration")
118 This task facilitates running plugins which will operate on a source catalog. These plugins may do things 119 such as classifying an object based on source record entries inserted during a measurement task. 121 Plugins may either take an entire catalog to work on at a time, or work on individual records 123 ConfigClass = CatalogCalculationConfig
124 _DefaultName =
"catalogCalculation" 126 def __init__(self, schema, plugMetadata=None, **kwargs):
128 Constructor; only called by derived classes 130 @param[in] plugMetaData An lsst.daf.base.PropertyList that will be filled with metadata 131 about the plugins being run. If None, an empty empty PropertyList 133 @param[in] **kwargs Additional arguments passed to lsst.pipe.base.Task.__init__. 135 lsst.pipe.base.Task.__init__(self, **kwargs)
137 if plugMetadata
is None:
146 Initialize the plugins according to the configuration. 149 pluginType = namedtuple(
'pluginType',
'single multi')
155 for executionOrder, name, config, PluginClass
in sorted(self.config.plugins.apply()):
157 self.
executionDict[executionOrder] = pluginType(single=[], multi=[])
158 if PluginClass.getExecutionOrder() >= BasePlugin.DEFAULT_CATALOGCALCULATION:
161 if plug.plugType ==
'single':
163 elif plug.plugType ==
'multi':
166 errorTuple = (PluginClass, PluginClass.getExecutionOrder(),
167 BasePlugin.DEFAULT_CATALOGCALCULATION)
168 raise ValueError(
"{} has an execution order less than the minimum for an catalogCalculation " 169 "plugin. Value {} : Minimum {}".format(*errorTuple))
171 @lsst.pipe.base.timeMethod
174 The entry point for the catalogCalculation task. This method should be called with a reference to a 181 Run each of the plugins on the catalog 182 @param[in] catalog The catalog on which the plugins will operate 188 plug.calculate(catalog)
190 for measRecord
in catalog:
192 with
CCContext(plug, measRecord, self.log):
193 plug.calculate(measRecord)
def __exit__(self, exc_type, exc_value, traceback)
Base class for measurement plugins.
def __init__(self, schema, plugMetadata=None, kwargs)
Base class measurement Plugin config classes.
Base class for plugin registries.
def __init__(self, plugin, cat, log)
def getExecutionOrder(cls)
def initializePlugins(self)
def callCompute(self, catalog)
Map of plugins (instances of subclasses of BasePlugin) to be run for a task.
def __init__(self, config, name, schema, metadata)
Initialize the catalogCalculation plugin.
def calculate(self, cat, kwargs)
Process either a single catalog enter or the whole catalog and produce output defined by the plugin...