LSST Applications g0f08755f38+9c285cab97,g1635faa6d4+13f3999e92,g1653933729+a8ce1bb630,g1a0ca8cf93+bf6eb00ceb,g28da252d5a+0829b12dee,g29321ee8c0+5700dc9eac,g2bbee38e9b+9634bc57db,g2bc492864f+9634bc57db,g2cdde0e794+c2c89b37c4,g3156d2b45e+41e33cbcdc,g347aa1857d+9634bc57db,g35bb328faa+a8ce1bb630,g3a166c0a6a+9634bc57db,g3e281a1b8c+9f2c4e2fc3,g414038480c+077ccc18e7,g41af890bb2+fde0dd39b6,g5fbc88fb19+17cd334064,g781aacb6e4+a8ce1bb630,g80478fca09+55a9465950,g82479be7b0+d730eedb7d,g858d7b2824+9c285cab97,g9125e01d80+a8ce1bb630,g9726552aa6+10f999ec6a,ga5288a1d22+2a84bb7594,gacf8899fa4+c69c5206e8,gae0086650b+a8ce1bb630,gb58c049af0+d64f4d3760,gc28159a63d+9634bc57db,gcf0d15dbbd+4b7d09cae4,gda3e153d99+9c285cab97,gda6a2b7d83+4b7d09cae4,gdaeeff99f8+1711a396fd,ge2409df99d+5e831397f4,ge79ae78c31+9634bc57db,gf0baf85859+147a0692ba,gf3967379c6+41c94011de,gf3fb38a9a8+8f07a9901b,gfb92a5be7c+9c285cab97,w.2024.46
LSST Data Management Base Package
Loading...
Searching...
No Matches
Classes | Functions | Variables
lsst.meas.deblender.baseline Namespace Reference

Classes

class  CachingPsf
 
class  DeblendedParent
 
class  DeblendedPeak
 
class  DeblenderResult
 
class  MultiColorPeak
 

Functions

 deblend (footprint, maskedImage, psf, psffwhm, psfChisqCut1=1.5, psfChisqCut2=1.5, psfChisqCut2b=1.5, fitPsfs=True, medianSmoothTemplate=True, medianFilterHalfsize=2, monotonicTemplate=True, weightTemplates=False, log=None, verbose=False, sigma1=None, maxNumberOfPeaks=0, assignStrayFlux=True, strayFluxToPointSources='necessary', strayFluxAssignment='r-to-peak', rampFluxAtEdge=False, patchEdges=False, tinyFootprintSize=2, getTemplateSum=False, clipStrayFluxFraction=0.001, clipFootprintToNonzero=True, removeDegenerateTemplates=False, maxTempDotProd=0.5)
 
 newDeblend (debPlugins, footprint, mMaskedImage, psfs, psfFwhms, log=None, verbose=False, avgNoise=None, maxNumberOfPeaks=0)
 

Variables

list DEFAULT_PLUGINS
 

Function Documentation

◆ deblend()

lsst.meas.deblender.baseline.deblend ( footprint,
maskedImage,
psf,
psffwhm,
psfChisqCut1 = 1.5,
psfChisqCut2 = 1.5,
psfChisqCut2b = 1.5,
fitPsfs = True,
medianSmoothTemplate = True,
medianFilterHalfsize = 2,
monotonicTemplate = True,
weightTemplates = False,
log = None,
verbose = False,
sigma1 = None,
maxNumberOfPeaks = 0,
assignStrayFlux = True,
strayFluxToPointSources = 'necessary',
strayFluxAssignment = 'r-to-peak',
rampFluxAtEdge = False,
patchEdges = False,
tinyFootprintSize = 2,
getTemplateSum = False,
clipStrayFluxFraction = 0.001,
clipFootprintToNonzero = True,
removeDegenerateTemplates = False,
maxTempDotProd = 0.5 )
Deblend a parent ``Footprint`` in a ``MaskedImageF``.

Deblending assumes that ``footprint`` has multiple peaks, as it will still create a
`PerFootprint` object with a list of peaks even if there is only one peak in the list.
It is recommended to first check that ``footprint`` has more than one peak, similar to the
execution of `lsst.meas.deblender.deblend.SourceDeblendTask`.

