LSST Applications  21.0.0+04719a4bac,21.0.0-1-ga51b5d4+f5e6047307,21.0.0-11-g2b59f77+a9c1acf22d,21.0.0-11-ga42c5b2+86977b0b17,21.0.0-12-gf4ce030+76814010d2,21.0.0-13-g1721dae+760e7a6536,21.0.0-13-g3a573fe+768d78a30a,21.0.0-15-g5a7caf0+f21cbc5713,21.0.0-16-g0fb55c1+b60e2d390c,21.0.0-19-g4cded4ca+71a93a33c0,21.0.0-2-g103fe59+bb20972958,21.0.0-2-g45278ab+04719a4bac,21.0.0-2-g5242d73+3ad5d60fb1,21.0.0-2-g7f82c8f+8babb168e8,21.0.0-2-g8f08a60+06509c8b61,21.0.0-2-g8faa9b5+616205b9df,21.0.0-2-ga326454+8babb168e8,21.0.0-2-gde069b7+5e4aea9c2f,21.0.0-2-gecfae73+1d3a86e577,21.0.0-2-gfc62afb+3ad5d60fb1,21.0.0-25-g1d57be3cd+e73869a214,21.0.0-3-g357aad2+ed88757d29,21.0.0-3-g4a4ce7f+3ad5d60fb1,21.0.0-3-g4be5c26+3ad5d60fb1,21.0.0-3-g65f322c+e0b24896a3,21.0.0-3-g7d9da8d+616205b9df,21.0.0-3-ge02ed75+a9c1acf22d,21.0.0-4-g591bb35+a9c1acf22d,21.0.0-4-g65b4814+b60e2d390c,21.0.0-4-gccdca77+0de219a2bc,21.0.0-4-ge8a399c+6c55c39e83,21.0.0-5-gd00fb1e+05fce91b99,21.0.0-6-gc675373+3ad5d60fb1,21.0.0-64-g1122c245+4fb2b8f86e,21.0.0-7-g04766d7+cd19d05db2,21.0.0-7-gdf92d54+04719a4bac,21.0.0-8-g5674e7b+d1bd76f71f,master-gac4afde19b+a9c1acf22d,w.2021.13
LSST Data Management Base Package
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
lsst.meas.base.forcedMeasurement.ForcedMeasurementTask Class Reference
Inheritance diagram for lsst.meas.base.forcedMeasurement.ForcedMeasurementTask:
lsst.meas.base.baseMeasurement.BaseMeasurementTask lsst.pipe.base.task.Task

Public Member Functions

def __init__ (self, refSchema, algMetadata=None, **kwds)
 
def run (self, measCat, exposure, refCat, refWcs, exposureId=None, beginOrder=None, endOrder=None)
 
def generateMeasCat (self, exposure, refCat, refWcs, idFactory=None)
 
def attachTransformedFootprints (self, sources, refCat, exposure, refWcs)
 
def getPluginLogName (self, pluginName)
 
def initializePlugins (self, **kwds)
 
def callMeasure (self, measRecord, *args, **kwds)
 
def doMeasurement (self, plugin, measRecord, *args, **kwds)
 
def callMeasureN (self, measCat, *args, **kwds)
 
def doMeasurementN (self, plugin, measCat, *args, **kwds)
 
def emptyMetadata (self)
 
def getSchemaCatalogs (self)
 
def getAllSchemaCatalogs (self)
 
def getFullMetadata (self)
 
def getFullName (self)
 
def getName (self)
 
def getTaskDict (self)
 
def makeSubtask (self, name, **keyArgs)
 
def timer (self, name, logLevel=Log.DEBUG)
 
def makeField (cls, doc)
 
def __reduce__ (self)
 

Public Attributes

 mapper
 
 schema
 
 undeblendedPlugins
 
 metadata
 
 log
 
 config
 

Static Public Attributes

 ConfigClass = ForcedMeasurementConfig
 
 plugins = None
 
 algMetadata = None
 

Detailed Description

Measure sources on an image, constrained by a reference catalog.

A subtask for measuring the properties of sources on a single image,
using an existing "reference" catalog to constrain some aspects of the
measurement.

Parameters
----------
refSchema : `lsst.afw.table.Schema`
    Schema of the reference catalog.  Must match the catalog later passed
    to 'ForcedMeasurementTask.generateMeasCat` and/or
    `ForcedMeasurementTask.run`.
algMetadata : `lsst.daf.base.PropertyList` or `None`
    Will be updated in place to to record information about each
    algorithm. An empty `~lsst.daf.base.PropertyList` will be created if
    `None`.
**kwds
    Keyword arguments are passed to the supertask constructor.

Notes
-----
Note that while `SingleFrameMeasurementTask` is passed an initial
`~lsst.afw.table.Schema` that is appended to in order to create the output
`~lsst.afw.table.Schema`, `ForcedMeasurementTask` is initialized with the
`~lsst.afw.table.Schema` of the reference catalog, from which a new
`~lsst.afw.table.Schema` for the output catalog is created.  Fields to be
copied directly from the reference `~lsst.afw.table.Schema` are added
before ``Plugin`` fields are added.

Definition at line 216 of file forcedMeasurement.py.

Constructor & Destructor Documentation

◆ __init__()

def lsst.meas.base.forcedMeasurement.ForcedMeasurementTask.__init__ (   self,
  refSchema,
  algMetadata = None,
**  kwds 
)

Definition at line 249 of file forcedMeasurement.py.

