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 | List of all members
lsst.meas.base.forcedMeasurement.ForcedMeasurementTask Class Reference

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

Inheritance diagram for lsst.meas.base.forcedMeasurement.ForcedMeasurementTask:

Public Member Functions

def __init__
 Initialize the task. More...
 
def run
 Perform forced measurement. More...
 
def generateMeasCat
 Initialize an output SourceCatalog using information from the reference catalog. More...
 
def attachTransformedFootprints
 Default implementation for attaching Footprints to blank sources prior to measurement. More...
 

Public Attributes

 mapper
 
 schema
 

Static Public Attributes

 ConfigClass = ForcedMeasurementConfig
 

Detailed Description

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

The task is configured with a list of "plugins": each plugin defines the values it measures (i.e. the columns in a table it will fill) and conducts that measurement on each detected source (see ForcedPlugin). The job of the measurement task is to initialize the set of plugins (which includes setting up the catalog schema) from their configuration, and then invoke each plugin on each source.

Most of the time, ForcedMeasurementTask will be used via one of the subclasses of ForcedPhotImageTask, ForcedPhotCcdTask and ForcedPhotCoaddTask. These combine this measurement subtask with a "references" subtask (see BaseReferencesTask and CoaddSrcReferencesTask) to perform forced measurement using measurements performed on another image as the references. There is generally little reason to use ForcedMeasurementTask outside of one of these drivers, unless it is necessary to avoid using the Butler for I/O.

ForcedMeasurementTask has only three methods: init(), run(), and generateMeasCat(). For configuration options, see SingleFrameMeasurementConfig.

Definition at line 175 of file forcedMeasurement.py.

Constructor & Destructor Documentation

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

Initialize the task.

Set up the execution order of the plugins and initialize the plugins, giving each plugin an opportunity to add its measurement fields to the output schema and to record information in the task metadata.

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

Parameters
[in]refSchemaSchema of the reference catalog. Must match the catalog later passed to generateMeasCat() and/or run().
[in,out]algMetadatalsst.daf.base.PropertyList used to record information about each algorithm. An empty PropertyList will be created if None.
[in]**kwdsKeyword arguments passed from lsst.pipe.base.Task.__init__

Definition at line 204 of file forcedMeasurement.py.

205  def __init__(self, refSchema, algMetadata=None, **kwds):
206  """!
207  Initialize the task. Set up the execution order of the plugins and initialize
208  the plugins, giving each plugin an opportunity to add its measurement fields to
209  the output schema and to record information in the task metadata.
210 
211  Note that while SingleFrameMeasurementTask is passed an initial Schema that is
212  appended to in order to create the output Schema, ForcedMeasurementTask is
213  initialized with the Schema of the reference catalog, from which a new Schema
214  for the output catalog is created. Fields to be copied directly from the
215  reference Schema are added before Plugin fields are added.
216 
217  @param[in] refSchema Schema of the reference catalog. Must match the catalog
218  later passed to generateMeasCat() and/or run().
219  @param[in,out] algMetadata lsst.daf.base.PropertyList used to record information about
220  each algorithm. An empty PropertyList will be created if None.
221  @param[in] **kwds Keyword arguments passed from lsst.pipe.base.Task.__init__
222  """
223  super(ForcedMeasurementTask, self).__init__(algMetadata=algMetadata, **kwds)
224  self.mapper = lsst.afw.table.SchemaMapper(refSchema)
225  self.mapper.addMinimalSchema(lsst.afw.table.SourceTable.makeMinimalSchema())
226  self.config.slots.setupSchema(self.mapper.editOutputSchema())
227  for refName, targetName in self.config.copyColumns.items():
228  refItem = refSchema.find(refName)
229  self.mapper.addMapping(refItem.key, targetName)
230  self.config.slots.setupSchema(self.mapper.editOutputSchema())
231  self.initializePlugins(schemaMapper=self.mapper)
232  self.schema = self.mapper.getOutputSchema()
233  self.makeSubtask("applyApCorr", schema=self.schema)
A mapping between the keys of two Schemas, used to copy data between them.
Definition: SchemaMapper.h:19
static Schema makeMinimalSchema()
Return a minimal schema for Source tables and records.
Definition: Source.h:242

Member Function Documentation

def lsst.meas.base.forcedMeasurement.ForcedMeasurementTask.attachTransformedFootprints (   self,
  sources,
  refCat,
  exposure,
  refWcs 
)

Default implementation for attaching Footprints to blank sources prior to measurement.

Footprints 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 refWcs to the exposure's Wcs, which downgrades HeavyFootprints into regular Footprints, destroying deblend information.

Note that ForcedPhotImageTask delegates to this method in its own attachFootprints method. attachFootprints can then be overridden by its subclasses to define how their Footprints should be generated.

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

Definition at line 364 of file forcedMeasurement.py.

