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.pipe.tasks.multiBand.MeasureMergedCoaddSourcesTask Class Reference
Inheritance diagram for lsst.pipe.tasks.multiBand.MeasureMergedCoaddSourcesTask:

Public Member Functions

def __init__
 
def run
 
def readSources
 
def setIsPrimaryFlag
 
def writeMatches
 
def write
 

Public Attributes

 schemaMapper
 
 schema
 
 algMetadata
 
 isPatchInnerKey
 
 isTractInnerKey
 
 isPrimaryKey
 

Static Public Attributes

 ConfigClass = MeasureMergedCoaddSourcesConfig
 
 RunnerClass = ButlerInitializedTaskRunner
 
tuple getSchemaCatalogs = _makeGetSchemaCatalogs("meas")
 
tuple makeIdFactory = _makeMakeIdFactory("MergedCoaddId")
 

Private Member Functions

def _makeArgumentParser
 

Static Private Attributes

string _DefaultName = "measureCoaddSources"
 

Detailed Description

Measure sources using the merged catalog of detections

This operation is performed separately on each band.  We deblend and measure on
the list of merge detections.  The results from each band will subsequently
be merged to create a final reference catalog for forced measurement.

Definition at line 482 of file multiBand.py.

Constructor & Destructor Documentation

def lsst.pipe.tasks.multiBand.MeasureMergedCoaddSourcesTask.__init__ (   self,
  butler = None,
  schema = None,
  peakSchema = None,
  kwargs 
)
Initialize the task.

Keyword arguments (in addition to those forwarded to CmdLineTask.__init__):
 - schema: the schema of the merged detection catalog used as input to this one
 - peakSchema: the schema of the PeakRecords in the Footprints in the merged detection catalog
 - butler: a butler used to read the input schemas from disk, if schema or peakSchema is None

The task will set its own self.schema attribute to the schema of the output measurement catalog.
This will include all fields from the input schema, as well as additional fields for all the
measurements.

Definition at line 502 of file multiBand.py.

503  def __init__(self, butler=None, schema=None, peakSchema=None, **kwargs):
504  """Initialize the task.
505 
506  Keyword arguments (in addition to those forwarded to CmdLineTask.__init__):
507  - schema: the schema of the merged detection catalog used as input to this one
508  - peakSchema: the schema of the PeakRecords in the Footprints in the merged detection catalog
509  - butler: a butler used to read the input schemas from disk, if schema or peakSchema is None
510 
511  The task will set its own self.schema attribute to the schema of the output measurement catalog.
512  This will include all fields from the input schema, as well as additional fields for all the
513  measurements.
514  """
515  CmdLineTask.__init__(self, **kwargs)
516  if schema is None:
517  assert butler is not None, "Neither butler nor schema is defined"
518  schema = butler.get(self.config.coaddName + "Coadd_mergeDet_schema", immediate=True).schema
519  self.schemaMapper = afwTable.SchemaMapper(schema)
520  self.schemaMapper.addMinimalSchema(schema)
521  self.schema = self.schemaMapper.getOutputSchema()
522  self.algMetadata = PropertyList()
523  if self.config.doDeblend:
524  if peakSchema is None:
525  assert butler is not None, "Neither butler nor peakSchema is defined"
526  peakSchema = butler.get(self.config.coaddName + "Coadd_peak_schema", immediate=True).schema
527  self.makeSubtask("deblend", schema=self.schema, peakSchema=peakSchema)
528  self.makeSubtask("measurement", schema=self.schema, algMetadata=self.algMetadata)
529  self.makeSubtask("astrometry", schema=self.schema)
531  self.isPatchInnerKey = self.schema.addField(
532  "detect_isPatchInner", type="Flag",
533  doc="true if source is in the inner region of a coadd patch",
534  )
535  self.isTractInnerKey = self.schema.addField(
536  "detect_isTractInner", type="Flag",
537  doc="true if source is in the inner region of a coadd tract",
538  )
539  self.isPrimaryKey = self.schema.addField(
540  "detect_isPrimary", type="Flag",
541  doc="true if source has no children and is in the inner region of a coadd patch " \
542  + "and is in the inner region of a coadd tract",
543  )
Class for storing ordered metadata with comments.
Definition: PropertyList.h:81
A mapping between the keys of two Schemas, used to copy data between them.
Definition: SchemaMapper.h:19

Member Function Documentation

def lsst.pipe.tasks.multiBand.MeasureMergedCoaddSourcesTask._makeArgumentParser (   cls)
private

Definition at line 496 of file multiBand.py.

