275 """Initialize plugins (and slots) according to configuration.
280 Keyword arguments forwarded directly to plugin constructors.
284 Derived class constructors should call this method to fill the
285 `plugins` attribute and add corresponding output fields and slot
286 aliases to the output schema.
288 In addition to the attributes added by `BaseMeasurementTask.__init__`,
289 a ``schema``` attribute holding the output schema must be present
290 before this method is called.
292 Keyword arguments are forwarded directly to plugin constructors,
293 allowing derived classes to use plugins with different signatures.
299 if self.config.slots.centroid
is not None:
300 self.
plugins[self.config.slots.centroid] =
None
303 for executionOrder, name, config, PluginClass
in sorted(self.config.plugins.apply()):
306 if getattr(PluginClass,
"hasLogName",
False):
308 logName=self.log.getChild(name).name, **kwds)
315 if self.config.slots.centroid
is not None and self.
plugins[self.config.slots.centroid]
is None:
316 del self.
plugins[self.config.slots.centroid]
318 for executionOrder, name, config, PluginClass
in sorted(self.config.undeblended.apply()):
319 undeblendedName = self.config.undeblendedPrefix + name
320 if getattr(PluginClass,
"hasLogName",
False):
323 logName=self.log.getChild(undeblendedName).name,
329 if "schemaMapper" in kwds:
330 schema = kwds[
"schemaMapper"].editOutputSchema()
332 schema = kwds[
"schema"]
334 invalidPsfName =
"base_InvalidPsf_flag"
335 if invalidPsfName
in schema:
341 doc=
"Invalid PSF at this location.",
345 """Call ``measure`` on all plugins and consistently handle exceptions.
349 measRecord : `lsst.afw.table.SourceRecord`
350 The record corresponding to the object being measured. Will be
351 updated in-place with the results of measurement.
353 Positional arguments forwarded to ``plugin.measure``
355 Keyword arguments. Two are handled locally:
358 Beginning execution order (inclusive). Measurements with
359 ``executionOrder`` < ``beginOrder`` are not executed. `None`
363 Ending execution order (exclusive). Measurements with
364 ``executionOrder`` >= ``endOrder`` are not executed. `None`
367 Others are forwarded to ``plugin.measure()``.
371 This method can be used with plugins that have different signatures;
372 the only requirement is that ``measRecord`` be the first argument.
373 Subsequent positional arguments and keyword arguments are forwarded
374 directly to the plugin.
376 This method should be considered "protected": it is intended for use by
377 derived classes, not users.
379 beginOrder = kwds.pop(
"beginOrder",
None)
380 endOrder = kwds.pop(
"endOrder",
None)
381 for plugin
in self.
plugins.iter():
382 if beginOrder
is not None and plugin.getExecutionOrder() < beginOrder:
384 if endOrder
is not None and plugin.getExecutionOrder() >= endOrder:
389 """Call ``measure`` on the specified plugin.
391 Exceptions are handled in a consistent way.
395 plugin : subclass of `BasePlugin`
396 Plugin that will be executed.
397 measRecord : `lsst.afw.table.SourceRecord`
398 The record corresponding to the object being measured. Will be
399 updated in-place with the results of measurement.
401 Positional arguments forwarded to ``plugin.measure()``.
403 Keyword arguments forwarded to ``plugin.measure()``.
407 This method can be used with plugins that have different signatures;
408 the only requirement is that ``plugin`` and ``measRecord`` be the first
409 two arguments. Subsequent positional arguments and keyword arguments
410 are forwarded directly to the plugin.
412 This method should be considered "protected": it is intended for use by
413 derived classes, not users.
416 plugin.measure(measRecord, *args, **kwds)
417 except FATAL_EXCEPTIONS:
419 except MeasurementError
as error:
420 self.log.getChild(plugin.name).debug(
421 "MeasurementError in %s.measure on record %s: %s",
422 plugin.name, measRecord.getId(), error)
423 plugin.fail(measRecord, error)
424 except InvalidPsfError
as error:
425 self.log.getChild(plugin.name).debug(
426 "InvalidPsfError in %s.measure on record %s: %s",
427 plugin.name, measRecord.getId(), error)
429 plugin.fail(measRecord)
430 except Exception
as error:
431 self.log.getChild(plugin.name).warning(
432 "Exception in %s.measure on record %s: %s",
433 plugin.name, measRecord.getId(), error)
434 plugin.fail(measRecord)
437 """Call ``measureN`` on all plugins and consistently handle exceptions.
441 measCat : `lsst.afw.table.SourceCatalog`
442 Catalog containing only the records for the source family to be
443 measured, and where outputs should be written.
445 Positional arguments forwarded to ``plugin.measure()``
447 Keyword arguments. Two are handled locally:
450 Beginning execution order (inclusive): Measurements with
451 ``executionOrder`` < ``beginOrder`` are not executed. `None`
454 Ending execution order (exclusive): measurements with
455 ``executionOrder`` >= ``endOrder`` are not executed. `None` for
458 Others are are forwarded to ``plugin.measure()``.
462 This method can be used with plugins that have different signatures;
463 the only requirement is that ``measRecord`` be the first argument.
464 Subsequent positional arguments and keyword arguments are forwarded
465 directly to the plugin.
467 This method should be considered "protected": it is intended for use by
468 derived classes, not users.
470 beginOrder = kwds.pop(
"beginOrder",
None)
471 endOrder = kwds.pop(
"endOrder",
None)
472 for plugin
in self.
plugins.iterN():
473 if beginOrder
is not None and plugin.getExecutionOrder() < beginOrder:
475 if endOrder
is not None and plugin.getExecutionOrder() >= endOrder:
480 """Call ``measureN`` on the specified plugin.
482 Exceptions are handled in a consistent way.
486 plugin : subclass of `BasePlugin`
487 Plugin that will be executed.
488 measCat : `lsst.afw.table.SourceCatalog`
489 Catalog containing only the records for the source family to be
490 measured, and where outputs should be written.
492 Positional arguments forwarded to ``plugin.measureN()``.
494 Keyword arguments forwarded to ``plugin.measureN()``.
498 This method can be used with plugins that have different signatures;
499 the only requirement is that the ``plugin`` and ``measCat`` be the
500 first two arguments. Subsequent positional arguments and keyword
501 arguments are forwarded directly to the plugin.
503 This method should be considered "protected": it is intended for use by
504 derived classes, not users.
507 plugin.measureN(measCat, *args, **kwds)
508 except FATAL_EXCEPTIONS:
511 except MeasurementError
as error:
512 self.log.getChild(plugin.name).debug(
513 "MeasurementError 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, error)
517 except InvalidPsfError
as error:
518 self.log.getChild(plugin.name).debug(
519 "InvalidPsfError in %s.measureN on records %s-%s: %s",
520 plugin.name, measCat[0].getId(), measCat[-1].getId(), error)
521 for measRecord
in measCat:
523 plugin.fail(measRecord, error)
524 except Exception
as error:
525 self.log.getChild(plugin.name).warning(
526 "Exception in %s.measureN on records %s-%s: %s",
527 plugin.name, measCat[0].getId(), measCat[-1].getId(), error)
528 for measRecord
in measCat:
529 plugin.fail(measRecord)