.. note::
This is the API for the old deblender, however the function builds the plugins necessary
to use the new deblender to perform identically to the old deblender.
To test out newer functionality use ``newDeblend`` instead.

Deblending involves several mandatory and optional steps:

# Optional: If ``fitPsfs`` is True, find all peaks that are well-fit by a PSF + background model

* Peaks that pass the cuts have their footprints modified to the PSF + background model
  and their ``deblendedAsPsf`` property set to ``True``.
* Relevant parameters: ``psfChisqCut1``, ``psfChisqCut2``, ``psfChisqCut2b``,
  ``tinyFootprintSize``.
* See the parameter descriptions for more.

# Build a symmetric template for each peak not well-fit by the PSF model

* Given ``maskedImageF``, ``footprint``, and a ``DeblendedPeak``, creates a symmetric
  template (``templateImage`` and ``templateFootprint``) around the peak
  for all peaks not flagged as ``skip`` or ``deblendedAsPsf``.
* If ``patchEdges=True`` and if ``footprint`` touches pixels with the
  ``EDGE`` bit set, then ``footprint`` is grown to include spans whose
  symmetric mirror is outside of the image.
* Relevant parameters: ``sigma1`` and ``patchEdges``.

# Optional: If ``rampFluxAtEdge`` is True, adjust flux on the edges of the template footprints

* Using the PSF, a peak ``Footprint`` with pixels on the edge of of ``footprint``
  is grown by the psffwhm*1.5 and filled in with zeros.
* The result is a new symmetric footprint template for the peaks near the edge.
* Relevant parameter: ``patchEdges``.

# Optionally (``medianSmoothTemplate=True``) filter the template images

* Apply a median smoothing filter to all of the template images.
* Relevant parameters: ``medianFilterHalfSize``

# Optional: If ``monotonicTemplate`` is True, 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.

# Optional: If ``clipFootprintToNonzero`` is True, clip non-zero spans in the template footprints

* 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).

# Optional: If ``weightTemplates`` is True,  weight the templates to best fit the observed image

* Re-weight the templates so that their linear combination
  best represents the observed ``maskedImage``

# Optional: If ``removeDegenerateTempaltes`` is True, reconstruct shredded galaxies

* 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.
* Relevant parameters: ``maxTempDotProduct``

# Apportion flux to all of the peak templates

* Divide the ``maskedImage`` flux amongst all of the templates based on the fraction of
  flux assigned to each ``tempalteFootprint``.
* Leftover "stray flux" is assigned to peaks based on the other parameters.
* Relevant parameters: ``clipStrayFluxFraction``, ``strayFluxAssignment``,
  ``strayFluxToPointSources``, ``assignStrayFlux``

Parameters
----------
footprint: `afw.detection.Footprint`
Parent footprint to deblend
maskedImage: `afw.image.MaskedImageF`
Masked image containing the ``footprint``
psf: `afw.detection.Psf`
Psf of the ``maskedImage``
psffwhm: `float`
FWHM of the ``maskedImage``\'s ``psf``
psfChisqCut*: `float`, optional
If ``fitPsfs==True``, all of the peaks are fit to the image PSF.
``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 ``DeblendedPeak``.
The default for ``psfChisqCut1``, ``psfChisqCut2``, and ``psfChisqCut2b`` is ``1.5``.
fitPsfs: `bool`, optional
If True then all of the peaks will be compared to the image PSF to
distinguish stars from galaxies.
medianSmoothTemplate: ``bool``, optional
If ``medianSmoothTemplate==True`` it a median smoothing filter is applied to the ``maskedImage``.
The default is ``True``.
medianFilterHalfSize: `int`, optional
Half the box size of the median filter, ie 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.
The default value is 2.
monotonicTempalte: `bool`, optional
If True then make the template monotonic.
The default is True.
weightTemplates: `bool`, optional
If True, re-weight the templates so that their linear combination best represents
the observed ``maskedImage``.
The default is False.
log:`lsst.log.Logger` or `lsst.utils.logging.LsstLogAdapter`, optional
LSST logger for logging purposes.
If `None`, a default logger will be created named after this module.
verbose: `bool`, optional
Whether or not to show a more verbose output. This option only affects
the logger creeated internally and will not change the reporting level
of an externally-supplied logger.
The default is ``False``.
sigma1: `float`, optional
Average noise level in ``maskedImage``.
The default is ``None``, which estimates the noise from the median value of ``maskedImage``.
maxNumberOfPeaks: `int`, optional
If nonzero, the maximum number of peaks to deblend.
If the total number of peaks is greater than ``maxNumberOfPeaks``,
then only the first ``maxNumberOfPeaks`` sources are deblended.
The default is 0, which deblends all of the peaks.
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``.
The default is True.
strayFluxToPointSources: `string`
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

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

