1 from collections
import namedtuple
3 from builtins
import object
9 from .pluginsBase
import BasePlugin, BasePluginConfig
10 from .pluginRegistry
import PluginRegistry, PluginMap
11 from .
import FatalAlgorithmError, MeasurementError
14 FATAL_EXCEPTIONS = (MemoryError, FatalAlgorithmError)
16 __all__ = (
"CatalogCalculationPluginConfig",
"CatalogCalculationPlugin",
"CatalogCalculationConfig",
17 "CatalogCalculationTask")
22 Default configuration class for catalogCalcuation plugins 29 Base class for after CatalogCalculation plugin 32 ConfigClass = CatalogCalculationPluginConfig
40 def __init__(self, config, name, schema, metadata):
42 Initialize the catalogCalculation plugin 44 @param[in] config An instance of catalogCalculation config class. 45 @param[in] name The string the plugin was registered with. 46 @param[in,out] schema The source schema, New fields should be added here to 47 hold output produced by this plugin. 48 @param[in] metadata Plugin metadata that will be attached to the output catalog 50 BasePlugin.__init__(self, config, name)
54 ''' Sets the relative order of plugins (smaller numbers run first). 56 CatalogCalculation plugins must run with BasePlugin.DEFAULT_CATALOGCALCULATION or higher 58 All plugins must implement this method with an appropriate run level 60 raise NotImplementedError()
64 Process either a single catalog enter or the whole catalog and produce output defined by the plugin 66 @param[in,out] cat Either a lsst source catalog or a catalog entery depending on the plug type 67 specified in the classes configuration. Results may be added to new columns, 68 or existing entries altered. 69 @param[in] kwargs Any additional kwargs that may be passed through the CatalogCalculationPlugin. 71 raise NotImplementedError()
76 Context manager to handle catching errors that may have been thrown in a catalogCalculation plugin 77 @param[in] plugin The plugin that is to be run 78 @param[in] cat Either a catalog or a source record entry of a catalog, depending of the plugin type, 79 i.e. either working on a whole catalog, or a single record. 80 @param[in] log The log which to write to, most likely will always be the log (self.log) of the object 81 in which the context manager is used. 92 def __exit__(self, exc_type, exc_value, traceback):
95 if exc_type
in FATAL_EXCEPTIONS:
97 elif exc_type
is MeasurementError:
98 self.plugin.fail(self.cat, exc_value)
100 self.log.warn(
"Error in {}.calculate: {}".format(self.plugin.name, exc_value))
106 Config class for catalog calculation driver task. 108 Specifies which plugins will execute when CatalogCalculationTask 109 associated with this configuration is run. 111 plugins = CatalogCalculationPlugin.registry.makeField(
113 default=[
"base_ClassificationExtendedness",
114 "base_FootprintArea"],
115 doc=
"Plugins to be run and their configuration")
120 This task facilitates running plugins which will operate on a source catalog. These plugins may do things 121 such as classifying an object based on source record entries inserted during a measurement task. 123 Plugins may either take an entire catalog to work on at a time, or work on individual records 125 ConfigClass = CatalogCalculationConfig
126 _DefaultName =
"catalogCalculation" 128 def __init__(self, schema, plugMetadata=None, **kwargs):
130 Constructor; only called by derived classes 132 @param[in] plugMetaData An lsst.daf.base.PropertyList that will be filled with metadata 133 about the plugins being run. If None, an empty empty PropertyList 135 @param[in] **kwargs Additional arguments passed to lsst.pipe.base.Task.__init__. 137 lsst.pipe.base.Task.__init__(self, **kwargs)
139 if plugMetadata
is None:
140 plugMetadata = lsst.daf.base.PropertyList()
148 Initialize the plugins according to the configuration. 151 pluginType = namedtuple(
'pluginType',
'single multi')
157 for executionOrder, name, config, PluginClass
in sorted(self.config.plugins.apply()):
159 self.
executionDict[executionOrder] = pluginType(single=[], multi=[])
160 if PluginClass.getExecutionOrder() >= BasePlugin.DEFAULT_CATALOGCALCULATION:
163 if plug.plugType ==
'single':
165 elif plug.plugType ==
'multi':
168 errorTuple = (PluginClass, PluginClass.getExecutionOrder(),
169 BasePlugin.DEFAULT_CATALOGCALCULATION)
170 raise ValueError(
"{} has an execution order less than the minimum for an catalogCalculation " 171 "plugin. Value {} : Minimum {}".format(*errorTuple))
173 @lsst.pipe.base.timeMethod
176 The entry point for the catalogCalculation task. This method should be called with a reference to a 183 Run each of the plugins on the catalog 184 @param[in] catalog The catalog on which the plugins will operate 190 plug.calculate(catalog)
192 for measRecord
in catalog:
194 with
CCContext(plug, measRecord, self.log):
195 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...