LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Static Private Attributes | List of all members
lsst.meas.base.baseMeasurement.BaseMeasurementTask Class Reference

Ultimate base class for all measurement tasks. More...

Inheritance diagram for lsst.meas.base.baseMeasurement.BaseMeasurementTask:

Public Member Functions

def __init__
 Constructor; only called by derived classes. More...
 
def initializePlugins
 
def callMeasure
 Call the measure() method on all plugins, handling exceptions in a consistent way. More...
 
def callMeasureN
 Call the measureN() method on all plugins, handling exceptions in a consistent way. More...
 

Public Attributes

 plugins
 
 algMetadata
 

Static Public Attributes

 ConfigClass = BaseMeasurementConfig
 

Private Member Functions

def _applyApCorrIfWanted
 Apply aperture corrections to a catalog, if wanted. More...
 

Static Private Attributes

string _DefaultName = "measurement"
 

Detailed Description

Ultimate base class for all measurement tasks.

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

Note
Tasks that use this task should usually set the default value of config parameter doApplyApCorr to "yes" or "no", depending if aperture corrections are wanted. The default value of "noButWarn" is intended to alert users who forget, and is appropriate for unit tests and temporary scripts that do not need aperture corrections.

Definition at line 242 of file baseMeasurement.py.

Constructor & Destructor Documentation

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

Constructor; only called by derived classes.

Parameters
[in]algMetadataAn lsst.daf.base.PropertyList that will be filled with metadata about the plugins being run. If None, an empty PropertyList will be created.
[in]**kwdsAdditional arguments passed to lsst.pipe.base.Task.__init__.

This attaches two public attributes to the class for use by derived classes and parent tasks:

  • plugins: an empty PluginMap, which will eventually contain all active plugins that will by invoked by the run() method (to be filled by subclasses). This should be considered read-only.
  • algMetadata: a lsst.daf.base.PropertyList that will contain additional information about the active plugins to be saved with the output catalog (to be filled by subclasses).

Definition at line 258 of file baseMeasurement.py.

259  def __init__(self, algMetadata=None, **kwds):
260  """!
261  Constructor; only called by derived classes.
262 
263  @param[in] algMetadata An lsst.daf.base.PropertyList that will be filled with metadata
264  about the plugins being run. If None, an empty PropertyList will
265  be created.
266  @param[in] **kwds Additional arguments passed to lsst.pipe.base.Task.__init__.
267 
268  This attaches two public attributes to the class for use by derived classes and parent tasks:
269  - plugins: an empty PluginMap, which will eventually contain all active plugins that will by
270  invoked by the run() method (to be filled by subclasses). This should be considered read-only.
271  - algMetadata: a lsst.daf.base.PropertyList that will contain additional information about the
272  active plugins to be saved with the output catalog (to be filled by subclasses).
273  """
274  super(BaseMeasurementTask, self).__init__(**kwds)
275  self.plugins = PluginMap()
276  if algMetadata is None:
278  self.algMetadata = algMetadata
def __init__
Constructor; only called by derived classes.
Class for storing ordered metadata with comments.
Definition: PropertyList.h:81

Member Function Documentation

def lsst.meas.base.baseMeasurement.BaseMeasurementTask._applyApCorrIfWanted (   self,
  sources,
  apCorrMap,
  endOrder 
)
private

Apply aperture corrections to a catalog, if wanted.

This method is intended to be called at the end of every subclass's run method or other measurement sequence. This is a thin wrapper around self.applyApCorr.run.

Parameters
[in,out]sourcescatalog of sources to which to apply aperture corrections
[in]apCorrMapaperture correction map (lsst.afw.image.ApCorrMap) or None; typically found in an lsst.afw.image.ExposureInfo if provided then it must contain two entries for each flux field:
  • flux field (e.g. base_PsfFlux_flux): 2d model
  • flux sigma field (e.g. base_PsfFlux_fluxSigma): 2d model of error
[in]endOrderending execution order, or None; if provided then aperture corrections are only wanted if endOrder > lsst.meas.base.BasePlugin.APCORR_ORDER
Returns
the results from applyApCorr if run, else None
Exceptions
lsst.pipe.base.TaskErrorif aperture corrections are wanted and the exposure does not contain an aperture correction map.

Definition at line 388 of file baseMeasurement.py.

