LSST Applications  21.0.0-147-g0e635eb1+1acddb5be5,22.0.0+052faf71bd,22.0.0+1ea9a8b2b2,22.0.0+6312710a6c,22.0.0+729191ecac,22.0.0+7589c3a021,22.0.0+9f079a9461,22.0.1-1-g7d6de66+b8044ec9de,22.0.1-1-g87000a6+536b1ee016,22.0.1-1-g8e32f31+6312710a6c,22.0.1-10-gd060f87+016f7cdc03,22.0.1-12-g9c3108e+df145f6f68,22.0.1-16-g314fa6d+c825727ab8,22.0.1-19-g93a5c75+d23f2fb6d8,22.0.1-19-gb93eaa13+aab3ef7709,22.0.1-2-g8ef0a89+b8044ec9de,22.0.1-2-g92698f7+9f079a9461,22.0.1-2-ga9b0f51+052faf71bd,22.0.1-2-gac51dbf+052faf71bd,22.0.1-2-gb66926d+6312710a6c,22.0.1-2-gcb770ba+09e3807989,22.0.1-20-g32debb5+b8044ec9de,22.0.1-23-gc2439a9a+fb0756638e,22.0.1-3-g496fd5d+09117f784f,22.0.1-3-g59f966b+1e6ba2c031,22.0.1-3-g849a1b8+f8b568069f,22.0.1-3-gaaec9c0+c5c846a8b1,22.0.1-32-g5ddfab5d3+60ce4897b0,22.0.1-4-g037fbe1+64e601228d,22.0.1-4-g8623105+b8044ec9de,22.0.1-5-g096abc9+d18c45d440,22.0.1-5-g15c806e+57f5c03693,22.0.1-7-gba73697+57f5c03693,master-g6e05de7fdc+c1283a92b8,master-g72cdda8301+729191ecac,w.2021.39
LSST Data Management Base Package
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
lsst.meas.base.diaCalculation.DiaObjectCalculationTask Class Reference
Inheritance diagram for lsst.meas.base.diaCalculation.DiaObjectCalculationTask:
lsst.meas.base.catalogCalculation.CatalogCalculationTask

Public Member Functions

def __init__ (self, plugMetadata=None, **kwargs)
 
def initializePlugins (self)
 
def run (self, diaObjectCat, diaSourceCat, updatedDiaObjectIds, filterNames)
 
def callCompute (self, diaObjectCat, diaSourceCat, updatedDiaObjectIds, filterNames)
 
def run (self, measCat)
 
def callCompute (self, catalog)
 

Public Attributes

 plugMetadata
 
 plugins
 
 outputCols
 
 executionDict
 
 schema
 

Static Public Attributes

 ConfigClass = DiaObjectCalculationConfig
 

Detailed Description

Run plugins which operate on a catalog of DIA sources.

This task facilitates running plugins which will operate on a source
catalog. These plugins may do things such as classifying an object based
on source record entries inserted during a measurement task.

This task differs from CatalogCaculationTask in the following ways:

-No multi mode is available for plugins. All plugins are assumed to run
 in single mode.

-Input and output catalog types are assumed to be `pandas.DataFrames` with
 columns following those used in the Apdb.

-No schema argument is passed to the plugins. Each plugin specifies
 output columns and required inputs.