rampFluxAtEdge: `bool`, optional
If True then extend footprints with excessive flux on the edges as described above.
The default is False.
patchEdges: `bool`, optional
If True and if the footprint touches pixels with the ``EDGE`` bit set,
then grow the footprint to include all symmetric templates.
The default is ``False``.
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.
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 `PerFootprint`).
The default is False.
clipStrayFluxFraction: `float`, optional
Minimum stray-flux portion.
Any stray-flux portion less than ``clipStrayFluxFraction`` is clipped to zero.
The default is 0.001.
clipFootprintToNonzero: `bool`, optional
If True then clip non-zero spans in the template footprints. See above for more.
The default is True.
removeDegenerateTemplates: `bool`, optional
If True then we try to identify "degenerate" peaks by looking at the inner product
(in pixel space) of pairs of templates.
The default is False.
maxTempDotProduct: `float`, optional
All dot products between templates greater than ``maxTempDotProduct`` will result in one
of the templates removed. This parameter is only used when ``removeDegenerateTempaltes==True``.
The default is 0.5.

Returns
-------
res: `PerFootprint`
Deblender result that contains a list of ``DeblendedPeak``\ s for each peak and (optionally)
the template sum.

Definition at line 431 of file baseline.py.

440 ):
441 r"""Deblend a parent ``Footprint`` in a ``MaskedImageF``.
442
443 Deblending assumes that ``footprint`` has multiple peaks, as it will still create a
444 `PerFootprint` object with a list of peaks even if there is only one peak in the list.
445 It is recommended to first check that ``footprint`` has more than one peak, similar to the
446 execution of `lsst.meas.deblender.deblend.SourceDeblendTask`.
447
448 .. note::
449 This is the API for the old deblender, however the function builds the plugins necessary
450 to use the new deblender to perform identically to the old deblender.
451 To test out newer functionality use ``newDeblend`` instead.
452
453 Deblending involves several mandatory and optional steps:
454
455 # Optional: If ``fitPsfs`` is True, find all peaks that are well-fit by a PSF + background model
456
457 * Peaks that pass the cuts have their footprints modified to the PSF + background model
458 and their ``deblendedAsPsf`` property set to ``True``.
459 * Relevant parameters: ``psfChisqCut1``, ``psfChisqCut2``, ``psfChisqCut2b``,
460 ``tinyFootprintSize``.
461 * See the parameter descriptions for more.
462
463 # Build a symmetric template for each peak not well-fit by the PSF model
464
465 * Given ``maskedImageF``, ``footprint``, and a ``DeblendedPeak``, creates a symmetric
466 template (``templateImage`` and ``templateFootprint``) around the peak
467 for all peaks not flagged as ``skip`` or ``deblendedAsPsf``.
468 * If ``patchEdges=True`` and if ``footprint`` touches pixels with the
469 ``EDGE`` bit set, then ``footprint`` is grown to include spans whose
470 symmetric mirror is outside of the image.
471 * Relevant parameters: ``sigma1`` and ``patchEdges``.
472
473 # Optional: If ``rampFluxAtEdge`` is True, adjust flux on the edges of the template footprints
474
475 * Using the PSF, a peak ``Footprint`` with pixels on the edge of of ``footprint``
476 is grown by the psffwhm*1.5 and filled in with zeros.
477 * The result is a new symmetric footprint template for the peaks near the edge.
478 * Relevant parameter: ``patchEdges``.
479
480 # Optionally (``medianSmoothTemplate=True``) filter the template images
481
482 * Apply a median smoothing filter to all of the template images.
483 * Relevant parameters: ``medianFilterHalfSize``
484
485 # Optional: If ``monotonicTemplate`` is True, make the templates monotonic.
486
487 * The pixels in the templates are modified such that pixels
488 further from the peak will have values smaller than those closer to the peak.
489
490 # Optional: If ``clipFootprintToNonzero`` is True, clip non-zero spans in the template footprints
491
492 * Peak ``Footprint``\ s are clipped to the region in the image containing non-zero values
493 by dropping spans that are completely zero and moving endpoints to non-zero pixels
494 (but does not split spans that have internal zeros).
495
496 # Optional: If ``weightTemplates`` is True, weight the templates to best fit the observed image
497
498 * Re-weight the templates so that their linear combination
499 best represents the observed ``maskedImage``
500
501 # Optional: If ``removeDegenerateTempaltes`` is True, reconstruct shredded galaxies
502
503 * If galaxies have substructure, such as face-on spirals, the process of identifying peaks can
504 "shred" the galaxy into many pieces. The templates of shredded galaxies are typically quite
505 similar because they represent the same galaxy, so we try to identify these "degenerate" peaks
506 by looking at the inner product (in pixel space) of pairs of templates.
507 * If they are nearly parallel, we only keep one of the peaks and reject the other.
508 * If only one of the peaks is a PSF template, the other template is used,
509 otherwise the one with the maximum template value is kept.
510 * Relevant parameters: ``maxTempDotProduct``
511
512 # Apportion flux to all of the peak templates
513
514 * Divide the ``maskedImage`` flux amongst all of the templates based on the fraction of
515 flux assigned to each ``tempalteFootprint``.
516 * Leftover "stray flux" is assigned to peaks based on the other parameters.
517 * Relevant parameters: ``clipStrayFluxFraction``, ``strayFluxAssignment``,
518 ``strayFluxToPointSources``, ``assignStrayFlux``
519
520 Parameters
521 ----------
522 footprint: `afw.detection.Footprint`
523 Parent footprint to deblend
524 maskedImage: `afw.image.MaskedImageF`
525 Masked image containing the ``footprint``
526 psf: `afw.detection.Psf`
527 Psf of the ``maskedImage``
528 psffwhm: `float`
529 FWHM of the ``maskedImage``\'s ``psf``
530 psfChisqCut*: `float`, optional
531 If ``fitPsfs==True``, all of the peaks are fit to the image PSF.
532 ``psfChisqCut1`` is the maximum chi-squared-per-degree-of-freedom allowed for a peak to
533 be considered a PSF match without recentering.
534 A fit is also made that includes terms to recenter the PSF.
535 ``psfChisqCut2`` is the same as ``psfChisqCut1`` except it determines the restriction on the
536 fit that includes recentering terms.
537 If the peak is a match for a re-centered PSF, the PSF is repositioned at the new center and
538 the peak footprint is fit again, this time to the new PSF.
539 If the resulting chi-squared-per-degree-of-freedom is less than ``psfChisqCut2b`` then it
540 passes the re-centering algorithm.
541 If the peak passes both the re-centered and fixed position cuts, the better of the two is accepted,
542 but parameters for all three psf fits are stored in the ``DeblendedPeak``.
543 The default for ``psfChisqCut1``, ``psfChisqCut2``, and ``psfChisqCut2b`` is ``1.5``.
544 fitPsfs: `bool`, optional
545 If True then all of the peaks will be compared to the image PSF to
546 distinguish stars from galaxies.
547 medianSmoothTemplate: ``bool``, optional
548 If ``medianSmoothTemplate==True`` it a median smoothing filter is applied to the ``maskedImage``.
549 The default is ``True``.
550 medianFilterHalfSize: `int`, optional
551 Half the box size of the median filter, ie a ``medianFilterHalfSize`` of 50 means that
552 each output pixel will be the median of the pixels in a 101 x 101-pixel box in the input image.
553 This parameter is only used when ``medianSmoothTemplate==True``, otherwise it is ignored.
554 The default value is 2.
555 monotonicTempalte: `bool`, optional
556 If True then make the template monotonic.
557 The default is True.
558 weightTemplates: `bool`, optional
559 If True, re-weight the templates so that their linear combination best represents
560 the observed ``maskedImage``.
561 The default is False.
562 log:`lsst.log.Logger` or `lsst.utils.logging.LsstLogAdapter`, optional
563 LSST logger for logging purposes.
564 If `None`, a default logger will be created named after this module.
565 verbose: `bool`, optional
566 Whether or not to show a more verbose output. This option only affects
567 the logger creeated internally and will not change the reporting level
568 of an externally-supplied logger.
569 The default is ``False``.
570 sigma1: `float`, optional
571 Average noise level in ``maskedImage``.
572 The default is ``None``, which estimates the noise from the median value of ``maskedImage``.
573 maxNumberOfPeaks: `int`, optional
574 If nonzero, the maximum number of peaks to deblend.
575 If the total number of peaks is greater than ``maxNumberOfPeaks``,
576 then only the first ``maxNumberOfPeaks`` sources are deblended.
577 The default is 0, which deblends all of the peaks.
578 assignStrayFlux: `bool`, optional
579 If True then flux in the parent footprint that is not covered by any of the
580 template footprints is assigned to templates based on their 1/(1+r^2) distance.
581 How the flux is apportioned is determined by ``strayFluxAssignment``.
582 The default is True.
583 strayFluxToPointSources: `string`
584 Determines how stray flux is apportioned to point sources
585
586 * ``never``: never apportion stray flux to point sources
587 * ``necessary`` (default): point sources are included only if there are no extended sources nearby
588 * ``always``: point sources are always included in the 1/(1+r^2) splitting
589
590 strayFluxAssignment: `string`, optional
591 Determines how stray flux is apportioned.
592
593 * ``trim``: Trim stray flux and do not include in any footprints
594 * ``r-to-peak`` (default): Stray flux is assigned based on (1/(1+r^2) from the peaks
595 * ``r-to-footprint``: Stray flux is distributed to the footprints based on 1/(1+r^2) of the
596 minimum distance from the stray flux to footprint
597 * ``nearest-footprint``: Stray flux is assigned to the footprint with lowest L-1 (Manhattan)
598 distance to the stray flux
599
600 rampFluxAtEdge: `bool`, optional
601 If True then extend footprints with excessive flux on the edges as described above.
602 The default is False.
603 patchEdges: `bool`, optional
604 If True and if the footprint touches pixels with the ``EDGE`` bit set,
605 then grow the footprint to include all symmetric templates.
606 The default is ``False``.
607 tinyFootprintSize: `float`, optional
608 The PSF model is shrunk to the size that contains the original footprint.
609 If the bbox of the clipped PSF model for a peak is smaller than ``max(tinyFootprintSize,2)``
610 then ``tinyFootprint`` for the peak is set to ``True`` and the peak is not fit.
611 The default is 2.
612 getTemplateSum: `bool`, optional
613 As part of the flux calculation, the sum of the templates is calculated.
614 If ``getTemplateSum==True`` then the sum of the templates is stored in the result (a `PerFootprint`).
615 The default is False.
616 clipStrayFluxFraction: `float`, optional
617 Minimum stray-flux portion.
618 Any stray-flux portion less than ``clipStrayFluxFraction`` is clipped to zero.
619 The default is 0.001.
620 clipFootprintToNonzero: `bool`, optional
621 If True then clip non-zero spans in the template footprints. See above for more.
622 The default is True.
623 removeDegenerateTemplates: `bool`, optional
624 If True then we try to identify "degenerate" peaks by looking at the inner product
625 (in pixel space) of pairs of templates.
626 The default is False.
627 maxTempDotProduct: `float`, optional
628 All dot products between templates greater than ``maxTempDotProduct`` will result in one
629 of the templates removed. This parameter is only used when ``removeDegenerateTempaltes==True``.
630 The default is 0.5.
631
632 Returns
633 -------
634 res: `PerFootprint`
635 Deblender result that contains a list of ``DeblendedPeak``\ s for each peak and (optionally)
636 the template sum.
637 """
638 avgNoise = sigma1
639
640 debPlugins = []
641
642 # Add activated deblender plugins
643 if fitPsfs:
644 debPlugins.append(plugins.DeblenderPlugin(plugins.fitPsfs,
645 psfChisqCut1=psfChisqCut1,
646 psfChisqCut2=psfChisqCut2,
647 psfChisqCut2b=psfChisqCut2b,
648 tinyFootprintSize=tinyFootprintSize))
649 debPlugins.append(plugins.DeblenderPlugin(plugins.buildSymmetricTemplates, patchEdges=patchEdges))
650 if rampFluxAtEdge:
651 debPlugins.append(plugins.DeblenderPlugin(plugins.rampFluxAtEdge, patchEdges=patchEdges))
652 if medianSmoothTemplate:
653 debPlugins.append(plugins.DeblenderPlugin(plugins.medianSmoothTemplates,
654 medianFilterHalfsize=medianFilterHalfsize))
655 if monotonicTemplate:
656 debPlugins.append(plugins.DeblenderPlugin(plugins.makeTemplatesMonotonic))
657 if clipFootprintToNonzero:
658 debPlugins.append(plugins.DeblenderPlugin(plugins.clipFootprintsToNonzero))
659 if weightTemplates:
660 debPlugins.append(plugins.DeblenderPlugin(plugins.weightTemplates))
661 if removeDegenerateTemplates:
662 if weightTemplates:
663 onReset = len(debPlugins)-1
664 else:
665 onReset = len(debPlugins)
666 debPlugins.append(plugins.DeblenderPlugin(plugins.reconstructTemplates,
667 onReset=onReset,
668 maxTempDotProd=maxTempDotProd))
669 debPlugins.append(plugins.DeblenderPlugin(plugins.apportionFlux,
670 clipStrayFluxFraction=clipStrayFluxFraction,
671 assignStrayFlux=assignStrayFlux,
672 strayFluxAssignment=strayFluxAssignment,
673 strayFluxToPointSources=strayFluxToPointSources,
674 getTemplateSum=getTemplateSum))
675
676 debResult = newDeblend(debPlugins, footprint, maskedImage, psf, psffwhm, log, verbose, avgNoise)
677
678 return debResult
679
680

