Skip to content

Commit

Permalink
Switch from lsst.pex.logging to lsst.log
Browse files Browse the repository at this point in the history
Make changes for tasks' logs and other individual logging to use lsst.log.
Replace lsst.pex.logging logdebug with lsst.log.Log DEBUG level
  • Loading branch information
Hsin-Fang Chiang committed Sep 1, 2016
1 parent 0b3652a commit b07f4d5
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 80 deletions.
54 changes: 26 additions & 28 deletions python/lsst/pipe/tasks/assembleCoadd.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,11 @@ def run(self, dataRef, selectDataList=[]):
if len(calExpRefList) == 0:
self.log.warn("No exposures to coadd")
return
self.log.info("Coadding %d exposures" % len(calExpRefList))
self.log.info("Coadding %d exposures", len(calExpRefList))

tempExpRefList = self.getTempExpRefList(dataRef, calExpRefList)
inputData = self.prepareInputs(tempExpRefList)
self.log.info("Found %d %s" % (len(inputData.tempExpRefList), self.getTempExpDatasetName()))
self.log.info("Found %d %s", len(inputData.tempExpRefList), self.getTempExpDatasetName())
if len(inputData.tempExpRefList) == 0:
self.log.warn("No coadd temporary exposures found")
return
Expand Down Expand Up @@ -415,7 +415,7 @@ def prepareInputs(self, refList):
tempExpName = self.getTempExpDatasetName()
for tempExpRef in refList:
if not tempExpRef.datasetExists(tempExpName):
self.log.warn("Could not find %s %s; skipping it" % (tempExpName, tempExpRef.dataId))
self.log.warn("Could not find %s %s; skipping it", tempExpName, tempExpRef.dataId)
continue

tempExp = tempExpRef.get(tempExpName, immediate=True)
Expand All @@ -427,16 +427,16 @@ 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.warn("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.warn("Non-finite weight for %s: skipping", tempExpRef.dataId)
continue
self.log.info("Weight of %s %s = %0.3f" % (tempExpName, tempExpRef.dataId, weight))
self.log.info("Weight of %s %s = %0.3f", tempExpName, tempExpRef.dataId, weight)

del maskedImage
del tempExp
Expand Down Expand Up @@ -476,7 +476,7 @@ def backgroundMatching(self, inputData, refExpDataRef=None, refImageScaler=None)
expDatasetType = self.getTempExpDatasetName(),
).backgroundInfoList
except Exception as e:
self.log.fatal("Cannot match backgrounds: %s" % (e))
self.log.fatal("Cannot match backgrounds: %s", e)
raise pipeBase.TaskError("Background matching failed.")