497  def _makeArgumentParser(cls):
498  parser = ArgumentParser(name=cls._DefaultName)
499  parser.add_id_argument("--id", "deepCoadd", help="data ID, e.g. --id tract=12345 patch=1,2 filter=r",
500  ContainerClass=ExistingCoaddDataIdContainer)
501  return parser
def lsst.pipe.tasks.multiBand.MeasureMergedCoaddSourcesTask.readSources (   self,
  dataRef 
)
Read input sources

We also need to add columns to hold the measurements we're about to make
so we can measure in-place.

Definition at line 562 of file multiBand.py.

563  def readSources(self, dataRef):
564  """Read input sources
565 
566  We also need to add columns to hold the measurements we're about to make
567  so we can measure in-place.
568  """
569  merged = dataRef.get(self.config.coaddName + "Coadd_mergeDet", immediate=True)
570  self.log.info("Read %d detections: %s" % (len(merged), dataRef.dataId))
571  idFactory = self.makeIdFactory(dataRef)
572  for s in merged:
573  idFactory.notify(s.getId())
574  table = afwTable.SourceTable.make(self.schema, idFactory)
575  sources = afwTable.SourceCatalog(table)
576  sources.extend(merged, self.schemaMapper)
577  return sources
Custom catalog class for record/table subclasses that are guaranteed to have an ID, and should generally be sorted by that ID.
Definition: fwd.h:55
def lsst.pipe.tasks.multiBand.MeasureMergedCoaddSourcesTask.run (   self,
  patchRef 
)
Measure and deblend

Definition at line 544 of file multiBand.py.

545  def run(self, patchRef):
546  """Measure and deblend"""
547  exposure = patchRef.get(self.config.coaddName + "Coadd_calexp_det", immediate=True)
548  sources = self.readSources(patchRef)
549  if self.config.doDeblend:
550  self.deblend.run(exposure, sources, exposure.getPsf())
551 
552  bigKey = sources.schema["deblend_parentTooBig"].asKey()
553  numBig = sum((s.get(bigKey) for s in sources)) # catalog is non-contiguous so can't extract column
554  if numBig > 0:
555  self.log.warn("Patch %s contains %d large footprints that were not deblended" %
556  (patchRef.dataId, numBig))
557  self.measurement.run(exposure, sources)
558  self.setIsPrimaryFlag(sources, patchRef)
559  if self.config.doMatchSources:
560  self.writeMatches(patchRef, exposure, sources)
561  self.write(patchRef, sources)
boost::enable_if< typename ExpressionTraits< Scalar >::IsScalar, Scalar >::type sum(Scalar const &scalar)
Definition: operators.h:1250
def lsst.pipe.tasks.multiBand.MeasureMergedCoaddSourcesTask.setIsPrimaryFlag (   self,
  sources,
  patchRef 
)
Set is-primary and related flags on sources

sources: a SourceTable
    - reads centroid fields and an nChild field
    - writes is-patch-inner, is-tract-inner and is-primary flags
patchRef: a patch reference (for retrieving sky info)

Will raise RuntimeError if self.config.doDeblend and the nChild key is not found in the table

Definition at line 578 of file multiBand.py.

579  def setIsPrimaryFlag(self, sources, patchRef):
580  """Set is-primary and related flags on sources
581 
582  sources: a SourceTable
583  - reads centroid fields and an nChild field
584  - writes is-patch-inner, is-tract-inner and is-primary flags
585  patchRef: a patch reference (for retrieving sky info)
586 
587  Will raise RuntimeError if self.config.doDeblend and the nChild key is not found in the table
588  """
589  skyInfo = getSkyInfo(coaddName=self.config.coaddName, patchRef=patchRef)
590 
591  # Test for the presence of the nchild key instead of checking config.doDeblend because sources
592  # might be unpersisted with deblend info, even if deblending is not run again.
593  nChildKeyName = "deblend_nChild"
594  try:
595  nChildKey = self.schema.find(nChildKeyName).key
596  except Exception:
597  nChildKey = None
598 
599  if self.config.doDeblend and nChildKey is None:
600  # deblending was run but the nChildKey was not found; this suggests a variant deblender
601  # was used that we cannot use the output from, or some obscure error.
602  raise RuntimeError("Ran the deblender but cannot find %r in the source table" % (nChildKeyName,))
603 
604  # set inner flags for each source and set primary flags for sources with no children
605  # (or all sources if deblend info not available)
606  innerFloatBBox = afwGeom.Box2D(skyInfo.patchInfo.getInnerBBox())
607  tractId = skyInfo.tractInfo.getId()
608  for source in sources:
609  if source.getCentroidFlag():
610  # centroid unknown, so leave the inner and primary flags False
611  continue
612 
613  centroidPos = source.getCentroid()
614  # Skip source whose centroidPos is nan
615  # I do not know why this can happen (NY)
616  if centroidPos[0] != centroidPos[0] or centroidPos[1] != centroidPos[1]:
617  continue
618  isPatchInner = innerFloatBBox.contains(centroidPos)
619  source.setFlag(self.isPatchInnerKey, isPatchInner)
620 
621  skyPos = source.getCoord()
622  sourceInnerTractId = skyInfo.skyMap.findTract(skyPos).getId()
623  isTractInner = sourceInnerTractId == tractId
624  source.setFlag(self.isTractInnerKey, isTractInner)
625 
626  if nChildKey is None or source.get(nChildKey) == 0:
627  source.setFlag(self.isPrimaryKey, isPatchInner and isTractInner)
def getSkyInfo
Return SkyMap, tract and patch.
Definition: coaddBase.py:212
A floating-point coordinate rectangle geometry.
Definition: Box.h:271
def lsst.pipe.tasks.multiBand.MeasureMergedCoaddSourcesTask.write (   self,
  dataRef,
  sources 
)
Write the source catalog