◆ newDeblend()

lsst.meas.deblender.baseline.newDeblend ( debPlugins,
footprint,
mMaskedImage,
psfs,
psfFwhms,
log = None,
verbose = False,
avgNoise = None,
maxNumberOfPeaks = 0 )
Deblend a parent ``Footprint`` in a ``MaskedImageF``.

Deblending assumes that ``footprint`` has multiple peaks, as it will still create a
`PerFootprint` object with a list of peaks even if there is only one peak in the list.
It is recommended to first check that ``footprint`` has more than one peak, similar to the
execution of `lsst.meas.deblender.deblend.SourceDeblendTask`.

This version of the deblender accepts a list of plugins to execute, with the option to re-run parts
of the deblender if templates are changed during any of the steps.

Parameters
----------
debPlugins: list of `meas.deblender.plugins.DeblenderPlugins`
    Plugins to execute (in order of execution) for the deblender.
footprint: `afw.detection.Footprint` or list of Footprints
    Parent footprint to deblend.
mMaskedImage: `MultibandMaskedImage` or `MaskedImage`
    Masked image in each band.
psfs: `afw.detection.Psf` or list of Psfs
    Psf of the ``maskedImage``.
psfFwhms: `float` or list of floats
    FWHM of the ``maskedImage``\'s ``psf``.