Parameters
----------
plugMetaData : `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.
**kwargs
    Additional arguments passed to the superclass constructor.

Notes
-----
Plugins may either take an entire catalog to work on at a time, or work on
individual records.

Definition at line 171 of file diaCalculation.py.

Constructor & Destructor Documentation

◆ __init__()

def lsst.meas.base.diaCalculation.DiaObjectCalculationTask.__init__ (   self,
  plugMetadata = None,
**  kwargs 
)

Definition at line 206 of file diaCalculation.py.

206  def __init__(self, plugMetadata=None, **kwargs):
207  lsst.pipe.base.Task.__init__(self, **kwargs)
208  if plugMetadata is None:
209  plugMetadata = lsst.daf.base.PropertyList()
210  self.plugMetadata = plugMetadata
211  self.plugins = PluginMap()
212  self.outputCols = []
213 
214  self.initializePlugins()
215 
Class for storing ordered metadata with comments.
Definition: PropertyList.h:68

Member Function Documentation

◆ callCompute() [1/2]

def lsst.meas.base.catalogCalculation.CatalogCalculationTask.callCompute (   self,
  catalog 
)
inherited
Run each of the plugins on the catalog.

Parameters
----------
catalog : `lsst.afw.table.SourceCatalog`
    The catalog on which the plugins will operate.

Definition at line 240 of file catalogCalculation.py.

240  def callCompute(self, catalog):
241  """Run each of the plugins on the catalog.
242 
243  Parameters
244  ----------
245  catalog : `lsst.afw.table.SourceCatalog`
246  The catalog on which the plugins will operate.
247  """
248  for runlevel in sorted(self.executionDict):
249  # Run all of the plugins which take a whole catalog first
250  for plug in self.executionDict[runlevel].multi:
251  with CCContext(plug, catalog, self.log):
252  plug.calculate(catalog)
253  # Run all the plugins which take single catalog entries
254  for measRecord in catalog:
255  for plug in self.executionDict[runlevel].single:
256  with CCContext(plug, measRecord, self.log):
257  plug.calculate(measRecord)

◆ callCompute() [2/2]

def lsst.meas.base.diaCalculation.DiaObjectCalculationTask.callCompute (   self,
  diaObjectCat,
  diaSourceCat,
  updatedDiaObjectIds,
  filterNames 
)
Run each of the plugins on the catalog.

For catalog column names see the lsst.cat schema definitions for the
DiaObject and DiaSource tables (http://github.com/lsst/cat).

Parameters
----------
diaObjectCat : `pandas.DataFrame`
    DiaObjects to update values of and append new objects to. DataFrame
    should be indexed on "diaObjectId"
diaSourceCat : `pandas.DataFrame`
    DiaSources associated with the DiaObjects in diaObjectCat.
    DataFrame must be indexed on
    ["diaObjectId", "filterName", "diaSourceId"]`
updatedDiaObjectIds : `numpy.ndarray`
    Integer ids of the DiaObjects to update and create.
filterNames : `list` of `str`
    List of string names of filters to be being processed.

Returns
-------
returnStruct : `lsst.pipe.base.Struct`
    Struct containing:

    ``diaObjectCat``
        Full set of DiaObjects including both un-updated and
        updated/new DiaObjects (`pandas.DataFrame`).
    ``updatedDiaObjects``
        Catalog of DiaObjects  that were updated or created by this
        task (`pandas.DataFrame`).

Raises
------
KeyError
    Raises if `pandas.DataFrame` indexing is not properly set.

Definition at line 345 of file diaCalculation.py.

