LSST Applications g04c3c9f7ca+2075667efa,g1e125bf412+5f448d5fcf,g2079a07aa2+3e9fd84d81,g2305ad1205+b635cf1488,g2bbee38e9b+6c6beb4891,g337abbeb29+6c6beb4891,g33d1c0ed96+6c6beb4891,g3a166c0a6a+6c6beb4891,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+42f171e1e6,g5c3423f6d4+d536b04327,g607f77f49a+d536b04327,g6f43f06aed+ca1339dc19,g858d7b2824+d536b04327,g8ee334c5b4+d7f9608c2f,g9963eaa53e+b3dc1655d3,g998f4353bf+d536b04327,g99cad8db69+8ef2408349,g9ddcbc5298+9a081db1e4,ga1e77700b3+2cbb763275,gadfd92a7e4+aec2f3b930,gae0086650b+585e252eca,gb0e22166c9+0e73c8378f,gb3b7280ab2+cb5fdb229e,gbb8dafda3b+a327199e22,gc120e1dc64+88074880ea,gc28159a63d+6c6beb4891,gcdd4ae20e8+bd241b2308,gcde1bda545+903e937d91,gcf0d15dbbd+bd241b2308,gdaeeff99f8+f9a426f77a,gddc38dedce+585e252eca,ge79ae78c31+6c6beb4891,gfbcc870c63+b310236976,w.2024.23
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Static Protected Attributes | List of all members
lsst.meas.base.baseMeasurement.BaseMeasurementTask Class Reference
Inheritance diagram for lsst.meas.base.baseMeasurement.BaseMeasurementTask:
lsst.meas.base.forcedMeasurement.ForcedMeasurementTask lsst.meas.base.sfm.SingleFrameMeasurementTask lsst.ip.diffim.dipoleMeasurement.DipoleMeasurementTask

Public Member Functions

 __init__ (self, algMetadata=None, **kwds)
 
 initializePlugins (self, **kwds)
 
 callMeasure (self, measRecord, *args, **kwds)
 
 doMeasurement (self, plugin, measRecord, *args, **kwds)
 
 callMeasureN (self, measCat, *args, **kwds)
 
 doMeasurementN (self, plugin, measCat, *args, **kwds)
 

Static Public Member Functions

 getFootprintsFromCatalog (catalog)
 

Public Attributes

 undeblendedPlugins
 
 keyInvalidPsf
 

Static Public Attributes

 ConfigClass = BaseMeasurementConfig
 
 plugins = None
 
 algMetadata = None
 

Static Protected Attributes

str _DefaultName = "measurement"
 

Detailed Description

Ultimate base class for all measurement tasks.

Parameters
----------
algMetadata : `lsst.daf.base.PropertyList` or `None`
    Will be modified in-place to contain metadata about the plugins being
    run. If `None`, an empty `~lsst.daf.base.PropertyList` will be
    created.
**kwds
    Additional arguments passed to `lsst.pipe.base.Task.__init__`.

Notes
-----
This base class for `SingleFrameMeasurementTask` and
`ForcedMeasurementTask` mostly exists to share code between the two, and
generally should not be used directly.

Definition at line 217 of file baseMeasurement.py.

Constructor & Destructor Documentation

◆ __init__()

lsst.meas.base.baseMeasurement.BaseMeasurementTask.__init__ ( self,
algMetadata = None,
** kwds )

Reimplemented in lsst.meas.base.forcedMeasurement.ForcedMeasurementTask, and lsst.meas.base.sfm.SingleFrameMeasurementTask.

Definition at line 253 of file baseMeasurement.py.

253 def __init__(self, algMetadata=None, **kwds):
254 super(BaseMeasurementTask, self).__init__(**kwds)
255 self.plugins = PluginMap()
256 self.undeblendedPlugins = PluginMap()
257 if algMetadata is None:
258 algMetadata = lsst.daf.base.PropertyList()
259 self.algMetadata = algMetadata
260
Class for storing ordered metadata with comments.

Member Function Documentation

◆ callMeasure()

lsst.meas.base.baseMeasurement.BaseMeasurementTask.callMeasure ( self,
measRecord,
* args,
** kwds )
Call ``measure`` on all plugins and consistently handle exceptions.

Parameters
----------
measRecord : `lsst.afw.table.SourceRecord`
    The record corresponding to the object being measured. Will be
    updated in-place with the results of measurement.
*args
    Positional arguments forwarded to ``plugin.measure``