249  def __init__(self, refSchema, algMetadata=None, **kwds):
250  super(ForcedMeasurementTask, self).__init__(algMetadata=algMetadata, **kwds)
251  self.mapper = lsst.afw.table.SchemaMapper(refSchema)
252  self.mapper.addMinimalSchema(lsst.afw.table.SourceTable.makeMinimalSchema(), False)
253  self.config.slots.setupSchema(self.mapper.editOutputSchema())
254  for refName, targetName in self.config.copyColumns.items():
255  refItem = refSchema.find(refName)
256  self.mapper.addMapping(refItem.key, targetName)
257  self.config.slots.setupSchema(self.mapper.editOutputSchema())
258  self.initializePlugins(schemaMapper=self.mapper)
259  self.schema = self.mapper.getOutputSchema()
260  self.schema.checkUnits(parse_strict=self.config.checkUnitsParseStrict)
261 
A mapping between the keys of two Schemas, used to copy data between them.
Definition: SchemaMapper.h:21
static Schema makeMinimalSchema()
Return a minimal schema for Source tables and records.
Definition: Source.h:260

Member Function Documentation

◆ __reduce__()

def lsst.pipe.base.task.Task.__reduce__ (   self)
inherited
Pickler.

Reimplemented in lsst.pipe.drivers.multiBandDriver.MultiBandDriverTask, and lsst.pipe.drivers.coaddDriver.CoaddDriverTask.

Definition at line 432 of file task.py.

432  def __reduce__(self):
433  """Pickler.
434  """
435  return self._unpickle_via_factory, (self.__class__, [], self._reduce_kwargs())

◆ attachTransformedFootprints()

def lsst.meas.base.forcedMeasurement.ForcedMeasurementTask.attachTransformedFootprints (   self,
  sources,
  refCat,
  exposure,
  refWcs 
)
Attach Footprints to blank sources prior to measurement.

Notes
-----
`~lsst.afw.detection.Footprint`\s for forced photometry must be in the
pixel coordinate system of the image being measured, while the actual
detections may start out in a different coordinate system. This
default implementation transforms the Footprints from the reference
catalog from the WCS to the exposure's WCS, which downgrades
``HeavyFootprint``\s into regular `~lsst.afw.detection.Footprint`\s,
destroying deblend information.

See the documentation for `run` for information about the
relationships between `run`, `generateMeasCat`, and
`attachTransformedFootprints`.

Definition at line 425 of file forcedMeasurement.py.

425  def attachTransformedFootprints(self, sources, refCat, exposure, refWcs):
426  r"""Attach Footprints to blank sources prior to measurement.
427 
428  Notes
429  -----
430  `~lsst.afw.detection.Footprint`\s for forced photometry must be in the
431  pixel coordinate system of the image being measured, while the actual
432  detections may start out in a different coordinate system. This
433  default implementation transforms the Footprints from the reference
434  catalog from the WCS to the exposure's WCS, which downgrades
435  ``HeavyFootprint``\s into regular `~lsst.afw.detection.Footprint`\s,
436  destroying deblend information.
437 
438  See the documentation for `run` for information about the
439  relationships between `run`, `generateMeasCat`, and
440  `attachTransformedFootprints`.
441  """
442  exposureWcs = exposure.getWcs()
443  region = exposure.getBBox(lsst.afw.image.PARENT)
444  for srcRecord, refRecord in zip(sources, refCat):
445  srcRecord.setFootprint(refRecord.getFootprint().transform(refWcs, exposureWcs, region))

◆ callMeasure()

def lsst.meas.base.baseMeasurement.BaseMeasurementTask.callMeasure (   self,
  measRecord,
args,
**  kwds 
)
inherited
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 289 of file baseMeasurement.py.

289  def callMeasure(self, measRecord, *args, **kwds):
290  """Call ``measure`` on all plugins and consistently handle exceptions.
291 
292  Parameters
293  ----------
294  measRecord : `lsst.afw.table.SourceRecord`
295  The record corresponding to the object being measured. Will be
296  updated in-place with the results of measurement.
297  *args
298  Positional arguments forwarded to ``plugin.measure``
299  **kwds
300  Keyword arguments. Two are handled locally:
301 
302  beginOrder : `int`
303  Beginning execution order (inclusive). Measurements with
304  ``executionOrder`` < ``beginOrder`` are not executed. `None`
305  for no limit.
306 
307  endOrder : `int`
308  Ending execution order (exclusive). Measurements with
309  ``executionOrder`` >= ``endOrder`` are not executed. `None`
310  for no limit.
311 
312  Others are forwarded to ``plugin.measure()``.
313 
314  Notes
315  -----
316  This method can be used with plugins that have different signatures;
317  the only requirement is that ``measRecord`` be the first argument.
318  Subsequent positional arguments and keyword arguments are forwarded
319  directly to the plugin.
320 
321  This method should be considered "protected": it is intended for use by
322  derived classes, not users.
323  """
324  beginOrder = kwds.pop("beginOrder", None)
325  endOrder = kwds.pop("endOrder", None)
326  for plugin in self.plugins.iter():
327  if beginOrder is not None and plugin.getExecutionOrder() < beginOrder:
328  continue
329  if endOrder is not None and plugin.getExecutionOrder() >= endOrder:
330  break
331  self.doMeasurement(plugin, measRecord, *args, **kwds)
332 

◆ callMeasureN()

def lsst.meas.base.baseMeasurement.BaseMeasurementTask.callMeasureN (   self,
  measCat,
args,
**  kwds 
)
inherited
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 375 of file baseMeasurement.py.