newWeightList = []
Expand All @@ -491,27 +491,25 @@ def backgroundMatching(self, inputData, refExpDataRef=None, refImageScaler=None)
# skip exposure if it has no backgroundModel
# or if fit was bad
if (bgInfo.backgroundModel is None):
self.log.info("No background offset model available for %s: skipping"%(
tempExpRef.dataId))
self.log.info("No background offset model available for %s: skipping", tempExpRef.dataId)
continue
try:
varianceRatio = bgInfo.matchedMSE / bgInfo.diffImVar
except Exception as e:
self.log.info("MSE/Var ratio not calculable (%s) for %s: skipping" %
(e, tempExpRef.dataId,))
self.log.info("MSE/Var ratio not calculable (%s) for %s: skipping",
e, tempExpRef.dataId)
continue
if not numpy.isfinite(varianceRatio):
self.log.info("MSE/Var ratio not finite (%.2f / %.2f) for %s: skipping" %
(bgInfo.matchedMSE, bgInfo.diffImVar,
tempExpRef.dataId,))
self.log.info("MSE/Var ratio not finite (%.2f / %.2f) for %s: skipping",
bgInfo.matchedMSE, bgInfo.diffImVar, tempExpRef.dataId)
continue
elif (varianceRatio > self.config.maxMatchResidualRatio):
self.log.info("Bad fit. MSE/Var ratio %.2f > %.2f for %s: skipping" % (
varianceRatio, self.config.maxMatchResidualRatio, tempExpRef.dataId,))
self.log.info("Bad fit. MSE/Var ratio %.2f > %.2f for %s: skipping",
varianceRatio, self.config.maxMatchResidualRatio, tempExpRef.dataId)
continue
elif ( bgInfo.fitRMS > self.config.maxMatchResidualRMS):
self.log.info("Bad fit. RMS %.2f > %.2f for %s: skipping" % (
bgInfo.fitRMS, self.config.maxMatchResidualRMS, tempExpRef.dataId,))
self.log.info("Bad fit. RMS %.2f > %.2f for %s: skipping",
bgInfo.fitRMS, self.config.maxMatchResidualRMS, tempExpRef.dataId)
continue
newWeightList.append(1 / (1 / weight + bgInfo.fitRMS**2))
newTempExpRefList.append(tempExpRef)
Expand Down Expand Up @@ -545,7 +543,7 @@ def assemble(self, skyInfo, tempExpRefList, imageScalerList, weightList, bgInfoL
\return coadded exposure
"""
tempExpName = self.getTempExpDatasetName()
self.log.info("Assembling %s %s" % (len(tempExpRefList), tempExpName))
self.log.info("Assembling %s %s", len(tempExpRefList), tempExpName)
if mask is None:
mask = self.getBadPixelMask()

Expand Down Expand Up @@ -583,7 +581,7 @@ def assemble(self, skyInfo, tempExpRefList, imageScalerList, weightList, bgInfoL
self.assembleSubregion(coaddExposure, subBBox, tempExpRefList, imageScalerList,
weightList, bgInfoList, altMaskList, statsFlags, statsCtrl)
except Exception as e:
self.log.fatal("Cannot compute coadd %s: %s" % (subBBox, e,))
self.log.fatal("Cannot compute coadd %s: %s", subBBox, e)

coaddUtils.setCoaddEdgeBits(coaddMaskedImage.getMask(), coaddMaskedImage.getVariance())

Expand Down Expand Up @@ -648,7 +646,7 @@ def assembleSubregion(self, coaddExposure, bbox, tempExpRefList, imageScalerList
\param[in] statsFlags: Statistic for coadd
\param[in] statsCtrl: Statistics control object for coadd
"""
self.log.logdebug("Computing coadd over %s" % bbox)
self.log.debug("Computing coadd over %s", bbox)
tempExpName = self.getTempExpDatasetName()
coaddMaskedImage = coaddExposure.getMaskedImage()
maskedImageList = afwImage.vectorMaskedImageF() # [] is rejected by afwMath.statisticsStack
Expand Down Expand Up @@ -678,7 +676,7 @@ def assembleSubregion(self, coaddExposure, bbox, tempExpRefList, imageScalerList
try:
mask &= ~mask.getPlaneBitMask(maskPlane)
except Exception as e:
self.log.warn("Unable to remove mask plane {}: {}".format(maskPlane, e))
self.log.warn("Unable to remove mask plane %s: %s", maskPlane, e)

maskedImageList.append(maskedImage)

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

def setBrightObjectMasks(self, exposure, dataId, brightObjectMasks):
Expand All @@ -733,14 +731,14 @@ def setBrightObjectMasks(self, exposure, dataId, brightObjectMasks):
if brightObjectMasks is None:
self.log.warn("Unable to apply bright object mask: none supplied")
return
self.log.info("Applying %d bright object masks to %s" % (len(brightObjectMasks), dataId))
self.log.info("Applying %d bright object masks to %s", len(brightObjectMasks), dataId)
md = brightObjectMasks.table.getMetadata()
for k in dataId:
if not md.exists(k):
self.log.warn("Expected to see %s in metadata" % k)
self.log.warn("Expected to see %s in metadata", k)
else:
if md.get(k) != dataId[k]:
self.log.warn("Expected to see %s == %s in metadata, saw %s" % (k, md.get(k), dataId[k]))
self.log.warn("Expected to see %s == %s in metadata, saw %s", k, md.get(k), dataId[k])

mask = exposure.getMaskedImage().getMask()
wcs = exposure.getWcs()
Expand Down Expand Up @@ -1076,7 +1074,7 @@ def assemble(self, skyInfo, tempExpRefList, imageScalerList, weightList, bgModel

result = self.detectClip(exp, tempExpRefList)

self.log.info('Found %d clipped objects' % len(result.clipFootprints))
self.log.info('Found %d clipped objects', len(result.clipFootprints))

# Go to individual visits for big footprints
maskClipValue = mask.getPlaneBitMask("CLIPPED")
Expand Down Expand Up @@ -1166,7 +1164,7 @@ def detectClip(self, exp, tempExpRefList):
# Merge positive and negative together footprints together
fpSet.positive.merge(fpSet.negative)
footprints = fpSet.positive
self.log.info('Found %d potential clipped objects' % len(footprints.getFootprints()))
self.log.info('Found %d potential clipped objects', len(footprints.getFootprints()))
ignoreMask = self.getBadPixelMask()

clipFootprints = []
Expand Down
28 changes: 14 additions & 14 deletions python/lsst/pipe/tasks/makeCoaddTempExp.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,25 +88,25 @@ def run(self, patchRef, selectDataList=[]):

calExpRefList = self.selectExposures(patchRef, skyInfo, selectDataList=selectDataList)
if len(calExpRefList) == 0:
self.log.warn("No exposures to coadd for patch %s" % patchRef.dataId)
self.log.warn("No exposures to coadd for patch %s", patchRef.dataId)
return None
self.log.info("Selected %d calexps for patch %s" % (len(calExpRefList), patchRef.dataId))
self.log.info("Selected %d calexps for patch %s", len(calExpRefList), patchRef.dataId)
calExpRefList = [calExpRef for calExpRef in calExpRefList if calExpRef.datasetExists("calexp")]
self.log.info("Processing %d existing calexps for patch %s" % (len(calExpRefList), patchRef.dataId))
self.log.info("Processing %d existing calexps for patch %s", len(calExpRefList), patchRef.dataId)

groupData = groupPatchExposures(patchRef, calExpRefList, self.getCoaddDatasetName(),
self.getTempExpDatasetName())
self.log.info("Processing %d tempExps for patch %s" % (len(groupData.groups), patchRef.dataId))
self.log.info("Processing %d tempExps for patch %s", len(groupData.groups), patchRef.dataId)

dataRefList = []
for i, (tempExpTuple, calexpRefList) in enumerate(groupData.groups.iteritems()):
tempExpRef = getGroupDataRef(patchRef.getButler(), self.getTempExpDatasetName(),
tempExpTuple, groupData.keys)
if not self.config.doOverwrite and tempExpRef.datasetExists(datasetType=self.getTempExpDatasetName()):
self.log.info("tempCoaddExp %s exists; skipping" % (tempExpRef.dataId,))
self.log.info("tempCoaddExp %s exists; skipping", tempExpRef.dataId)
dataRefList.append(tempExpRef)
continue
self.log.info("Processing tempExp %d/%d: id=%s" % (i, len(groupData.groups), tempExpRef.dataId))
self.log.info("Processing tempExp %d/%d: id=%s", i, len(groupData.groups), tempExpRef.dataId)

# TODO: mappers should define a way to go from the "grouping keys" to a numeric ID (#2776).
# For now, we try to get a long integer "visit" key, and if we can't, we just use the index
Expand All @@ -122,7 +122,7 @@ def run(self, patchRef, selectDataList=[]):
if self.config.doWrite:
self.writeCoaddOutput(tempExpRef, exp, "tempExp")
else:
self.log.warn("tempExp %s could not be created" % (tempExpRef.dataId,))
self.log.warn("tempExp %s could not be created", tempExpRef.dataId)
return dataRefList

def createTempExp(self, calexpRefList, skyInfo, visitId=0):
Expand Down Expand Up @@ -150,8 +150,8 @@ def createTempExp(self, calexpRefList, skyInfo, visitId=0):
didSetMetadata = False
modelPsf = self.config.modelPsf.apply() if self.config.doPsfMatch else None
for calExpInd, calExpRef in enumerate(calexpRefList):
self.log.info("Processing calexp %d of %d for this tempExp: id=%s" %
(calExpInd+1, len(calexpRefList), calExpRef.dataId))
self.log.info("Processing calexp %d of %d for this tempExp: id=%s",
calExpInd+1, len(calexpRefList), calExpRef.dataId)
try:
ccdId = calExpRef.get("ccdExposureId", immediate=True)
except Exception:
Expand All @@ -173,14 +173,14 @@ def createTempExp(self, calexpRefList, skyInfo, visitId=0):
numGoodPix = coaddUtils.copyGoodPixels(
coaddTempExp.getMaskedImage(), exposure.getMaskedImage(), self.getBadPixelMask())
totGoodPix += numGoodPix
self.log.logdebug("Calexp %s has %d good pixels in this patch (%.1f%%)" %
(calExpRef.dataId, numGoodPix, 100.0*numGoodPix/skyInfo.bbox.getArea()))
self.log.debug("Calexp %s has %d good pixels in this patch (%.1f%%)",
calExpRef.dataId, numGoodPix, 100.0*numGoodPix/skyInfo.bbox.getArea())
if numGoodPix > 0 and not didSetMetadata:
coaddTempExp.setCalib(exposure.getCalib())
coaddTempExp.setFilter(exposure.getFilter())
didSetMetadata = True
except Exception, e:
self.log.warn("Error processing calexp %s; skipping it: %s" % (calExpRef.dataId, e))
self.log.warn("Error processing calexp %s; skipping it: %s", calExpRef.dataId, e)
continue
inputRecorder.addCalExp(calExp, ccdId, numGoodPix)

Expand All @@ -189,6 +189,6 @@ def createTempExp(self, calexpRefList, skyInfo, visitId=0):
coaddTempExp.setPsf(modelPsf if self.config.doPsfMatch else
CoaddPsf(inputRecorder.coaddInputs.ccds, skyInfo.wcs))

self.log.info("coaddTempExp has %d good pixels (%.1f%%)" %
(totGoodPix, 100.0*totGoodPix/skyInfo.bbox.getArea()))
self.log.info("coaddTempExp has %d good pixels (%.1f%%)",
totGoodPix, 100.0*totGoodPix/skyInfo.bbox.getArea())
return coaddTempExp if totGoodPix > 0 and didSetMetadata else None
4 changes: 2 additions & 2 deletions python/lsst/pipe/tasks/multiBand.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,8 +720,8 @@ def mergeCatalogs(self, catalogs, patchRef):
s.setFootprint(foot)
s.set(key, True)

self.log.info("Added %d sky sources (%.0f%% of requested)" % (
len(skySourceFootprints), 100*len(skySourceFootprints)/float(self.config.nSkySourcesPerPatch)))
self.log.info("Added %d sky sources (%.0f%% of requested)",
len(skySourceFootprints), 100*len(skySourceFootprints)/float(self.config.nSkySourcesPerPatch))

# Sort Peaks from brightest to faintest
for record in mergedList:
Expand Down
4 changes: 2 additions & 2 deletions python/lsst/pipe/tasks/objectMasks.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import re
import lsst.daf.base as dafBase
import lsst.pex.logging as pexLog
import lsst.afw.coord as afwCoord
import lsst.afw.geom as afwGeom
import lsst.afw.table as afwTable
from lsst.log import Log

class ObjectMaskCatalog(object):
"""Class to support bright object masks
Expand Down Expand Up @@ -64,7 +64,7 @@ def readFits(fileName, hdu=0, flags=0):
currently.
"""

log = pexLog.getDefaultLog().createChildLog("ObjectMaskCatalog")
log = Log.getLogger("ObjectMaskCatalog")

brightObjects = ObjectMaskCatalog()
checkedWcsIsFk5 = False
Expand Down

0 comments on commit b07f4d5

Please sign in to comment.