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-6999: Logging framework migration #47

Merged
merged 3 commits into from
Sep 2, 2016
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
16 changes: 8 additions & 8 deletions python/lsst/meas/base/applyApCorr.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ def __init__(self, schema, **kwds):
ignoreSet = set(self.config.ignoreList)
missingNameSet = ignoreSet - set(apCorrNameSet)
if missingNameSet:
self.log.warn("Fields in ignoreList that are not in fluxCorrectList: %s" %
(sorted(list(missingNameSet)),))
self.log.warn("Fields in ignoreList that are not in fluxCorrectList: %s",
sorted(list(missingNameSet)))
for name in apCorrNameSet - ignoreSet:
if name + "_flux" in schema:
self.apCorrInfoDict[name] = ApCorrInfo(schema=schema, name=name)
Expand All @@ -141,7 +141,7 @@ def run(self, catalog, apCorrMap):
If you show debug-level log messages then you will see statistics for the effects of
aperture correction.
"""
self.log.info("Applying aperture corrections to %d flux fields" % (len(self.apCorrInfoDict),))
self.log.info("Applying aperture corrections to %d flux fields", len(self.apCorrInfoDict))
if UseNaiveFluxSigma:
self.log.info("Use naive flux sigma computation")
else:
Expand Down Expand Up @@ -194,11 +194,11 @@ def run(self, catalog, apCorrMap):
if self.config.doFlagApCorrFailures:
source.set(apCorrInfo.fluxFlagKey, oldFluxFlagState)

if self.log.getThreshold() <= self.log.DEBUG:
if self.log.getLevel() <= self.log.DEBUG:
# log statistics on the effects of aperture correction
apCorrArr = numpy.array([s.get(apCorrInfo.apCorrKey) for s in catalog])
apCorrSigmaArr = numpy.array([s.get(apCorrInfo.apCorrSigmaKey) for s in catalog])
self.log.logdebug("For flux field %r: mean apCorr=%s, stdDev apCorr=%s, "
"mean apCorrSigma=%s, stdDev apCorrSigma=%s for %s sources" %
(apCorrInfo.name, apCorrArr.mean(), apCorrArr.std(),
apCorrSigmaArr.mean(), apCorrSigmaArr.std(), len(catalog)))
self.log.debug("For flux field %r: mean apCorr=%s, stdDev apCorr=%s, "
"mean apCorrSigma=%s, stdDev apCorrSigma=%s for %s sources",
apCorrInfo.name, apCorrArr.mean(), apCorrArr.std(),
apCorrSigmaArr.mean(), apCorrSigmaArr.std(), len(catalog))
14 changes: 7 additions & 7 deletions python/lsst/meas/base/forcedPhotCcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import lsst.pex.config
import lsst.pex.exceptions
import lsst.pex.logging
from lsst.log import Log
import lsst.pipe.base
import lsst.afw.image
import lsst.afw.table
Expand Down Expand Up @@ -66,14 +66,14 @@ def makeDataRefList(self, namespace):
"""
if self.datasetType is None:
raise RuntimeError("Must call setDatasetType first")
log = lsst.pex.logging.Log.getDefaultLog()
log = Log.getLogger("meas.base.forcedPhotCcd.PerTractCcdDataIdContainer")
skymap = None
visitTract = collections.defaultdict(set) # Set of tracts for each visit
visitRefs = collections.defaultdict(list) # List of data references for each visit
for dataId in self.idList:
if "tract" not in dataId:
# Discover which tracts the data overlaps
log.info("Reading WCS for components of dataId=%s to determine tracts" % (dict(dataId),))
log.info("Reading WCS for components of dataId=%s to determine tracts", dict(dataId))
if skymap is None:
skymap = namespace.butler.get(namespace.config.coaddName + "Coadd_skyMap")

Expand Down Expand Up @@ -108,7 +108,7 @@ def makeDataRefList(self, namespace):
tractCounter = collections.Counter()
for tractSet in visitTract.values():
tractCounter.update(tractSet)
log.info("Number of visits for each tract: %s" % (dict(tractCounter),))
log.info("Number of visits for each tract: %s", dict(tractCounter))