375  def callMeasureN(self, measCat, *args, **kwds):
376  """Call ``measureN`` on all plugins and consistently handle exceptions.
377 
378  Parameters
379  ----------
380  measCat : `lsst.afw.table.SourceCatalog`
381  Catalog containing only the records for the source family to be
382  measured, and where outputs should be written.
383  *args
384  Positional arguments forwarded to ``plugin.measure()``
385  **kwds
386  Keyword arguments. Two are handled locally:
387 
388  beginOrder:
389  Beginning execution order (inclusive): Measurements with
390  ``executionOrder`` < ``beginOrder`` are not executed. `None`
391  for no limit.
392  endOrder:
393  Ending execution order (exclusive): measurements with
394  ``executionOrder`` >= ``endOrder`` are not executed. `None` for
395  no ``limit``.
396 
397  Others are are forwarded to ``plugin.measure()``.
398 
399  Notes
400  -----
401  This method can be used with plugins that have different signatures;
402  the only requirement is that ``measRecord`` be the first argument.
403  Subsequent positional arguments and keyword arguments are forwarded
404  directly to the plugin.
405 
406  This method should be considered "protected": it is intended for use by
407  derived classes, not users.
408  """
409  beginOrder = kwds.pop("beginOrder", None)
410  endOrder = kwds.pop("endOrder", None)
411  for plugin in self.plugins.iterN():
412  if beginOrder is not None and plugin.getExecutionOrder() < beginOrder:
413  continue
414  if endOrder is not None and plugin.getExecutionOrder() >= endOrder:
415  break
416  self.doMeasurementN(plugin, measCat, *args, **kwds)
417 

◆ doMeasurement()

def lsst.meas.base.baseMeasurement.BaseMeasurementTask.doMeasurement (   self,
  plugin,
  measRecord,
args,
**  kwds 
)
inherited
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 333 of file baseMeasurement.py.

333  def doMeasurement(self, plugin, measRecord, *args, **kwds):
334  """Call ``measure`` on the specified plugin.
335 
336  Exceptions are handled in a consistent way.
337 
338  Parameters
339  ----------
340  plugin : subclass of `BasePlugin`
341  Plugin that will be executed.
342  measRecord : `lsst.afw.table.SourceRecord`
343  The record corresponding to the object being measured. Will be
344  updated in-place with the results of measurement.
345  *args
346  Positional arguments forwarded to ``plugin.measure()``.
347  **kwds
348  Keyword arguments forwarded to ``plugin.measure()``.
349 
350  Notes
351  -----
352  This method can be used with plugins that have different signatures;
353  the only requirement is that ``plugin`` and ``measRecord`` be the first
354  two arguments. Subsequent positional arguments and keyword arguments
355  are forwarded directly to the plugin.
356 
357  This method should be considered "protected": it is intended for use by
358  derived classes, not users.
359  """
360  try:
361  plugin.measure(measRecord, *args, **kwds)
362  except FATAL_EXCEPTIONS:
363  raise
364  except MeasurementError as error:
365  lsst.log.Log.getLogger(self.getPluginLogName(plugin.name)).debug(
366  "MeasurementError in %s.measure on record %s: %s"
367  % (plugin.name, measRecord.getId(), error))
368  plugin.fail(measRecord, error)
369  except Exception as error:
370  lsst.log.Log.getLogger(self.getPluginLogName(plugin.name)).debug(
371  "Exception in %s.measure on record %s: %s"
372  % (plugin.name, measRecord.getId(), error))
373  plugin.fail(measRecord)
374 
static Log getLogger(Log const &logger)
Definition: Log.h:760

◆ doMeasurementN()

def lsst.meas.base.baseMeasurement.BaseMeasurementTask.doMeasurementN (   self,
  plugin,
  measCat,
args,
**  kwds 
)
inherited
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 418 of file baseMeasurement.py.

418  def doMeasurementN(self, plugin, measCat, *args, **kwds):
419  """Call ``measureN`` on the specified plugin.
420 
421  Exceptions are handled in a consistent way.
422 
423  Parameters
424  ----------
425  plugin : subclass of `BasePlugin`
426  Plugin that will be executed.
427  measCat : `lsst.afw.table.SourceCatalog`
428  Catalog containing only the records for the source family to be
429  measured, and where outputs should be written.
430  *args
431  Positional arguments forwarded to ``plugin.measureN()``.
432  **kwds
433  Keyword arguments forwarded to ``plugin.measureN()``.
434 
435  Notes
436  -----
437  This method can be used with plugins that have different signatures;
438  the only requirement is that the ``plugin`` and ``measCat`` be the
439  first two arguments. Subsequent positional arguments and keyword
440  arguments are forwarded directly to the plugin.
441 
442  This method should be considered "protected": it is intended for use by
443  derived classes, not users.
444  """
445  try:
446  plugin.measureN(measCat, *args, **kwds)
447  except FATAL_EXCEPTIONS:
448  raise
449 
450  except MeasurementError as error:
451  for measRecord in measCat:
452  lsst.log.Log.getLogger(self.getPluginLogName(plugin.name)).debug(
453  "MeasurementError in %s.measureN on records %s-%s: %s"
454  % (plugin.name, measCat[0].getId(), measCat[-1].getId(), error))
455  plugin.fail(measRecord, error)
456  except Exception as error:
457  for measRecord in measCat:
458  plugin.fail(measRecord)
459  lsst.log.Log.getLogger(self.getPluginLogName(plugin.name)).debug(
460  "Exception in %s.measureN on records %s-%s: %s"
461  % (plugin.name, measCat[0].getId(), measCat[-1].getId(), error))

◆ emptyMetadata()

def lsst.pipe.base.task.Task.emptyMetadata (   self)
inherited
Empty (clear) the metadata for this Task and all sub-Tasks.

Definition at line 166 of file task.py.

