23 """Registry for measurement plugins and associated utilities generateAlgorithmName and PluginMap
30 from .apCorrRegistry
import addApCorrName
32 __all__ = (
"generateAlgorithmName",
"PluginRegistry",
"register",
"PluginMap")
35 """Generate a string name for an algorithm class that strips away terms that are generally redundant
36 while (hopefully) remaining easy to trace to the code.
38 The returned name will cobmine the package name, with any "lsst" and/or "meas" prefix removed,
39 with the class name, with any "Algorithm" suffix removed. For instance,
40 lsst.meas.base.SdssShapeAlgorithm becomes "base_SdssShape".
42 name = AlgClass.__name__
43 pkg = AlgClass.__module__
44 name = name.replace(
"Algorithm",
"")
45 terms = pkg.split(
".")
46 if terms[-1].endswith(
"Lib"):
48 if terms[0] ==
"lsst":
50 if terms[0] ==
"meas":
52 if name.lower().startswith(terms[-1].lower()):
54 return "%s_%s" % (
"_".join(terms), name)
58 Base class for plugin registries
60 The Plugin class allowed in the registry is defined in the ctor of the registry.
62 Single-frame and forced plugins have different registries.
67 Class used as the actual element in the registry
69 Rather than constructing a Plugin instance, its __call__ method
70 (invoked by RegistryField.apply) returns a tuple
71 of (executionOrder, name, config, PluginClass), which can then
72 be sorted before the plugins are instantiated.
75 __slots__ =
"PluginClass",
"name"
79 Create a Configurable object for the given PluginClass and name
88 return (self.PluginClass.getExecutionOrder(), self.
name, config, self.
PluginClass)
90 def register(self, name, PluginClass, shouldApCorr=False, apCorrList=()):
92 Register a Plugin class with the given name.
94 The same Plugin may be registered multiple times with different names; this can
95 be useful if we often want to run it multiple times with different configuration.
97 @param[in] name name of plugin class. This is used as a prefix for all fields produced by the Plugin,
98 and it should generally contain the name of the Plugin or Algorithm class itself
99 as well as enough of the namespace to make it clear where to find the code.
100 For example "base_GaussianFlux" indicates an algorithm in meas_base
101 that measures Gaussian Flux and produces fields such as "base_GaussianFlux_flux",
102 "base_GaussianFlux_fluxSigma" and "base_GaussianFlux_flag".
103 @param[in] shouldApCorr if True then this algorithm measures a flux that should be aperture
104 corrected. This is shorthand for apCorrList=[name] and is ignored if apCorrList is specified.
105 @param[in] apCorrList list of field name prefixes for flux fields that should be aperture corrected.
106 If an algorithm produces a single flux that should be aperture corrected then it is simpler
107 to set shouldApCorr=True. But if an algorithm produces multiple such fields then it must
108 specify apCorrList, instead. For example modelfit_CModel produces 3 such fields:
109 apCorrList=("modelfit_CModel_exp", "modelfit_CModel_exp", "modelfit_CModel_def")
110 If apCorrList is non-empty then shouldApCorr is ignored.
112 lsst.pex.config.Registry.register(self, name, self.
Configurable(name, PluginClass))
113 if shouldApCorr
and not apCorrList:
115 for prefix
in apCorrList:
118 def makeField(self, doc, default=None, optional=False, multi=False):
119 return lsst.pex.config.RegistryField(doc, self, default, optional, multi)
124 A Python decorator that registers a class, using the given name, in its base class's PluginRegistry.
127 @register("base_TransformedCentroid")
128 class ForcedTransformedCentroidPlugin(ForcedPlugin):
133 class ForcedTransformedCentroidPlugin(ForcedPlugin):
135 @ForcedPlugin.registry.register("base_TransformedCentroid", ForcedTransformedCentroidPlugin)
138 def decorate(PluginClass):
139 PluginClass.registry.register(name, PluginClass, shouldApCorr=shouldApCorr)
146 Map of plugins (instances of subclasses of BasePlugin) to be run for a task
148 We assume plugins are added to the PluginMap according to their "Execution Order", so this
149 class doesn't actually do any of the sorting (though it does have to maintain that order,
150 which it does by inheriting from OrderedDict).
154 """!Return an iterator over plugins for which plugin.config.doMeasure is true
156 @note plugin.config.doMeasure is usually a simple boolean class attribute, not a normal Config field.
158 for plugin
in self.itervalues():
159 if plugin.config.doMeasure:
163 """!Return an iterator over plugins for which plugin.config.doMeasureN is true
165 @note plugin.config.doMeasureN is usually a simple boolean class attribute, not a normal Config field.
167 for plugin
in self.itervalues():
168 if plugin.config.doMeasureN:
def __init__
Create a Configurable object for the given PluginClass and name.
Class used as the actual element in the registry.
Base class for plugin registries.
def generateAlgorithmName
def iter
Return an iterator over plugins for which plugin.config.doMeasure is true.
def register
Register a Plugin class with the given name.
def register
A Python decorator that registers a class, using the given name, in its base class's PluginRegistry...
def addApCorrName
Add to the set of field name prefixes for fluxes that should be aperture corrected.
Map of plugins (instances of subclasses of BasePlugin) to be run for a task.
def iterN
Return an iterator over plugins for which plugin.config.doMeasureN is true.