lsst.meas.algorithms  13.0-13-gf5c99ad+4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
lsst.meas.algorithms.detection.SourceDetectionTask Class Reference

Detect positive and negative sources on an exposure and return a new table.SourceCatalog. More...

Inheritance diagram for lsst.meas.algorithms.detection.SourceDetectionTask:

Public Member Functions

def __init__
 Create the detection task. More...
 
def run
 Run source detection and create a SourceCatalog. More...
 
def detectFootprints
 Detect footprints. More...
 
def makeThreshold
 
def updatePeaks
 

Static Public Member Functions

def setEdgeBits
 Set the edgeBitmask bits for all of maskedImage outside goodBBox. More...
 

Public Attributes

 negativeFlagKey
 

Static Public Attributes

 ConfigClass = SourceDetectionConfig
 
 makeSourceCatalog = run
 An alias for run. More...
 

Detailed Description

Detect positive and negative sources on an exposure and return a new table.SourceCatalog.

Contents

Description

Detect positive and negative sources on an exposure and return a new table.SourceCatalog.

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
**kwdsKeyword arguments passed to lsst.pipe.base.task.Task.__init__.

If schema is not None and configured for 'both' detections, a 'flags.negative' field will be added to label detections made with a negative threshold.

Note
This task can add fields to the schema, so any code calling this task must ensure that these columns are indeed present in the input match list; see Example

Invoking the Task

Run source detection and create a SourceCatalog.

Parameters
tablelsst.afw.table.SourceTable object that will be used to create the SourceCatalog.
exposureExposure to process; DETECTED mask plane will be set in-place.
doSmoothif True, smooth the image before detection using a Gaussian of width sigma (default: True)
sigmasigma of PSF (pixels); used for smoothing and to grow detections; if None then measure the sigma of the PSF of the exposure (default: None)
clearMaskClear DETECTED{,_NEGATIVE} planes before running detection (default: True)
Returns
a lsst.pipe.base.Struct with:
  • sources – an lsst.afw.table.SourceCatalog object
  • fpSets — lsst.pipe.base.Struct returned by detectFootprints
Exceptions
ValueErrorif flags.negative is needed, but isn't in table's schema
lsst.pipe.base.TaskErrorif sigma=None, doSmooth=True and the exposure has no PSF
Note
If you want to avoid dealing with Sources and Tables, you can use detectFootprints() to just get the afw::detection::FootprintSets.

Configuration parameters

See SourceDetectionConfig

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.

The available variables in SourceDetectionTask are:

display
  • If True, display the exposure on ds9's frame 0. +ve detections in blue, -ve detections in cyan
  • If display > 1, display the convolved exposure on frame 1

A complete example of using SourceDetectionTask

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

1 examples/measAlgTasks.py --ds9
The example also runs the SourceMeasurementTask; see meas_algorithms_measurement_Example for more explanation.

