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.sfm.SingleFrameMeasurementTask Class Reference

A subtask for measuring the properties of sources on a single exposure. More...

Inheritance diagram for lsst.meas.base.sfm.SingleFrameMeasurementTask:

Public Member Functions

def __init__
 Initialize the task. More...
 
def run
 Run single frame measurement over an exposure and source catalog. More...
 
def measure
 Backwards-compatibility alias for run() More...
 

Public Attributes

 schema
 

Static Public Attributes

 ConfigClass = SingleFrameMeasurementConfig
 

Detailed Description

A subtask for measuring the properties of sources on a single exposure.

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 SingleFramePlugin). 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.

When run after the deblender (see lsst.meas.deblender.SourceDeblendTask), SingleFrameMeasurementTask also replaces each source's neighbors with noise before measuring each source, utilizing the HeavyFootprints created by the deblender (see NoiseReplacer).

SingleFrameMeasurementTask has only two methods: init() and run(). For configuration options, see SingleFrameMeasurementConfig.

A complete example of using SingleFrameMeasurementTask

The code below is in examples/runSingleFrameTask.py

See meas_algorithms_detection_Example for more information on SourceDetectionTask.

First, import the required tasks (there are some other standard imports; read the file if you're confused):

1 from lsst.meas.algorithms.detection import SourceDetectionTask
2 from lsst.meas.base import SingleFrameMeasurementTask

We need to create our tasks before processing any data as the task constructors can add extra columns to the schema. The most important argument we pass these to these is an lsst.afw.table.Schema object, which contains information about the fields (i.e. columns) of the measurement catalog we'll create, including names, types, and additional documentation. Tasks that operate on a catalog are typically passed a Schema upon construction, to which they add the fields they'll fill later when run. We construct a mostly empty Schema that contains just the fields required for a SourceCatalog like this:

1  schema = afwTable.SourceTable.makeMinimalSchema()

Now we can configure and create the SourceDetectionTask:

1  #
2  # Create the detection task
3  #
4  config = SourceDetectionTask.ConfigClass()
5  config.thresholdPolarity = "both"
6  config.background.isNanSafe = True
7  config.thresholdValue = 3
8  detectionTask = SourceDetectionTask(config=config, schema=schema)

We then move on to configuring the measurement task:

1  #
2  # And the measurement Task
3  #
4  config = SingleFrameMeasurementTask.ConfigClass()

While a reasonable set of plugins is configured by default, we'll customize the list. We also need to unset one of the slots at the same time, because we're not running the algorithm that it's set to by default, and that would cause problems later:

1  config.plugins.names.clear()
2  for plugin in ["base_SdssCentroid", "base_SdssShape", "base_CircularApertureFlux", "base_GaussianFlux"]:
3  config.plugins.names.add(plugin)
4  config.slots.psfFlux = None

Now, finally, we can construct the measurement task:

1  measureTask = SingleFrameMeasurementTask(schema, config=config)

After constructing all the tasks, we can inspect the Schema we've created:

1  print schema

All of the fields in the schema can be accessed via the get() method on a record object. See afwTable for more information.

We're now ready to process the data (we could loop over multiple exposures/catalogs using the same task objects). First create the output table and process the image to find sources:

1  tab = afwTable.SourceTable.make(schema)
1  result = detectionTask.run(tab, exposure)
2 
3  sources = result.sources

Then measure them:

1  measureTask.run(sources, exposure)

We then might plot the results (e.g. if you set --ds9 on the command line)

1  if display: # display on ds9 (see also --debug argparse option)
2  frame = 1
3  ds9.mtv(exposure, frame=frame)
4 
5  with ds9.Buffering():
6  for s in sources:
7  xy = s.getCentroid()
8  ds9.dot('+', *xy, ctype=ds9.CYAN if s.get("flags_negative") else ds9.GREEN, frame=frame)
9  ds9.dot(s.getShape(), *xy, ctype=ds9.RED, frame=frame)

and end up with something like

runSingleFrameTask-ds9.png

Definition at line 138 of file sfm.py.

Constructor & Destructor Documentation

def lsst.meas.base.sfm.SingleFrameMeasurementTask.__init__ (   self,
  schema,
  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.

Parameters
[in,out]schemalsst.afw.table.Schema, to be initialized to include the measurement fields from the plugins already
[in,out]algMetadatalsst.daf.base.PropertyList used to record information about each algorithm. An empty PropertyList will be created if None.
[in]**kwdsKeyword arguments forwarded to lsst.pipe.base.Task.__init__

Definition at line 232 of file sfm.py.

233  def __init__(self, schema, algMetadata=None, **kwds):
234  """!
235  Initialize the task. Set up the execution order of the plugins and initialize
236  the plugins, giving each plugin an opportunity to add its measurement fields to
237  the output schema and to record information in the task metadata.
238 
239  @param[in,out] schema lsst.afw.table.Schema, to be initialized to include the
240  measurement fields from the plugins already
241  @param[in,out] algMetadata lsst.daf.base.PropertyList used to record information about
242  each algorithm. An empty PropertyList will be created if None.
243  @param[in] **kwds Keyword arguments forwarded to lsst.pipe.base.Task.__init__
244  """
245  super(SingleFrameMeasurementTask, self).__init__(algMetadata=algMetadata, **kwds)
246  self.schema = schema
247  self.config.slots.setupSchema(self.schema)
248  self.initializePlugins(schema=self.schema)
249  self.makeSubtask("applyApCorr", schema=self.schema)
def __init__
Initialize the task.
Definition: sfm.py:232

Member Function Documentation

def lsst.meas.base.sfm.SingleFrameMeasurementTask.measure (   self,
  measCat,
  exposure 
)

Backwards-compatibility alias for run()

Definition at line 331 of file sfm.py.

332  def measure(self, measCat, exposure):
333  """!
334  Backwards-compatibility alias for run()
335  """
336  self.run(measCat, exposure)
def run
Run single frame measurement over an exposure and source catalog.
Definition: sfm.py:251
def measure
Backwards-compatibility alias for run()
Definition: sfm.py:331
def lsst.meas.base.sfm.SingleFrameMeasurementTask.run (   self,
  measCat,
  exposure,
  noiseImage = None,
  exposureId = None,
  beginOrder = None,
  endOrder = None,
  allowApCorr = True 
)

Run single frame measurement over an exposure and source catalog.

Parameters
[in,out]measCatlsst.afw.table.SourceCatalog to be filled with outputs. Must contain all the SourceRecords to be measured (with Footprints attached), and have a schema that is a superset of self.schema.
[in]exposurelsst.afw.image.ExposureF, containing the pixel data to be measured and the associated Psf, Wcs, etc.
[in]noiseImageoptional lsst.afw.image.ImageF for test which need to control noiseReplacement
[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?

Definition at line 251 of file sfm.py.

252  allowApCorr=True):
253  """!
254  Run single frame measurement over an exposure and source catalog
255 
256  @param[in,out] measCat lsst.afw.table.SourceCatalog to be filled with outputs. Must
257  contain all the SourceRecords to be measured (with Footprints
258  attached), and have a schema that is a superset of self.schema.
259 
260  @param[in] exposure lsst.afw.image.ExposureF, containing the pixel data to
261  be measured and the associated Psf, Wcs, etc.
262  @param[in] noiseImage optional lsst.afw.image.ImageF for test which need to control
263  noiseReplacement
264  @param[in] exposureId optional unique exposureId used to calculate random number
265  generator seed in the NoiseReplacer.
266  @param[in] beginOrder beginning execution order (inclusive): measurements with
267  executionOrder < beginOrder are not executed. None for no limit.
268  @param[in] endOrder ending execution order (exclusive): measurements with
269  executionOrder >= endOrder are not executed. None for no limit.
270  @param[in] allowApCorr allow application of aperture correction?
271  """
272  # Temporary workaround for change in order of arguments; will be removed when transition
273  # from meas_algorithms to meas_base is complete.
274  if exposure.__class__.__name__ == "SourceCatalog":
275  temp = exposure
276  exposure = measCat
277  measCat = temp
278  assert measCat.getSchema().contains(self.schema)
279  footprints = {measRecord.getId(): (measRecord.getParent(), measRecord.getFootprint())
280  for measRecord in measCat}
281 
282  # noiseReplacer is used to fill the footprints with noise and save heavy footprints
283  # of the source pixels so that they can be restored one at a time for measurement.
284  # After the NoiseReplacer is constructed, all pixels in the exposure.getMaskedImage()
285  # which belong to objects in measCat will be replaced with noise
286  if self.config.doReplaceWithNoise:
287  noiseReplacer = NoiseReplacer(self.config.noiseReplacer, exposure, footprints,
288  noiseImage=noiseImage, log=self.log, exposureId=exposureId)
289  algMetadata = measCat.getMetadata()
290  if not algMetadata is None:
291  algMetadata.addInt("NOISE_SEED_MULTIPLIER", self.config.noiseReplacer.noiseSeedMultiplier)
292  algMetadata.addString("NOISE_SOURCE", self.config.noiseReplacer.noiseSource)
293  algMetadata.addDouble("NOISE_OFFSET", self.config.noiseReplacer.noiseOffset)
294  if not exposureId is None:
295  algMetadata.addLong("NOISE_EXPOSURE_ID", exposureId)
296  else:
297  noiseReplacer = DummyNoiseReplacer()
298 
299  # First, create a catalog of all parentless sources
300  # Loop through all the parent sources, first processing the children, then the parent
301  measParentCat = measCat.getChildren(0)
302 
303  self.log.info("Measuring %d sources (%d parents, %d children) "
304  % (len(measCat), len(measParentCat), len(measCat) - len(measParentCat)))
305 
306  for parentIdx, measParentRecord in enumerate(measParentCat):
307  # first get all the children of this parent, insert footprint in turn, and measure
308  measChildCat = measCat.getChildren(measParentRecord.getId())
309  # TODO: skip this loop if there are no plugins configured for single-object mode
310  for measChildRecord in measChildCat:
311  noiseReplacer.insertSource(measChildRecord.getId())
312  self.callMeasure(measChildRecord, exposure, beginOrder=beginOrder, endOrder=endOrder)
313  noiseReplacer.removeSource(measChildRecord.getId())
314  # Then insert the parent footprint, and measure that
315  noiseReplacer.insertSource(measParentRecord.getId())
316  self.callMeasure(measParentRecord, exposure, beginOrder=beginOrder, endOrder=endOrder)
317  # Finally, process both the parent and the child set through measureN
318  self.callMeasureN(measParentCat[parentIdx:parentIdx+1], exposure,
319  beginOrder=beginOrder, endOrder=endOrder)
320  self.callMeasureN(measChildCat, exposure, beginOrder=beginOrder, endOrder=endOrder)
321  noiseReplacer.removeSource(measParentRecord.getId())
322  # when done, restore the exposure to its original state
323  noiseReplacer.end()
324 
325  if allowApCorr:
326  self._applyApCorrIfWanted(
327  sources = measCat,
328  apCorrMap = exposure.getInfo().getApCorrMap(),
329  endOrder = endOrder,
330  )

Member Data Documentation

lsst.meas.base.sfm.SingleFrameMeasurementTask.ConfigClass = SingleFrameMeasurementConfig
static

Definition at line 230 of file sfm.py.

lsst.meas.base.sfm.SingleFrameMeasurementTask.schema

Definition at line 245 of file sfm.py.


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