349  filterNames):
350  """Run each of the plugins on the catalog.
351 
352  For catalog column names see the lsst.cat schema definitions for the
353  DiaObject and DiaSource tables (http://github.com/lsst/cat).
354 
355  Parameters
356  ----------
357  diaObjectCat : `pandas.DataFrame`
358  DiaObjects to update values of and append new objects to. DataFrame
359  should be indexed on "diaObjectId"
360  diaSourceCat : `pandas.DataFrame`
361  DiaSources associated with the DiaObjects in diaObjectCat.
362  DataFrame must be indexed on
363  ["diaObjectId", "filterName", "diaSourceId"]`
364  updatedDiaObjectIds : `numpy.ndarray`
365  Integer ids of the DiaObjects to update and create.
366  filterNames : `list` of `str`
367  List of string names of filters to be being processed.
368 
369  Returns
370  -------
371  returnStruct : `lsst.pipe.base.Struct`
372  Struct containing:
373 
374  ``diaObjectCat``
375  Full set of DiaObjects including both un-updated and
376  updated/new DiaObjects (`pandas.DataFrame`).
377  ``updatedDiaObjects``
378  Catalog of DiaObjects that were updated or created by this
379  task (`pandas.DataFrame`).
380 
381  Raises
382  ------
383  KeyError
384  Raises if `pandas.DataFrame` indexing is not properly set.
385  """
386  # DiaObjects will be updated in place.
387  diaObjectsToUpdate = diaObjectCat.loc[updatedDiaObjectIds, :]
388  self.log.info("Calculating summary stats for %i DiaObjects",
389  len(diaObjectsToUpdate))
390 
391  updatingDiaSources = diaSourceCat.loc[updatedDiaObjectIds, :]
392  diaSourcesGB = updatingDiaSources.groupby(level=0)
393  for runlevel in sorted(self.executionDict):
394  for plug in self.executionDict[runlevel].single:
395  if plug.needsFilter:
396  continue
397  for updatedDiaObjectId in updatedDiaObjectIds:
398 
399  # Sub-select diaSources associated with this diaObject.
400  objDiaSources = updatingDiaSources.loc[updatedDiaObjectId]
401 
402  # Sub-select on diaSources observed in the current filter.
403  with CCContext(plug, updatedDiaObjectId, self.log):
404  # We feed the catalog we need to update and the id
405  # so as to get a few into the catalog and not a copy.
406  # This updates the values in the catalog.
407  plug.calculate(diaObjects=diaObjectsToUpdate,
408  diaObjectId=updatedDiaObjectId,
409  diaSources=objDiaSources,
410  filterDiaSources=None,
411  filterName=None)
412  for plug in self.executionDict[runlevel].multi:
413  if plug.needsFilter:
414  continue
415  with CCContext(plug, diaObjectsToUpdate, self.log):
416  plug.calculate(diaObjects=diaObjectsToUpdate,
417  diaSources=diaSourcesGB,
418  filterDiaSources=None,
419  filterName=None)
420 
421  for filterName in filterNames:
422  try:
423  updatingFilterDiaSources = updatingDiaSources.loc[
424  (slice(None), filterName), :
425  ]
426  except KeyError:
427  self.log.warning("No DiaSource data with fitler=%s. "
428  "Continuing...", filterName)
429  continue
430  # Level=0 here groups by diaObjectId.
431  filterDiaSourcesGB = updatingFilterDiaSources.groupby(level=0)
432 
433  for runlevel in sorted(self.executionDict):
434  for plug in self.executionDict[runlevel].single:
435  if not plug.needsFilter:
436  continue
437  for updatedDiaObjectId in updatedDiaObjectIds:
438 
439  # Sub-select diaSources associated with this diaObject.
440  objDiaSources = updatingDiaSources.loc[updatedDiaObjectId]
441 
442  # Sub-select on diaSources observed in the current filter.
443  try:
444  filterObjDiaSources = objDiaSources.loc[filterName]
445  except KeyError:
446  self.log.warning(
447  "DiaObjectId={updatedDiaObjectId} has no "
448  "DiaSources for filter=%s. "
449  "Continuing...", filterName)
450  with CCContext(plug, updatedDiaObjectId, self.log):
451  # We feed the catalog we need to update and the id
452  # so as to get a few into the catalog and not a copy.
453  # This updates the values in the catalog.
454  plug.calculate(diaObjects=diaObjectsToUpdate,
455  diaObjectId=updatedDiaObjectId,
456  diaSources=objDiaSources,
457  filterDiaSources=filterObjDiaSources,
458  filterName=filterName)
459  for plug in self.executionDict[runlevel].multi:
460  if not plug.needsFilter:
461  continue
462  with CCContext(plug, diaObjectsToUpdate, self.log):
463  plug.calculate(diaObjects=diaObjectsToUpdate,
464  diaSources=diaSourcesGB,
465  filterDiaSources=filterDiaSourcesGB,
466  filterName=filterName)
467  # Need to store the newly updated diaObjects directly as the editing
468  # a view into diaObjectsToUpdate does not update the values of
469  # diaObjectCat.
470  diaObjectCat.loc[updatedDiaObjectIds, :] = diaObjectsToUpdate
471  return lsst.pipe.base.Struct(
472  diaObjectCat=diaObjectCat,
473  updatedDiaObjects=diaObjectsToUpdate)
474 

