3 from .base
import generateAlgorithmName
4 from .sfm
import SingleFramePlugin, SingleFramePluginConfig
5 from .forcedMeasurement
import ForcedPlugin, ForcedPluginConfig
7 __all__ = (
"wrapSingleFrameAlgorithm",
"wrapForcedAlgorithm",
"wrapSimpleAlgorithm")
12 def __init__(self, config, name, schema, metadata):
13 SingleFramePlugin.__init__(self, config, name, schema, metadata)
14 self.
cpp = self.factory(config, name, schema, metadata)
17 self.cpp.measure(measRecord, exposure)
20 self.cpp.measureN(measRecord, exposure)
22 def fail(self, measRecord, error=None):
23 self.cpp.fail(measRecord, error.cpp
if error
is not None else None)
28 def __init__(self, config, name, schemaMapper, metadata):
29 ForcedPlugin.__init__(self, config, name, schemaMapper, metadata)
30 self.
cpp = self.factory(config, name, schemaMapper, metadata)
32 def measure(self, measRecord, exposure, refRecord, refWcs):
33 self.cpp.measure(measRecord, exposure, refRecord, refWcs)
35 def measureN(self, measCat, exposure, refCat, refWcs):
36 self.cpp.measureN(measRecord, exposure, refCat, refWcs)
38 def fail(self, measRecord, error=None):
39 self.cpp.fail(measRecord, error.cpp
if error
is not None else None)
44 Wrap a C++ algorithm's control class into a Python Config class.
46 @param[in] Base Base class for the returned ConfigClass; one of SingleFramePluginConfig or
48 @param[in] Control Control class to be wrapped (a Swigged C++ class)
49 @param[in] hasMeasureN Whether the plugin supports fitting multiple objects at once (if so, a
50 config option to enable/disable this will be added).
51 @param[in] executionOrder If not None, an override for the default executionOrder for this plugin.
53 @return a new subclass of lsst.pex.config.Config
55 This function is generally only called by wrapAlgorithm; it is unlikely users will have to call it
64 Control.__name__.replace(
"Control",
"Config"),
66 {
"doMeasureN": lsst.pex.config.Field(dtype=bool, default=
True,
67 doc=
"whether to run this plugin in multi-object mode")}
69 ConfigClass = lsst.pex.config.makeConfigClass(Control, module=Control.__module__, cls=cls)
73 ConfigClass = lsst.pex.config.makeConfigClass(Control, module=Control.__module__, base=Base)
74 if executionOrder
is not None:
75 ConfigClass.executionOrder.default = float(executionOrder)
79 def wrapAlgorithm(Base, AlgClass, factory, name=None, Control=None, ConfigClass=None, doRegister=True,
82 Wrap a C++ Algorithm class into a Python Plugin class.
84 @param[in] Base Base class for the returned Plugin; one of SingleFramePlugin or
86 @param[in] AlgClass Swigged C++ Algorithm class to convert; must be a subclass of
87 SingleFrameAlgorithm or ForcedAlgorithm (matching the Base argument), or
88 an unrelated class with the same measure() and measureN() signatures as
90 @param[in] factory A callable that is used to construct an instance of AlgClass. It must take
91 four arguments, either (config, name, schema, metadata) or
92 (config, name, schemaMapper, metadata), depending on whether the algorithm is
93 single-frame or forced.
94 @param[in] name String to use when registering the algorithm. Ignored if doRegistry=False,
95 set to generateAlgorithmName(AlgClass) if None.
96 @param[in] Control Swigged C++ Control class for the algorithm; AlgClass.Control is used if None.
97 Ignored if ConfigClass is not None.
98 @param[in] ConfigClass Python Config class that wraps the C++ Algorithm's swigged Control class. If
99 None, wrapAlgorithmControl is called to generate a Config class using the
101 @param[in] doRegister If True (the default), register the plugin with Base's registry, allowing it
102 to be used by measurement Tasks.
103 @param[in] **kwds Additional keyword arguments passed to generateAlgorithmControl, including:
104 - hasMeasureN: Whether the plugin supports fitting multiple objects at once
105 (if so, a config option to enable/disable this will be added).
106 - executionOrder: If not None, an override for the default executionOrder for
107 this plugin (the default is 2.0, which is usually appropriate for fluxes).
109 @return the new Plugin class, a subclass of Base
111 This function is generally only called by the public wrapSingleFrameAlgorithm, wrapForcedAlgorithm, and
112 wrapSimpleAlgorithm functions; it is unlikely users will have to call it directly.
114 if ConfigClass
is None:
116 Control = AlgClass.Control
118 PluginClass = type(AlgClass.__name__ + Base.__name__, (Base,),
119 dict(AlgClass=AlgClass, ConfigClass=ConfigClass, factory=staticmethod(factory)))
123 Base.registry.register(name, PluginClass)
129 Wrap a C++ SingleFrameAlgorithm class into a Python SingleFramePlugin class.
131 @param[in] AlgClass Swigged C++ Algorithm class to convert; must be a subclass of
132 SingleFrameAlgorithm, or an unrelated class with the same measure(),
133 measureN(), and fail() signatures.
134 @param[in] name String to use when registering the algorithm. Ignored if doRegistry=False,
135 set to generateAlgorithmName(AlgClass) if None.
136 @param[in] needsMetadata Sets whether the AlgClass's constructor should be passed a PropertySet
138 @param[in] hasMeasureN Whether the algorithm supports simultaneous measurement of multiple sources.
139 If True, a bool doMeasureN field will be added to the generated Config class,
140 and its value will be passed as the last argument when calling the AlgClass
142 @param[in] **kwds Additional keyword arguments passed to the lower-level wrapAlgorithm and
143 wrapAlgorithmControl classes. These include:
144 - Control: Swigged C++ Control class for the algorithm; AlgClass.Control
145 is used if None. Ignored if ConfigClass is not None.
146 - ConfigClass: Python Config class that wraps the C++ Algorithm's swigged
147 Control class. If None, wrapAlgorithmControl is called to generate a
148 Config class using the Control argument.
149 - doRegister: If True (the default), register the plugin with
150 SingleFramePlugin.registry, allowing it to be used by
151 SingleFrameMeasurementTask.
152 - executionOrder: If not None, an override for the default executionOrder for
153 this plugin (the default is 2.0, which is usually appropriate for fluxes).
155 @return the new SingleFramePlugin subclass
157 The needsMetadata and hasMeasureN arguments combine to determine the expected constructor signature;
158 we always expect the first three arguments to be:
160 Control const & ctrl, std::string const & name, Schema & schema
162 If needsMetadata, we also append:
164 PropertySet & metadata
166 If hasMeasureN, we also append:
170 If both are True, the metadata PropertySet precedes the doMeasureN bool.
174 def factory(config, name, schema, metadata):
175 return AlgClass(config.makeControl(), name, schema, metadata, config.doMeasureN)
177 def factory(config, name, schema, metadata):
178 return AlgClass(config.makeControl(), name, schema, config.doMeasureN)
181 def factory(config, name, schema, metadata):
182 return AlgClass(config.makeControl(), name, schema, metadata)
184 def factory(config, name, schema, metadata):
185 return AlgClass(config.makeControl(), name, schema)
186 return wrapAlgorithm(WrappedSingleFramePlugin, AlgClass, factory=factory,
187 hasMeasureN=hasMeasureN, **kwds)
190 def wrapForcedAlgorithm(AlgClass, name=None, needsMetadata=False, hasMeasureN=False, needsSchemaOnly=False,
193 Wrap a C++ ForcedAlgorithm class into a Python ForcedPlugin class.
195 @param[in] AlgClass Swigged C++ Algorithm class to convert; must be a subclass of
196 ForcedAlgorithm, or an unrelated class with the same measure(), measureN(),
197 and fail() signatures.
198 @param[in] name String to use when registering the algorithm. Ignored if doRegistry=False,
199 set to generateAlgorithmName(AlgClass) if None.
200 @param[in] needsMetadata Sets whether the AlgClass's constructor should be passed a PropertySet
202 @param[in] hasMeasureN Whether the algorithm supports simultaneous measurement of multiple sources.
203 If True, a bool doMeasureN field will be added to the generated Config class,
204 and its value will be passed as the last argument when calling the AlgClass
206 @param[in] needsSchemaOnly Whether the algorithm constructor expects a Schema argument (representing the
207 output Schema) rather than the full SchemaMapper (which provides access to
208 both the reference Schema and the output Schema).
209 @param[in] **kwds Additional keyword arguments passed to the lower-level wrapAlgorithm and
210 wrapAlgorithmControl classes. These include:
211 - Control: Swigged C++ Control class for the algorithm; AlgClass.Control
212 is used if None. Ignored if ConfigClass is not None.
213 - ConfigClass: Python Config class that wraps the C++ Algorithm's swigged
214 Control class. If None, wrapAlgorithmControl is called to generate a
215 Config class using the Control argument.
216 - doRegister: If True (the default), register the plugin with
217 ForcedPlugin.registry, allowing it to be used by ForcedMeasurementTask.
218 - executionOrder: If not None, an override for the default executionOrder for
219 this plugin (the default is 2.0, which is usually appropriate for fluxes).
221 @return the new ForcedPlugin subclass
223 The needsMetadata, hasMeasureN, and needsSchemaOnly arguments combine to determine the expected
224 constructor signature; we always expect the first two arguments to be:
226 Control const & ctrl, std::string const & name
228 If needsSchemaOnly is True, then the third argument will be
232 otherwise, it will be:
234 SchemaMapper & schemaMapper
236 If needsMetadata, we also append:
238 PropertySet & metadata
240 If hasMeasureN, we also append:
244 If both are True, the metadata PropertySet precedes the doMeasureN bool.
247 extractSchemaArg =
lambda m: m.editOutputSchema()
249 extractSchemaArg =
lambda m: m
252 def factory(config, name, schemaMapper, metadata):
253 return AlgClass(config.makeControl(), name, extractSchemaArg(schemaMapper),
254 metadata, config.doMeasureN)
256 def factory(config, name, schemaMapper, metadata):
257 return AlgClass(config.makeControl(), name, extractSchemaArg(schemaMapper),
261 def factory(config, name, schemaMapper, metadata):
262 return AlgClass(config.makeControl(), name, extractSchemaArg(schemaMapper),
265 def factory(config, name, schemaMapper, metadata):
266 return AlgClass(config.makeControl(), name, extractSchemaArg(schemaMapper))
267 return wrapAlgorithm(WrappedForcedPlugin, AlgClass, factory=factory, **kwds)
272 Wrap a C++ SimpleAlgorithm class into both a Python SingleFramePlugin and ForcedPlugin classes
274 @param[in] AlgClass Swigged C++ Algorithm class to convert; must be a subclass of
275 simpleAlgorithm, or an unrelated class with the same measure(), measureN(),
276 and fail() signatures.
277 @param[in] name String to use when registering the algorithm. Ignored if doRegistry=False,
278 set to generateAlgorithmName(AlgClass) if None.
279 @param[in] needsMetadata Sets whether the AlgClass's constructor should be passed a PropertySet
281 @param[in] hasMeasureN Whether the algorithm supports simultaneous measurement of multiple sources.
282 If True, a bool doMeasureN field will be added to the generated Config class,
283 and its value will be passed as the last argument when calling the AlgClass
285 @param[in] **kwds Additional keyword arguments passed to the lower-level wrapAlgorithm and
286 wrapAlgorithmControl classes. These include:
287 - Control: Swigged C++ Control class for the algorithm; AlgClass.Control
288 is used if None. Ignored if ConfigClass is not None.
289 - ConfigClass: Python Config class that wraps the C++ Algorithm's swigged
290 Control class. If None, wrapAlgorithmControl is called to generate a
291 Config class using the Control argument.
292 - doRegister: If True (the default), register the plugins with Base's
293 registry, allowing it to be used by measurement Tasks.
294 - executionOrder: If not None, an override for the default executionOrder for
295 this plugin (the default is 2.0, which is usually appropriate for fluxes).
297 @return a two-element tuple, containing the new SingleFramePlugin and ForcedPlugin subclasses
299 The needsMetadata and hasMeasureN arguments combine to determine the expected constructor signature;
300 we always expect the first three arguments to be:
302 Control const & ctrl, std::string const & name, Schema & schema
304 If needsMetadata, we also append:
306 PropertySet & metadata
308 If hasMeasureN, we also append:
312 If both are True, the metadata PropertySet precedes the doMeasureN bool.
316 needsSchemaOnly=
True, **kwds))
def wrapSingleFrameAlgorithm
Wrap a C++ SingleFrameAlgorithm class into a Python SingleFramePlugin class.
def generateAlgorithmName
def wrapAlgorithm
Wrap a C++ Algorithm class into a Python Plugin class.
def wrapAlgorithmControl
Wrap a C++ algorithm's control class into a Python Config class.
def wrapForcedAlgorithm
Wrap a C++ ForcedAlgorithm class into a Python ForcedPlugin class.
def wrapSimpleAlgorithm
Wrap a C++ SimpleAlgorithm class into both a Python SingleFramePlugin and ForcedPlugin classes...