23 """Registry for measurement plugins and associated utilities generateAlgorithmName and PluginMap 29 from .apCorrRegistry
import addApCorrName
31 __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(
".")
47 if len(terms) > 1
and terms[-1].startswith(
"_"):
49 if len(terms) > 1
and terms[-1].endswith(
"Lib"):
51 if terms[0] ==
"lsst":
53 if terms[0] ==
"meas":
55 if name.lower().startswith(terms[-1].lower()):
57 return "%s_%s" % (
"_".join(terms), name)
62 Base class for plugin registries 64 The Plugin class allowed in the registry is defined in the ctor of the registry. 66 Single-frame and forced plugins have different registries. 71 Class used as the actual element in the registry 73 Rather than constructing a Plugin instance, its __call__ method 74 (invoked by RegistryField.apply) returns a tuple 75 of (executionOrder, name, config, PluginClass), which can then 76 be sorted before the plugins are instantiated. 79 __slots__ =
"PluginClass",
"name" 83 Create a Configurable object for the given PluginClass and name 95 def register(self, name, PluginClass, shouldApCorr=False, apCorrList=()):
97 Register a Plugin class with the given name. 99 The same Plugin may be registered multiple times with different names; this can 100 be useful if we often want to run it multiple times with different configuration. 102 @param[in] name name of plugin class. This is used as a prefix for all fields produced by the Plugin, 103 and it should generally contain the name of the Plugin or Algorithm class itself 104 as well as enough of the namespace to make it clear where to find the code. 105 For example "base_GaussianFlux" indicates an algorithm in meas_base 106 that measures Gaussian Flux and produces fields such as "base_GaussianFlux_flux", 107 "base_GaussianFlux_fluxErr" and "base_GaussianFlux_flag". 108 @param[in] shouldApCorr if True then this algorithm measures a flux that should be aperture 109 corrected. This is shorthand for apCorrList=[name] and is ignored if apCorrList is specified. 110 @param[in] apCorrList list of field name prefixes for flux fields that should be aperture corrected. 111 If an algorithm produces a single flux that should be aperture corrected then it is simpler 112 to set shouldApCorr=True. But if an algorithm produces multiple such fields then it must 113 specify apCorrList, instead. For example modelfit_CModel produces 3 such fields: 114 apCorrList=("modelfit_CModel_exp", "modelfit_CModel_exp", "modelfit_CModel_def") 115 If apCorrList is non-empty then shouldApCorr is ignored. 117 lsst.pex.config.Registry.register(self, name, self.
Configurable(name, PluginClass))
118 if shouldApCorr
and not apCorrList:
120 for prefix
in apCorrList:
123 def makeField(self, doc, default=None, optional=False, multi=False):
124 return lsst.pex.config.RegistryField(doc, self, default, optional, multi)
127 def register(name, shouldApCorr=False, apCorrList=()):
129 A Python decorator that registers a class, using the given name, in its base class's PluginRegistry. 132 @register("base_TransformedCentroid") 133 class ForcedTransformedCentroidPlugin(ForcedPlugin): 138 class ForcedTransformedCentroidPlugin(ForcedPlugin): 140 @ForcedPlugin.registry.register("base_TransformedCentroid", ForcedTransformedCentroidPlugin) 143 def decorate(PluginClass):
144 PluginClass.registry.register(name, PluginClass, shouldApCorr=shouldApCorr, apCorrList=apCorrList)
151 Map of plugins (instances of subclasses of BasePlugin) to be run for a task 153 We assume plugins are added to the PluginMap according to their "Execution Order", so this 154 class doesn't actually do any of the sorting (though it does have to maintain that order, 155 which it does by inheriting from OrderedDict). 159 """!Return an iterator over plugins for which plugin.config.doMeasure is true 161 @note plugin.config.doMeasure is usually a simple boolean class attribute, not a normal Config field. 163 for plugin
in self.values():
164 if plugin.config.doMeasure:
168 """!Return an iterator over plugins for which plugin.config.doMeasureN is true 170 @note plugin.config.doMeasureN is usually a simple boolean class attribute, not a normal Config field. 172 for plugin
in self.values():
173 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.