**kwds
    Keyword arguments. Two are handled locally:

    beginOrder : `int`
        Beginning execution order (inclusive). Measurements with
        ``executionOrder`` < ``beginOrder`` are not executed. `None`
        for no limit.

    endOrder : `int`
        Ending execution order (exclusive). Measurements with
        ``executionOrder`` >= ``endOrder`` are not executed. `None`
        for no limit.

    Others are forwarded to ``plugin.measure()``.

Notes
-----
This method can be used with plugins that have different signatures;
the only requirement is that ``measRecord`` be the first argument.
Subsequent positional arguments and keyword arguments are forwarded
directly to the plugin.

This method should be considered "protected": it is intended for use by
derived classes, not users.

Definition at line 331 of file baseMeasurement.py.

331 def callMeasure(self, measRecord, *args, **kwds):
332 """Call ``measure`` on all plugins and consistently handle exceptions.
333
334 Parameters
335 ----------
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.
339 *args
340 Positional arguments forwarded to ``plugin.measure``
341 **kwds
342 Keyword arguments. Two are handled locally:
343
344 beginOrder : `int`
345 Beginning execution order (inclusive). Measurements with
346 ``executionOrder`` < ``beginOrder`` are not executed. `None`
347 for no limit.
348
349 endOrder : `int`
350 Ending execution order (exclusive). Measurements with
351 ``executionOrder`` >= ``endOrder`` are not executed. `None`
352 for no limit.
353
354 Others are forwarded to ``plugin.measure()``.
355
356 Notes
357 -----
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.
362
363 This method should be considered "protected": it is intended for use by
364 derived classes, not users.
365 """
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:
370 continue
371 if endOrder is not None and plugin.getExecutionOrder() >= endOrder:
372 break
373 self.doMeasurement(plugin, measRecord, *args, **kwds)
374

◆ callMeasureN()

lsst.meas.base.baseMeasurement.BaseMeasurementTask.callMeasureN ( self,
measCat,
* args,
** kwds )
Call ``measureN`` on all plugins and consistently handle exceptions.

Parameters
----------
measCat : `lsst.afw.table.SourceCatalog`
    Catalog containing only the records for the source family to be
    measured, and where outputs should be written.
*args
    Positional arguments forwarded to ``plugin.measure()``
**kwds
    Keyword arguments. Two are handled locally:

    beginOrder:
        Beginning execution order (inclusive): Measurements with
        ``executionOrder`` < ``beginOrder`` are not executed. `None`
        for no limit.
    endOrder:
        Ending execution order (exclusive): measurements with
        ``executionOrder`` >= ``endOrder`` are not executed. `None` for
        no ``limit``.

    Others are are forwarded to ``plugin.measure()``.

Notes
-----
This method can be used with plugins that have different signatures;
the only requirement is that ``measRecord`` be the first argument.
Subsequent positional arguments and keyword arguments are forwarded
directly to the plugin.

This method should be considered "protected": it is intended for use by
derived classes, not users.

Definition at line 423 of file baseMeasurement.py.

423 def callMeasureN(self, measCat, *args, **kwds):
424 """Call ``measureN`` on all plugins and consistently handle exceptions.
425
426 Parameters
427 ----------
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.
431 *args
432 Positional arguments forwarded to ``plugin.measure()``
433 **kwds
434 Keyword arguments. Two are handled locally:
435
436 beginOrder:
437 Beginning execution order (inclusive): Measurements with
438 ``executionOrder`` < ``beginOrder`` are not executed. `None`
439 for no limit.
440 endOrder:
441 Ending execution order (exclusive): measurements with
442 ``executionOrder`` >= ``endOrder`` are not executed. `None` for
443 no ``limit``.
444
445 Others are are forwarded to ``plugin.measure()``.
446
447 Notes
448 -----
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.
453
454 This method should be considered "protected": it is intended for use by
455 derived classes, not users.
456 """
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:
461 continue
462 if endOrder is not None and plugin.getExecutionOrder() >= endOrder:
463 break
464 self.doMeasurementN(plugin, measCat, *args, **kwds)
465

◆ doMeasurement()

lsst.meas.base.baseMeasurement.BaseMeasurementTask.doMeasurement ( self,
plugin,
measRecord,
* args,
** kwds )
Call ``measure`` on the specified plugin.

Exceptions are handled in a consistent way.

Parameters
----------
plugin : subclass of `BasePlugin`
    Plugin that will be executed.
