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-31060: Clean up some log usage #549

Merged
merged 5 commits into from
Jul 10, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin.src/reportImagesToCoadd.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def runDataRef(self, dataRef):
).exposureInfoList

numExp = len(exposureInfoList)
self.log.info("Found %s exposures that match your selection criteria" % (numExp,))
self.log.info("Found %s exposures that match your selection criteria", numExp)
if numExp < 1:
return

Expand Down
8 changes: 4 additions & 4 deletions bin.src/reportTaskTiming.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ def reportUsage(self):
if not startList:
if not endList:
continue
self.log.warn("%s: %s not set; skipping" % (self, startName))
self.log.warning("%s: %s not set; skipping", self, startName)
continue
if not endList:
self.log.warn("%s: %s not set; skipping" % (self, endName))
self.log.warning("%s: %s not set; skipping", self, endName)
continue
if len(startList) != len(endList):
self.log.warn("%s: len(%s) = %d != %d = len(%s); skipping" %
(self, startName, len(startList), endName, len(endList)))
self.log.warning("%s: len(%s) = %d != %d = len(%s); skipping",
self, startName, len(startList), endName, len(endList))
continue

deltaList = numpy.array([e - s for s, e in zip(startList, endList)])
Expand Down
30 changes: 15 additions & 15 deletions python/lsst/pipe/tasks/assembleCoadd.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,10 @@ def validate(self):
if self.doPsfMatch:
# Backwards compatibility.
# Configs do not have loggers
log.warn("Config doPsfMatch deprecated. Setting warpType='psfMatched'")
log.warning("Config doPsfMatch deprecated. Setting warpType='psfMatched'")
self.warpType = 'psfMatched'
if self.doSigmaClip and self.statistic != "MEANCLIP":
log.warn('doSigmaClip deprecated. To replicate behavior, setting statistic to "MEANCLIP"')
log.warning('doSigmaClip deprecated. To replicate behavior, setting statistic to "MEANCLIP"')
self.statistic = "MEANCLIP"
if self.doInterp and self.statistic not in ['MEAN', 'MEDIAN', 'MEANCLIP', 'VARIANCE', 'VARIANCECLIP']:
raise ValueError("Must set doInterp=False for statistic=%s, which does not "
Expand Down Expand Up @@ -525,7 +525,7 @@ def runDataRef(self, dataRef, selectDataList=None, warpRefList=None):
if warpRefList is None:
calExpRefList = self.selectExposures(dataRef, skyInfo, selectDataList=selectDataList)
if len(calExpRefList) == 0:
self.log.warn("No exposures to coadd")
self.log.warning("No exposures to coadd")
return
self.log.info("Coadding %d exposures", len(calExpRefList))

Expand All @@ -535,7 +535,7 @@ def runDataRef(self, dataRef, selectDataList=None, warpRefList=None):
self.log.info("Found %d %s", len(inputData.tempExpRefList),
self.getTempExpDatasetName(self.warpType))
if len(inputData.tempExpRefList) == 0:
self.log.warn("No coadd temporary exposures found")
self.log.warning("No coadd temporary exposures found")
return

supplementaryData = self.makeSupplementaryData(dataRef, warpRefList=inputData.tempExpRefList)
Expand All @@ -551,7 +551,7 @@ def runDataRef(self, dataRef, selectDataList=None, warpRefList=None):
coaddDatasetName = "fakes_" + self.getCoaddDatasetName(self.warpType)
else:
coaddDatasetName = self.getCoaddDatasetName(self.warpType)
self.log.info("Persisting %s" % coaddDatasetName)
self.log.info("Persisting %s", coaddDatasetName)
dataRef.put(retStruct.coaddExposure, coaddDatasetName)
if self.config.doNImage and retStruct.nImage is not None:
dataRef.put(retStruct.nImage, self.getCoaddDatasetName(self.warpType) + '_nImage')
Expand Down Expand Up @@ -684,7 +684,7 @@ def prepareInputs(self, refList):
# therefore have no datasetExists() method
if not isinstance(tempExpRef, DeferredDatasetHandle):
if not tempExpRef.datasetExists(tempExpName):
self.log.warn("Could not find %s %s; skipping it", tempExpName, tempExpRef.dataId)
self.log.warning("Could not find %s %s; skipping it", tempExpName, tempExpRef.dataId)
continue

tempExp = tempExpRef.get(datasetType=tempExpName, immediate=True)
Expand All @@ -699,14 +699,14 @@ def prepareInputs(self, refList):
try:
imageScaler.scaleMaskedImage(maskedImage)
except Exception as e:
self.log.warn("Scaling failed for %s (skipping it): %s", tempExpRef.dataId, e)
self.log.warning("Scaling failed for %s (skipping it): %s", tempExpRef.dataId, e)
continue
statObj = afwMath.makeStatistics(maskedImage.getVariance(), maskedImage.getMask(),
afwMath.MEANCLIP, statsCtrl)
meanVar, meanVarErr = statObj.getResult(afwMath.MEANCLIP)
weight = 1.0 / float(meanVar)
if not numpy.isfinite(weight):
self.log.warn("Non-finite weight for %s: skipping", tempExpRef.dataId)
self.log.warning("Non-finite weight for %s: skipping", tempExpRef.dataId)
continue
self.log.info("Weight of %s %s = %0.3f", tempExpName, tempExpRef.dataId, weight)

Expand Down Expand Up @@ -1111,7 +1111,7 @@ def readBrightObjectMasks(self, dataRef):
try:
return dataRef.get(datasetType="brightObjectMask", immediate=True)
except Exception as e:
self.log.warn("Unable to read brightObjectMask for %s: %s", dataRef.dataId, e)
self.log.warning("Unable to read brightObjectMask for %s: %s", dataRef.dataId, e)
return None

def setBrightObjectMasks(self, exposure, brightObjectMasks, dataId=None):
Expand All @@ -1128,7 +1128,7 @@ def setBrightObjectMasks(self, exposure, brightObjectMasks, dataId=None):
"""

if brightObjectMasks is None:
self.log.warn("Unable to apply bright object mask: none supplied")
self.log.warning("Unable to apply bright object mask: none supplied")
return
self.log.info("Applying %d bright object masks to %s", len(brightObjectMasks), dataId)
mask = exposure.getMaskedImage().getMask()
Expand All @@ -1152,7 +1152,7 @@ def setBrightObjectMasks(self, exposure, brightObjectMasks, dataId=None):
radius = int(rec["radius"].asArcseconds()/plateScale) # convert to pixels
spans = afwGeom.SpanSet.fromShape(radius, offset=center)
else:
self.log.warn("Unexpected region type %s at %s" % rec["type"], center)
self.log.warning("Unexpected region type %s at %s", rec["type"], center)
continue
spans.clippedTo(mask.getBBox()).setMask(mask, self.brightObjectBitmask)

Expand Down Expand Up @@ -1366,8 +1366,8 @@ def setDefaults(self):

def validate(self):
if self.doSigmaClip:
log.warn("Additional Sigma-clipping not allowed in Safe-clipped Coadds. "
"Ignoring doSigmaClip.")
log.warning("Additional Sigma-clipping not allowed in Safe-clipped Coadds. "
"Ignoring doSigmaClip.")
self.doSigmaClip = False
if self.statistic != "MEAN":
raise ValueError("Only MEAN statistic allowed for final stacking in SafeClipAssembleCoadd "
Expand Down Expand Up @@ -2477,7 +2477,7 @@ def _readAndComputeWarpDiff(self, warpRef, imageScaler, templateCoadd):
warpName = self.getTempExpDatasetName('psfMatched')
if not isinstance(warpRef, DeferredDatasetHandle):
if not warpRef.datasetExists(warpName):
self.log.warn("Could not find %s %s; skipping it", warpName, warpRef.dataId)
self.log.warning("Could not find %s %s; skipping it", warpName, warpRef.dataId)
return None
warp = warpRef.get(datasetType=warpName, immediate=True)
# direct image scaler OK for PSF-matched Warp
Expand All @@ -2487,7 +2487,7 @@ def _readAndComputeWarpDiff(self, warpRef, imageScaler, templateCoadd):
try:
self.scaleWarpVariance.run(mi)
except Exception as exc:
self.log.warn("Unable to rescale variance of warp (%s); leaving it as-is" % (exc,))
self.log.warning("Unable to rescale variance of warp (%s); leaving it as-is", exc)
mi -= templateCoadd.getMaskedImage()
return warp

Expand Down
28 changes: 14 additions & 14 deletions python/lsst/pipe/tasks/calibrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ def runDataRef(self, dataRef, exposure=None, background=None, icSourceCat=None,
command-line task, False for running as a subtask
@return same data as the calibrate method
"""
self.log.info("Processing %s" % (dataRef.dataId))
self.log.info("Processing %s", dataRef.dataId)

if doUnpersist:
if any(item is not None for item in (exposure, background,
Expand Down Expand Up @@ -741,23 +741,23 @@ def run(self, exposure, exposureIdInfo=None, background=None,
except Exception as e:
if self.config.requireAstrometry:
raise
self.log.warn("Unable to perform astrometric calibration "
"(%s): attempting to proceed" % e)
self.log.warning("Unable to perform astrometric calibration "
"(%s): attempting to proceed", e)

# compute photometric calibration
if self.config.doPhotoCal:
try:
photoRes = self.photoCal.run(exposure, sourceCat=sourceCat, expId=exposureIdInfo.expId)
exposure.setPhotoCalib(photoRes.photoCalib)
# TODO: reword this to phrase it in terms of the calibration factor?
self.log.info("Photometric zero-point: %f" %
self.log.info("Photometric zero-point: %f",
photoRes.photoCalib.instFluxToMagnitude(1.0))
self.setMetadata(exposure=exposure, photoRes=photoRes)
except Exception as e:
if self.config.requirePhotoCal:
raise
self.log.warn("Unable to perform photometric calibration "
"(%s): attempting to proceed" % e)
self.log.warning("Unable to perform photometric calibration "
"(%s): attempting to proceed", e)
self.setMetadata(exposure=exposure, photoRes=None)

if self.config.doInsertFakes:
Expand Down Expand Up @@ -870,8 +870,8 @@ def setMetadata(self, exposure, photoRes=None):
exposureTime = exposure.getInfo().getVisitInfo().getExposureTime()
magZero = photoRes.zp - 2.5*math.log10(exposureTime)
except Exception:
self.log.warn("Could not set normalized MAGZERO in header: no "
"exposure time")
self.log.warning("Could not set normalized MAGZERO in header: no "
"exposure time")
magZero = math.nan

try:
Expand All @@ -882,7 +882,7 @@ def setMetadata(self, exposure, photoRes=None):
metadata.set('COLORTERM2', 0.0)
metadata.set('COLORTERM3', 0.0)
except Exception as e:
self.log.warn("Could not set exposure metadata: %s" % (e,))
self.log.warning("Could not set exposure metadata: %s", e)

def copyIcSourceFields(self, icSourceCat, sourceCat):
"""!Match sources in icSourceCat and sourceCat and copy the specified fields
Expand All @@ -902,8 +902,8 @@ def copyIcSourceFields(self, icSourceCat, sourceCat):
raise RuntimeError("icSourceCat and sourceCat must both be "
"specified")
if len(self.config.icSourceFieldsToCopy) == 0:
self.log.warn("copyIcSourceFields doing nothing because "
"icSourceFieldsToCopy is empty")
self.log.warning("copyIcSourceFields doing nothing because "
"icSourceFieldsToCopy is empty")
return

mc = afwTable.MatchControl()
Expand Down Expand Up @@ -933,11 +933,11 @@ def copyIcSourceFields(self, icSourceCat, sourceCat):
numMatches = len(matches)
numUniqueSources = len(set(m[1].getId() for m in matches))
if numUniqueSources != numMatches:
self.log.warn("{} icSourceCat sources matched only {} sourceCat "
"sources".format(numMatches, numUniqueSources))
self.log.warning("%d icSourceCat sources matched only %d sourceCat "
"sources", numMatches, numUniqueSources)

self.log.info("Copying flags from icSourceCat to sourceCat for "
"%s sources" % (numMatches,))
"%d sources", numMatches)

# For each match: set the calibSourceKey flag and copy the desired
# fields
Expand Down
14 changes: 7 additions & 7 deletions python/lsst/pipe/tasks/characterizeImage.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ def runDataRef(self, dataRef, exposure=None, background=None, doUnpersist=True):
@return same data as the characterize method
"""
self._frame = self._initialFrame # reset debug display frame
self.log.info("Processing %s" % (dataRef.dataId))
self.log.info("Processing %s", dataRef.dataId)

if doUnpersist:
if exposure is not None or background is not None:
Expand Down Expand Up @@ -474,7 +474,7 @@ def run(self, exposure, exposureIdInfo=None, background=None):
self._frame = self._initialFrame # reset debug display frame

if not self.config.doMeasurePsf and not exposure.hasPsf():
self.log.warn("Source catalog detected and measured with placeholder or default PSF")
self.log.warning("Source catalog detected and measured with placeholder or default PSF")
self.installSimplePsf.run(exposure=exposure)

if exposureIdInfo is None:
Expand All @@ -495,8 +495,8 @@ def run(self, exposure, exposureIdInfo=None, background=None):
psfSigma = psf.computeShape().getDeterminantRadius()
psfDimensions = psf.computeImage().getDimensions()
medBackground = np.median(dmeRes.background.getImage().getArray())
self.log.info("iter %s; PSF sigma=%0.2f, dimensions=%s; median background=%0.2f" %
(i + 1, psfSigma, psfDimensions, medBackground))
self.log.info("iter %s; PSF sigma=%0.2f, dimensions=%s; median background=%0.2f",
i + 1, psfSigma, psfDimensions, medBackground)

self.display("psf", exposure=dmeRes.exposure, sourceCat=dmeRes.sourceCat)

Expand Down Expand Up @@ -558,7 +558,7 @@ def detectMeasureAndEstimatePsf(self, exposure, exposureIdInfo, background):
"""
# install a simple PSF model, if needed or wanted
if not exposure.hasPsf() or (self.config.doMeasurePsf and self.config.useSimplePsf):
self.log.warn("Source catalog detected and measured with placeholder or default PSF")
self.log.warning("Source catalog detected and measured with placeholder or default PSF")
self.installSimplePsf.run(exposure=exposure)

# run repair, but do not interpolate over cosmic rays (do that elsewhere, with the final PSF model)
Expand All @@ -568,8 +568,8 @@ def detectMeasureAndEstimatePsf(self, exposure, exposureIdInfo, background):
try:
self.repair.run(exposure=exposure, keepCRs=True)
except LengthError:
self.log.warn("Skipping cosmic ray detection: Too many CR pixels (max %0.f)" %
self.config.repair.cosmicray.nCrPixelMax)
self.log.warning("Skipping cosmic ray detection: Too many CR pixels (max %0.f)",
self.config.repair.cosmicray.nCrPixelMax)

self.display("repair_iter", exposure=exposure)

Expand Down
2 changes: 1 addition & 1 deletion python/lsst/pipe/tasks/coaddBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def makeDataRefList(self, namespace):
wcs = afwGeom.makeSkyWcs(md)
data = SelectStruct(dataRef=ref, wcs=wcs, bbox=afwImage.bboxFromMetadata(md))
except FitsError:
namespace.log.warn("Unable to construct Wcs from %s" % (ref.dataId))
namespace.log.warning("Unable to construct Wcs from %s", ref.dataId)
continue
self.dataList.append(data)

Expand Down
16 changes: 8 additions & 8 deletions python/lsst/pipe/tasks/coaddInputRecorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ def addCalExp(self, calExp, ccdId, nGoodPix):
try:
record.setI(self.task.ccdCcdKey, calExp.getDetector().getId())
except Exception as e:
self.task.log.warn("Error getting detector serial number in visit %d; using -1; error=%s"
% (self.visitRecord.getId(), e))
self.task.log.warning("Error getting detector serial number in visit %d; using -1; error=%s",
self.visitRecord.getId(), e)
record.setI(self.task.ccdCcdKey, -1)
record.setI(self.task.ccdGoodPixKey, nGoodPix)
if calExp is not None:
Expand Down Expand Up @@ -208,9 +208,9 @@ def addVisitToCoadd(self, coaddInputs, coaddTempExp, weight):
"""
tempExpInputs = coaddTempExp.getInfo().getCoaddInputs()
if len(tempExpInputs.visits) != 1:
self.log.warn("CoaddInputs for coaddTempExp should have exactly one record in visits table "
"(found %d). CoaddInputs for this visit will not be saved."
% len(tempExpInputs.visits))
self.log.warning("CoaddInputs for coaddTempExp should have exactly one record in visits table "
"(found %d). CoaddInputs for this visit will not be saved.",
len(tempExpInputs.visits))
return None
inputVisitRecord = tempExpInputs.visits[0]
outputVisitRecord = coaddInputs.visits.addNew()
Expand All @@ -219,9 +219,9 @@ def addVisitToCoadd(self, coaddInputs, coaddTempExp, weight):
outputVisitRecord.set(self.visitFilterKey, coaddTempExp.getFilterLabel().physicalLabel)
for inputCcdRecord in tempExpInputs.ccds:
if inputCcdRecord.getL(self.ccdVisitKey) != inputVisitRecord.getId():
self.log.warn("CoaddInputs for coaddTempExp with id %d contains CCDs with visit=%d. "
"CoaddInputs may be unreliable."
% (inputVisitRecord.getId(), inputCcdRecord.getL(self.ccdVisitKey)))
self.log.warning("CoaddInputs for coaddTempExp with id %d contains CCDs with visit=%d. "
"CoaddInputs may be unreliable.",
inputVisitRecord.getId(), inputCcdRecord.getL(self.ccdVisitKey))
outputCcdRecord = coaddInputs.ccds.addNew()
outputCcdRecord.assign(inputCcdRecord)
if self.config.saveCcdWeights:
Expand Down