166  def emptyMetadata(self):
167  """Empty (clear) the metadata for this Task and all sub-Tasks.
168  """
169  for subtask in self._taskDict.values():
170  subtask.metadata = dafBase.PropertyList()
171 
Class for storing ordered metadata with comments.
Definition: PropertyList.h:68

◆ generateMeasCat()

def lsst.meas.base.forcedMeasurement.ForcedMeasurementTask.generateMeasCat (   self,
  exposure,
  refCat,
  refWcs,
  idFactory = None 
)
Initialize an output catalog from the reference catalog.

Parameters
----------
exposure : `lsst.afw.image.exposureF`
    Image to be measured.
refCat : iterable of `lsst.afw.table.SourceRecord`
    Catalog of reference sources.
refWcs : `lsst.afw.geom.SkyWcs`
    Defines the X,Y coordinate system of ``refCat``.
idFactory : `lsst.afw.table.IdFactory`, optional
    Factory for creating IDs for sources.

Returns
-------
meascat : `lsst.afw.table.SourceCatalog`
    Source catalog ready for measurement.

Notes
-----
This generates a new blank `~lsst.afw.table.SourceRecord` for each
record in ``refCat``. Note that this method does not attach any
`~lsst.afw.detection.Footprint`\ s.  Doing so is up to the caller (who
may call `attachedTransformedFootprints` or define their own method -
see `run` for more information).

Definition at line 386 of file forcedMeasurement.py.

386  def generateMeasCat(self, exposure, refCat, refWcs, idFactory=None):
387  r"""Initialize an output catalog from the reference catalog.
388 
389  Parameters
390  ----------
391  exposure : `lsst.afw.image.exposureF`
392  Image to be measured.
393  refCat : iterable of `lsst.afw.table.SourceRecord`
394  Catalog of reference sources.
395  refWcs : `lsst.afw.geom.SkyWcs`
396  Defines the X,Y coordinate system of ``refCat``.
397  idFactory : `lsst.afw.table.IdFactory`, optional
398  Factory for creating IDs for sources.
399 
400  Returns
401  -------
402  meascat : `lsst.afw.table.SourceCatalog`
403  Source catalog ready for measurement.
404 
405  Notes
406  -----
407  This generates a new blank `~lsst.afw.table.SourceRecord` for each
408  record in ``refCat``. Note that this method does not attach any
409  `~lsst.afw.detection.Footprint`\ s. Doing so is up to the caller (who
410  may call `attachedTransformedFootprints` or define their own method -
411  see `run` for more information).
412  """
413  if idFactory is None:
415  table = lsst.afw.table.SourceTable.make(self.schema, idFactory)
416  measCat = lsst.afw.table.SourceCatalog(table)
417  table = measCat.table
418  table.setMetadata(self.algMetadata)
419  table.preallocate(len(refCat))
420  for ref in refCat:
421  newSource = measCat.addNew()
422  newSource.assign(ref, self.mapper)
423  return measCat
424 
static std::shared_ptr< IdFactory > makeSimple()
Return a simple IdFactory that simply counts from 1.
Definition: IdFactory.cc:70
static std::shared_ptr< SourceTable > make(Schema const &schema, std::shared_ptr< IdFactory > const &idFactory)
Construct a new table.
Definition: Source.cc:382

◆ getAllSchemaCatalogs()

def lsst.pipe.base.task.Task.getAllSchemaCatalogs (   self)
inherited
Get schema catalogs for all tasks in the hierarchy, combining the
results into a single dict.

Returns
-------
schemacatalogs : `dict`
    Keys are butler dataset type, values are a empty catalog (an
    instance of the appropriate `lsst.afw.table` Catalog type) for all
    tasks in the hierarchy, from the top-level task down
    through all subtasks.

Notes
-----
This method may be called on any task in the hierarchy; it will return
the same answer, regardless.

The default implementation should always suffice. If your subtask uses
schemas the override `Task.getSchemaCatalogs`, not this method.

Definition at line 204 of file task.py.

204  def getAllSchemaCatalogs(self):
205  """Get schema catalogs for all tasks in the hierarchy, combining the
206  results into a single dict.
207 
208  Returns
209  -------
210  schemacatalogs : `dict`
211  Keys are butler dataset type, values are a empty catalog (an
212  instance of the appropriate `lsst.afw.table` Catalog type) for all
213  tasks in the hierarchy, from the top-level task down
214  through all subtasks.
215 
216  Notes
217  -----
218  This method may be called on any task in the hierarchy; it will return
219  the same answer, regardless.
220 
221  The default implementation should always suffice. If your subtask uses
222  schemas the override `Task.getSchemaCatalogs`, not this method.
223  """
224  schemaDict = self.getSchemaCatalogs()
225  for subtask in self._taskDict.values():
226  schemaDict.update(subtask.getSchemaCatalogs())
227  return schemaDict
228 

◆ getFullMetadata()

def lsst.pipe.base.task.Task.getFullMetadata (   self)
inherited
Get metadata for all tasks.

Returns
-------
metadata : `lsst.daf.base.PropertySet`
    The `~lsst.daf.base.PropertySet` keys are the full task name.
    Values are metadata for the top-level task and all subtasks,
    sub-subtasks, etc.

Notes
-----
The returned metadata includes timing information (if
``@timer.timeMethod`` is used) and any metadata set by the task. The
name of each item consists of the full task name with ``.`` replaced
by ``:``, followed by ``.`` and the name of the item, e.g.::

    topLevelTaskName:subtaskName:subsubtaskName.itemName

using ``:`` in the full task name disambiguates the rare situation
that a task has a subtask and a metadata item with the same name.

Definition at line 229 of file task.py.

