lsst.ip.diffim g3dd0db44d0+dde568935d
Loading...
Searching...
No Matches
lsst.ip.diffim.subtractImages.AlardLuptonPreconvolveSubtractTask Class Reference
Inheritance diagram for lsst.ip.diffim.subtractImages.AlardLuptonPreconvolveSubtractTask:
lsst.ip.diffim.subtractImages.AlardLuptonSubtractTask

Public Member Functions

 run (self, template, science, sources, visitSummary=None)
 
 runPreconvolve (self, template, science, matchedScience, kernelSources, preConvKernel)
 
 runQuantum (self, butlerQC, inputRefs, outputRefs)
 
 chooseConvolutionMethod (self, template, science)
 
 runMakeKernel (self, template, science, sources=None, convolveTemplate=True, runSourceDetection=False)
 
 runKernelSourceDetection (self, template, science)
 
 runConvolveTemplate (self, template, science, psfMatchingKernel, backgroundModel=None)
 
 runConvolveScience (self, template, science, psfMatchingKernel, backgroundModel=None)
 
 finalize (self, template, science, difference, kernel, templateMatched=True, preConvMode=False, preConvKernel=None, spatiallyVarying=False)
 
 updateMasks (self, template, science)
 

Public Attributes

 convolutionControl = lsst.afw.math.ConvolutionControl()
 
 matchedPsfSize = self.sciencePsfSize if convolveTemplate else self.templatePsfSize
 
 templatePsfSize
 
 log
 
 sciencePsfSize = getPsfFwhm(science.psf)
 

Static Public Attributes

 ConfigClass = AlardLuptonSubtractConfig
 
bool usePreconvolution = False
 

Protected Member Functions

 _applyExternalCalibrations (self, exposure, visitSummary)
 
 _calculateMagLim (self, exposure, nsigma=5.0, fallbackPsfSize=None)
 
 _convolveExposure (self, exposure, kernel, convolutionControl, bbox=None, psf=None, photoCalib=None, interpolateBadMaskPlanes=False)
 
 _sourceSelector (self, template, science, sources, fallback=False)
 
 _prepareInputs (self, template, science, visitSummary=None)
 
 _clearMask (self, mask, clearMaskPlanes=None)
 

Static Protected Member Functions

 _flagScoreEdge (mask, innerBBox)
 
 _makePreconvolutionKernel (psf)
 
 _validateExposures (template, science)
 
 _renameMaskPlanes (mask, maskPlane, newMaskPlane)
 

Static Protected Attributes

str _DefaultName = "alardLuptonSubtract"
 

Detailed Description

Subtract a template from a science image, convolving the science image
before computing the kernel, and also convolving the template before
subtraction.

Definition at line 1181 of file subtractImages.py.

Member Function Documentation

◆ _applyExternalCalibrations()

lsst.ip.diffim.subtractImages.AlardLuptonSubtractTask._applyExternalCalibrations ( self,
exposure,
visitSummary )
protectedinherited
Replace calibrations (psf, and ApCorrMap) on this exposure with
external ones.".

Parameters
----------
exposure : `lsst.afw.image.exposure.Exposure`
    Input exposure to adjust calibrations.
visitSummary : `lsst.afw.table.ExposureCatalog`
    Exposure catalog with external calibrations to be applied. Catalog
    uses the detector id for the catalog id, sorted on id for fast
    lookup.

Returns
-------
exposure : `lsst.afw.image.exposure.Exposure`
    Exposure with adjusted calibrations.

Definition at line 370 of file subtractImages.py.

◆ _calculateMagLim()

lsst.ip.diffim.subtractImages.AlardLuptonSubtractTask._calculateMagLim ( self,
exposure,
nsigma = 5.0,
fallbackPsfSize = None )
protectedinherited
Calculate an exposure's limiting magnitude.

This method uses the photometric zeropoint together with the
PSF size from the average position of the exposure.

Parameters
----------
exposure : `lsst.afw.image.Exposure`
    The target exposure to calculate the limiting magnitude for.
nsigma : `float`, optional
    The detection threshold in sigma.
fallbackPsfSize : `float`, optional
    PSF FWHM to use in the event the exposure PSF cannot be retrieved.

Returns
-------
maglim : `astropy.units.Quantity`
    The limiting magnitude of the exposure, or np.nan.

Definition at line 792 of file subtractImages.py.

◆ _clearMask()

lsst.ip.diffim.subtractImages.AlardLuptonSubtractTask._clearMask ( self,
mask,
clearMaskPlanes = None )
protectedinherited
Clear the mask plane of an exposure.

Parameters
----------
mask : `lsst.afw.image.Mask`
    The mask plane to erase, which will be modified in place.
clearMaskPlanes : `list` of `str`, optional
    Erase the specified mask planes.
    If not supplied, the entire mask will be erased.

Definition at line 1153 of file subtractImages.py.

◆ _convolveExposure()

lsst.ip.diffim.subtractImages.AlardLuptonSubtractTask._convolveExposure ( self,
exposure,
kernel,
convolutionControl,
bbox = None,
psf = None,
photoCalib = None,
interpolateBadMaskPlanes = False )
protectedinherited
Convolve an exposure with the given kernel.

Parameters
----------
exposure : `lsst.afw.Exposure`
    exposure to convolve.
kernel : `lsst.afw.math.LinearCombinationKernel`
    PSF matching kernel computed in the ``makeKernel`` subtask.
convolutionControl : `lsst.afw.math.ConvolutionControl`
    Configuration for convolve algorithm.
bbox : `lsst.geom.Box2I`, optional
    Bounding box to trim the convolved exposure to.
psf : `lsst.afw.detection.Psf`, optional
    Point spread function (PSF) to set for the convolved exposure.
photoCalib : `lsst.afw.image.PhotoCalib`, optional
    Photometric calibration of the convolved exposure.
interpolateBadMaskPlanes : `bool`, optional
    If set, interpolate over mask planes specified in
    ``config.badMaskPlanes`` before convolving the image.

Returns
-------
convolvedExp : `lsst.afw.Exposure`
    The convolved image.

Definition at line 862 of file subtractImages.py.

◆ _flagScoreEdge()

lsst.ip.diffim.subtractImages.AlardLuptonPreconvolveSubtractTask._flagScoreEdge ( mask,
innerBBox )
staticprotected
Set the EDGE mask bit on pixels outside a known-valid region.

Parameters
----------
mask : `~lsst.afw.image.Mask`
    Exposure mask that will be modified in place. Must have
    an ``EDGE`` mask plane.
innerBBox : `~lsst.geom.Box2I`
    The valid inner region. Pixels
    outside this bbox will have their ``EDGE`` bit set.

Definition at line 1258 of file subtractImages.py.

◆ _makePreconvolutionKernel()

lsst.ip.diffim.subtractImages.AlardLuptonPreconvolveSubtractTask._makePreconvolutionKernel ( psf)
staticprotected
Build a normalized, reflected matched-filter kernel from a PSF.

Convolving an image with this kernel is equivalent to correlating
the image with the PSF, so peaks in the output align with the PSF's
centroid — even for asymmetric PSFs. The kernel is evaluated at the
PSF's average position and returned as a constant
`~lsst.afw.math.Kernel`.

Parameters
----------
psf : `~lsst.afw.detection.Psf`
    The PSF to derive the preconvolution kernel from.

Returns
-------
kernel : `~lsst.afw.math.Kernel`
    The PSF reflected about both axes, normalized to sum to one.

Raises
------
ValueError
    Raised if the PSF kernel has an even size along either axis.
    It's not possible to center an even-sized kernel.

Definition at line 1286 of file subtractImages.py.

◆ _prepareInputs()

lsst.ip.diffim.subtractImages.AlardLuptonSubtractTask._prepareInputs ( self,
template,
science,
visitSummary = None )
protectedinherited
Perform preparatory calculations common to all Alard&Lupton Tasks.

Parameters
----------
template : `lsst.afw.image.ExposureF`
    Template exposure, warped to match the science exposure. The
    variance plane of the template image is modified in place.
science : `lsst.afw.image.ExposureF`
    Science exposure to subtract from the template. The variance plane
    of the science image is modified in place.
visitSummary : `lsst.afw.table.ExposureCatalog`, optional
    Exposure catalog with external calibrations to be applied.  Catalog
    uses the detector id for the catalog id, sorted on id for fast
    lookup.

Definition at line 994 of file subtractImages.py.

◆ _renameMaskPlanes()

lsst.ip.diffim.subtractImages.AlardLuptonSubtractTask._renameMaskPlanes ( mask,
maskPlane,
newMaskPlane )
staticprotectedinherited
Rename a mask plane by adding the new name and copying the data.

Parameters
----------
mask : `lsst.afw.image.Mask`
    The mask image to update in place.
maskPlane : `str`
    The name of the existing mask plane to copy.
newMaskPlane : `str`
    The new name of the mask plane that will be added.
    If the mask plane already exists, it will be updated in place.

Definition at line 1135 of file subtractImages.py.

◆ _sourceSelector()

lsst.ip.diffim.subtractImages.AlardLuptonSubtractTask._sourceSelector ( self,
template,
science,
sources,
fallback = False )
protectedinherited
Select sources from a catalog that meet the selection criteria.
The selection criteria include any configured parameters of the
`sourceSelector` subtask, as well as checking the science and template
mask planes.

Parameters
----------
template : `lsst.afw.image.ExposureF`
    Template exposure, warped to match the science exposure.
science : `lsst.afw.image.ExposureF`
    Science exposure to subtract from the template.
sources : `lsst.afw.table.SourceCatalog`
    Input source catalog to select sources from.
fallback : `bool`, optional
    Switch indicating the source selector is being called after
    running the fallback source detection subtask, which does not run a
    full set of measurement plugins and can't use the same settings for
    the source selector.

Returns
-------
kernelSources : `lsst.afw.table.SourceCatalog`
    The input source catalog, with flagged and low signal-to-noise
    sources removed and footprints added.

Raises
------
InsufficientKernelSourcesError
    An AlgorithmError that is raised if there are not enough PSF
    candidates to construct the PSF matching kernel.

Definition at line 910 of file subtractImages.py.

◆ _validateExposures()

lsst.ip.diffim.subtractImages.AlardLuptonSubtractTask._validateExposures ( template,
science )
staticprotectedinherited
Check that the WCS of the two Exposures match, the template bbox
contains the science bbox, and that the bands match.

Parameters
----------
template : `lsst.afw.image.ExposureF`
    Template exposure, warped to match the science exposure.
science : `lsst.afw.image.ExposureF`
    Science exposure to subtract from the template.

Raises
------
AssertionError
    Raised if the WCS of the template is not equal to the science WCS,
    if the science image is not fully contained in the template
    bounding box, or if the bands do not match.

Definition at line 833 of file subtractImages.py.

◆ chooseConvolutionMethod()

lsst.ip.diffim.subtractImages.AlardLuptonSubtractTask.chooseConvolutionMethod ( self,
template,
science )
inherited
Determine whether the template should be convolved with the PSF
matching kernel.

Parameters
----------
template : `lsst.afw.image.ExposureF`
    Template exposure, warped to match the science exposure.
science : `lsst.afw.image.ExposureF`
    Science exposure to subtract from the template.

Returns
-------
convolveTemplate : `bool`
    Convolve the template to match the two images?

Raises
------
RuntimeError
    If an unsupported convolution mode is supplied.

Definition at line 492 of file subtractImages.py.

◆ finalize()

lsst.ip.diffim.subtractImages.AlardLuptonSubtractTask.finalize ( self,
template,
science,
difference,
kernel,
templateMatched = True,
preConvMode = False,
preConvKernel = None,
spatiallyVarying = False )
inherited
Decorrelate the difference image to undo the noise correlations
caused by convolution.

Parameters
----------
template : `lsst.afw.image.ExposureF`
    Template exposure, warped to match the science exposure.
science : `lsst.afw.image.ExposureF`
    Science exposure to subtract from the template.
difference : `lsst.afw.image.ExposureF`
    Result of subtracting template and science.
kernel : `lsst.afw.math.Kernel`
    An (optionally spatially-varying) PSF matching kernel
templateMatched : `bool`, optional
    Was the template PSF-matched to the science image?
preConvMode : `bool`, optional
    Was the science image preconvolved with its own PSF
    before PSF matching the template?
preConvKernel : `lsst.afw.detection.Psf`, optional
    If not `None`, then the science image was pre-convolved with
    (the reflection of) this kernel. Must be normalized to sum to 1.
spatiallyVarying : `bool`, optional
    Compute the decorrelation kernel spatially varying across the image?

Returns
-------
correctedExposure : `lsst.afw.image.ExposureF`
    The decorrelated image difference.

Definition at line 743 of file subtractImages.py.

◆ run()

lsst.ip.diffim.subtractImages.AlardLuptonPreconvolveSubtractTask.run ( self,
template,
science,
sources,
visitSummary = None )
Preconvolve the science image with its own PSF,
convolve the template image with a PSF-matching kernel and subtract
from the preconvolved science image.

Parameters
----------
template : `lsst.afw.image.ExposureF`
    The template image, which has previously been warped to the science
    image. The template bbox will be padded by a few pixels compared to
    the science bbox.
science : `lsst.afw.image.ExposureF`
    The science exposure.
sources : `lsst.afw.table.SourceCatalog`
    Identified sources on the science exposure. This catalog is used to
    select sources in order to perform the AL PSF matching on stamp
    images around them.
visitSummary : `lsst.afw.table.ExposureCatalog`, optional
    Exposure catalog with complete external calibrations. Catalog uses
    the detector id for the catalog id, sorted on id for fast lookup.

Returns
-------
results : `lsst.pipe.base.Struct`
    ``scoreExposure`` : `lsst.afw.image.ExposureF`
        Result of subtracting the convolved template and science
        images. Attached PSF is that of the original science image.
    ``matchedTemplate`` : `lsst.afw.image.ExposureF`
        Warped and PSF-matched template exposure. Attached PSF is that
        of the original science image.
    ``matchedScience`` : `lsst.afw.image.ExposureF`
        The science exposure after convolving with its own PSF.
        Attached PSF is that of the original science image.
    ``backgroundModel`` : `lsst.afw.math.Function2D`
        Background model that was fit while solving for the
        PSF-matching kernel
    ``psfMatchingKernel`` : `lsst.afw.math.Kernel`
        Final kernel used to PSF-match the template to the science
        image.

Reimplemented from lsst.ip.diffim.subtractImages.AlardLuptonSubtractTask.

Definition at line 1190 of file subtractImages.py.

◆ runConvolveScience()

lsst.ip.diffim.subtractImages.AlardLuptonSubtractTask.runConvolveScience ( self,
template,
science,
psfMatchingKernel,
backgroundModel = None )
inherited
Convolve the science image with a PSF-matching kernel and subtract
the template image.

Parameters
----------
template : `lsst.afw.image.ExposureF`
    Template exposure, warped to match the science exposure.
science : `lsst.afw.image.ExposureF`
    Science exposure to subtract from the template.
psfMatchingKernel : `lsst.afw.math.Kernel`
    Kernel to be used to PSF-match the science image to the template.
backgroundModel : `lsst.afw.math.Function2D`, optional
    Background model that was fit while solving for the PSF-matching
    kernel.

Returns
-------
results : `lsst.pipe.base.Struct`

    ``difference`` : `lsst.afw.image.ExposureF`
        Result of subtracting template and science.
    ``matchedTemplate`` : `lsst.afw.image.ExposureF`
        Warped template exposure. Note that in this case, the template
        is not PSF-matched to the science image.
    ``backgroundModel`` : `lsst.afw.math.Function2D`
        Background model that was fit while solving for the PSF-matching kernel
    ``psfMatchingKernel`` : `lsst.afw.math.Kernel`
       Kernel used to PSF-match the science image to the template.

Definition at line 679 of file subtractImages.py.

◆ runConvolveTemplate()

lsst.ip.diffim.subtractImages.AlardLuptonSubtractTask.runConvolveTemplate ( self,
template,
science,
psfMatchingKernel,
backgroundModel = None )
inherited
Convolve the template image with a PSF-matching kernel and subtract
from the science image.

Parameters
----------
template : `lsst.afw.image.ExposureF`
    Template exposure, warped to match the science exposure.
science : `lsst.afw.image.ExposureF`
    Science exposure to subtract from the template.
psfMatchingKernel : `lsst.afw.math.Kernel`
    Kernel to be used to PSF-match the science image to the template.
backgroundModel : `lsst.afw.math.Function2D`, optional
    Background model that was fit while solving for the PSF-matching
    kernel.

Returns
-------
results : `lsst.pipe.base.Struct`

    ``difference`` : `lsst.afw.image.ExposureF`
        Result of subtracting template and science.
    ``matchedTemplate`` : `lsst.afw.image.ExposureF`
        Warped and PSF-matched template exposure.
    ``backgroundModel`` : `lsst.afw.math.Function2D`
        Background model that was fit while solving for the PSF-matching kernel
    ``psfMatchingKernel`` : `lsst.afw.math.Kernel`
        Kernel used to PSF-match the template to the science image.

Definition at line 631 of file subtractImages.py.

◆ runKernelSourceDetection()

lsst.ip.diffim.subtractImages.AlardLuptonSubtractTask.runKernelSourceDetection ( self,
template,
science )
inherited
Run detection on the science image and use the template mask plane
to reject candidate sources.

Parameters
----------
template : `lsst.afw.image.ExposureF`
    Template exposure, warped to match the science exposure.
science : `lsst.afw.image.ExposureF`
    Science exposure to subtract from the template.

Returns
-------
kernelSources : `lsst.afw.table.SourceCatalog`
        Sources from the input catalog to use to construct the
        PSF-matching kernel.

Definition at line 607 of file subtractImages.py.

◆ runMakeKernel()

lsst.ip.diffim.subtractImages.AlardLuptonSubtractTask.runMakeKernel ( self,
template,
science,
sources = None,
convolveTemplate = True,
runSourceDetection = False )
inherited
Construct the PSF-matching kernel. Not used for preconvolution.

Parameters
----------
template : `lsst.afw.image.ExposureF`
    Template exposure, warped to match the science exposure.
science : `lsst.afw.image.ExposureF`
    Science exposure to subtract from the template.
sources : `lsst.afw.table.SourceCatalog`
    Identified sources on the science exposure. This catalog is used to
    select sources in order to perform the AL PSF matching on stamp
    images around them.
    Not used if ``runSourceDetection`` is set.
convolveTemplate : `bool`, optional
    Construct the matching kernel to convolve the template?
runSourceDetection : `bool`, optional
    Run a minimal version of source detection to determine kernel
    candidates? If False, a source list to select kernel candidates
    from must be supplied.

Returns
-------
results : `lsst.pipe.base.Struct`
    ``backgroundModel`` : `lsst.afw.math.Function2D`
        Background model that was fit while solving for the
        PSF-matching kernel
    ``psfMatchingKernel`` : `lsst.afw.math.Kernel`
        Kernel used to PSF-match the convolved image.
    ``kernelSources` : `lsst.afw.table.SourceCatalog`
        Sources from the input catalog that were used to construct the
        PSF-matching kernel.

Definition at line 538 of file subtractImages.py.

◆ runPreconvolve()

lsst.ip.diffim.subtractImages.AlardLuptonPreconvolveSubtractTask.runPreconvolve ( self,
template,
science,
matchedScience,
kernelSources,
preConvKernel )
Convolve the science image with its own PSF, then convolve the
template with a matching kernel and subtract to form the Score
exposure.

Parameters
----------
template : `lsst.afw.image.ExposureF`
    Template exposure, warped to match the science exposure.
science : `lsst.afw.image.ExposureF`
    Science exposure to subtract from the template.
matchedScience : `lsst.afw.image.ExposureF`
    The science exposure, convolved with the reflection of its own PSF.
kernelSources : `lsst.afw.table.SourceCatalog`
    Identified sources on the science exposure. This catalog is used to
    select sources in order to perform the AL PSF matching on stamp
    images around them.
preConvKernel : `lsst.afw.math.Kernel`
    The kernel that was used to preconvolve the ``science``
    exposure. Must be normalized to sum to 1.

Returns
-------
results : `lsst.pipe.base.Struct`

    ``scoreExposure`` : `lsst.afw.image.ExposureF`
        Result of subtracting the convolved template and science
        images. Attached PSF is that of the original science image.
    ``matchedTemplate`` : `lsst.afw.image.ExposureF`
        Warped and PSF-matched template exposure. Attached PSF is that
        of the original science image.
    ``matchedScience`` : `lsst.afw.image.ExposureF`
        The science exposure after convolving with its own PSF.
        Attached PSF is that of the original science image.
    ``backgroundModel`` : `lsst.afw.math.Function2D`
        Background model that was fit while solving for the
        PSF-matching kernel
    ``psfMatchingKernel`` : `lsst.afw.math.Kernel`
        Final kernel used to PSF-match the template to the science
        image.

Definition at line 1325 of file subtractImages.py.

◆ runQuantum()

lsst.ip.diffim.subtractImages.AlardLuptonSubtractTask.runQuantum ( self,
butlerQC,
inputRefs,
outputRefs )
inherited

Definition at line 411 of file subtractImages.py.

◆ updateMasks()

lsst.ip.diffim.subtractImages.AlardLuptonSubtractTask.updateMasks ( self,
template,
science )
inherited
Update the science and template mask planes before differencing.

Parameters
----------
template : `lsst.afw.image.Exposure`
    Template exposure, warped to match the science exposure.
    The template mask planes will be erased, except for a few specified
    in the task config.
science : `lsst.afw.image.Exposure`
    Science exposure to subtract from the template.
    The DETECTED and DETECTED_NEGATIVE mask planes of the science image
    will be erased.

Definition at line 1090 of file subtractImages.py.

Member Data Documentation

◆ _DefaultName

str lsst.ip.diffim.subtractImages.AlardLuptonSubtractTask._DefaultName = "alardLuptonSubtract"
staticprotectedinherited

Definition at line 349 of file subtractImages.py.

◆ ConfigClass

lsst.ip.diffim.subtractImages.AlardLuptonSubtractTask.ConfigClass = AlardLuptonSubtractConfig
staticinherited

Definition at line 348 of file subtractImages.py.

◆ convolutionControl

lsst.ip.diffim.subtractImages.AlardLuptonSubtractTask.convolutionControl = lsst.afw.math.ConvolutionControl()
inherited

Definition at line 364 of file subtractImages.py.

◆ log

lsst.ip.diffim.subtractImages.AlardLuptonSubtractTask.log
inherited
Initial value:
= self.makeKernel.run(reference, target, kernelSources,
preconvolved=False,
templateFwhmPix=referenceFwhmPix,
scienceFwhmPix=targetFwhmPix)

Definition at line 596 of file subtractImages.py.

◆ matchedPsfSize

lsst.ip.diffim.subtractImages.AlardLuptonSubtractTask.matchedPsfSize = self.sciencePsfSize if convolveTemplate else self.templatePsfSize
inherited

Definition at line 461 of file subtractImages.py.

◆ sciencePsfSize

lsst.ip.diffim.subtractImages.AlardLuptonSubtractTask.sciencePsfSize = getPsfFwhm(science.psf)
inherited

Definition at line 1049 of file subtractImages.py.

◆ templatePsfSize

lsst.ip.diffim.subtractImages.AlardLuptonSubtractTask.templatePsfSize
inherited
Initial value:
= _shapeTest(template,
science,
fwhmExposureBuffer=self.config.makeKernel.fwhmExposureBuffer,
fwhmExposureGrid=self.config.makeKernel.fwhmExposureGrid)

Definition at line 521 of file subtractImages.py.

◆ usePreconvolution

bool lsst.ip.diffim.subtractImages.AlardLuptonSubtractTask.usePreconvolution = False
staticinherited

Definition at line 350 of file subtractImages.py.


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