389  def _applyApCorrIfWanted(self, sources, apCorrMap, endOrder):
390  """!Apply aperture corrections to a catalog, if wanted
391 
392  This method is intended to be called at the end of every subclass's run method or other
393  measurement sequence. This is a thin wrapper around self.applyApCorr.run.
394 
395  @param[in,out] sources catalog of sources to which to apply aperture corrections
396  @param[in] apCorrMap aperture correction map (lsst.afw.image.ApCorrMap) or None;
397  typically found in an lsst.afw.image.ExposureInfo
398  if provided then it must contain two entries for each flux field:
399  - flux field (e.g. base_PsfFlux_flux): 2d model
400  - flux sigma field (e.g. base_PsfFlux_fluxSigma): 2d model of error
401  @param[in] endOrder ending execution order, or None; if provided then aperture corrections
402  are only wanted if endOrder > lsst.meas.base.BasePlugin.APCORR_ORDER
403  @return the results from applyApCorr if run, else None
404 
405  @throw lsst.pipe.base.TaskError if aperture corrections are wanted and the exposure does not contain
406  an aperture correction map.
407  """
408  if endOrder is not None and endOrder <= BasePlugin.APCORR_ORDER:
409  # it is not appropriate to apply aperture corrections
410  return
411 
412  if self.config.doApplyApCorr.startswith("yes"):
413  if apCorrMap is not None:
414  self.applyApCorr.run(catalog=sources, apCorrMap=apCorrMap)
415  else:
416  errMsg = "Cannot apply aperture corrections; apCorrMap is None"
417  if self.config.doApplyApCorr == "yesOrWarn":
418  self.log.warn(errMsg)
419  else:
420  raise lsst.pipe.base.TaskError(errMsg)
421  elif self.config.doApplyApCorr == "noButWarn":
422  if apCorrMap is not None:
423  self.log.warn("Aperture corrections are disabled but the data to apply them is available;"
424  " change doApplyApCorr to suppress this warning")
425 
426 
def _applyApCorrIfWanted
Apply aperture corrections to a catalog, if wanted.
def lsst.meas.base.baseMeasurement.BaseMeasurementTask.callMeasure (   self,
  measRecord,
  args,
  kwds 
)

Call the measure() method on all plugins, handling exceptions in a consistent way.

Parameters
[in,out]measRecordlsst.afw.table.SourceRecord that corresponds to the object being measured, and where outputs should be written.
[in]*argsPositional arguments forwarded to Plugin.measure()
[in]**kwdsKeyword 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. the rest are forwarded to Plugin.measure()

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 305 of file baseMeasurement.py.

306  def callMeasure(self, measRecord, *args, **kwds):
307  """!
308  Call the measure() method on all plugins, handling exceptions in a consistent way.
309 
310  @param[in,out] measRecord lsst.afw.table.SourceRecord that corresponds to the object being
311  measured, and where outputs should be written.
312  @param[in] *args Positional arguments forwarded to Plugin.measure()
313  @param[in] **kwds Keyword arguments. Two are handled locally:
314  - beginOrder: beginning execution order (inclusive): measurements with
315  executionOrder < beginOrder are not executed. None for no limit.
316  - endOrder: ending execution order (exclusive): measurements with
317  executionOrder >= endOrder are not executed. None for no limit.
318  the rest are forwarded to Plugin.measure()
319 
320  This method can be used with plugins that have different signatures; the only requirement is that
321  'measRecord' be the first argument. Subsequent positional arguments and keyword arguments are
322  forwarded directly to the plugin.
323 
324  This method should be considered "protected"; it is intended for use by derived classes, not users.
325  """
326  beginOrder = kwds.pop("beginOrder", None)
327  endOrder = kwds.pop("endOrder", None)
328  for plugin in self.plugins.iter():
329  if beginOrder is not None and plugin.getExecutionOrder() < beginOrder:
330  continue
331  if endOrder is not None and plugin.getExecutionOrder() >= endOrder:
332  break
333  try:
334  plugin.measure(measRecord, *args, **kwds)
335  except FATAL_EXCEPTIONS:
336  raise
337  except MeasurementError as error:
338  plugin.fail(measRecord, error)
339  except Exception as error:
340  self.log.warn("Error in %s.measure on record %s: %s"
341  % (plugin.name, measRecord.getId(), error))
342  plugin.fail(measRecord)
def callMeasure
Call the measure() method on all plugins, handling exceptions in a consistent way.
def lsst.meas.base.baseMeasurement.BaseMeasurementTask.callMeasureN (   self,
  measCat,
  args,
  kwds 
)

Call the measureN() method on all plugins, handling exceptions in a consistent way.

Parameters
[in,out]measCatlsst.afw.table.SourceCatalog containing records for just the source family to be measured, and where outputs should be written.
[in]beginOrderbeginning execution order (inclusive): measurements with executionOrder < beginOrder are not executed. None for no limit.
[in]endOrderending execution order (exclusive): measurements with executionOrder >= endOrder are not executed. None for no limit.
[in]*argsPositional arguments forwarded to Plugin.measure()
[in]**kwdsKeyword 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. the rest are forwarded to Plugin.measure()

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 343 of file baseMeasurement.py.