365  def attachTransformedFootprints(self, sources, refCat, exposure, refWcs):
366  """!Default implementation for attaching Footprints to blank sources prior to measurement
367 
368  Footprints for forced photometry must be in the pixel coordinate system of the image being
369  measured, while the actual detections may start out in a different coordinate system.
370  This default implementation transforms the Footprints from the reference catalog from the
371  refWcs to the exposure's Wcs, which downgrades HeavyFootprints into regular Footprints,
372  destroying deblend information.
373 
374  Note that ForcedPhotImageTask delegates to this method in its own attachFootprints method.
375  attachFootprints can then be overridden by its subclasses to define how their Footprints
376  should be generated.
377 
378  See the documentation for run() for information about the relationships between run(),
379  generateMeasCat(), and attachTransformedFootprints().
380  """
381  exposureWcs = exposure.getWcs()
382  region = exposure.getBBox(lsst.afw.image.PARENT)
383  for srcRecord, refRecord in zip(sources, refCat):
384  srcRecord.setFootprint(refRecord.getFootprint().transform(refWcs, exposureWcs, region))
def attachTransformedFootprints
Default implementation for attaching Footprints to blank sources prior to measurement.
def lsst.meas.base.forcedMeasurement.ForcedMeasurementTask.generateMeasCat (   self,
  exposure,
  refCat,
  refWcs,
  idFactory = None 
)

Initialize an output SourceCatalog using information from the reference catalog.

This generates a new blank SourceRecord for each record in refCat. Note that this method does not attach any Footprints. Doing so is up to the caller (who may call attachedTransformedFootprints or define their own method - see run() for more information).

Parameters
[in]exposureExposure to be measured
[in]refCatSequence (not necessarily a SourceCatalog) of reference SourceRecords.
[in]refWcsWcs that defines the X,Y coordinate system of refCat
[in]idFactoryfactory for creating IDs for sources
Returns
Source catalog ready for measurement

Definition at line 337 of file forcedMeasurement.py.

338  def generateMeasCat(self, exposure, refCat, refWcs, idFactory=None):
339  """!Initialize an output SourceCatalog using information from the reference catalog.
340 
341  This generates a new blank SourceRecord for each record in refCat. Note that this
342  method does not attach any Footprints. Doing so is up to the caller (who may
343  call attachedTransformedFootprints or define their own method - see run() for more
344  information).
345 
346  @param[in] exposure Exposure to be measured
347  @param[in] refCat Sequence (not necessarily a SourceCatalog) of reference SourceRecords.
348  @param[in] refWcs Wcs that defines the X,Y coordinate system of refCat
349  @param[in] idFactory factory for creating IDs for sources
350 
351  @return Source catalog ready for measurement
352  """
353  if idFactory == None:
355  table = lsst.afw.table.SourceTable.make(self.schema, idFactory)
356  measCat = lsst.afw.table.SourceCatalog(table)
357  table = measCat.table
358  table.setMetadata(self.algMetadata)
359  table.preallocate(len(refCat))
360  for ref in refCat:
361  newSource = measCat.addNew()
362  newSource.assign(ref, self.mapper)
363  return measCat
static boost::shared_ptr< IdFactory > makeSimple()
Return a simple IdFactory that simply counts from 1.
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
static boost::shared_ptr< SourceTable > make(Schema const &schema, boost::shared_ptr< IdFactory > const &idFactory)
Construct a new table.
def generateMeasCat
Initialize an output SourceCatalog using information from the reference catalog.
def lsst.meas.base.forcedMeasurement.ForcedMeasurementTask.run (   self,
  measCat,
  exposure,
  refCat,
  refWcs,
  exposureId = None,
  beginOrder = None,
  endOrder = None,
  allowApCorr = True 
)

Perform forced measurement.

Parameters
[in]exposurelsst.afw.image.ExposureF to be measured; must have at least a Wcs attached.
[in]measCatSource catalog for measurement results; must be initialized with empty records already corresponding to those in refCat (via e.g. generateMeasCat).
[in]refCatA sequence of SourceRecord objects that provide reference information for the measurement. These will be passed to each Plugin in addition to the output SourceRecord.
[in]refWcsWcs that defines the X,Y coordinate system of refCat
[in]exposureIdoptional unique exposureId used to calculate random number generator seed in the NoiseReplacer.
[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]allowApCorrallow application of aperture correction?

Fills the initial empty SourceCatalog with forced measurement results. Two steps must occur before run() can be called:

Definition at line 235 of file forcedMeasurement.py.

