lsst.ip.diffim g180d380827+c1373eaf06
Loading...
Searching...
No Matches
Classes | Functions | Variables
lsst.ip.diffim.utils Namespace Reference

Classes

class  DipoleTestImage
 

Functions

 showSourceSet (sSet, xy0=(0, 0), frame=0, ctype=afwDisplay.GREEN, symb="+", size=2)
 
 showKernelSpatialCells (maskedIm, kernelCellSet, showChi2=False, symb="o", ctype=None, ctypeUnused=None, ctypeBad=None, size=3, frame=None, title="Spatial Cells")
 
 showDiaSources (sources, exposure, isFlagged, isDipole, frame=None)
 
 showKernelCandidates (kernelCellSet, kernel, background, frame=None, showBadCandidates=True, resids=False, kernels=False)
 
 showKernelBasis (kernel, frame=None)
 
 plotKernelSpatialModel (kernel, kernelCellSet, showBadCandidates=True, numSample=128, keepPlots=True, maxCoeff=10)
 
 plotKernelCoefficients (spatialKernel, kernelCellSet, showBadCandidates=False, keepPlots=True)
 
 showKernelMosaic (bbox, kernel, nx=7, ny=None, frame=None, title=None, showCenter=True, showEllipticity=True)
 
 plotWhisker (results, newWcs)
 
 getPsfFwhm (psf, average=True, position=None)
 
float evaluateMeanPsfFwhm (afwImage.Exposure exposure, float fwhmExposureBuffer, int fwhmExposureGrid)
 
afwImage.ImageD computeAveragePsf (afwImage.Exposure exposure, float psfExposureBuffer, int psfExposureGrid)
 
 detectTestSources (exposure, addMaskPlanes=None)
 
 makeFakeWcs ()
 
 makeTestImage (seed=5, nSrc=20, psfSize=2., noiseLevel=5., noiseSeed=6, fluxLevel=500., fluxRange=2., kernelSize=32, templateBorderSize=0, background=None, xSize=256, ySize=256, x0=12345, y0=67890, calibration=1., doApplyCalibration=False, xLoc=None, yLoc=None, flux=None, clearEdgeMask=False, addMaskPlanes=None)
 
 _makeTruthSchema ()
 
 _fillTruthCatalog (injectList)
 
 makeStats (badMaskPlanes=None)
 
 computeRobustStatistics (image, mask, statsCtrl, statistic=afwMath.MEANCLIP)
 
 computePSFNoiseEquivalentArea (psf)
 
 angleMean (angles)
 
 evaluateMaskFraction (mask, maskPlane)
 

Variables

bool keptPlots = False
 
 _LOG = getLogger(__name__)
 

Detailed Description

Support utilities for Measuring sources

Function Documentation

◆ _fillTruthCatalog()

lsst.ip.diffim.utils._fillTruthCatalog ( injectList)
protected
Add injected sources to the truth catalog.

Parameters
----------
injectList : `list` [`float`]
    Sources that were injected; tuples of (x, y, flux, size).

Returns
-------
catalog : `lsst.afw.table.SourceCatalog`
    Catalog with centroids and instFlux/instFluxErr values filled in and
    appropriate slots set.

Definition at line 1228 of file utils.py.

◆ _makeTruthSchema()

lsst.ip.diffim.utils._makeTruthSchema ( )
protected
Make a schema for the truth catalog produced by `makeTestImage`.

Returns
-------
keys : `dict` [`str`]
    Fields added to the catalog, to make it easier to set them.
schema : `lsst.afw.table.Schema`
    Schema to use to make a "truth" SourceCatalog.
    Calib, Ap, and Psf flux slots all are set to ``truth_instFlux``.

Definition at line 1196 of file utils.py.

◆ angleMean()

lsst.ip.diffim.utils.angleMean ( angles)
Calculate the mean of an array of angles.

Parameters
----------
angles : `ndarray`
    An array of angles, in degrees

Returns
-------
`lsst.geom.Angle`
    The mean angle

Definition at line 1323 of file utils.py.

◆ computeAveragePsf()

afwImage.ImageD lsst.ip.diffim.utils.computeAveragePsf ( afwImage.Exposure exposure,
float psfExposureBuffer,
int psfExposureGrid )
Get the average PSF by evaluating it on a grid within an exposure.