measRecord : `lsst.afw.table.SourceRecord`
    The record corresponding to the object being measured. Will be
    updated in-place with the results of measurement.
*args
    Positional arguments forwarded to ``plugin.measure()``.
**kwds
    Keyword arguments forwarded to ``plugin.measure()``.

Notes
-----
This method can be used with plugins that have different signatures;
the only requirement is that ``plugin`` and ``measRecord`` be the first
two arguments.  Subsequent positional arguments and keyword arguments
are forwarded directly to the plugin.

This method should be considered "protected": it is intended for use by
derived classes, not users.

Definition at line 375 of file baseMeasurement.py.

375 def doMeasurement(self, plugin, measRecord, *args, **kwds):
376 """Call ``measure`` on the specified plugin.
377
378 Exceptions are handled in a consistent way.
379
380 Parameters
381 ----------
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.
387 *args
388 Positional arguments forwarded to ``plugin.measure()``.
389 **kwds
390 Keyword arguments forwarded to ``plugin.measure()``.
391
392 Notes
393 -----
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.
398
399 This method should be considered "protected": it is intended for use by
400 derived classes, not users.
401 """
402 try:
403 plugin.measure(measRecord, *args, **kwds)
404 except FATAL_EXCEPTIONS:
405 raise
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)
415 measRecord.set(self.keyInvalidPsf, True)
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)
422

◆ doMeasurementN()

lsst.meas.base.baseMeasurement.BaseMeasurementTask.doMeasurementN ( self,
plugin,
measCat,
* args,
** kwds )
Call ``measureN`` on the specified plugin.

Exceptions are handled in a consistent way.

Parameters
----------
plugin : subclass of `BasePlugin`
    Plugin that will be executed.
measCat : `lsst.afw.table.SourceCatalog`
    Catalog containing only the records for the source family to be
    measured, and where outputs should be written.
*args
    Positional arguments forwarded to ``plugin.measureN()``.
**kwds
    Keyword arguments forwarded to ``plugin.measureN()``.

Notes
-----
This method can be used with plugins that have different signatures;
the only requirement is that the ``plugin`` and ``measCat`` be the
first two arguments. Subsequent positional arguments and keyword
arguments are forwarded directly to the plugin.

This method should be considered "protected": it is intended for use by
derived classes, not users.

Definition at line 466 of file baseMeasurement.py.

466 def doMeasurementN(self, plugin, measCat, *args, **kwds):
467 """Call ``measureN`` on the specified plugin.
468
469 Exceptions are handled in a consistent way.
470
471 Parameters
472 ----------
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.
478 *args
479 Positional arguments forwarded to ``plugin.measureN()``.
480 **kwds
481 Keyword arguments forwarded to ``plugin.measureN()``.
482
483 Notes
484 -----
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.
489
490 This method should be considered "protected": it is intended for use by
491 derived classes, not users.
492 """
493 try:
494 plugin.measureN(measCat, *args, **kwds)
495 except FATAL_EXCEPTIONS:
496 raise
497
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:
509 measRecord.set(self.keyInvalidPsf, True)
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)
517

◆ getFootprintsFromCatalog()

lsst.meas.base.baseMeasurement.BaseMeasurementTask.getFootprintsFromCatalog ( catalog)
static
Get a set of footprints from a catalog, keyed by id.

Parameters
----------
catalog : `lsst.afw.table.SourceCatalog`
    Catalog with `lsst.afw.detection.Footprint`s attached.

Returns
-------
footprints : `dict` [`int`: (`int`, `lsst.afw.detection.Footprint`)]
    Dictionary of footprint, keyed by id number, with a tuple of
    the parent id and footprint.

Definition at line 519 of file baseMeasurement.py.

519 def getFootprintsFromCatalog(catalog):
520 """Get a set of footprints from a catalog, keyed by id.
521
522 Parameters
523 ----------
524 catalog : `lsst.afw.table.SourceCatalog`
525 Catalog with `lsst.afw.detection.Footprint`s attached.
526
527 Returns
528 -------
529 footprints : `dict` [`int`: (`int`, `lsst.afw.detection.Footprint`)]
530 Dictionary of footprint, keyed by id number, with a tuple of
531 the parent id and footprint.
532 """
533 return {measRecord.getId(): (measRecord.getParent(), measRecord.getFootprint())
534 for measRecord in catalog}

◆ initializePlugins()