log: `lsst.log.Logger` or `lsst.utils.logging.LsstLogAdapter`, optional
    Logger for logging purposes. Must support a ``trace`` method.
    If `None`, a default logger will be created named after this module.
verbose: `bool`, optional
    Whether or not to show a more verbose output. This option only affects
    the logger creeated internally and will not change the reporting level
    of an externally-supplied logger.
    The default is ``False``.
avgNoise: `float`or list of `float`\ s, optional
    Average noise level in each ``maskedImage``.
    The default is ``None``, which estimates the noise from the median value of the
    variance plane of ``maskedImage`` for each filter.
maxNumberOfPeaks: `int`, optional
    If nonzero, the maximum number of peaks to deblend.
    If the total number of peaks is greater than ``maxNumberOfPeaks``,
    then only the first ``maxNumberOfPeaks`` sources are deblended.

Returns
-------
debResult: `DeblendedParent`
    Deblender result that contains a list of ``MultiColorPeak``\ s for each peak and
    information that describes the footprint in all filters.

Definition at line 681 of file baseline.py.

682 log=None, verbose=False, avgNoise=None, maxNumberOfPeaks=0):
683 r"""Deblend a parent ``Footprint`` in a ``MaskedImageF``.
684
685 Deblending assumes that ``footprint`` has multiple peaks, as it will still create a
686 `PerFootprint` object with a list of peaks even if there is only one peak in the list.
687 It is recommended to first check that ``footprint`` has more than one peak, similar to the
688 execution of `lsst.meas.deblender.deblend.SourceDeblendTask`.
689
690 This version of the deblender accepts a list of plugins to execute, with the option to re-run parts
691 of the deblender if templates are changed during any of the steps.
692
693 Parameters
694 ----------
695 debPlugins: list of `meas.deblender.plugins.DeblenderPlugins`
696 Plugins to execute (in order of execution) for the deblender.
697 footprint: `afw.detection.Footprint` or list of Footprints
698 Parent footprint to deblend.
699 mMaskedImage: `MultibandMaskedImage` or `MaskedImage`
700 Masked image in each band.
701 psfs: `afw.detection.Psf` or list of Psfs
702 Psf of the ``maskedImage``.
703 psfFwhms: `float` or list of floats
704 FWHM of the ``maskedImage``\'s ``psf``.
705 log: `lsst.log.Logger` or `lsst.utils.logging.LsstLogAdapter`, optional
706 Logger for logging purposes. Must support a ``trace`` method.
707 If `None`, a default logger will be created named after this module.
708 verbose: `bool`, optional
709 Whether or not to show a more verbose output. This option only affects
710 the logger creeated internally and will not change the reporting level
711 of an externally-supplied logger.
712 The default is ``False``.
713 avgNoise: `float`or list of `float`\ s, optional
714 Average noise level in each ``maskedImage``.
715 The default is ``None``, which estimates the noise from the median value of the
716 variance plane of ``maskedImage`` for each filter.
717 maxNumberOfPeaks: `int`, optional
718 If nonzero, the maximum number of peaks to deblend.
719 If the total number of peaks is greater than ``maxNumberOfPeaks``,
720 then only the first ``maxNumberOfPeaks`` sources are deblended.
721
722 Returns
723 -------
724 debResult: `DeblendedParent`
725 Deblender result that contains a list of ``MultiColorPeak``\ s for each peak and
726 information that describes the footprint in all filters.
727 """
728 # Import C++ routines
729
730 if log is None:
731 log = lsst.utils.logging.getLogger(__name__)
732
733 if verbose:
734 log.setLevel(log.TRACE)
735 else:
736 log.setLevel(log.INFO)
737
738 # get object that will hold our results
739 debResult = DeblenderResult(footprint, mMaskedImage, psfs, psfFwhms, log,
740 maxNumberOfPeaks=maxNumberOfPeaks, avgNoise=avgNoise)
741
742 step = 0
743 while step < len(debPlugins):
744 # If a failure occurs at any step,
745 # the result is flagged as `failed`
746 # and the remaining steps are skipped
747 if not debResult.failed:
748 reset = debPlugins[step].run(debResult, log)
749 else:
750 log.warning("Skipping steps %s", debPlugins[step:])
751 return debResult
752 if reset:
753 step = debPlugins[step].onReset
754 else:
755 step += 1
756
757 return debResult
758
759

Variable Documentation

◆ DEFAULT_PLUGINS

list lsst.meas.deblender.baseline.DEFAULT_PLUGINS
Initial value:
1= [
2 plugins.DeblenderPlugin(plugins.fitPsfs),
3 plugins.DeblenderPlugin(plugins.buildSymmetricTemplates),
4 plugins.DeblenderPlugin(plugins.medianSmoothTemplates),
5 plugins.DeblenderPlugin(plugins.makeTemplatesMonotonic),
6 plugins.DeblenderPlugin(plugins.clipFootprintsToNonzero),
7 plugins.DeblenderPlugin(plugins.reconstructTemplates, onReset=5),
8 plugins.DeblenderPlugin(plugins.apportionFlux),
9]

Definition at line 37 of file baseline.py.