Parameters
----------
exposure : `~lsst.afw.image.Exposure`
    The exposure for which the average PSF is to be computed.
    The exposure must contain a `psf` attribute.
psfExposureBuffer : `float`
    Fractional buffer margin to be left out of all sides of the image
    during the construction of the grid to compute average PSF in an
    exposure.
psfExposureGrid : `int`
    Grid size to compute the average PSF in an exposure.

Returns
-------
psfImage : `~lsst.afw.image.Image`
    The average PSF across the exposure.

Raises
------
ValueError
    Raised if the PSF cannot be computed at any of the grid points.

See Also
--------
`evaluateMeanPsfFwhm`

Definition at line 952 of file utils.py.

◆ computePSFNoiseEquivalentArea()

lsst.ip.diffim.utils.computePSFNoiseEquivalentArea ( psf)
Compute the noise equivalent area for an image psf

Parameters
----------
psf : `lsst.afw.detection.Psf`

Returns
-------
nea : `float`

Definition at line 1307 of file utils.py.

◆ computeRobustStatistics()

lsst.ip.diffim.utils.computeRobustStatistics ( image,
mask,
statsCtrl,
statistic = afwMath.MEANCLIP )
Calculate a robust mean of the variance plane of an exposure.

Parameters
----------
image : `lsst.afw.image.Image`
    Image or variance plane of an exposure to evaluate.
mask : `lsst.afw.image.Mask`
    Mask plane to use for excluding pixels.
statsCtrl : `lsst.afw.math.StatisticsControl`
    Statistics control object for configuring the calculation.
statistic : `lsst.afw.math.Property`, optional
    The type of statistic to compute. Typical values are
    ``afwMath.MEANCLIP`` or ``afwMath.STDEVCLIP``.

Returns
-------
value : `float`
    The result of the statistic calculated from the unflagged pixels.

Definition at line 1283 of file utils.py.

◆ detectTestSources()

lsst.ip.diffim.utils.detectTestSources ( exposure,
addMaskPlanes = None )
Minimal source detection wrapper suitable for unit tests.

Parameters
----------
exposure : `lsst.afw.image.Exposure`
    Exposure on which to run detection/measurement
    The exposure is modified in place to set the 'DETECTED' mask plane.
addMaskPlanes : `list` of `str`, optional
    Additional mask planes to add to the maskedImage of the exposure.

Returns
-------
selectSources
    Source catalog containing candidates

Definition at line 1017 of file utils.py.

◆ evaluateMaskFraction()

lsst.ip.diffim.utils.evaluateMaskFraction ( mask,
maskPlane )
Evaluate the fraction of masked pixels in a mask plane.

Parameters
----------
mask : `lsst.afw.image.Mask`
    The mask to evaluate the fraction on
maskPlane : `str`
    The particular mask plane to evaluate the fraction

Returns
-------
value : `float`
    The calculated fraction of masked pixels

Definition at line 1340 of file utils.py.

◆ evaluateMeanPsfFwhm()

float lsst.ip.diffim.utils.evaluateMeanPsfFwhm ( afwImage.Exposure exposure,
float fwhmExposureBuffer,
int fwhmExposureGrid )
Get the mean PSF FWHM by evaluating it on a grid within an exposure.

Parameters
----------
exposure : `~lsst.afw.image.Exposure`
    The exposure for which the mean FWHM of the PSF is to be computed.
    The exposure must contain a `psf` attribute.
fwhmExposureBuffer : `float`
    Fractional buffer margin to be left out of all sides of the image
    during the construction of the grid to compute mean PSF FWHM in an
    exposure.
fwhmExposureGrid : `int`
    Grid size to compute the mean FWHM in an exposure.

Returns
-------
meanFwhm : `float`
    The mean PSF FWHM on the exposure.

Raises
------
ValueError
    Raised if the PSF cannot be computed at any of the grid points.

See Also
--------
`getPsfFwhm`
`computeAveragePsf`

Definition at line 892 of file utils.py.

◆ getPsfFwhm()

lsst.ip.diffim.utils.getPsfFwhm ( psf,
average = True,
position = None )
Directly calculate the horizontal and vertical widths
of a PSF at half its maximum value.

