lsst.meas.algorithms  20.0.0-10-g0891cd99+ae55087059
Public Member Functions | Static Public Attributes | List of all members
lsst.meas.algorithms.subtractBackground.SubtractBackgroundTask Class Reference

Subtract the background from an exposure. More...

Inheritance diagram for lsst.meas.algorithms.subtractBackground.SubtractBackgroundTask:

Public Member Functions

def run (self, exposure, background=None, stats=True, statsKeys=None)
 Fit and subtract the background of an exposure. More...
 
def fitBackground (self, maskedImage, nx=0, ny=0, algorithm=None)
 Estimate the background of a masked image. More...
 

Static Public Attributes

 ConfigClass = SubtractBackgroundConfig
 

Detailed Description

Subtract the background from an exposure.

Contents

Description

Fit a model of the background of an exposure and subtract it.

Task initialisation

Invoking the Task

Call run to fit the background and subtract it.

Call fitBackground to fit the background without subtracting it.

Configuration parameters

See SubtractBackgroundConfig

Quantities set in exposure Metadata

The run method will optionally set the following items of exposure metadata; the names may be overridden; the defaults are shown:

BGMEAN
mean value of background
BGVAR
standard deviation of background

Debug variables

The command line task interface supports a flag --debug to import debug.py from your $PYTHONPATH; see Using lsstDebug to control debugging output for more about debug.py.

SubtractBackgroundTask has a debug dictionary containing three integer keys:

unsubtracted
If >0: fitBackground displays the unsubtracted masked image overlaid with the grid of cells used to fit the background in the specified frame
subtracted
If >0: run displays the background-subtracted exposure is the specified frame
background
If >0: run displays the background image in the specified frame

For example, put something like:

import lsstDebug
def DebugInfo(name):
di = lsstDebug.getInfo(name) # N.b. lsstDebug.Info(name) would call us recursively
if name == "lsst.meas.algorithms.subtractBackground":
di.display = dict(
unsubtracted = 1,
subtracted = 2,
background = 3,
)
return di
lsstDebug.Info = DebugInfo

into your debug.py file and run your task with the --debug flag.

A complete example of using SubtractBackgroundTask

This code is in subtractBackgroundExample.py in the examples directory, and can be run as:

python examples/subtractBackgroundExample.py

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

0 from lsst.meas.algorithms import SubtractBackgroundTask

Create the task, run it, and report mean and variance of background.

44  # create the task
45  backgroundConfig = SubtractBackgroundTask.ConfigClass()
46  backgroundTask = SubtractBackgroundTask(config=backgroundConfig)
47 
48  # load the data
49  exposure = loadData()
50 
51  # subtract an initial estimate of background level
52  bgRes = backgroundTask.run(exposure=exposure)
53  background = bgRes.background
54 
55  # compute mean and variance of the background
56  backgroundImage = background.getImage()
57  s = afwMath.makeStatistics(backgroundImage, afwMath.MEAN | afwMath.VARIANCE)
58  bgmean = s.getValue(afwMath.MEAN)
59  bgvar = s.getValue(afwMath.VARIANCE)
60  print("background mean=%0.1f; variance=%0.1f" % (bgmean, bgvar))

Definition at line 126 of file subtractBackground.py.

Member Function Documentation

◆ fitBackground()

def lsst.meas.algorithms.subtractBackground.SubtractBackgroundTask.fitBackground (   self,
  maskedImage,
  nx = 0,
  ny = 0,
  algorithm = None 
)

Estimate the background of a masked image.

Parameters
[in]maskedImagemasked image whose background is to be computed
[in]nxnumber of x bands; if 0 compute from width and config.binSizeX
[in]nynumber of y bands; if 0 compute from height and config.binSizeY
[in]algorithmname of interpolation algorithm; if None use self.config.algorithm
Returns
fit background as an lsst.afw.math.Background
Exceptions
RuntimeErrorif lsst.afw.math.makeBackground returns None, which is apparently one way it indicates failure

Definition at line 285 of file subtractBackground.py.

◆ run()

def lsst.meas.algorithms.subtractBackground.SubtractBackgroundTask.run (   self,
  exposure,
  background = None,
  stats = True,
  statsKeys = None 
)

Fit and subtract the background of an exposure.

Parameters
[in,out]exposureexposure whose background is to be subtracted
[in,out]backgroundinitial background model already subtracted from exposure (an lsst.afw.math.BackgroundList). May be None if no background has been subtracted.
[in]statsif True then measure the mean and variance of the full background model and record the results in the exposure's metadata
[in]statsKeyskey names used to store the mean and variance of the background in the exposure's metadata (a pair of strings); if None then use ("BGMEAN", "BGVAR"); ignored if stats is false
Returns
an lsst.pipe.base.Struct containing:
  • background full background model (initial model with changes), an lsst.afw.math.BackgroundList

Definition at line 220 of file subtractBackground.py.

Member Data Documentation

◆ ConfigClass

lsst.meas.algorithms.subtractBackground.SubtractBackgroundTask.ConfigClass = SubtractBackgroundConfig
static

Definition at line 217 of file subtractBackground.py.


The documentation for this class was generated from the following file:
lsstDebug::Info
lsstDebug::getInfo
getInfo
lsst::meas::algorithms
Fit spatial kernel using approximate fluxes for candidates, and solving a linear system of equations.
Definition: mainpage.dox:13