◆ initializePlugins()

def lsst.meas.base.diaCalculation.DiaObjectCalculationTask.initializePlugins (   self)
Initialize the plugins according to the configuration.

Reimplemented from lsst.meas.base.catalogCalculation.CatalogCalculationTask.

Definition at line 216 of file diaCalculation.py.

216  def initializePlugins(self):
217  """Initialize the plugins according to the configuration.
218  """
219 
220  pluginType = namedtuple('pluginType', 'single multi')
221  self.executionDict = {}
222  # Read the properties for each plugin. Allocate a dictionary entry for
223  # each run level. Verify that the plugins are above the minimum run
224  # level for an catalogCalculation plugin. For each run level, the
225  # plugins are sorted into either single record, or multi record groups
226  # to later be run appropriately
227  for executionOrder, name, config, PluginClass in sorted(self.config.plugins.apply()):
228  if executionOrder not in self.executionDict:
229  self.executionDict[executionOrder] = pluginType(single=[], multi=[])
230  if PluginClass.getExecutionOrder() >= BasePlugin.DEFAULT_CATALOGCALCULATION:
231  plug = PluginClass(config, name, metadata=self.plugMetadata)
232 
233  self._validatePluginCols(plug)
234 
235  self.plugins[name] = plug
236  if plug.plugType == 'single':
237  self.executionDict[executionOrder].single.append(plug)
238  elif plug.plugType == 'multi':
239  self.executionDict[executionOrder].multi.append(plug)
240  else:
241  errorTuple = (PluginClass, PluginClass.getExecutionOrder(),
242  BasePlugin.DEFAULT_CATALOGCALCULATION)
243  raise ValueError("{} has an execution order less than the minimum for an catalogCalculation "
244  "plugin. Value {} : Minimum {}".format(*errorTuple))
245 
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:174

◆ run() [1/2]

def lsst.meas.base.diaCalculation.DiaObjectCalculationTask.run (   self,
  diaObjectCat,
  diaSourceCat,
  updatedDiaObjectIds,
  filterNames 
)
The entry point for the DIA catalog calculation task.