Parameters
----------
psf : `~lsst.afw.detection.Psf`
    Point spread function (PSF) to evaluate.
average : `bool`, optional
    Set to return the average width over Y and X axes.
position : `~lsst.geom.Point2D`, optional
    The position at which to evaluate the PSF. If `None`, then the
    average position is used.

Returns
-------
psfSize : `float` | `tuple` [`float`]
    The FWHM of the PSF computed at its average position.
    Returns the widths along the Y and X axes,
    or the average of the two if `average` is set.

See Also
--------
evaluateMeanPsfFwhm

Definition at line 856 of file utils.py.

◆ makeFakeWcs()

lsst.ip.diffim.utils.makeFakeWcs ( )
Make a fake, affine Wcs.

Definition at line 1058 of file utils.py.

◆ makeStats()

lsst.ip.diffim.utils.makeStats ( badMaskPlanes = None)
Create a statistics control for configuring calculations on images.

Parameters
----------
badMaskPlanes : `list` of `str`, optional
    List of mask planes to exclude from calculations.

Returns
-------
statsControl : ` lsst.afw.math.StatisticsControl`
    Statistics control object for configuring calculations on images.

Definition at line 1260 of file utils.py.

◆ makeTestImage()

lsst.ip.diffim.utils.makeTestImage ( seed = 5,
nSrc = 20,
psfSize = 2.,
noiseLevel = 5.,
noiseSeed = 6,
fluxLevel = 500.,
fluxRange = 2.,
kernelSize = 32,
templateBorderSize = 0,
background = None,
xSize = 256,
ySize = 256,
x0 = 12345,
y0 = 67890,
calibration = 1.,
doApplyCalibration = False,
xLoc = None,
yLoc = None,
flux = None,
clearEdgeMask = False,
addMaskPlanes = None )
Make a reproduceable PSF-convolved exposure for testing.

Parameters
----------
seed : `int`, optional
    Seed value to initialize the random number generator for sources.
nSrc : `int`, optional
    Number of sources to simulate.
psfSize : `float`, optional
    Width of the PSF of the simulated sources, in pixels.
noiseLevel : `float`, optional
    Standard deviation of the noise to add to each pixel.
noiseSeed : `int`, optional
    Seed value to initialize the random number generator for noise.
fluxLevel : `float`, optional
    Reference flux of the simulated sources.
fluxRange : `float`, optional
    Range in flux amplitude of the simulated sources.
kernelSize : `int`, optional
    Size in pixels of the kernel for simulating sources.
templateBorderSize : `int`, optional
    Size in pixels of the image border used to pad the image.
background : `lsst.afw.math.Chebyshev1Function2D`, optional
    Optional background to add to the output image.
xSize, ySize : `int`, optional
    Size in pixels of the simulated image.
x0, y0 : `int`, optional
    Origin of the image.
calibration : `float`, optional
    Conversion factor between instFlux and nJy.
doApplyCalibration : `bool`, optional
    Apply the photometric calibration and return the image in nJy?
xLoc, yLoc : `list` of `float`, optional
    User-specified coordinates of the simulated sources.
    If specified, must have length equal to ``nSrc``
flux : `list` of `float`, optional
    User-specified fluxes of the simulated sources.
    If specified, must have length equal to ``nSrc``
clearEdgeMask : `bool`, optional
    Clear the "EDGE" mask plane after source detection.
addMaskPlanes : `list` of `str`, optional
    Mask plane names to add to the image.

Returns
-------
modelExposure : `lsst.afw.image.Exposure`
    The model image, with the mask and variance planes. The DETECTED
    plane is filled in for the injected source footprints.
sourceCat : `lsst.afw.table.SourceCatalog`
    Catalog of sources inserted in the model image.

Raises
------
ValueError
    If `xloc`, `yloc`, or `flux` are supplied with inconsistant lengths.

Definition at line 1068 of file utils.py.

◆ plotKernelCoefficients()

lsst.ip.diffim.utils.plotKernelCoefficients ( spatialKernel,
kernelCellSet,
showBadCandidates = False,
keepPlots = True )
Plot the individual kernel candidate and the spatial kernel solution coefficients.

Parameters
----------