229  def getFullMetadata(self):
230  """Get metadata for all tasks.
231 
232  Returns
233  -------
234  metadata : `lsst.daf.base.PropertySet`
235  The `~lsst.daf.base.PropertySet` keys are the full task name.
236  Values are metadata for the top-level task and all subtasks,
237  sub-subtasks, etc.
238 
239  Notes
240  -----
241  The returned metadata includes timing information (if
242  ``@timer.timeMethod`` is used) and any metadata set by the task. The
243  name of each item consists of the full task name with ``.`` replaced
244  by ``:``, followed by ``.`` and the name of the item, e.g.::
245 
246  topLevelTaskName:subtaskName:subsubtaskName.itemName
247 
248  using ``:`` in the full task name disambiguates the rare situation
249  that a task has a subtask and a metadata item with the same name.
250  """
251  fullMetadata = dafBase.PropertySet()
252  for fullName, task in self.getTaskDict().items():
253  fullMetadata.set(fullName.replace(".", ":"), task.metadata)
254  return fullMetadata
255 
std::vector< SchemaItem< Flag > > * items
Class for storing generic metadata.
Definition: PropertySet.h:67

◆ getFullName()

def lsst.pipe.base.task.Task.getFullName (   self)
inherited
Get the task name as a hierarchical name including parent task
names.

Returns
-------
fullName : `str`
    The full name consists of the name of the parent task and each
    subtask separated by periods. For example:

    - The full name of top-level task "top" is simply "top".
    - The full name of subtask "sub" of top-level task "top" is
      "top.sub".
    - The full name of subtask "sub2" of subtask "sub" of top-level
      task "top" is "top.sub.sub2".

Definition at line 256 of file task.py.

256  def getFullName(self):
257  """Get the task name as a hierarchical name including parent task
258  names.
259 
260  Returns
261  -------
262  fullName : `str`
263  The full name consists of the name of the parent task and each
264  subtask separated by periods. For example:
265 
266  - The full name of top-level task "top" is simply "top".
267  - The full name of subtask "sub" of top-level task "top" is
268  "top.sub".
269  - The full name of subtask "sub2" of subtask "sub" of top-level
270  task "top" is "top.sub.sub2".
271  """
272  return self._fullName
273 

◆ getName()

def lsst.pipe.base.task.Task.getName (   self)
inherited
Get the name of the task.

Returns
-------
taskName : `str`
    Name of the task.

See also
--------
getFullName

Definition at line 274 of file task.py.

274  def getName(self):
275  """Get the name of the task.
276 
277  Returns
278  -------
279  taskName : `str`
280  Name of the task.
281 
282  See also
283  --------
284  getFullName
285  """
286  return self._name
287 
std::string const & getName() const noexcept
Return a filter's name.
Definition: Filter.h:78

◆ getPluginLogName()

def lsst.meas.base.baseMeasurement.BaseMeasurementTask.getPluginLogName (   self,
  pluginName 
)
inherited

Definition at line 239 of file baseMeasurement.py.

239  def getPluginLogName(self, pluginName):
240  return self.log.getName() + '.' + pluginName
241 

◆ getSchemaCatalogs()

def lsst.pipe.base.task.Task.getSchemaCatalogs (   self)
inherited
Get the schemas generated by this task.

Returns
-------
schemaCatalogs : `dict`
    Keys are butler dataset type, values are an empty catalog (an
    instance of the appropriate `lsst.afw.table` Catalog type) for
    this task.

Notes
-----

.. warning::

   Subclasses that use schemas must override this method. The default
   implementation returns an empty dict.

This method may be called at any time after the Task is constructed,
which means that all task schemas should be computed at construction
time, *not* when data is actually processed. This reflects the
philosophy that the schema should not depend on the data.

Returning catalogs rather than just schemas allows us to save e.g.
slots for SourceCatalog as well.

See also
--------
Task.getAllSchemaCatalogs

Definition at line 172 of file task.py.

172  def getSchemaCatalogs(self):
173  """Get the schemas generated by this task.
174 
175  Returns
176  -------
177  schemaCatalogs : `dict`
178  Keys are butler dataset type, values are an empty catalog (an
179  instance of the appropriate `lsst.afw.table` Catalog type) for
180  this task.
181 
182  Notes
183  -----
184 
185  .. warning::
186 
187  Subclasses that use schemas must override this method. The default
188  implementation returns an empty dict.
189 
190  This method may be called at any time after the Task is constructed,
191  which means that all task schemas should be computed at construction
192  time, *not* when data is actually processed. This reflects the
193  philosophy that the schema should not depend on the data.
194 
195  Returning catalogs rather than just schemas allows us to save e.g.
196  slots for SourceCatalog as well.
197 
198  See also
199  --------
200  Task.getAllSchemaCatalogs
201  """
202  return {}
203 

◆ getTaskDict()

def lsst.pipe.base.task.Task.getTaskDict (   self)
inherited
Get a dictionary of all tasks as a shallow copy.

Returns
-------
taskDict : `dict`
    Dictionary containing full task name: task object for the top-level
    task and all subtasks, sub-subtasks, etc.

Definition at line 288 of file task.py.

288  def getTaskDict(self):
289  """Get a dictionary of all tasks as a shallow copy.
290 
291  Returns
292  -------
293  taskDict : `dict`
294  Dictionary containing full task name: task object for the top-level
295  task and all subtasks, sub-subtasks, etc.
296  """
297  return self._taskDict.copy()
298 
def getTaskDict(config, taskDict=None, baseName="")

◆ initializePlugins()

def lsst.meas.base.baseMeasurement.BaseMeasurementTask.initializePlugins (   self,
**  kwds 
)
inherited
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 242 of file baseMeasurement.py.

