262 """Initialize plugins (and slots) according to configuration.
267 Keyword arguments forwarded directly to plugin constructors.
271 Derived class constructors should call this method to fill the
272 `plugins` attribute and add corresponding output fields and slot
273 aliases to the output schema.
275 In addition to the attributes added by `BaseMeasurementTask.__init__`,
276 a ``schema``` attribute holding the output schema must be present
277 before this method is called.
279 Keyword arguments are forwarded directly to plugin constructors,
280 allowing derived classes to use plugins with different signatures.
286 if self.config.slots.centroid
is not None:
287 self.
plugins[self.config.slots.centroid] =
None
290 for executionOrder, name, config, PluginClass
in sorted(self.config.plugins.apply()):
293 if getattr(PluginClass,
"hasLogName",
False):
295 logName=self.log.getChild(name).name, **kwds)
302 if self.config.slots.centroid
is not None and self.
plugins[self.config.slots.centroid]
is None:
303 del self.
plugins[self.config.slots.centroid]
305 for executionOrder, name, config, PluginClass
in sorted(self.config.undeblended.apply()):
306 undeblendedName = self.config.undeblendedPrefix + name
307 if getattr(PluginClass,
"hasLogName",
False):
310 logName=self.log.getChild(undeblendedName).name,
316 if "schemaMapper" in kwds:
317 schema = kwds[
"schemaMapper"].editOutputSchema()
319 schema = kwds[
"schema"]
321 invalidPsfName =
"base_InvalidPsf_flag"
322 if invalidPsfName
in schema:
328 doc=
"Invalid PSF at this location.",
332 """Call ``measure`` on all plugins and consistently handle exceptions.
336 measRecord : `lsst.afw.table.SourceRecord`
337 The record corresponding to the object being measured. Will be
338 updated in-place with the results of measurement.
340 Positional arguments forwarded to ``plugin.measure``
342 Keyword arguments. Two are handled locally:
345 Beginning execution order (inclusive). Measurements with
346 ``executionOrder`` < ``beginOrder`` are not executed. `None`
350 Ending execution order (exclusive). Measurements with
351 ``executionOrder`` >= ``endOrder`` are not executed. `None`
354 Others are forwarded to ``plugin.measure()``.
358 This method can be used with plugins that have different signatures;
359 the only requirement is that ``measRecord`` be the first argument.
360 Subsequent positional arguments and keyword arguments are forwarded
361 directly to the plugin.
363 This method should be considered "protected": it is intended for use by
364 derived classes, not users.
366 beginOrder = kwds.pop(
"beginOrder",
None)
367 endOrder = kwds.pop(
"endOrder",
None)
368 for plugin
in self.
plugins.iter():
369 if beginOrder
is not None and plugin.getExecutionOrder() < beginOrder:
371 if endOrder
is not None and plugin.getExecutionOrder() >= endOrder:
376 """Call ``measure`` on the specified plugin.
378 Exceptions are handled in a consistent way.
382 plugin : subclass of `BasePlugin`
383 Plugin that will be executed.
384 measRecord : `lsst.afw.table.SourceRecord`
385 The record corresponding to the object being measured. Will be
386 updated in-place with the results of measurement.
388 Positional arguments forwarded to ``plugin.measure()``.
390 Keyword arguments forwarded to ``plugin.measure()``.
394 This method can be used with plugins that have different signatures;
395 the only requirement is that ``plugin`` and ``measRecord`` be the first
396 two arguments. Subsequent positional arguments and keyword arguments
397 are forwarded directly to the plugin.
399 This method should be considered "protected": it is intended for use by
400 derived classes, not users.
403 plugin.measure(measRecord, *args, **kwds)
404 except FATAL_EXCEPTIONS:
406 except MeasurementError
as error:
407 self.log.getChild(plugin.name).debug(
408 "MeasurementError in %s.measure on record %s: %s",
409 plugin.name, measRecord.getId(), error)
410 plugin.fail(measRecord, error)
411 except InvalidPsfError
as error:
412 self.log.getChild(plugin.name).debug(
413 "InvalidPsfError in %s.measure on record %s: %s",
414 plugin.name, measRecord.getId(), error)
416 plugin.fail(measRecord)
417 except Exception
as error:
418 self.log.getChild(plugin.name).
warning(
419 "Exception in %s.measure on record %s: %s",
420 plugin.name, measRecord.getId(), error)
421 plugin.fail(measRecord)
424 """Call ``measureN`` on all plugins and consistently handle exceptions.
428 measCat : `lsst.afw.table.SourceCatalog`
429 Catalog containing only the records for the source family to be
430 measured, and where outputs should be written.
432 Positional arguments forwarded to ``plugin.measure()``
434 Keyword arguments. Two are handled locally:
437 Beginning execution order (inclusive): Measurements with
438 ``executionOrder`` < ``beginOrder`` are not executed. `None`
441 Ending execution order (exclusive): measurements with
442 ``executionOrder`` >= ``endOrder`` are not executed. `None` for
445 Others are are forwarded to ``plugin.measure()``.
449 This method can be used with plugins that have different signatures;
450 the only requirement is that ``measRecord`` be the first argument.
451 Subsequent positional arguments and keyword arguments are forwarded
452 directly to the plugin.
454 This method should be considered "protected": it is intended for use by
455 derived classes, not users.
457 beginOrder = kwds.pop(
"beginOrder",
None)
458 endOrder = kwds.pop(
"endOrder",
None)
459 for plugin
in self.
plugins.iterN():
460 if beginOrder
is not None and plugin.getExecutionOrder() < beginOrder:
462 if endOrder
is not None and plugin.getExecutionOrder() >= endOrder:
467 """Call ``measureN`` on the specified plugin.
469 Exceptions are handled in a consistent way.
473 plugin : subclass of `BasePlugin`
474 Plugin that will be executed.
475 measCat : `lsst.afw.table.SourceCatalog`
476 Catalog containing only the records for the source family to be
477 measured, and where outputs should be written.
479 Positional arguments forwarded to ``plugin.measureN()``.
481 Keyword arguments forwarded to ``plugin.measureN()``.
485 This method can be used with plugins that have different signatures;
486 the only requirement is that the ``plugin`` and ``measCat`` be the
487 first two arguments. Subsequent positional arguments and keyword
488 arguments are forwarded directly to the plugin.
490 This method should be considered "protected": it is intended for use by
491 derived classes, not users.
494 plugin.measureN(measCat, *args, **kwds)
495 except FATAL_EXCEPTIONS:
498 except MeasurementError
as error:
499 self.log.getChild(plugin.name).debug(
500 "MeasurementError in %s.measureN on records %s-%s: %s",
501 plugin.name, measCat[0].getId(), measCat[-1].getId(), error)
502 for measRecord
in measCat:
503 plugin.fail(measRecord, error)
504 except InvalidPsfError
as error:
505 self.log.getChild(plugin.name).debug(
506 "InvalidPsfError in %s.measureN on records %s-%s: %s",
507 plugin.name, measCat[0].getId(), measCat[-1].getId(), error)
508 for measRecord
in measCat:
510 plugin.fail(measRecord, error)
511 except Exception
as error:
512 self.log.getChild(plugin.name).
warning(
513 "Exception in %s.measureN on records %s-%s: %s",
514 plugin.name, measCat[0].getId(), measCat[-1].getId(), error)
515 for measRecord
in measCat:
516 plugin.fail(measRecord)