spatialKernel : `lsst.afw.math.LinearCombinationKernel`
    The spatial spatialKernel solution model which is a spatially varying linear combination
    of the spatialKernel basis functions.
    Typically returned by `lsst.ip.diffim.SpatialKernelSolution.getSolutionPair()`.

kernelCellSet : `lsst.afw.math.SpatialCellSet`
    The spatial cells that was used for solution for the spatialKernel. They contain the
    local solutions of the AL kernel for the selected sources.

showBadCandidates : `bool`, optional
    If True, plot the coefficient values for kernel candidates where the solution was marked
    bad by the numerical algorithm. Defaults to False.

keepPlots: `bool`, optional
    If True, sets ``plt.show()`` to be called before the task terminates, so that the plots
    can be explored interactively. Defaults to True.

Notes
-----
This function produces 3 figures per image subtraction operation.
* A grid plot of the local solutions. Each grid cell corresponds to a proportional area in
  the image. In each cell, local kernel solution coefficients are plotted of kernel candidates (color)
  that fall into this area as a function of the kernel basis function number.
* A grid plot of the spatial solution. Each grid cell corresponds to a proportional area in
  the image. In each cell, the spatial solution coefficients are evaluated for the center of the cell.
* Histogram of the local solution coefficients. Red line marks the spatial solution value at
  center of the image.

This function is called if ``lsst.ip.diffim.psfMatch.plotKernelCoefficients==True`` in lsstDebug. This
function was implemented as part of DM-17825.

Definition at line 432 of file utils.py.

◆ plotKernelSpatialModel()

lsst.ip.diffim.utils.plotKernelSpatialModel ( kernel,
kernelCellSet,
showBadCandidates = True,
numSample = 128,
keepPlots = True,
maxCoeff = 10 )
Plot the Kernel spatial model.

Definition at line 282 of file utils.py.

◆ plotWhisker()

lsst.ip.diffim.utils.plotWhisker ( results,
newWcs )
Plot whisker diagram of astromeric offsets between results.matches.

Definition at line 674 of file utils.py.

◆ showDiaSources()

lsst.ip.diffim.utils.showDiaSources ( sources,
exposure,
isFlagged,
isDipole,
frame = None )
Display Dia Sources.

Definition at line 110 of file utils.py.

◆ showKernelBasis()

lsst.ip.diffim.utils.showKernelBasis ( kernel,
frame = None )
Display a Kernel's basis images.

Definition at line 264 of file utils.py.

◆ showKernelCandidates()

lsst.ip.diffim.utils.showKernelCandidates ( kernelCellSet,
kernel,
background,
frame = None,
showBadCandidates = True,
resids = False,
kernels = False )
Display the Kernel candidates.

If kernel is provided include spatial model and residuals;
If chi is True, generate a plot of residuals/sqrt(variance), i.e. chi.

Definition at line 146 of file utils.py.

◆ showKernelMosaic()

lsst.ip.diffim.utils.showKernelMosaic ( bbox,
kernel,
nx = 7,
ny = None,
frame = None,
title = None,
showCenter = True,
showEllipticity = True )
Show a mosaic of Kernel images.

Definition at line 591 of file utils.py.

◆ showKernelSpatialCells()

lsst.ip.diffim.utils.showKernelSpatialCells ( maskedIm,
kernelCellSet,
showChi2 = False,
symb = "o",
ctype = None,
ctypeUnused = None,
ctypeBad = None,
size = 3,
frame = None,
title = "Spatial Cells" )
Show the SpatialCells.

If symb is something that display.dot understands (e.g. "o"), the top
nMaxPerCell candidates will be indicated with that symbol, using ctype
and size.

Definition at line 71 of file utils.py.

◆ showSourceSet()

lsst.ip.diffim.utils.showSourceSet ( sSet,
xy0 = (0, 0),
frame = 0,
ctype = afwDisplay.GREEN,
symb = "+",
size = 2 )
Draw the (XAstrom, YAstrom) positions of a set of Sources.

Image has the given XY0.

Definition at line 51 of file utils.py.

Variable Documentation

◆ _LOG

lsst.ip.diffim.utils._LOG = getLogger(__name__)
protected

Definition at line 48 of file utils.py.

◆ keptPlots

bool lsst.ip.diffim.utils.keptPlots = False

Definition at line 46 of file utils.py.