Run method both updates the values in the diaObjectCat and appends
newly created DiaObjects to the catalog. For catalog column names
see the lsst.cat schema definitions for the DiaObject and DiaSource
tables (http://github.com/lsst/cat).

Parameters
----------
diaObjectCat : `pandas.DataFrame`
    DiaObjects to update values of and append new objects to. DataFrame
    should be indexed on "diaObjectId"
diaSourceCat : `pandas.DataFrame`
    DiaSources associated with the DiaObjects in diaObjectCat.
    DataFrame should be indexed on
    `["diaObjectId", "filterName", "diaSourceId"]`
updatedDiaObjectIds : `numpy.ndarray`
    Integer ids of the DiaObjects to update and create.
filterNames : `list` of `str`
    List of string names of filters to be being processed.

Returns
-------
returnStruct : `lsst.pipe.base.Struct`
    Struct containing:

    ``diaObjectCat``
        Full set of DiaObjects including both un-updated and
        updated/new DiaObjects (`pandas.DataFrame`).
    ``updatedDiaObjects``
        Catalog of DiaObjects  that were updated or created by this
        task (`pandas.DataFrame`).

Definition at line 277 of file diaCalculation.py.

281  filterNames):
282  """The entry point for the DIA catalog calculation task.
283 
284  Run method both updates the values in the diaObjectCat and appends
285  newly created DiaObjects to the catalog. For catalog column names
286  see the lsst.cat schema definitions for the DiaObject and DiaSource
287  tables (http://github.com/lsst/cat).
288 
289  Parameters
290  ----------
291  diaObjectCat : `pandas.DataFrame`
292  DiaObjects to update values of and append new objects to. DataFrame
293  should be indexed on "diaObjectId"
294  diaSourceCat : `pandas.DataFrame`
295  DiaSources associated with the DiaObjects in diaObjectCat.
296  DataFrame should be indexed on
297  `["diaObjectId", "filterName", "diaSourceId"]`
298  updatedDiaObjectIds : `numpy.ndarray`
299  Integer ids of the DiaObjects to update and create.
300  filterNames : `list` of `str`
301  List of string names of filters to be being processed.
302 
303  Returns
304  -------
305  returnStruct : `lsst.pipe.base.Struct`
306  Struct containing:
307 
308  ``diaObjectCat``
309  Full set of DiaObjects including both un-updated and
310  updated/new DiaObjects (`pandas.DataFrame`).
311  ``updatedDiaObjects``
312  Catalog of DiaObjects that were updated or created by this
313  task (`pandas.DataFrame`).
314  """
315  if diaObjectCat.index.name is None:
316  diaObjectCat.set_index("diaObjectId", inplace=True, drop=False)
317  elif diaObjectCat.index.name != "diaObjectId":
318  self.log.warning(
319  "Input diaObjectCat is indexed on column(s) incompatible with "
320  "this task. Should be indexed on 'diaObjectId'. Trying to set "
321  "index regardless")
322  diaObjectCat.set_index("diaObjectId", inplace=True, drop=False)
323 
324  # ``names`` by default is FrozenList([None]) hence we access the first
325  # element and test for None.
326  if diaSourceCat.index.names[0] is None:
327  diaSourceCat.set_index(
328  ["diaObjectId", "filterName", "diaSourceId"],
329  inplace=True,
330  drop=False)
331  elif (diaSourceCat.index.names
332  != ["diaObjectId", "filterName", "diaSourceId"]):
333  diaSourceCat.reset_index(inplace=True)
334  diaSourceCat.set_index(
335  ["diaObjectId", "filterName", "diaSourceId"],
336  inplace=True,
337  drop=False)
338 
339  return self.callCompute(diaObjectCat,
340  diaSourceCat,
341  updatedDiaObjectIds,
342  filterNames)
343 

◆ run() [2/2]

def lsst.meas.base.catalogCalculation.CatalogCalculationTask.run (   self,
  measCat 
)
inherited
The entry point for the catalog calculation task.

Parameters
----------
meascat : `lsst.afw.table.SourceCatalog`
    Catalog for measurement.

Definition at line 230 of file catalogCalculation.py.

230  def run(self, measCat):
231  """The entry point for the catalog calculation task.
232 
233  Parameters
234  ----------
235  meascat : `lsst.afw.table.SourceCatalog`
236  Catalog for measurement.
237  """
238  self.callCompute(measCat)
239 
def run(self, coaddExposures, bbox, wcs)
Definition: getTemplate.py:603

Member Data Documentation

◆ ConfigClass

lsst.meas.base.diaCalculation.DiaObjectCalculationTask.ConfigClass = DiaObjectCalculationConfig
static

Definition at line 203 of file diaCalculation.py.

◆ executionDict

lsst.meas.base.diaCalculation.DiaObjectCalculationTask.executionDict

Definition at line 221 of file diaCalculation.py.

◆ outputCols

lsst.meas.base.diaCalculation.DiaObjectCalculationTask.outputCols

Definition at line 212 of file diaCalculation.py.

◆ plugins

lsst.meas.base.diaCalculation.DiaObjectCalculationTask.plugins

Definition at line 211 of file diaCalculation.py.

◆ plugMetadata

lsst.meas.base.diaCalculation.DiaObjectCalculationTask.plugMetadata

Definition at line 210 of file diaCalculation.py.

◆ schema

lsst.meas.base.catalogCalculation.CatalogCalculationTask.schema
inherited

Definition at line 195 of file catalogCalculation.py.


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