Definition at line 643 of file multiBand.py.

644  def write(self, dataRef, sources):
645  """Write the source catalog"""
646  dataRef.put(sources, self.config.coaddName + "Coadd_meas")
647  self.log.info("Wrote %d sources: %s" % (len(sources), dataRef.dataId))
648 
def lsst.pipe.tasks.multiBand.MeasureMergedCoaddSourcesTask.writeMatches (   self,
  dataRef,
  exposure,
  sources 
)
Write matches of the sources to the astrometric reference catalog

We use the Wcs in the exposure to match sources.

dataRef: data reference
exposure: exposure with Wcs
sources: source catalog

Definition at line 628 of file multiBand.py.

629  def writeMatches(self, dataRef, exposure, sources):
630  """Write matches of the sources to the astrometric reference catalog
631 
632  We use the Wcs in the exposure to match sources.
633 
634  dataRef: data reference
635  exposure: exposure with Wcs
636  sources: source catalog
637  """
638  result = self.astrometry.loadAndMatch(exposure=exposure, sourceCat=sources)
639  if result.matches:
640  matches = afwTable.packMatches(result.matches)
641  matches.table.setMetadata(result.matchMeta)
642  dataRef.put(matches, self.config.coaddName + "Coadd_srcMatch")
BaseCatalog packMatches(std::vector< Match< Record1, Record2 > > const &matches)
Return a table representation of a MatchVector that can be used to persist it.

Member Data Documentation

string lsst.pipe.tasks.multiBand.MeasureMergedCoaddSourcesTask._DefaultName = "measureCoaddSources"
staticprivate

Definition at line 489 of file multiBand.py.

lsst.pipe.tasks.multiBand.MeasureMergedCoaddSourcesTask.algMetadata

Definition at line 521 of file multiBand.py.

lsst.pipe.tasks.multiBand.MeasureMergedCoaddSourcesTask.ConfigClass = MeasureMergedCoaddSourcesConfig
static

Definition at line 490 of file multiBand.py.

tuple lsst.pipe.tasks.multiBand.MeasureMergedCoaddSourcesTask.getSchemaCatalogs = _makeGetSchemaCatalogs("meas")
static

Definition at line 492 of file multiBand.py.

lsst.pipe.tasks.multiBand.MeasureMergedCoaddSourcesTask.isPatchInnerKey

Definition at line 530 of file multiBand.py.

lsst.pipe.tasks.multiBand.MeasureMergedCoaddSourcesTask.isPrimaryKey

Definition at line 538 of file multiBand.py.

lsst.pipe.tasks.multiBand.MeasureMergedCoaddSourcesTask.isTractInnerKey

Definition at line 534 of file multiBand.py.

tuple lsst.pipe.tasks.multiBand.MeasureMergedCoaddSourcesTask.makeIdFactory = _makeMakeIdFactory("MergedCoaddId")
static

Definition at line 493 of file multiBand.py.

lsst.pipe.tasks.multiBand.MeasureMergedCoaddSourcesTask.RunnerClass = ButlerInitializedTaskRunner
static

Definition at line 491 of file multiBand.py.

lsst.pipe.tasks.multiBand.MeasureMergedCoaddSourcesTask.schema

Definition at line 520 of file multiBand.py.

lsst.pipe.tasks.multiBand.MeasureMergedCoaddSourcesTask.schemaMapper

Definition at line 518 of file multiBand.py.


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