Import the task (there are some other standard imports; read the file if you're confused)

1 from lsst.meas.algorithms.detection import SourceDetectionTask

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

1  schema = afwTable.SourceTable.makeMinimalSchema()
after which we can call the constructor:
1  config = SourceDetectionTask.ConfigClass()
2  config.thresholdPolarity = "both"
3  config.background.isNanSafe = True
4  config.thresholdValue = 3
5  detectionTask = SourceDetectionTask(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:

1  tab = afwTable.SourceTable.make(schema)

And process the image

1  result = detectionTask.run(tab, exposure)
(You may not be happy that the threshold was set in the config before creating the Task rather than being set separately for each exposure. You can reset it just before calling the run method if you must, but we should really implement a better solution).

We can then unpack and use the results:

1  sources = result.sources
2 
3  print("Found %d sources (%d +ve, %d -ve)" % (len(sources), result.fpSets.numPos, result.fpSets.numNeg))


To investigate the Debug variables, put something like

1 import lsstDebug
2 def DebugInfo(name):
3  di = lsstDebug.getInfo(name) # N.b. lsstDebug.Info(name) would call us recursively
4  if name == "lsst.meas.algorithms.detection":
5  di.display = 1
6 
7  return di
8 
9 lsstDebug.Info = DebugInfo

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

Definition at line 126 of file detection.py.

Constructor & Destructor Documentation

def lsst.meas.algorithms.detection.SourceDetectionTask.__init__ (   self,
  schema = None,
  kwds 
)

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
**kwdsKeyword arguments passed to lsst.pipe.base.task.Task.__init__.

If schema is not None and configured for 'both' detections, a 'flags.negative' field will be added to label detections made with a negative threshold.

Note
This task can add fields to the schema, so any code calling this task must ensure that these columns are indeed present in the input match list; see Example

Definition at line 222 of file detection.py.

Member Function Documentation

def lsst.meas.algorithms.detection.SourceDetectionTask.detectFootprints (   self,
  exposure,
  doSmooth = True,
  sigma = None,
  clearMask = True 
)

Detect footprints.

Parameters
exposureExposure to process; DETECTED{,_NEGATIVE} mask plane will be set in-place.
doSmoothif True, smooth the image before detection using a Gaussian of width sigma
sigmasigma of PSF (pixels); used for smoothing and to grow detections; if None then measure the sigma of the PSF of the exposure
clearMaskClear both DETECTED and DETECTED_NEGATIVE planes before running detection
Returns
a lsst.pipe.base.Struct with fields:
  • positive: lsst.afw.detection.FootprintSet with positive polarity footprints (may be None)
  • negative: lsst.afw.detection.FootprintSet with negative polarity footprints (may be None)
  • numPos: number of footprints in positive or 0 if detection polarity was negative
  • numNeg: number of footprints in negative or 0 if detection polarity was positive
  • background: re-estimated background. None if reEstimateBackground==False
Exceptions
lsst.pipe.base.TaskErrorif sigma=None and the exposure has no PSF

Definition at line 296 of file detection.py.

def lsst.meas.algorithms.detection.SourceDetectionTask.makeThreshold (   self,
  image,
  thresholdParity 
)
Make an afw.detection.Threshold object corresponding to the task's
configuration and the statistics of the given image.

Parameters
----------
image : `afw.image.MaskedImage`
    Image to measure noise statistics from if needed.
thresholdParity: `str`
    One of "positive" or "negative", to set the kind of fluctuations
    the Threshold will detect.

Definition at line 477 of file detection.py.

def lsst.meas.algorithms.detection.SourceDetectionTask.run (   self,
  table,
  exposure,
  doSmooth = True,
  sigma = None,
  clearMask = True 
)

Run source detection and create a SourceCatalog.

Parameters
tablelsst.afw.table.SourceTable object that will be used to create the SourceCatalog.
exposureExposure to process; DETECTED mask plane will be set in-place.
doSmoothif True, smooth the image before detection using a Gaussian of width sigma (default: True)
sigmasigma of PSF (pixels); used for smoothing and to grow detections; if None then measure the sigma of the PSF of the exposure (default: None)
clearMaskClear DETECTED{,_NEGATIVE} planes before running detection (default: True)
Returns
a lsst.pipe.base.Struct with:
  • sources – an lsst.afw.table.SourceCatalog object
  • fpSets — lsst.pipe.base.Struct returned by detectFootprints
Exceptions
ValueErrorif flags.negative is needed, but isn't in table's schema
lsst.pipe.base.TaskErrorif sigma=None, doSmooth=True and the exposure has no PSF
Note
If you want to avoid dealing with Sources and Tables, you can use detectFootprints() to just get the afw::detection::FootprintSets.

Definition at line 252 of file detection.py.

def lsst.meas.algorithms.detection.SourceDetectionTask.setEdgeBits (   maskedImage,
  goodBBox,
  edgeBitmask 
)
static

Set the edgeBitmask bits for all of maskedImage outside goodBBox.

Parameters
[in,out]maskedImageimage on which to set edge bits in the mask
[in]goodBBoxbounding box of good pixels, in LOCAL coordinates
[in]edgeBitmaskbit mask to OR with the existing mask bits in the region outside goodBBox

Definition at line 552 of file detection.py.

def lsst.meas.algorithms.detection.SourceDetectionTask.updatePeaks (   self,
  fpSet,
  image,
  threshold 
)
Update the Peaks in a FootprintSet by detecting new Footprints and
Peaks in an image and using the new Peaks instead of the old ones.

Parameters
----------
fpSet : `afw.detection.FootprintSet`
    Set of Footprints whose Peaks should be updated.
image : `afw.image.MaskedImage`
    Image to detect new Footprints and Peak in.
threshold : `afw.detection.Threshold`
    Threshold object for detection.

Input Footprints with fewer Peaks than self.config.nPeaksMaxSimple
are not modified, and if no new Peaks are detected in an input
Footprint, the brightest original Peak in that Footprint is kept.

Definition at line 509 of file detection.py.

Member Data Documentation

lsst.meas.algorithms.detection.SourceDetectionTask.ConfigClass = SourceDetectionConfig
static

Definition at line 219 of file detection.py.

lsst.meas.algorithms.detection.SourceDetectionTask.makeSourceCatalog = run
static

An alias for run.

Deprecated:
Remove this alias after checking for where it's used

Definition at line 293 of file detection.py.

lsst.meas.algorithms.detection.SourceDetectionTask.negativeFlagKey

Definition at line 237 of file detection.py.


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