23 """Registry for measurement plugins and associated utilities generateAlgorithmName and PluginMap 27 from builtins
import object
31 from .apCorrRegistry
import addApCorrName
33 __all__ = (
"generateAlgorithmName",
"PluginRegistry",
"register",
"PluginMap")
37 """Generate a string name for an algorithm class that strips away terms that are generally redundant 38 while (hopefully) remaining easy to trace to the code. 40 The returned name will cobmine the package name, with any "lsst" and/or "meas" prefix removed, 41 with the class name, with any "Algorithm" suffix removed. For instance, 42 lsst.meas.base.SdssShapeAlgorithm becomes "base_SdssShape". 44 name = AlgClass.__name__
45 pkg = AlgClass.__module__
46 name = name.replace(
"Algorithm",
"")
47 terms = pkg.split(
".")
49 if len(terms) > 1
and terms[-1].startswith(
"_"):
51 if len(terms) > 1
and terms[-1].endswith(
"Lib"):
53 if terms[0] ==
"lsst":
55 if terms[0] ==
"meas":
57 if name.lower().startswith(terms[-1].lower()):
59 return "%s_%s" % (
"_".join(terms), name)
64 Base class for plugin registries 66 The Plugin class allowed in the registry is defined in the ctor of the registry. 68 Single-frame and forced plugins have different registries. 73 Class used as the actual element in the registry 75 Rather than constructing a Plugin instance, its __call__ method 76 (invoked by RegistryField.apply) returns a tuple 77 of (executionOrder, name, config, PluginClass), which can then 78 be sorted before the plugins are instantiated. 81 __slots__ =
"PluginClass",
"name" 85 Create a Configurable object for the given PluginClass and name 97 def register(self, name, PluginClass, shouldApCorr=False, apCorrList=()):
99 Register a Plugin class with the given name. 101 The same Plugin may be registered multiple times with different names; this can 102 be useful if we often want to run it multiple times with different configuration. 104 @param[in] name name of plugin class. This is used as a prefix for all fields produced by the Plugin, 105 and it should generally contain the name of the Plugin or Algorithm class itself 106 as well as enough of the namespace to make it clear where to find the code. 107 For example "base_GaussianFlux" indicates an algorithm in meas_base 108 that measures Gaussian Flux and produces fields such as "base_GaussianFlux_flux", 109 "base_GaussianFlux_fluxSigma" and "base_GaussianFlux_flag". 110 @param[in] shouldApCorr if True then this algorithm measures a flux that should be aperture 111 corrected. This is shorthand for apCorrList=[name] and is ignored if apCorrList is specified. 112 @param[in] apCorrList list of field name prefixes for flux fields that should be aperture corrected. 113 If an algorithm produces a single flux that should be aperture corrected then it is simpler 114 to set shouldApCorr=True. But if an algorithm produces multiple such fields then it must 115 specify apCorrList, instead. For example modelfit_CModel produces 3 such fields: 116 apCorrList=("modelfit_CModel_exp", "modelfit_CModel_exp", "modelfit_CModel_def") 117 If apCorrList is non-empty then shouldApCorr is ignored. 119 lsst.pex.config.Registry.register(self, name, self.
Configurable(name, PluginClass))
120 if shouldApCorr
and not apCorrList:
122 for prefix
in apCorrList:
125 def makeField(self, doc, default=None, optional=False, multi=False):
126 return lsst.pex.config.RegistryField(doc, self, default, optional, multi)
129 def register(name, shouldApCorr=False, apCorrList=()):
131 A Python decorator that registers a class, using the given name, in its base class's PluginRegistry. 134 @register("base_TransformedCentroid") 135 class ForcedTransformedCentroidPlugin(ForcedPlugin): 140 class ForcedTransformedCentroidPlugin(ForcedPlugin): 142 @ForcedPlugin.registry.register("base_TransformedCentroid", ForcedTransformedCentroidPlugin) 145 def decorate(PluginClass):
146 PluginClass.registry.register(name, PluginClass, shouldApCorr=shouldApCorr, apCorrList=apCorrList)
153 Map of plugins (instances of subclasses of BasePlugin) to be run for a task 155 We assume plugins are added to the PluginMap according to their "Execution Order", so this 156 class doesn't actually do any of the sorting (though it does have to maintain that order, 157 which it does by inheriting from OrderedDict). 161 """!Return an iterator over plugins for which plugin.config.doMeasure is true 163 @note plugin.config.doMeasure is usually a simple boolean class attribute, not a normal Config field. 165 for plugin
in self.values():
166 if plugin.config.doMeasure:
170 """!Return an iterator over plugins for which plugin.config.doMeasureN is true 172 @note plugin.config.doMeasureN is usually a simple boolean class attribute, not a normal Config field. 174 for plugin
in self.values():
175 if plugin.config.doMeasureN:
def generateAlgorithmName(AlgClass)
def makeField(self, doc, default=None, optional=False, multi=False)
def addApCorrName(name)
Add to the set of field name prefixes for fluxes that should be aperture corrected.
Class used as the actual element in the registry.
def register(name, shouldApCorr=False, apCorrList=())
A Python decorator that registers a class, using the given name, in its base class's PluginRegistry...
Base class for plugin registries.
def __call__(self, config)
def iter(self)
Return an iterator over plugins for which plugin.config.doMeasure is true.
Map of plugins (instances of subclasses of BasePlugin) to be run for a task.
def register(self, name, PluginClass, shouldApCorr=False, apCorrList=())
Register a Plugin class with the given name.
def iterN(self)
Return an iterator over plugins for which plugin.config.doMeasureN is true.
def __init__(self, name, PluginClass)
Create a Configurable object for the given PluginClass and name.