242  def initializePlugins(self, **kwds):
243  """Initialize plugins (and slots) according to configuration.
244 
245  Parameters
246  ----------
247  **kwds
248  Keyword arguments forwarded directly to plugin constructors.
249 
250  Notes
251  -----
252  Derived class constructors should call this method to fill the
253  `plugins` attribute and add corresponding output fields and slot
254  aliases to the output schema.
255 
256  In addition to the attributes added by `BaseMeasurementTask.__init__`,
257  a ``schema``` attribute holding the output schema must be present
258  before this method is called.
259 
260  Keyword arguments are forwarded directly to plugin constructors,
261  allowing derived classes to use plugins with different signatures.
262  """
263  # Make a place at the beginning for the centroid plugin to run first (because it's an OrderedDict,
264  # adding an empty element in advance means it will get run first when it's reassigned to the
265  # actual Plugin).
266  if self.config.slots.centroid is not None:
267  self.plugins[self.config.slots.centroid] = None
268  # Init the plugins, sorted by execution order. At the same time add to the schema
269  for executionOrder, name, config, PluginClass in sorted(self.config.plugins.apply()):
270  # Pass logName to the plugin if the plugin is marked as using it
271  # The task will use this name to log plugin errors, regardless.
272  if hasattr(PluginClass, "hasLogName") and PluginClass.hasLogName:
273  self.plugins[name] = PluginClass(config, name, metadata=self.algMetadata,
274  logName=self.getPluginLogName(name), **kwds)
275  else:
276  self.plugins[name] = PluginClass(config, name, metadata=self.algMetadata, **kwds)
277 
278  # In rare circumstances (usually tests), the centroid slot not be coming from an algorithm,
279  # which means we'll have added something we don't want to the plugins map, and we should
280  # remove it.
281  if self.config.slots.centroid is not None and self.plugins[self.config.slots.centroid] is None:
282  del self.plugins[self.config.slots.centroid]
283  # Initialize the plugins to run on the undeblended image
284  for executionOrder, name, config, PluginClass in sorted(self.config.undeblended.apply()):
285  undeblendedName = self.config.undeblendedPrefix + name
286  self.undeblendedPlugins[name] = PluginClass(config, undeblendedName, metadata=self.algMetadata,
287  **kwds)
288 

◆ makeField()

def lsst.pipe.base.task.Task.makeField (   cls,
  doc 
)
inherited
Make a `lsst.pex.config.ConfigurableField` for this task.

Parameters
----------
doc : `str`
    Help text for the field.

Returns
-------
configurableField : `lsst.pex.config.ConfigurableField`
    A `~ConfigurableField` for this task.

Examples
--------
Provides a convenient way to specify this task is a subtask of another
task.

Here is an example of use:

.. code-block:: python

    class OtherTaskConfig(lsst.pex.config.Config):
        aSubtask = ATaskClass.makeField("brief description of task")

Definition at line 359 of file task.py.

359  def makeField(cls, doc):
360  """Make a `lsst.pex.config.ConfigurableField` for this task.
361 
362  Parameters
363  ----------
364  doc : `str`
365  Help text for the field.
366 
367  Returns
368  -------
369  configurableField : `lsst.pex.config.ConfigurableField`
370  A `~ConfigurableField` for this task.
371 
372  Examples
373  --------
374  Provides a convenient way to specify this task is a subtask of another
375  task.
376 
377  Here is an example of use:
378 
379  .. code-block:: python
380 
381  class OtherTaskConfig(lsst.pex.config.Config):
382  aSubtask = ATaskClass.makeField("brief description of task")
383  """
384  return ConfigurableField(doc=doc, target=cls)
385 

◆ makeSubtask()

def lsst.pipe.base.task.Task.makeSubtask (   self,
  name,
**  keyArgs 
)
inherited
Create a subtask as a new instance as the ``name`` attribute of this
task.

Parameters
----------
name : `str`
    Brief name of the subtask.
keyArgs
    Extra keyword arguments used to construct the task. The following
    arguments are automatically provided and cannot be overridden:

    - "config".
    - "parentTask".

Notes
-----
The subtask must be defined by ``Task.config.name``, an instance of
`~lsst.pex.config.ConfigurableField` or
`~lsst.pex.config.RegistryField`.

Definition at line 299 of file task.py.

299  def makeSubtask(self, name, **keyArgs):
300  """Create a subtask as a new instance as the ``name`` attribute of this
301  task.
302 
303  Parameters
304  ----------
305  name : `str`
306  Brief name of the subtask.
307  keyArgs
308  Extra keyword arguments used to construct the task. The following
309  arguments are automatically provided and cannot be overridden:
310 
311  - "config".
312  - "parentTask".
313 
314  Notes
315  -----
316  The subtask must be defined by ``Task.config.name``, an instance of
317  `~lsst.pex.config.ConfigurableField` or
318  `~lsst.pex.config.RegistryField`.
319  """
320  taskField = getattr(self.config, name, None)
321  if taskField is None:
322  raise KeyError(f"{self.getFullName()}'s config does not have field {name!r}")
323  subtask = taskField.apply(name=name, parentTask=self, **keyArgs)
324  setattr(self, name, subtask)
325 

◆ run()

def lsst.meas.base.forcedMeasurement.ForcedMeasurementTask.run (   self,
  measCat,
  exposure,
  refCat,
  refWcs,
  exposureId = None,
  beginOrder = None,
  endOrder = None 
)
Perform forced measurement.

Parameters
----------
exposure : `lsst.afw.image.exposureF`
    Image to be measured. Must have at least a `lsst.afw.geom.SkyWcs`
    attached.
