lsst.pipe.tasks  13.0-66-gfbf2f2ce+5
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
lsst.pipe.tasks.measurePsf.MeasurePsfTask Class Reference

Measure the PSF. More...

Inheritance diagram for lsst.pipe.tasks.measurePsf.MeasurePsfTask:

Public Member Functions

def __init__ (self, schema=None, kwargs)
 Create the detection task. More...
 
def run (self, exposure, sources, expId=0, matches=None)
 Measure the PSF. More...
 
def usesMatches (self)
 

Public Attributes

 candidateKey
 
 usedKey
 
 reservedKey
 

Static Public Attributes

 ConfigClass = MeasurePsfConfig
 

Detailed Description

Measure the PSF.

Contents

Description

A task that selects stars from a catalog of sources and uses those to measure the PSF.

The star selector is a subclass of lsst.meas.algorithms.BaseStarSelectorTask and the PSF determiner is a sublcass of lsst.meas.algorithms.BasePsfDeterminerTask

Warning
There is no establised set of configuration parameters for these algorithms, so once you start modifying parameters (as we do in A complete example of using MeasurePsfTask) your code is no longer portable.

Task initialisation

Create the detection task. Most arguments are simply passed onto pipe.base.Task.

Parameters
schemaAn lsst::afw::table::Schema used to create the output lsst.afw.table.SourceCatalog
**kwargsKeyword arguments passed to lsst.pipe.base.task.Task.__init__.

If schema is not None, 'calib.psf.candidate' and 'calib.psf.used' fields will be added to identify which stars were employed in the PSF estimation.

Note
This task can add fields to the schema, so any code calling this task must ensure that these fields are indeed present in the input table.

Invoking the Task

Measure the PSF.

Parameters
[in,out]exposureExposure to process; measured PSF will be added.
[in,out]sourcesMeasured sources on exposure; flag fields will be set marking stars chosen by the star selector and the PSF determiner if a schema was passed to the task constructor.
[in]expIdExposure id used for generating random seed.
[in]matchesA list of lsst.afw.table.ReferenceMatch objects (i.e. of lsst.afw.table.Match with first being of type lsst.afw.table.SimpleRecord and second type lsst.afw.table.SourceRecord — the reference object and detected object respectively) as returned by e.g. the AstrometryTask. Used by star selectors that choose to refer to an external catalog.
Returns
a pipe.base.Struct with fields:
  • psf: The measured PSF (also set in the input exposure)
  • cellSet: an lsst.afw.math.SpatialCellSet containing the PSF candidates as returned by the psf determiner.

Configuration parameters

See MeasurePsfConfig.

Debug variables

The command line task interface supports a flag -d to import debug.py from your PYTHONPATH; see baseDebug for more about debug.py files.

display
If True, display debugging plots
displayExposure
display the Exposure + spatialCells
displayPsfCandidates
show mosaic of candidates
showBadCandidates
Include bad candidates
displayPsfMosaic
show mosaic of reconstructed PSF(xy)
displayResiduals
show residuals
normalizeResiduals
Normalise residuals by object amplitude

Additionally you can enable any debug outputs that your chosen star selector and psf determiner support.

A complete example of using MeasurePsfTask

This code is in measurePsfTask.py in the examples directory, and can be run as e.g.

examples/measurePsfTask.py --ds9

The example also runs SourceDetectionTask and SourceMeasurementTask; see meas_algorithms_measurement_Example for more explanation.

Import the tasks (there are some other standard imports; read the file to see them all):

from lsst.meas.algorithms.detection import SourceDetectionTask
from lsst.meas.base import SingleFrameMeasurementTask
from lsst.pipe.tasks.measurePsf import MeasurePsfTask

We need to create the tasks before processing any data as the task constructor can add an extra column to the schema, but first we need an almost-empty Schema:

schema = afwTable.SourceTable.makeMinimalSchema()

We can now call the constructors for the tasks we need to find and characterize candidate PSF stars:

config = SourceDetectionTask.ConfigClass()
config.reEstimateBackground = False
detectionTask = SourceDetectionTask(config=config, schema=schema)
config = SingleFrameMeasurementTask.ConfigClass()
# Use the minimum set of plugins required.
config.plugins.names.clear()
for plugin in ["base_SdssCentroid", "base_SdssShape", "base_CircularApertureFlux", "base_PixelFlags"]:
config.plugins.names.add(plugin)
config.plugins["base_CircularApertureFlux"].radii = [7.0]
# Use of the PSF flux is hardcoded in secondMomentStarSelector
config.slots.psfFlux = "base_CircularApertureFlux_7_0"
measureTask = SingleFrameMeasurementTask(schema, config=config)

Note that we've chosen a minimal set of measurement plugins: we need the outputs of base_SdssCentroid, base_SdssShape and base_CircularApertureFlux as inputs to the PSF measurement algorithm, while base_PixelFlags identifies and flags bad sources (e.g. with pixels too close to the edge) so they can be removed later.