236  allowApCorr=True):
237  """!
238  Perform forced measurement.
239 
240  @param[in] exposure lsst.afw.image.ExposureF to be measured; must have at least a Wcs attached.
241  @param[in] measCat Source catalog for measurement results; must be initialized with empty
242  records already corresponding to those in refCat (via e.g. generateMeasCat).
243  @param[in] refCat A sequence of SourceRecord objects that provide reference information
244  for the measurement. These will be passed to each Plugin in addition
245  to the output SourceRecord.
246  @param[in] refWcs Wcs that defines the X,Y coordinate system of refCat
247  @param[in] exposureId optional unique exposureId used to calculate random number
248  generator seed in the NoiseReplacer.
249  @param[in] beginOrder beginning execution order (inclusive): measurements with
250  executionOrder < beginOrder are not executed. None for no limit.
251  @param[in] endOrder ending execution order (exclusive): measurements with
252  executionOrder >= endOrder are not executed. None for no limit.
253  @param[in] allowApCorr allow application of aperture correction?
254 
255  Fills the initial empty SourceCatalog with forced measurement results. Two steps must occur
256  before run() can be called:
257  - generateMeasCat() must be called to create the output measCat argument.
258  - Footprints appropriate for the forced sources must be attached to the measCat records. The
259  attachTransformedFootprints() method can be used to do this, but this degrades HeavyFootprints
260  to regular Footprints, leading to non-deblended measurement, so most callers should provide
261  Footprints some other way. Typically, calling code will have access to information that will
262  allow them to provide HeavyFootprints - for instance, ForcedPhotCoaddTask uses the HeavyFootprints
263  from deblending run in the same band just before non-forced is run measurement in that band.
264  """
265  # First check that the reference catalog does not contain any children for which
266  # any member of their parent chain is not within the list. This can occur at
267  # boundaries when the parent is outside and one of the children is within.
268  # Currently, the parent chain is always only one deep, but just in case, this
269  # code checks for any case where when the parent chain to a child's topmost
270  # parent is broken and raises an exception if it occurs.
271  #
272  # I.e. this code checks that this precondition is satisfied by whatever reference
273  # catalog provider is being paired with it.
274  refCatIdDict = {ref.getId(): ref.getParent() for ref in refCat}
275  for ref in refCat:
276  refId = ref.getId()
277  topId = refId
278  while(topId > 0):
279  if not topId in refCatIdDict.keys():
280  raise RuntimeError("Reference catalog contains a child for which at least "
281  "one parent in its parent chain is not in the catalog.")
282  topId = refCatIdDict[topId]
283 
284  # Construct a footprints dict which looks like
285  # {ref.getId(): (ref.getParent(), source.getFootprint())}
286  # (i.e. getting the footprint from the transformed source footprint)
287  footprints = {ref.getId(): (ref.getParent(), measRecord.getFootprint())
288  for (ref, measRecord) in zip(refCat, measCat)}
289 
290  self.log.info("Performing forced measurement on %d sources" % len(refCat))
291 
292  if self.config.doReplaceWithNoise:
293  noiseReplacer = NoiseReplacer(self.config.noiseReplacer, exposure, footprints, log=self.log, exposureId=exposureId)
294  algMetadata = measCat.getTable().getMetadata()
295  if not algMetadata is None:
296  algMetadata.addInt("NOISE_SEED_MULTIPLIER", self.config.noiseReplacer.noiseSeedMultiplier)
297  algMetadata.addString("NOISE_SOURCE", self.config.noiseReplacer.noiseSource)
298  algMetadata.addDouble("NOISE_OFFSET", self.config.noiseReplacer.noiseOffset)
299  if not exposureId is None:
300  algMetadata.addLong("NOISE_EXPOSURE_ID", exposureId)
301  else:
302  noiseReplacer = DummyNoiseReplacer()
303 
304  # Create parent cat which slices both the refCat and measCat (sources)
305  # first, get the reference and source records which have no parent
306  refParentCat, measParentCat = refCat.getChildren(0, measCat)
307  for parentIdx, (refParentRecord, measParentRecord) in enumerate(zip(refParentCat,measParentCat)):
308 
309  # first process the records which have the current parent as children
310  refChildCat, measChildCat = refCat.getChildren(refParentRecord.getId(), measCat)
311  # TODO: skip this loop if there are no plugins configured for single-object mode
312  for refChildRecord, measChildRecord in zip(refChildCat, measChildCat):
313  noiseReplacer.insertSource(refChildRecord.getId())
314  self.callMeasure(measChildRecord, exposure, refChildRecord, refWcs,
315  beginOrder=beginOrder, endOrder=endOrder)
316  noiseReplacer.removeSource(refChildRecord.getId())
317 
318  # then process the parent record
319  noiseReplacer.insertSource(refParentRecord.getId())
320  self.callMeasure(measParentRecord, exposure, refParentRecord, refWcs,
321  beginOrder=beginOrder, endOrder=endOrder)
322  self.callMeasureN(measParentCat[parentIdx:parentIdx+1], exposure,
323  refParentCat[parentIdx:parentIdx+1],
324  beginOrder=beginOrder, endOrder=endOrder)
325  # measure all the children simultaneously
326  self.callMeasureN(measChildCat, exposure, refChildCat,
327  beginOrder=beginOrder, endOrder=endOrder)
328  noiseReplacer.removeSource(refParentRecord.getId())
329  noiseReplacer.end()
330 
331  if allowApCorr:
332  self._applyApCorrIfWanted(
333  sources = measCat,
334  apCorrMap = exposure.getInfo().getApCorrMap(),
335  endOrder = endOrder,
336  )

Member Data Documentation

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

Definition at line 202 of file forcedMeasurement.py.

lsst.meas.base.forcedMeasurement.ForcedMeasurementTask.mapper

Definition at line 223 of file forcedMeasurement.py.

lsst.meas.base.forcedMeasurement.ForcedMeasurementTask.schema

Definition at line 231 of file forcedMeasurement.py.


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