measCat : `lsst.afw.table.SourceCatalog`
    Source catalog for measurement results; must be initialized with
    empty records already corresponding to those in ``refCat`` (via
    e.g. `generateMeasCat`).
refCat : `lsst.afw.table.SourceCatalog`
    A sequence of `lsst.afw.table.SourceRecord` objects that provide
    reference information for the measurement.  These will be passed
    to each plugin in addition to the output
    `~lsst.afw.table.SourceRecord`.
refWcs : `lsst.afw.geom.SkyWcs`
    Defines the X,Y coordinate system of ``refCat``.
exposureId : `int`, optional
    Optional unique exposureId used to calculate random number
    generator seed in the NoiseReplacer.
beginOrder : `int`, optional
    Beginning execution order (inclusive). Algorithms with
    ``executionOrder`` < ``beginOrder`` are not executed. `None` for no limit.
endOrder : `int`, optional
    Ending execution order (exclusive). Algorithms with
    ``executionOrder`` >= ``endOrder`` are not executed. `None` for no limit.

Notes
-----
Fills the initial empty `~lsst.afw.table.SourceCatalog` with forced
measurement results.  Two steps must occur before `run` can be called:

- `generateMeasCat` must be called to create the output ``measCat``
  argument.
- `~lsst.afw.detection.Footprint`\ s appropriate for the forced sources
  must be attached to the ``measCat`` records. The
  `attachTransformedFootprints` method can be used to do this, but
  this degrades "heavy" (i.e., including pixel values)
  `~lsst.afw.detection.Footprint`\s to regular
  `~lsst.afw.detection.Footprint`\s, leading to non-deblended
  measurement, so most callers should provide
  `~lsst.afw.detection.Footprint`\s some other way. Typically, calling
  code will have access to information that will allow them to provide
  heavy footprints - for instance, `ForcedPhotCoaddTask` uses the
  heavy footprints from deblending run in the same band just before
  non-forced is run measurement in that band.

Definition at line 262 of file forcedMeasurement.py.

262  def run(self, measCat, exposure, refCat, refWcs, exposureId=None, beginOrder=None, endOrder=None):
263  r"""Perform forced measurement.
264 
265  Parameters
266  ----------
267  exposure : `lsst.afw.image.exposureF`
268  Image to be measured. Must have at least a `lsst.afw.geom.SkyWcs`
269  attached.
270  measCat : `lsst.afw.table.SourceCatalog`
271  Source catalog for measurement results; must be initialized with
272  empty records already corresponding to those in ``refCat`` (via
273  e.g. `generateMeasCat`).
274  refCat : `lsst.afw.table.SourceCatalog`
275  A sequence of `lsst.afw.table.SourceRecord` objects that provide
276  reference information for the measurement. These will be passed
277  to each plugin in addition to the output
278  `~lsst.afw.table.SourceRecord`.
279  refWcs : `lsst.afw.geom.SkyWcs`
280  Defines the X,Y coordinate system of ``refCat``.
281  exposureId : `int`, optional
282  Optional unique exposureId used to calculate random number
283  generator seed in the NoiseReplacer.
284  beginOrder : `int`, optional
285  Beginning execution order (inclusive). Algorithms with
286  ``executionOrder`` < ``beginOrder`` are not executed. `None` for no limit.
287  endOrder : `int`, optional
288  Ending execution order (exclusive). Algorithms with
289  ``executionOrder`` >= ``endOrder`` are not executed. `None` for no limit.
290 
291  Notes
292  -----
293  Fills the initial empty `~lsst.afw.table.SourceCatalog` with forced
294  measurement results. Two steps must occur before `run` can be called:
295 
296  - `generateMeasCat` must be called to create the output ``measCat``
297  argument.
298  - `~lsst.afw.detection.Footprint`\ s appropriate for the forced sources
299  must be attached to the ``measCat`` records. The
300  `attachTransformedFootprints` method can be used to do this, but
301  this degrades "heavy" (i.e., including pixel values)
302  `~lsst.afw.detection.Footprint`\s to regular
303  `~lsst.afw.detection.Footprint`\s, leading to non-deblended
304  measurement, so most callers should provide
305  `~lsst.afw.detection.Footprint`\s some other way. Typically, calling
306  code will have access to information that will allow them to provide
307  heavy footprints - for instance, `ForcedPhotCoaddTask` uses the
308  heavy footprints from deblending run in the same band just before
309  non-forced is run measurement in that band.
310  """
311  # First check that the reference catalog does not contain any children
312  # for which any member of their parent chain is not within the list.
313  # This can occur at boundaries when the parent is outside and one of
314  # the children is within. Currently, the parent chain is always only
315  # one deep, but just in case, this code checks for any case where when
316  # the parent chain to a child's topmost parent is broken and raises an
317  # exception if it occurs.
318  #
319  # I.e. this code checks that this precondition is satisfied by
320  # whatever reference catalog provider is being paired with it.
321  refCatIdDict = {ref.getId(): ref.getParent() for ref in refCat}
322  for ref in refCat:
323  refId = ref.getId()
324  topId = refId
325  while(topId > 0):
326  if topId not in refCatIdDict:
327  raise RuntimeError("Reference catalog contains a child for which at least "
328  "one parent in its parent chain is not in the catalog.")
329  topId = refCatIdDict[topId]
330 
331  # Construct a footprints dict which looks like
332  # {ref.getId(): (ref.getParent(), source.getFootprint())}
333  # (i.e. getting the footprint from the transformed source footprint)
334  footprints = {ref.getId(): (ref.getParent(), measRecord.getFootprint())
335  for (ref, measRecord) in zip(refCat, measCat)}
336 
337  self.log.info("Performing forced measurement on %d source%s", len(refCat),
338  "" if len(refCat) == 1 else "s")
339 
340  if self.config.doReplaceWithNoise:
341  noiseReplacer = NoiseReplacer(self.config.noiseReplacer, exposure,
342  footprints, log=self.log, exposureId=exposureId)
343  algMetadata = measCat.getTable().getMetadata()
344  if algMetadata is not None:
345  algMetadata.addInt("NOISE_SEED_MULTIPLIER", self.config.noiseReplacer.noiseSeedMultiplier)
346  algMetadata.addString("NOISE_SOURCE", self.config.noiseReplacer.noiseSource)
347  algMetadata.addDouble("NOISE_OFFSET", self.config.noiseReplacer.noiseOffset)
348  if exposureId is not None:
349  algMetadata.addLong("NOISE_EXPOSURE_ID", exposureId)
350  else:
351  noiseReplacer = DummyNoiseReplacer()
352 
353  # Create parent cat which slices both the refCat and measCat (sources)
354  # first, get the reference and source records which have no parent
355  refParentCat, measParentCat = refCat.getChildren(0, measCat)
356  for parentIdx, (refParentRecord, measParentRecord) in enumerate(zip(refParentCat, measParentCat)):
357 
358  # first process the records which have the current parent as children
359  refChildCat, measChildCat = refCat.getChildren(refParentRecord.getId(), measCat)
360  # TODO: skip this loop if there are no plugins configured for single-object mode
361  for refChildRecord, measChildRecord in zip(refChildCat, measChildCat):
362  noiseReplacer.insertSource(refChildRecord.getId())
363  self.callMeasure(measChildRecord, exposure, refChildRecord, refWcs,
364  beginOrder=beginOrder, endOrder=endOrder)
365  noiseReplacer.removeSource(refChildRecord.getId())
366 
367  # then process the parent record
368  noiseReplacer.insertSource(refParentRecord.getId())
369  self.callMeasure(measParentRecord, exposure, refParentRecord, refWcs,
370  beginOrder=beginOrder, endOrder=endOrder)
371  self.callMeasureN(measParentCat[parentIdx:parentIdx+1], exposure,
372  refParentCat[parentIdx:parentIdx+1],
373  beginOrder=beginOrder, endOrder=endOrder)
374  # measure all the children simultaneously
375  self.callMeasureN(measChildCat, exposure, refChildCat,
376  beginOrder=beginOrder, endOrder=endOrder)
377  noiseReplacer.removeSource(refParentRecord.getId())
378  noiseReplacer.end()
379 
380  # Undeblended plugins only fire if we're running everything
381  if endOrder is None:
382  for measRecord, refRecord in zip(measCat, refCat):
383  for plugin in self.undeblendedPlugins.iter():
384  self.doMeasurement(plugin, measRecord, exposure, refRecord, refWcs)
385 
def run(self, skyInfo, tempExpRefList, imageScalerList, weightList, altMaskList=None, mask=None, supplementaryData=None)

