Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-45131: Use LsstLogAdapter for logger and document it as an option #100

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions python/lsst/meas/deblender/baseline.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import lsst.afw.detection as afwDet
import lsst.geom as geom
import lsst.afw.math as afwMath
import lsst.utils.logging

from . import plugins

Expand Down Expand Up @@ -558,11 +559,13 @@ def deblend(footprint, maskedImage, psf, psffwhm,
If True, re-weight the templates so that their linear combination best represents
the observed ``maskedImage``.
The default is False.
log: `log.Log`, optional
log:`lsst.log.Logger` or `lsst.utils.logging.LsstLogAdapter`, optional
LSST logger for logging purposes.
The default is ``None`` (no logging).
If `None`, a default logger will be created named after this module.
verbose: `bool`, optional
Whether or not to show a more verbose output.
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``.
Expand Down Expand Up @@ -699,11 +702,13 @@ def newDeblend(debPlugins, footprint, mMaskedImage, psfs, psfFwhms,
Psf of the ``maskedImage``.
psfFwhms: `float` or list of floats
FWHM of the ``maskedImage``\'s ``psf``.
log: `log.Log`, optional
LSST logger for logging purposes.
The default is ``None`` (no logging).
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.
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``.
Expand All @@ -723,12 +728,12 @@ def newDeblend(debPlugins, footprint, mMaskedImage, psfs, psfFwhms,
# Import C++ routines

if log is None:
import lsst.log as lsstLog

log = lsstLog.Log.getLogger(__name__)
log = lsst.utils.logging.getLogger(__name__)

if verbose:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I retained the logic where verbose is only used if log is None. That might not be intentional but it is what was implemented before. The logger is reset if verbose is not set because (1) by default it's WARNING and (2) otherwise calling this with verbose True and then False would leave the trace logger set.

log.setLevel(lsstLog.Log.TRACE)
log.setLevel(log.TRACE)
else:
log.setLevel(log.INFO)

# get object that will hold our results
debResult = DeblenderResult(footprint, mMaskedImage, psfs, psfFwhms, log,
Expand Down
27 changes: 14 additions & 13 deletions python/lsst/meas/deblender/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ def __init__(self, func, onReset=None, maxIterations=50, **kwargs):
Function to run when the plugin is executed.
The function should always take
`debResult`, a `DeblenderResult` that stores the deblender result,
and `log`, an `lsst.log`, as the first two arguments, as well as
any additional keyword arguments (that must
and `log`, an `lsst.log.Logger` or
`lsst.utils.logging.LsstLogAdapter`, as the first two arguments,
as well as any additional keyword arguments (that must
be specified in ``kwargs``). The function should also return
``modified``, a `bool` that tells the deblender whether
or not any templates have been modified by the function.
Expand Down Expand Up @@ -136,7 +137,7 @@ def _setPeakError(debResult, log, pk, cx, cy, filters, msg, flag):
----------
debResult: `lsst.meas.deblender.baseline.DeblenderResult`
Container for the final deblender results.
log: `log.Log`
log: `lsst.log.Logger` or `lsst.utils.logging.LsstLogAdapter`
LSST logger for logging purposes.
pk: int
Number of the peak that failed
Expand Down Expand Up @@ -179,7 +180,7 @@ def fitPsfs(debResult, log, psfChisqCut1=1.5, psfChisqCut2=1.5, psfChisqCut2b=1.
----------
debResult: `lsst.meas.deblender.baseline.DeblenderResult`
Container for the final deblender results.
log: `log.Log`
log: `lsst.log.Logger` or `lsst.utils.logging.LsstLogAdapter`
LSST logger for logging purposes.
psfChisqCut*: `float`, optional
``psfChisqCut1`` is the maximum chi-squared-per-degree-of-freedom
Expand Down Expand Up @@ -715,7 +716,7 @@ def buildSymmetricTemplates(debResult, log, patchEdges=False, setOrigTemplate=Tr
----------
debResult: `lsst.meas.deblender.baseline.DeblenderResult`
Container for the final deblender results.
log: `log.Log`
log : `lsst.log.Logger` or `lsst.utils.logging.LsstLogAdapter`
LSST logger for logging purposes.
patchEdges: `bool`, optional
If True and if the parent Footprint touches pixels with the
Expand Down Expand Up @@ -778,7 +779,7 @@ def rampFluxAtEdge(debResult, log, patchEdges=False):
----------
debResult: `lsst.meas.deblender.baseline.DeblenderResult`
Container for the final deblender results.
log: `log.Log`
log: `lsst.log.Logger` or `lsst.utils.logging.LsstLogAdapter`
LSST logger for logging purposes.
patchEdges: `bool`, optional
If True and if the parent Footprint touches pixels with the
Expand Down Expand Up @@ -832,7 +833,7 @@ def _handle_flux_at_edge(log, psffwhm, t1, tfoot, fp, maskedImage,
Parameters
----------
log: `log.Log`
log: `lsst.log.Logger` or `lsst.utils.logging.LsstLogAdapter`
LSST logger for logging purposes.
psffwhm: `float`
PSF FWHM in pixels.
Expand Down Expand Up @@ -960,7 +961,7 @@ def medianSmoothTemplates(debResult, log, medianFilterHalfsize=2):
----------
debResult: `lsst.meas.deblender.baseline.DeblenderResult`
Container for the final deblender results.
log: `log.Log`
log: `lsst.log.Logger` or `lsst.utils.logging.LsstLogAdapter`
LSST logger for logging purposes.
medianFilterHalfSize: `int`, optional
Half the box size of the median filter, i.e. a
Expand Down Expand Up @@ -1011,7 +1012,7 @@ def makeTemplatesMonotonic(debResult, log):
----------
debResult: `lsst.meas.deblender.baseline.DeblenderResult`
Container for the final deblender results.
log: `log.Log`
log: `lsst.log.Logger` or `lsst.utils.logging.LsstLogAdapter`
LSST logger for logging purposes.
Returns
Expand Down Expand Up @@ -1049,7 +1050,7 @@ def clipFootprintsToNonzero(debResult, log):
----------
debResult: `lsst.meas.deblender.baseline.DeblenderResult`
Container for the final deblender results.
log: `log.Log`
log: `lsst.log.Logger` or `lsst.utils.logging.LsstLogAdapter`
LSST logger for logging purposes.
Returns
Expand Down Expand Up @@ -1085,7 +1086,7 @@ def weightTemplates(debResult, log):
----------
debResult: `lsst.meas.deblender.baseline.DeblenderResult`
Container for the final deblender results.
log: `log.Log`
log: `lsst.log.Logger` or `lsst.utils.logging.LsstLogAdapter`
LSST logger for logging purposes.
Returns
Expand Down Expand Up @@ -1161,7 +1162,7 @@ def reconstructTemplates(debResult, log, maxTempDotProd=0.5):
----------
debResult: `lsst.meas.deblender.baseline.DeblenderResult`
Container for the final deblender results.
log: `log.Log`
log: `lsst.log.Logger` or `lsst.utils.logging.LsstLogAdapter`
LSST logger for logging purposes.
maxTempDotProd: `float`, optional
All dot products between templates greater than ``maxTempDotProd``
Expand Down Expand Up @@ -1259,7 +1260,7 @@ def apportionFlux(debResult, log, assignStrayFlux=True, strayFluxAssignment='r-t
----------
debResult: `lsst.meas.deblender.baseline.DeblenderResult`
Container for the final deblender results.
log: `log.Log`
log: `lsst.log.Logger` or `lsst.utils.logging.LsstLogAdapter`
LSST logger for logging purposes.
assignStrayFlux: `bool`, optional
If True then flux in the parent footprint that is not covered by any
Expand Down
Loading