lsst.meas.base.baseMeasurement.BaseMeasurementTask.initializePlugins ( self,
** kwds )
Initialize plugins (and slots) according to configuration.

Parameters
----------
**kwds
    Keyword arguments forwarded directly to plugin constructors.

Notes
-----
Derived class constructors should call this method to fill the
`plugins` attribute and add corresponding output fields and slot
aliases to the output schema.

In addition to the attributes added by `BaseMeasurementTask.__init__`,
a ``schema``` attribute holding the output schema must be present
before this method is called.

Keyword arguments are forwarded directly to plugin constructors,
allowing derived classes to use plugins with different signatures.

Definition at line 261 of file baseMeasurement.py.

261 def initializePlugins(self, **kwds):
262 """Initialize plugins (and slots) according to configuration.
263
264 Parameters
265 ----------
266 **kwds
267 Keyword arguments forwarded directly to plugin constructors.
268
269 Notes
270 -----
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.
274
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.
278
279 Keyword arguments are forwarded directly to plugin constructors,
280 allowing derived classes to use plugins with different signatures.
281 """
282 # Make a place at the beginning for the centroid plugin to run first
283 # (because it's an OrderedDict, adding an empty element in advance
284 # means it will get run first when it's reassigned to the actual
285 # Plugin).
286 if self.config.slots.centroid is not None:
287 self.plugins[self.config.slots.centroid] = None
288 # Init the plugins, sorted by execution order. At the same time add to
289 # the schema
290 for executionOrder, name, config, PluginClass in sorted(self.config.plugins.apply()):
291 # Pass logName to the plugin if the plugin is marked as using it
292 # The task will use this name to log plugin errors, regardless.
293 if getattr(PluginClass, "hasLogName", False):
294 self.plugins[name] = PluginClass(config, name, metadata=self.algMetadata,
295 logName=self.log.getChild(name).name, **kwds)
296 else:
297 self.plugins[name] = PluginClass(config, name, metadata=self.algMetadata, **kwds)
298
299 # In rare circumstances (usually tests), the centroid slot not be
300 # coming from an algorithm, which means we'll have added something we
301 # don't want to the plugins map, and we should remove it.
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]
304 # Initialize the plugins to run on the undeblended image
305 for executionOrder, name, config, PluginClass in sorted(self.config.undeblended.apply()):
306 undeblendedName = self.config.undeblendedPrefix + name
307 if getattr(PluginClass, "hasLogName", False):
308 self.undeblendedPlugins[name] = PluginClass(config, undeblendedName,
309 metadata=self.algMetadata,
310 logName=self.log.getChild(undeblendedName).name,
311 **kwds)
312 else:
313 self.undeblendedPlugins[name] = PluginClass(config, undeblendedName,
314 metadata=self.algMetadata, **kwds)
315
316 if "schemaMapper" in kwds:
317 schema = kwds["schemaMapper"].editOutputSchema()
318 else:
319 schema = kwds["schema"]
320
321 invalidPsfName = "base_InvalidPsf_flag"
322 if invalidPsfName in schema:
323 self.keyInvalidPsf = schema.find(invalidPsfName).key
324 else:
325 self.keyInvalidPsf = schema.addField(
326 invalidPsfName,
327 type="Flag",
328 doc="Invalid PSF at this location.",
329 )
330

Member Data Documentation

◆ _DefaultName

str lsst.meas.base.baseMeasurement.BaseMeasurementTask._DefaultName = "measurement"
staticprotected

Definition at line 237 of file baseMeasurement.py.

◆ algMetadata

lsst.meas.base.baseMeasurement.BaseMeasurementTask.algMetadata = None
static

Definition at line 246 of file baseMeasurement.py.

◆ ConfigClass

lsst.meas.base.baseMeasurement.BaseMeasurementTask.ConfigClass = BaseMeasurementConfig
static

Definition at line 236 of file baseMeasurement.py.

◆ keyInvalidPsf

lsst.meas.base.baseMeasurement.BaseMeasurementTask.keyInvalidPsf

Definition at line 323 of file baseMeasurement.py.

◆ plugins

lsst.meas.base.baseMeasurement.BaseMeasurementTask.plugins = None
static

Definition at line 239 of file baseMeasurement.py.

◆ undeblendedPlugins

lsst.meas.base.baseMeasurement.BaseMeasurementTask.undeblendedPlugins

Definition at line 256 of file baseMeasurement.py.


The documentation for this class was generated from the following file: