lsst.meas.deblender gb700894bec+6ff4458e4b
Loading...
Searching...
No Matches
Classes | Functions
lsst.meas.deblender.plugins Namespace Reference

Classes

class  DeblenderPlugin
 

Functions

 clipFootprintToNonzeroImpl (foot, image)
 
 _setPeakError (debResult, log, pk, cx, cy, filters, msg, flag)
 
 fitPsfs (debResult, log, psfChisqCut1=1.5, psfChisqCut2=1.5, psfChisqCut2b=1.5, tinyFootprintSize=2)
 
 _fitPsf (fp, fmask, pk, pkF, pkres, fbb, peaks, peaksF, log, psf, psffwhm, img, varimg, psfChisqCut1, psfChisqCut2, psfChisqCut2b, tinyFootprintSize=2)
 
 buildSymmetricTemplates (debResult, log, patchEdges=False, setOrigTemplate=True)
 
 rampFluxAtEdge (debResult, log, patchEdges=False)
 
 _handle_flux_at_edge (log, psffwhm, t1, tfoot, fp, maskedImage, x0, x1, y0, y1, psf, pk, sigma1, patchEdges)
 
 medianSmoothTemplates (debResult, log, medianFilterHalfsize=2)
 
 makeTemplatesMonotonic (debResult, log)
 
 clipFootprintsToNonzero (debResult, log)
 
 weightTemplates (debResult, log)
 
 _weightTemplates (dp)
 
 reconstructTemplates (debResult, log, maxTempDotProd=0.5)
 
 apportionFlux (debResult, log, assignStrayFlux=True, strayFluxAssignment='r-to-peak', strayFluxToPointSources='necessary', clipStrayFluxFraction=0.001, getTemplateSum=False)
 

Function Documentation

◆ _fitPsf()

lsst.meas.deblender.plugins._fitPsf (   fp,
  fmask,
  pk,
  pkF,
  pkres,
  fbb,
  peaks,
  peaksF,
  log,
  psf,
  psffwhm,
  img,
  varimg,
  psfChisqCut1,
  psfChisqCut2,
  psfChisqCut2b,
  tinyFootprintSize = 2 
)
protected
Fit a PSF + smooth background model (linear) to a small region
around a peak.

See fitPsfs for a more thorough description, including all
parameters not described below.

Parameters
----------
fp: `afw.detection.Footprint`
Footprint containing the Peaks to model.
fmask: `afw.image.Mask`
The Mask plane for pixels in the Footprint
pk: `afw.detection.PeakRecord`
The peak within the Footprint that we are going to fit with PSF model
pkF: `afw.geom.Point2D`
Floating point coordinates of the peak.
pkres: `meas.deblender.DeblendedPeak`
Peak results object that will hold the results.
fbb: `afw.geom.Box2I`
Bounding box of ``fp``
peaks: `afw.detection.PeakCatalog`
    Catalog of peaks contained in the parent footprint.
peaksF: list of `afw.geom.Point2D`
List of floating point coordinates of all of the peaks.
psf: list of `afw.detection.Psf`\ s
Psf of the ``maskedImage`` for each band.
psffwhm: list pf `float`\ s
FWHM of the ``maskedImage``\ 's ``psf`` in each band.
img: `afw.image.ImageF`
The image that contains the footprint.
varimg: `afw.image.ImageF`
The variance of the image that contains the footprint.

Results
-------
ispsf: `bool`
Whether or not the peak matches a PSF model.

Definition at line 239 of file plugins.py.

◆ _handle_flux_at_edge()

lsst.meas.deblender.plugins._handle_flux_at_edge (   log,
  psffwhm,
  t1,
  tfoot,
  fp,
  maskedImage,
  x0,
  x1,
  y0,
  y1,
  psf,
  pk,
  sigma1,
  patchEdges 
)
protected
Extend a template by the PSF to fill in the footprint.

Using the PSF, a footprint that touches the edge is passed to the
function and is grown by the psffwhm*1.5 and filled in with
ramped pixels.

Parameters
----------
log: `log.Log`
    LSST logger for logging purposes.
psffwhm: `float`
    PSF FWHM in pixels.
t1: `afw.image.ImageF`
    The image template that contains the footprint to extend.
tfoot: `afw.detection.Footprint`
    Symmetric Footprint to extend.
fp: `afw.detection.Footprint`
    Parent Footprint that is being deblended.
maskedImage: `afw.image.MaskedImageF`
    Full MaskedImage containing the parent footprint ``fp``.
x0,y0: `init`
    Minimum x,y for the bounding box of the footprint ``fp``.
x1,y1: `int`
    Maximum x,y for the bounding box of the footprint ``fp``.
psf: `afw.detection.Psf`
    PSF of the image.
pk: `afw.detection.PeakRecord`
    The peak within the Footprint whose footprint is being extended.
sigma1: `float`
    Estimated noise level in the image.
patchEdges: `bool`
    If ``patchEdges==True`` and if the footprint touches pixels with the
    ``EDGE`` bit set, then for spans whose symmetric mirror are outside
    the image, the symmetric footprint is grown to include them and their
    pixel values are stored.

Results
-------
t2: `afw.image.ImageF`
    Image of the extended footprint.
tfoot2: `afw.detection.Footprint`
    Extended Footprint.
patched: `bool`
    If the footprint touches an edge pixel, ``patched`` will be set to
    ``True``. Otherwise ``patched`` is ``False``.

Definition at line 825 of file plugins.py.

◆ _setPeakError()

lsst.meas.deblender.plugins._setPeakError (   debResult,
  log,
  pk,
  cx,
  cy,
  filters,
  msg,
  flag 
)
protected
Update the peak in each band with an error

This function logs an error that occurs during deblending and sets the
relevant flag.

Parameters
----------
debResult: `lsst.meas.deblender.baseline.DeblenderResult`
    Container for the final deblender results.
log: `log.Log`
    LSST logger for logging purposes.
pk: int
    Number of the peak that failed
cx: float
    x coordinate of the peak
cy: float
    y coordinate of the peak
filters: list of str
    List of filter names for the exposures
msg: str
    Message to display in log traceback
flag: str
    Name of the flag to set

Returns
-------
None

Definition at line 129 of file plugins.py.

◆ _weightTemplates()

lsst.meas.deblender.plugins._weightTemplates (   dp)
protected
Weight the templates to best match the parent Footprint in a single
filter

This includes weighting both regular templates and point source templates

Parameter
---------
dp: `DeblendedParent`
    The deblended parent to re-weight

Returns
-------
None

Definition at line 1105 of file plugins.py.

◆ apportionFlux()

lsst.meas.deblender.plugins.apportionFlux (   debResult,
  log,
  assignStrayFlux = True,
  strayFluxAssignment = 'r-to-peak',
  strayFluxToPointSources = 'necessary',
  clipStrayFluxFraction = 0.001,
  getTemplateSum = False 
)
Apportion flux to all of the peak templates in each filter

Divide the ``maskedImage`` flux amongst all of the templates based
on the fraction of flux assigned to each ``template``.
Leftover "stray flux" is assigned to peaks based on the other parameters.

Parameters
----------
debResult: `lsst.meas.deblender.baseline.DeblenderResult`
    Container for the final deblender results.
log: `log.Log`
    LSST logger for logging purposes.
assignStrayFlux: `bool`, optional
    If True then flux in the parent footprint that is not covered by any
    of the template footprints is assigned to templates based on
    their 1/(1+r^2) distance.
    How the flux is apportioned is determined by ``strayFluxAssignment``.
strayFluxAssignment: `string`, optional
    Determines how stray flux is apportioned.

    * ``trim``: Trim stray flux and do not include in any footprints
    * ``r-to-peak`` (default): Stray flux is assigned based on
      (1/(1+r^2) from the peaks
    * ``r-to-footprint``: Stray flux is distributed to the footprints
      based on 1/(1+r^2) of the minimum distance from the stray flux
      to footprint
    * ``nearest-footprint``: Stray flux is assigned to the footprint
      with lowest L-1 (Manhattan) distance to the stray flux

strayFluxToPointSources: `string`, optional
    Determines how stray flux is apportioned to point sources

    * ``never``: never apportion stray flux to point sources
    * ``necessary`` (default): point sources are included only if there
      are no extended sources nearby
    * ``always``: point sources are always included in
      the 1/(1+r^2) splitting

clipStrayFluxFraction: `float`, optional
    Minimum stray-flux portion.
    Any stray-flux portion less than ``clipStrayFluxFraction`` is
    clipped to zero.
getTemplateSum: `bool`, optional
    As part of the flux calculation, the sum of the templates is
    calculated. If ``getTemplateSum==True`` then the sum of the
    templates is stored in the result (a `DeblendedFootprint`).

Returns
-------
modified: `bool`
    Apportion flux always modifies the templates, so ``modified`` is
    always ``True``. However, this should likely be the final step and
    it is unlikely that any deblender plugins will be re-run.

Definition at line 1249 of file plugins.py.

◆ buildSymmetricTemplates()

lsst.meas.deblender.plugins.buildSymmetricTemplates (   debResult,
  log,
  patchEdges = False,
  setOrigTemplate = True 
)
Build a symmetric template for each peak in each filter

Given ``maskedImageF``, ``footprint``, and a ``DebldendedPeak``, creates
a symmetric template (``templateImage`` and ``templateFootprint``) around
the peak for all peaks not flagged as ``skip`` or ``deblendedAsPsf``.

Parameters
----------
debResult: `lsst.meas.deblender.baseline.DeblenderResult`
    Container for the final deblender results.
log: `log.Log`
    LSST logger for logging purposes.
patchEdges: `bool`, optional
    If True and if the parent Footprint touches pixels with the
    ``EDGE`` bit set, then grow the parent Footprint to include
    all symmetric templates.

Returns
-------
modified: `bool`
    If any peaks are not skipped or marked as point sources,
    ``modified`` is ``True. Otherwise ``modified`` is ``False``.

Definition at line 707 of file plugins.py.

◆ clipFootprintsToNonzero()

lsst.meas.deblender.plugins.clipFootprintsToNonzero (   debResult,
  log 
)
Clip non-zero spans in the template footprints for every peak in each filter.

Peak ``Footprint``\ s are clipped to the region in the image containing
non-zero values by dropping spans that are completely zero and moving
endpoints to non-zero pixels (but does not split spans that have
internal zeros).

Parameters
----------
debResult: `lsst.meas.deblender.baseline.DeblenderResult`
    Container for the final deblender results.
log: `log.Log`
    LSST logger for logging purposes.

Returns
-------
modified: `bool`
    Whether or not any templates were modified.
    This will be ``True`` as long as there is at least one source that
    is not flagged as a PSF.

Definition at line 1040 of file plugins.py.

◆ clipFootprintToNonzeroImpl()

lsst.meas.deblender.plugins.clipFootprintToNonzeroImpl (   foot,
  image 
)
Clips the given *Footprint* to the region in the *Image*
containing non-zero values.

The clipping drops spans that are
totally zero, and moves endpoints to non-zero; it does not
split spans that have internal zeros.

Definition at line 38 of file plugins.py.

◆ fitPsfs()

lsst.meas.deblender.plugins.fitPsfs (   debResult,
  log,
  psfChisqCut1 = 1.5,
  psfChisqCut2 = 1.5,
  psfChisqCut2b = 1.5,
  tinyFootprintSize = 2 
)
Fit a PSF + smooth background model (linear) to a small region
around each peak.

This function will iterate over all filters in deblender result but does
not compare results across filters.
DeblendedPeaks that pass the cuts have their templates modified to the
PSF + background model and their ``deblendedAsPsf`` property set
to ``True``.

This will likely be replaced in the future with a function that compares
the psf chi-squared cuts so that peaks flagged as point sources will be
considered point sources in all bands.

Parameters
----------
debResult: `lsst.meas.deblender.baseline.DeblenderResult`
    Container for the final deblender results.
log: `log.Log`
    LSST logger for logging purposes.
psfChisqCut*: `float`, optional
    ``psfChisqCut1`` is the maximum chi-squared-per-degree-of-freedom
    allowed for a peak to be considered a PSF match without recentering.
    A fit is also made that includes terms to recenter the PSF.
    ``psfChisqCut2`` is the same as ``psfChisqCut1`` except it
    determines the restriction on the fit that includes
    recentering terms.
    If the peak is a match for a re-centered PSF, the PSF is
    repositioned at the new center and
    the peak footprint is fit again, this time to the new PSF.
    If the resulting chi-squared-per-degree-of-freedom is less than
    ``psfChisqCut2b`` then it passes the re-centering algorithm.
    If the peak passes both the re-centered and fixed position cuts,
    the better of the two is accepted, but parameters for all three psf
    fits are stored in the ``DebldendedPeak``.
    The default for ``psfChisqCut1``, ``psfChisqCut2``, and
    ``psfChisqCut2b`` is ``1.5``.
tinyFootprintSize: `float`, optional
    The PSF model is shrunk to the size that contains the original
    footprint. If the bbox of the clipped PSF model for a peak is
    smaller than ``max(tinyFootprintSize,2)`` then ``tinyFootprint`` for
    the peak is set to ``True`` and the peak is not fit. The default is 2.

Returns
-------
modified: `bool`
    If any templates have been assigned to PSF point sources then
    ``modified`` is ``True``, otherwise it is ``False``.

Definition at line 164 of file plugins.py.

◆ makeTemplatesMonotonic()

lsst.meas.deblender.plugins.makeTemplatesMonotonic (   debResult,
  log 
)
Make the templates monotonic.

The pixels in the templates are modified such that pixels further
from the peak will have values smaller than those closer to the peak.

Parameters
----------
debResult: `lsst.meas.deblender.baseline.DeblenderResult`
    Container for the final deblender results.
log: `log.Log`
    LSST logger for logging purposes.

Returns
-------
modified: `bool`
    Whether or not any templates were modified.
    This will be ``True`` as long as there is at least one source that
    is not flagged as a PSF.

Definition at line 1004 of file plugins.py.

◆ medianSmoothTemplates()

lsst.meas.deblender.plugins.medianSmoothTemplates (   debResult,
  log,
  medianFilterHalfsize = 2 
)
Applying median smoothing filter to the template images for every
peak in every filter.

Parameters
----------
debResult: `lsst.meas.deblender.baseline.DeblenderResult`
    Container for the final deblender results.
log: `log.Log`
    LSST logger for logging purposes.
medianFilterHalfSize: `int`, optional
    Half the box size of the median filter, i.e. a
    ``medianFilterHalfSize`` of 50 means that each output pixel will
    be the median of  the pixels in a 101 x 101-pixel box in the input
    image. This parameter is only used when
    ``medianSmoothTemplate==True``, otherwise it is ignored.

Returns
-------
modified: `bool`
    Whether or not any templates were modified.
    This will be ``True`` as long as there is at least one source that
    is not flagged as a PSF.

Definition at line 955 of file plugins.py.

◆ rampFluxAtEdge()

lsst.meas.deblender.plugins.rampFluxAtEdge (   debResult,
  log,
  patchEdges = False 
)
Adjust flux on the edges of the template footprints.

Using the PSF, a peak ``~afw.detection.Footprint`` with pixels on the edge
of ``footprint`` is grown by the ``psffwhm*1.5`` and filled in
with ramped pixels. The result is a new symmetric footprint
template for the peaks near the edge.

Parameters
----------
debResult: `lsst.meas.deblender.baseline.DeblenderResult`
Container for the final deblender results.
log: `log.Log`
LSST logger for logging purposes.
patchEdges: `bool`, optional
If True and if the parent Footprint touches pixels with the
``EDGE`` bit set, then grow the parent Footprint to include
all symmetric templates.

Returns
-------
modified: `bool`
If any peaks have their templates modified to include flux at the
edges, ``modified`` is ``True``.

Definition at line 769 of file plugins.py.

◆ reconstructTemplates()

lsst.meas.deblender.plugins.reconstructTemplates (   debResult,
  log,
  maxTempDotProd = 0.5 
)
Remove "degenerate templates"

If galaxies have substructure, such as face-on spirals, the process of
identifying peaks can "shred" the galaxy into many pieces. The templates
of shredded galaxies are typically quite similar because they represent
the same galaxy, so we try to identify these "degenerate" peaks
by looking at the inner product (in pixel space) of pairs of templates.
If they are nearly parallel, we only keep one of the peaks and reject
the other. If only one of the peaks is a PSF template, the other template
is used, otherwise the one with the maximum template value is kept.

Parameters
----------
debResult: `lsst.meas.deblender.baseline.DeblenderResult`
    Container for the final deblender results.
log: `log.Log`
    LSST logger for logging purposes.
maxTempDotProd: `float`, optional
    All dot products between templates greater than ``maxTempDotProd``
    will result in one of the templates removed.

Returns
-------
modified: `bool`
    If any degenerate templates are found, ``modified`` is ``True``.

Definition at line 1148 of file plugins.py.

◆ weightTemplates()

lsst.meas.deblender.plugins.weightTemplates (   debResult,
  log 
)
Weight the templates to best fit the observed image in each filter

This function re-weights the templates so that their linear combination
best represents the observed image in that filter.
In the future it may be useful to simultaneously weight all of the
filters together.

Parameters
----------
debResult: `lsst.meas.deblender.baseline.DeblenderResult`
    Container for the final deblender results.
log: `log.Log`
    LSST logger for logging purposes.

Returns
-------
modified: `bool`
    ``weightTemplates`` does not actually modify the ``Footprint``
    templates other than to add a weight to them, so ``modified``
    is always ``False``.

Definition at line 1076 of file plugins.py.