◆ timer()

def lsst.pipe.base.task.Task.timer (   self,
  name,
  logLevel = Log.DEBUG 
)
inherited
Context manager to log performance data for an arbitrary block of
code.

Parameters
----------
name : `str`
    Name of code being timed; data will be logged using item name:
    ``Start`` and ``End``.
logLevel
    A `lsst.log` level constant.

Examples
--------
Creating a timer context:

.. code-block:: python

    with self.timer("someCodeToTime"):
        pass  # code to time

See also
--------
timer.logInfo

Definition at line 327 of file task.py.

327  def timer(self, name, logLevel=Log.DEBUG):
328  """Context manager to log performance data for an arbitrary block of
329  code.
330 
331  Parameters
332  ----------
333  name : `str`
334  Name of code being timed; data will be logged using item name:
335  ``Start`` and ``End``.
336  logLevel
337  A `lsst.log` level constant.
338 
339  Examples
340  --------
341  Creating a timer context:
342 
343  .. code-block:: python
344 
345  with self.timer("someCodeToTime"):
346  pass # code to time
347 
348  See also
349  --------
350  timer.logInfo
351  """
352  logInfo(obj=self, prefix=name + "Start", logLevel=logLevel)
353  try:
354  yield
355  finally:
356  logInfo(obj=self, prefix=name + "End", logLevel=logLevel)
357 
def logInfo(obj, prefix, logLevel=Log.DEBUG)
Definition: timer.py:63

Member Data Documentation

◆ algMetadata

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

Definition at line 224 of file baseMeasurement.py.

◆ config

lsst.pipe.base.task.Task.config
inherited

Definition at line 162 of file task.py.

◆ ConfigClass

lsst.meas.base.forcedMeasurement.ForcedMeasurementTask.ConfigClass = ForcedMeasurementConfig
static

Definition at line 247 of file forcedMeasurement.py.

◆ log

lsst.pipe.base.task.Task.log
inherited

Definition at line 161 of file task.py.

◆ mapper

lsst.meas.base.forcedMeasurement.ForcedMeasurementTask.mapper

Definition at line 251 of file forcedMeasurement.py.

◆ metadata

lsst.pipe.base.task.Task.metadata
inherited

Definition at line 134 of file task.py.

◆ plugins

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

Definition at line 217 of file baseMeasurement.py.

◆ schema

lsst.meas.base.forcedMeasurement.ForcedMeasurementTask.schema

Definition at line 259 of file forcedMeasurement.py.

◆ undeblendedPlugins

lsst.meas.base.baseMeasurement.BaseMeasurementTask.undeblendedPlugins
inherited

Definition at line 234 of file baseMeasurement.py.


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