344  def callMeasureN(self, measCat, *args, **kwds):
345  """!
346  Call the measureN() method on all plugins, handling exceptions in a consistent way.
347 
348  @param[in,out] measCat lsst.afw.table.SourceCatalog containing records for just
349  the source family to be measured, and where outputs should
350  be written.
351  @param[in] beginOrder beginning execution order (inclusive): measurements with
352  executionOrder < beginOrder are not executed. None for no limit.
353  @param[in] endOrder ending execution order (exclusive): measurements with
354  executionOrder >= endOrder are not executed. None for no limit.
355  @param[in] *args Positional arguments forwarded to Plugin.measure()
356  @param[in] **kwds Keyword arguments. Two are handled locally:
357  - beginOrder: beginning execution order (inclusive): measurements with
358  executionOrder < beginOrder are not executed. None for no limit.
359  - endOrder: ending execution order (exclusive): measurements with
360  executionOrder >= endOrder are not executed. None for no limit.
361  the rest are forwarded to Plugin.measure()
362 
363  This method can be used with plugins that have different signatures; the only requirement is that
364  'measRecord' be the first argument. Subsequent positional arguments and keyword arguments are
365  forwarded directly to the plugin.
366 
367  This method should be considered "protected"; it is intended for use by derived classes, not users.
368  """
369  beginOrder = kwds.pop("beginOrder", None)
370  endOrder = kwds.pop("endOrder", None)
371  for plugin in self.plugins.iterN():
372  if beginOrder is not None and plugin.getExecutionOrder() < beginOrder:
373  continue
374  if endOrder is not None and plugin.getExecutionOrder() >= endOrder:
375  break
376  try:
377  plugin.measureN(measCat, *args, **kwds)
378  except FATAL_EXCEPTIONS:
379  raise
380  except MeasurementError as error:
381  for measRecord in measCat:
382  plugin.fail(measRecord, error)
383  except Exception as error:
384  for measRecord in measCat:
385  plugin.fail(measRecord)
386  self.log.warn("Error in %s.measureN on records %s-%s: %s"
387  % (plugin.name, measCat[0].getId(), measCat[-1].getId(), error))
def callMeasureN
Call the measureN() method on all plugins, handling exceptions in a consistent way.
def lsst.meas.base.baseMeasurement.BaseMeasurementTask.initializePlugins (   self,
  kwds 
)
Initialize the plugins (and slots) according to the configuration.

Derived class constructors should call this method to fill the self.plugins
attribute and add correspond output fields and slot aliases to the output schema.

In addition to the attributes added by BaseMeasurementTask.__init__, a self.schema
attribute holding the output schema must also 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 279 of file baseMeasurement.py.

280  def initializePlugins(self, **kwds):
281  """Initialize the plugins (and slots) according to the configuration.
282 
283  Derived class constructors should call this method to fill the self.plugins
284  attribute and add correspond output fields and slot aliases to the output schema.
285 
286  In addition to the attributes added by BaseMeasurementTask.__init__, a self.schema
287  attribute holding the output schema must also be present before this method is called, .
288 
289  Keyword arguments are forwarded directly to plugin constructors, allowing derived
290  classes to use plugins with different signatures.
291  """
292  # Make a place at the beginning for the centroid plugin to run first (because it's an OrderedDict,
293  # adding an empty element in advance means it will get run first when it's reassigned to the
294  # actual Plugin).
295  if self.config.slots.centroid != None:
296  self.plugins[self.config.slots.centroid] = None
297  # Init the plugins, sorted by execution order. At the same time add to the schema
298  for executionOrder, name, config, PluginClass in sorted(self.config.plugins.apply()):
299  self.plugins[name] = PluginClass(config, name, metadata=self.algMetadata, **kwds)
300  # In rare circumstances (usually tests), the centroid slot not be coming from an algorithm,
301  # which means we'll have added something we don't want to the plugins map, and we should
302  # remove it.
303  if self.config.slots.centroid is not None and self.plugins[self.config.slots.centroid] is None:
304  del self.plugins[self.config.slots.centroid]

Member Data Documentation

string lsst.meas.base.baseMeasurement.BaseMeasurementTask._DefaultName = "measurement"
staticprivate

Definition at line 256 of file baseMeasurement.py.

lsst.meas.base.baseMeasurement.BaseMeasurementTask.algMetadata

Definition at line 277 of file baseMeasurement.py.

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

Definition at line 255 of file baseMeasurement.py.

lsst.meas.base.baseMeasurement.BaseMeasurementTask.plugins

Definition at line 274 of file baseMeasurement.py.


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