Now we can create and configure the task that we're interested in:

config = MeasurePsfTask.ConfigClass()
psfDeterminer = config.psfDeterminer.apply()
psfDeterminer.config.sizeCellX = 128
psfDeterminer.config.sizeCellY = 128
psfDeterminer.config.spatialOrder = 1
psfDeterminer.config.nEigenComponents = 3
measurePsfTask = MeasurePsfTask(config=config, schema=schema)

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

tab = afwTable.SourceTable.make(schema)

And process the image:

sources = detectionTask.run(tab, exposure, sigma=2).sources
measureTask.measure(exposure, sources)
result = measurePsfTask.run(exposure, sources)

We can then unpack and use the results:

psf = result.psf
cellSet = result.cellSet

If you specified –ds9 you can see the PSF candidates:

if display: # display on ds9 (see also --debug argparse option)
frame = 1
ds9.mtv(exposure, frame=frame)
with ds9.Buffering():
for s in sources:
xy = s.getCentroid()
ds9.dot('+', *xy, frame=frame)
if s.get("calib.psf.candidate"):
ds9.dot('x', *xy, ctype=ds9.YELLOW, frame=frame)
if s.get("calib.psf.used"):
ds9.dot('o', *xy, size=4, ctype=ds9.RED, frame=frame)


To investigate the Debug variables, put something like

import lsstDebug
def DebugInfo(name):
di = lsstDebug.getInfo(name) # N.b. lsstDebug.Info(name) would call us recursively
if name == "lsst.pipe.tasks.measurePsf" :
di.display = True
di.displayExposure = False # display the Exposure + spatialCells
di.displayPsfCandidates = True # show mosaic of candidates
di.displayPsfMosaic = True # show mosaic of reconstructed PSF(xy)
di.displayResiduals = True # show residuals
di.showBadCandidates = True # Include bad candidates
di.normalizeResiduals = False # Normalise residuals by object amplitude
return di
lsstDebug.Info = DebugInfo

into your debug.py file and run measurePsfTask.py with the –debug flag.

Definition at line 55 of file measurePsf.py.

Constructor & Destructor Documentation

◆ __init__()

def lsst.pipe.tasks.measurePsf.MeasurePsfTask.__init__ (   self,
  schema = None,
  kwargs 
)

Create the detection task.

Most arguments are simply passed onto pipe.base.Task.

Parameters
schemaAn lsst::afw::table::Schema used to create the output lsst.afw.table.SourceCatalog
**kwargsKeyword arguments passed to lsst.pipe.base.task.Task.__init__.

If schema is not None, 'calib.psf.candidate' and 'calib.psf.used' fields will be added to identify which stars were employed in the PSF estimation.

Note
This task can add fields to the schema, so any code calling this task must ensure that these fields are indeed present in the input table.

Definition at line 204 of file measurePsf.py.

Member Function Documentation

◆ run()

def lsst.pipe.tasks.measurePsf.MeasurePsfTask.run (   self,
  exposure,
  sources,
  expId = 0,
  matches = None 
)

Measure the PSF.

Parameters
[in,out]exposureExposure to process; measured PSF will be added.
[in,out]sourcesMeasured sources on exposure; flag fields will be set marking stars chosen by the star selector and the PSF determiner if a schema was passed to the task constructor.
[in]expIdExposure id used for generating random seed.
[in]matchesA list of lsst.afw.table.ReferenceMatch objects (i.e. of lsst.afw.table.Match with first being of type lsst.afw.table.SimpleRecord and second type lsst.afw.table.SourceRecord — the reference object and detected object respectively) as returned by e.g. the AstrometryTask. Used by star selectors that choose to refer to an external catalog.
Returns
a pipe.base.Struct with fields:
  • psf: The measured PSF (also set in the input exposure)
  • cellSet: an lsst.afw.math.SpatialCellSet containing the PSF candidates as returned by the psf determiner.

Definition at line 240 of file measurePsf.py.

◆ usesMatches()

def lsst.pipe.tasks.measurePsf.MeasurePsfTask.usesMatches (   self)
Return True if this task makes use of the "matches" argument to the run method

Definition at line 347 of file measurePsf.py.

Member Data Documentation

◆ candidateKey

lsst.pipe.tasks.measurePsf.MeasurePsfTask.candidateKey

Definition at line 219 of file measurePsf.py.

◆ ConfigClass

lsst.pipe.tasks.measurePsf.MeasurePsfTask.ConfigClass = MeasurePsfConfig
static

Definition at line 201 of file measurePsf.py.

◆ reservedKey

lsst.pipe.tasks.measurePsf.MeasurePsfTask.reservedKey

Definition at line 229 of file measurePsf.py.

◆ usedKey

lsst.pipe.tasks.measurePsf.MeasurePsfTask.usedKey

Definition at line 224 of file measurePsf.py.


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