def overlapsTract(tract, imageWcs, imageBox):
Expand Down Expand Up @@ -217,10 +217,10 @@ def fetchReferences(self, dataRef, exposure):
for record in unfiltered:
if record.getFootprint() is None or record.getFootprint().getArea() == 0:
if record.getParent() != 0:
self.log.warn("Skipping reference %s (child of %s) with bad Footprint" %
(record.getId(), record.getParent()))
self.log.warn("Skipping reference %s (child of %s) with bad Footprint",
record.getId(), record.getParent())
else:
self.log.warn("Skipping reference parent %s with bad Footprint" % (record.getId(),))
self.log.warn("Skipping reference parent %s with bad Footprint", record.getId())
badParents.add(record.getId())
elif record.getParent() not in badParents:
references.append(record)
Expand Down
30 changes: 15 additions & 15 deletions python/lsst/meas/base/noiseReplacer.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def __init__(self, config, exposure, footprints, noiseImage=None, exposureId=Non
@param[in] footprints dict of {id: (parent, footprint)};
@param[in] noiseImage an afw.image.ImageF used as a predictable noise replacement source
(for tests only)
@param[in] log pex.logging.Log object to use for status messages; no status messages
@param[in] log Log object to use for status messages; no status messages
will be printed if None

'footprints' is a dict of {id: (parent, footprint)}; when used in SFM, the ID will be the
Expand Down Expand Up @@ -123,7 +123,7 @@ def __init__(self, config, exposure, footprints, noiseImage=None, exposureId=Non
# does it already exist?
plane = mask.getMaskPlane(maskname)
if self.log:
self.log.logdebug('Mask plane "%s" already existed' % (maskname,))
self.log.debug('Mask plane "%s" already existed', maskname)
except:
# if not, add it; we should delete it when done.
plane = mask.addMaskPlane(maskname)
Expand All @@ -132,8 +132,8 @@ def __init__(self, config, exposure, footprints, noiseImage=None, exposureId=Non
bitmask = mask.getPlaneBitMask(maskname)
bitmasks.append(bitmask)
if self.log:
self.log.logdebug('Mask plane "%s": plane %i, bitmask %i = 0x%x'
% (maskname, plane, bitmask, bitmask))
self.log.debug('Mask plane "%s": plane %i, bitmask %i = 0x%x',
maskname, plane, bitmask, bitmask)
self.thisbitmask, self.otherbitmask = bitmasks
del bitmasks
self.heavies = {}
Expand Down Expand Up @@ -166,7 +166,7 @@ def __init__(self, config, exposure, footprints, noiseImage=None, exposureId=Non
self.noiseGenMean = noisegen.mean
self.noiseGenStd = noisegen.std
if self.log:
self.log.logdebug('Using noise generator: %s' % (str(noisegen),))
self.log.debug('Using noise generator: %s', str(noisegen))
for id in self.heavies:
fp = footprints[id][1]
noiseFp = noisegen.getHeavyFootprint(fp)
Expand Down Expand Up @@ -275,13 +275,13 @@ def getNoiseGenerator(self, exposure, noiseImage, noiseMeanVar, exposureId=None)
noiseVar = float(noiseVar)
noiseStd = math.sqrt(noiseVar)
if self.log:
self.log.logdebug('Using passed-in noise mean = %g, variance = %g -> stdev %g'
% (noiseMean, noiseVar, noiseStd))
self.log.debug('Using passed-in noise mean = %g, variance = %g -> stdev %g',
noiseMean, noiseVar, noiseStd)
return FixedGaussianNoiseGenerator(noiseMean, noiseStd, rand=rand)
except:
if self.log:
self.log.logdebug('Failed to cast passed-in noiseMeanVar to floats: %s'
% (str(noiseMeanVar),))
self.log.debug('Failed to cast passed-in noiseMeanVar to floats: %s',
str(noiseMeanVar))
offset = self.noiseOffset
noiseSource = self.noiseSource

Expand All @@ -294,16 +294,16 @@ def getNoiseGenerator(self, exposure, noiseImage, noiseMeanVar, exposureId=None)
# We would have to adjust for GAIN if ip_isr didn't make it 1.0
noiseStd = math.sqrt(bgMean)
if self.log:
self.log.logdebug('Using noise variance = (BGMEAN = %g) from exposure metadata'
% (bgMean,))
self.log.debug('Using noise variance = (BGMEAN = %g) from exposure metadata',
bgMean)
return FixedGaussianNoiseGenerator(offset, noiseStd, rand=rand)
except:
if self.log:
self.log.logdebug('Failed to get BGMEAN from exposure metadata')
self.log.debug('Failed to get BGMEAN from exposure metadata')

if noiseSource == 'variance':
if self.log:
self.log.logdebug('Will draw noise according to the variance plane.')
self.log.debug('Will draw noise according to the variance plane.')
var = exposure.getMaskedImage().getVariance()
return VariancePlaneNoiseGenerator(var, mean=offset, rand=rand)

Expand All @@ -313,8 +313,8 @@ def getNoiseGenerator(self, exposure, noiseImage, noiseMeanVar, exposureId=None)
noiseMean = s.getValue(afwMath.MEANCLIP)
noiseStd = s.getValue(afwMath.STDEVCLIP)
if self.log:
self.log.logdebug("Measured from image: clipped mean = %g, stdev = %g"
% (noiseMean, noiseStd))
self.log.debug("Measured from image: clipped mean = %g, stdev = %g",
noiseMean, noiseStd)
return FixedGaussianNoiseGenerator(noiseMean + offset, noiseStd, rand=rand)


Expand Down
1 change: 0 additions & 1 deletion src/SdssCentroid.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include "ndarray/eigen.h"
#include "lsst/afw/detection/Psf.h"
#include "lsst/pex/exceptions.h"
#include "lsst/pex/logging/Trace.h"
#include "lsst/afw/math/ConvolveImage.h"
#include "lsst/afw/math/offsetImage.h"
#include "lsst/afw/geom/Angle.h"
Expand Down
2 changes: 0 additions & 2 deletions src/SdssShape.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

#include "boost/tuple/tuple.hpp"
#include "Eigen/LU"
#include "lsst/pex/logging/Trace.h"
#include "lsst/afw/image.h"
#include "lsst/afw/detection/Psf.h"
#include "lsst/afw/geom/Angle.h"
Expand All @@ -38,7 +37,6 @@

namespace pexPolicy = lsst::pex::policy;
namespace pexExceptions = lsst::pex::exceptions;
namespace pexLogging = lsst::pex::logging;
namespace afwDet = lsst::afw::detection;
namespace afwImage = lsst::afw::image;
namespace afwGeom = lsst::afw::geom;
Expand Down
6 changes: 3 additions & 3 deletions tests/testFlagHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def testPluginUnexpectedError(self):
schema = self.dataset.makeMinimalSchema()
task = lsst.meas.base.SingleFrameMeasurementTask(schema=schema, config=self.config)
exposure, cat = self.dataset.realize(noise=100.0, schema=schema)
task.log.setThreshold(task.log.FATAL)
task.log.setLevel(task.log.FATAL)
task.run(cat, exposure)
source = cat[0]
self.assertTrue(source.get(self.algName + "_flag"))
Expand Down Expand Up @@ -278,7 +278,7 @@ def testPluginEdgeError(self):
exposure, cat = self.dataset.realize(noise=100.0, schema=schema)
# Set the size large enough to trigger the edge error
self.config.plugins[self.algName].size = exposure.getDimensions()[1]//2
task.log.setThreshold(task.log.FATAL)
task.log.setLevel(task.log.FATAL)
task.run(cat, exposure)
source = cat[0]
self.assertTrue(source.get(self.algName + "_flag"))
Expand All @@ -292,7 +292,7 @@ def testSafeCentroider(self):
# Normal case should use the centroid slot to get the center, which should succeed
schema = self.dataset.makeMinimalSchema()
task = lsst.meas.base.SingleFrameMeasurementTask(schema=schema, config=self.config)
task.log.setThreshold(task.log.FATAL)
task.log.setLevel(task.log.FATAL)
exposure, cat = self.dataset.realize(noise=0.0, schema=schema)
source = cat[0]
task.run(cat, exposure)
Expand Down
7 changes: 0 additions & 7 deletions tests/testMeasureSources.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

import numpy as np

import lsst.pex.logging as pexLogging
import lsst.pex.exceptions
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you forget to remove this, and the code below that uses it? (I didn't see any other instances, but suggest a global search to be sure).

Copy link
Author

Choose a reason for hiding this comment

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

Log is used in line 53 below, also added by this commit.

However, I actually cannot find any logs in afw that logs to afwDetection.Measure. It's likely for some old codes that have been replaced? I will delete these debugging placeholders.

import lsst.daf.base as dafBase
import lsst.afw.detection as afwDetection
Expand All @@ -44,12 +43,6 @@
import lsst.meas.base as measBase
import lsst.utils.tests

try:
type(verbose)
except NameError:
verbose = 0
pexLogging.Trace_setVerbosity("afwDetection.Measure", verbose)

try:
type(display)
except NameError:
Expand Down
6 changes: 3 additions & 3 deletions tests/testPeakCentroid.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ def onlyLogFatal(log):
want to be able to check that they have set appropriate flags without
spewing alarming & confusing error messages to the console.
"""
oldLevel = log.getThreshold()
log.setThreshold(log.FATAL)
oldLevel = log.getLevel()
log.setLevel(log.FATAL)
try:
yield
finally:
log.setThreshold(oldLevel)
log.setLevel(oldLevel)


class SingleFramePeakCentroidTestCase(AlgorithmTestCase, lsst.utils.tests.TestCase):
Expand Down