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 #38

Merged
merged 4 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
1 change: 0 additions & 1 deletion examples/solvestats.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import lsst.pex.policy as policy
import lsst.meas.astrom as measAstrom
import lsst.afw.image as afwImage
from lsst.pex.logging import Log
from lsst.afw.coord import DEGREES

import imsimUtils
Expand Down
2 changes: 0 additions & 2 deletions include/lsst/meas/astrom/sip/LeastSqFitter1d.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@
#include "Eigen/SVD"

#include "lsst/pex/exceptions/Runtime.h"
#include "lsst/pex/logging/Trace.h"
#include "lsst/afw/math/FunctionLibrary.h"

namespace except = lsst::pex::exceptions;
namespace pexLogging = lsst::pex::logging;


namespace lsst {
Expand Down
2 changes: 0 additions & 2 deletions include/lsst/meas/astrom/sip/LeastSqFitter2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@
#include "Eigen/SVD"

#include "lsst/pex/exceptions/Runtime.h"
#include "lsst/pex/logging/Trace.h"
#include "lsst/afw/math/FunctionLibrary.h"

namespace except = lsst::pex::exceptions;
namespace pexLogging = lsst::pex::logging;


namespace lsst {
Expand Down
93 changes: 46 additions & 47 deletions python/lsst/meas/astrom/anetBasicAstrometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import numpy as np

import lsst.daf.base as dafBase
import lsst.pex.logging as pexLog
from lsst.pex.config import Field, RangeField, ListField
import lsst.pex.exceptions as pexExceptions
import lsst.pipe.base as pipeBase
Expand Down Expand Up @@ -278,7 +277,7 @@ def __init__(self,

def memusage(self, prefix=''):
# Not logging at DEBUG: do nothing
if self.log.getThreshold() > pexLog.Log.DEBUG:
if self.log.getLevel() > self.log.DEBUG:
return
from astrometry.util.ttime import get_memusage
mu = get_memusage()
Expand All @@ -290,7 +289,7 @@ def memusage(self, prefix=''):
ss.append('Mmaps: %i' % len(mu['mmaps']))
if 'mmaps_total' in mu:
ss.append('Mmaps: %i kB' % (mu['mmaps_total'] / 1024))
self.log.logdebug(prefix + 'Memory: ' + ', '.join(ss))
self.log.debug(prefix + 'Memory: ' + ', '.join(ss))

def _getImageParams(self, exposure=None, bbox=None, wcs=None, filterName=None, wcsRequired=True):
"""Get image parameters
Expand All @@ -310,13 +309,13 @@ def _getImageParams(self, exposure=None, bbox=None, wcs=None, filterName=None, w
if exposure is not None:
if bbox is None:
bbox = exposure.getBBox()
self.log.logdebug("Setting bbox = %s from exposure metadata" % (bbox,))
self.log.debug("Setting bbox = %s from exposure metadata", bbox)
if wcs is None:
self.log.logdebug("Setting wcs from exposure metadata")
self.log.debug("Setting wcs from exposure metadata")
wcs = exposure.getWcs()
if filterName is None:
filterName = exposure.getFilter().getName()
self.log.logdebug("Setting filterName = %r from exposure metadata" % (filterName,))
self.log.debug("Setting filterName = %r from exposure metadata", filterName)
if bbox is None:
raise RuntimeError("bbox or exposure must be specified")
if wcs is None and wcsRequired:
Expand Down Expand Up @@ -366,17 +365,17 @@ def useKnownWcs(self, sourceCat, wcs=None, exposure=None, filterName=None, bbox=
astrom.refCat = refCat
catids = [src.getId() for src in refCat]
uids = set(catids)
self.log.logdebug('%i reference sources; %i unique IDs' % (len(catids), len(uids)))
self.log.debug('%i reference sources; %i unique IDs', len(catids), len(uids))
matches = self._getMatchList(sourceCat, refCat, wcs)
uniq = set([sm.second.getId() for sm in matches])
if len(matches) != len(uniq):
self.log.warn(('The list of matched stars contains duplicate reference source IDs ' +
'(%i sources, %i unique ids)') % (len(matches), len(uniq)))
self.log.warn('The list of matched stars contains duplicate reference source IDs ' +
'(%i sources, %i unique ids)', len(matches), len(uniq))
if len(matches) == 0:
self.log.warn('No matches found between input sources and reference catalogue.')
return astrom

self.log.logdebug('%i reference objects match input sources using input WCS' % (len(matches)))
self.log.debug('%i reference objects match input sources using input WCS', len(matches))
astrom.tanMatches = matches
astrom.tanWcs = wcs

Expand All @@ -388,10 +387,10 @@ def useKnownWcs(self, sourceCat, wcs=None, exposure=None, filterName=None, bbox=
if calculateSip:
sipwcs, matches = self._calculateSipTerms(wcs, refCat, sourceCat, matches, bbox=bbox)
if sipwcs == wcs:
self.log.logdebug('Failed to find a SIP WCS better than the initial one.')
self.log.debug('Failed to find a SIP WCS better than the initial one.')
else:
self.log.logdebug('%i reference objects match input sources using SIP WCS' %
(len(matches),))
self.log.debug('%i reference objects match input sources using SIP WCS',
len(matches))
astrom.sipWcs = sipwcs
astrom.sipMatches = matches

Expand Down Expand Up @@ -527,28 +526,28 @@ def getBlindWcsSolution(self, sourceCat,
if pixelScale is None:
if usePixelScale:
pixelScale = wcs.pixelScale()
self.log.logdebug('Setting pixel scale estimate = %.3f from given WCS estimate' %
(pixelScale.asArcseconds()))
self.log.debug('Setting pixel scale estimate = %.3f from given WCS estimate',
pixelScale.asArcseconds())

if radecCenter is None:
if useRaDecCenter:
radecCenter = wcs.pixelToSky(xc, yc)
self.log.logdebug(('Setting RA,Dec center estimate = (%.3f, %.3f) from given WCS '
+ 'estimate, using pixel center = (%.1f, %.1f)') %
(radecCenter.getLongitude().asDegrees(),
radecCenter.getLatitude().asDegrees(), xc, yc))
self.log.debug('Setting RA,Dec center estimate = (%.3f, %.3f) from given WCS ' +
'estimate, using pixel center = (%.1f, %.1f)',
radecCenter.getLongitude().asDegrees(),
radecCenter.getLatitude().asDegrees(), xc, yc)

if searchRadius is None:
if useRaDecCenter:
assert(pixelScale is not None)
pixRadius = math.hypot(*bboxD.getDimensions()) / 2
searchRadius = (pixelScale * pixRadius * searchRadiusScale)
self.log.logdebug(('Using RA,Dec search radius = %.3f deg, from pixel scale, '
+ 'image size, and searchRadiusScale = %g') %
(searchRadius, searchRadiusScale))
self.log.debug('Using RA,Dec search radius = %.3f deg, from pixel scale, ' +
'image size, and searchRadiusScale = %g',
searchRadius, searchRadiusScale)
if useParity:
parity = wcs.isFlipped()
self.log.logdebug('Using parity = %s' % (parity and 'True' or 'False'))
self.log.debug('Using parity = %s' % (parity and 'True' or 'False'))

if doTrim:
n = len(sourceCat)
Expand All @@ -557,7 +556,7 @@ def getBlindWcsSolution(self, sourceCat,
else:
exposureBBoxD = bboxD
sourceCat = self._trimBadPoints(sourceCat, exposureBBoxD)
self.log.logdebug("Trimming: kept %i of %i sources" % (n, len(sourceCat)))
self.log.debug("Trimming: kept %i of %i sources", n, len(sourceCat))

wcs, qa = self._solve(
sourceCat=sourceCat,
Expand All @@ -574,8 +573,8 @@ def getBlindWcsSolution(self, sourceCat,
self.log.info('Got astrometric solution from Astrometry.net')

rdc = wcs.pixelToSky(xc, yc)
self.log.logdebug('New WCS says image center pixel (%.1f, %.1f) -> RA,Dec (%.3f, %.3f)' %
(xc, yc, rdc.getLongitude().asDegrees(), rdc.getLatitude().asDegrees()))
self.log.debug('New WCS says image center pixel (%.1f, %.1f) -> RA,Dec (%.3f, %.3f)',
xc, yc, rdc.getLongitude().asDegrees(), rdc.getLatitude().asDegrees())
return wcs, qa

def getSipWcsFromWcs(self, wcs, bbox, ngrid=20, linearizeAtCenter=True):
Expand Down Expand Up @@ -675,15 +674,15 @@ def _calculateSipTerms(self, origWcs, refCat, sourceCat, matches, bbox):
proposedWcs = sipObject.getNewWcs()
self.plotSolution(matches, proposedWcs, bbox.getDimensions())
except pexExceptions.Exception as e:
self.log.warn('Failed to calculate distortion terms. Error: ' + str(e))
self.log.warn('Failed to calculate distortion terms. Error: ', str(e))
break

# use new WCS to get new matchlist.
proposedMatchlist = self._getMatchList(sourceCat, refCat, proposedWcs)
proposedMatchSize = len(proposedMatchlist)
proposedMatchStats = self._computeMatchStatsOnSky(wcs=proposedWcs, matchList=proposedMatchlist)

self.log.logdebug(
self.log.debug(
"SIP iteration %i: %i objects match, previous = %i;" %
(i, proposedMatchSize, lastMatchSize) +
" clipped mean scatter = %s arcsec, previous = %s; " %
Expand All @@ -694,7 +693,7 @@ def _calculateSipTerms(self, origWcs, refCat, sourceCat, matches, bbox):
)

if lastMatchStats.maxMatchDist <= proposedMatchStats.maxMatchDist:
self.log.logdebug(
self.log.debug(
"Fit WCS: use iter %s because max match distance no better in next iter: " % (i-1,) +
" %g < %g arcsec" % (lastMatchStats.maxMatchDist.asArcseconds(),
proposedMatchStats.maxMatchDist.asArcseconds()))
Expand Down Expand Up @@ -823,10 +822,10 @@ def _getMatchList(self, sourceCat, refCat, wcs):
R2 = [src.getRa().asDegrees() for src in refCat]
D2 = [src.getDec().asDegrees() for src in refCat]
# for src in sourceCat:
# self.log.logdebug("source: x,y (%.1f, %.1f), RA,Dec (%.3f, %.3f)" %
# self.log.debug("source: x,y (%.1f, %.1f), RA,Dec (%.3f, %.3f)" %
#(src.getX(), src.getY(), src.getRa().asDegrees(), src.getDec().asDegrees()))
# for src in refCat:
# self.log.logdebug("ref: RA,Dec (%.3f, %.3f)" %
# self.log.debug("ref: RA,Dec (%.3f, %.3f)" %
#(src.getRa().asDegrees(), src.getDec().asDegrees()))
self.loginfo('_getMatchList: %i sources, %i reference sources' % (len(sourceCat), len(refCat)))
if len(sourceCat):
Expand Down Expand Up @@ -875,11 +874,11 @@ def _solve(self, sourceCat, wcs, bbox, pixelScale, radecCenter, searchRadius, pa
xybb.include(afwGeom.Point2D(s.getX() - x0, s.getY() - y0))
self.log.info("Number of selected sources for astrometry : %d" % (len(goodsources)))
if len(goodsources) < len(sourceCat):
self.log.logdebug('Keeping %i of %i sources with finite X,Y positions and PSF flux' %
(len(goodsources), len(sourceCat)))
self.log.logdebug(('Feeding sources in range x=[%.1f, %.1f], y=[%.1f, %.1f] ' +
'(after subtracting x0,y0 = %.1f,%.1f) to Astrometry.net') %
(xybb.getMinX(), xybb.getMaxX(), xybb.getMinY(), xybb.getMaxY(), x0, y0))
self.log.debug('Keeping %i of %i sources with finite X,Y positions and PSF flux',
len(goodsources), len(sourceCat))
self.log.debug('Feeding sources in range x=[%.1f, %.1f], y=[%.1f, %.1f] ' +
'(after subtracting x0,y0 = %.1f,%.1f) to Astrometry.net',
xybb.getMinX(), xybb.getMaxX(), xybb.getMinY(), xybb.getMaxY(), x0, y0)
# setStars sorts them by PSF flux.
solver.setStars(goodsources, x0, y0)
solver.setMaxStars(self.config.maxStars)
Expand All @@ -890,22 +889,22 @@ def _solve(self, sourceCat, wcs, bbox, pixelScale, radecCenter, searchRadius, pa
raDecRadius = (radecCenter.getLongitude().asDegrees(), radecCenter.getLatitude().asDegrees(),
searchRadius.asDegrees())
solver.setRaDecRadius(*raDecRadius)
self.log.logdebug('Searching for match around RA,Dec = (%g, %g) with radius %g deg' %
raDecRadius)
self.log.debug('Searching for match around RA,Dec = (%g, %g) with radius %g deg' %
raDecRadius)

if pixelScale is not None:
dscale = self.config.pixelScaleUncertainty
scale = pixelScale.asArcseconds()
lo = scale / dscale
hi = scale * dscale
solver.setPixelScaleRange(lo, hi)
self.log.logdebug(
'Searching for matches with pixel scale = %g +- %g %% -> range [%g, %g] arcsec/pix' %
(scale, 100.*(dscale-1.), lo, hi))
self.log.debug(
'Searching for matches with pixel scale = %g +- %g %% -> range [%g, %g] arcsec/pix',
scale, 100.*(dscale-1.), lo, hi)

if parity is not None:
solver.setParity(parity)
self.log.logdebug('Searching for match with parity = ' + str(parity))
self.log.debug('Searching for match with parity = %s', str(parity))

# Find and load index files within RA,Dec range and scale range.
if radecCenter is not None:
Expand Down Expand Up @@ -943,14 +942,14 @@ def _solve(self, sourceCat, wcs, bbox, pixelScale, radecCenter, searchRadius, pa
self.memusage('Index files unloaded: ')

if solver.didSolve():
self.log.logdebug('Solved!')
self.log.debug('Solved!')
wcs = solver.getWcs()
self.log.logdebug('WCS: %s' % wcs.getFitsMetadata().toString())
self.log.debug('WCS: %s', wcs.getFitsMetadata().toString())

if x0 != 0 or y0 != 0:
wcs.shiftReferencePixel(x0, y0)
self.log.logdebug('After shifting reference pixel by x0,y0 = (%i,%i), WCS is: %s' %
(x0, y0, wcs.getFitsMetadata().toString()))
self.log.debug('After shifting reference pixel by x0,y0 = (%i,%i), WCS is: %s',
x0, y0, wcs.getFitsMetadata().toString())

else:
self.log.warn('Did not get an astrometric solution from Astrometry.net')
Expand All @@ -963,7 +962,7 @@ def _solve(self, sourceCat, wcs, bbox, pixelScale, radecCenter, searchRadius, pa
self.refObjLoader.loadSkyCircle(radecCenter, searchRadius, filterName)

qa = solver.getSolveStats()
self.log.logdebug('qa: %s' % qa.toString())
self.log.debug('qa: %s', qa.toString())
return wcs, qa

def _isGoodSource(self, candsource, keys):
Expand Down
1 change: 0 additions & 1 deletion python/lsst/meas/astrom/astromLib.i
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Python interface to lsst::meas::astrom
%module(package="lsst.meas.astrom", docstring=astromLib_DOCSTRING) astromLib

%{
#include "lsst/pex/logging.h"
#include "lsst/afw/image.h"
#include "lsst/afw/cameraGeom.h"
#include "lsst/afw/table.h"
Expand Down
22 changes: 11 additions & 11 deletions python/lsst/meas/astrom/astrometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,26 +319,26 @@ def solve(self, exposure, sourceCat):
raise

tryMatchDist = self._computeMatchStatsOnSky(tryRes.matches)
self.log.logdebug(
self.log.debug(
"Match and fit WCS iteration %d: found %d matches with scatter = %0.3f +- %0.3f arcsec; "
"max match distance = %0.3f arcsec" %
(iterNum, len(tryRes.matches), tryMatchDist.distMean.asArcseconds(),
tryMatchDist.distStdDev.asArcseconds(), tryMatchDist.maxMatchDist.asArcseconds()))
"max match distance = %0.3f arcsec",
iterNum, len(tryRes.matches), tryMatchDist.distMean.asArcseconds(),
tryMatchDist.distStdDev.asArcseconds(), tryMatchDist.maxMatchDist.asArcseconds())
if maxMatchDist is not None:
if tryMatchDist.maxMatchDist >= maxMatchDist:
self.log.logdebug(
"Iteration %d had no better maxMatchDist; using previous iteration" % (iterNum,))
self.log.debug(
"Iteration %d had no better maxMatchDist; using previous iteration", iterNum)
iterNum -= 1
break

maxMatchDist = tryMatchDist.maxMatchDist
res = tryRes
wcs = res.wcs
if tryMatchDist.maxMatchDist.asArcseconds() < self.config.minMatchDistanceArcSec:
self.log.logdebug(
self.log.debug(
"Max match distance = %0.3f arcsec < %0.3f = config.minMatchDistanceArcSec; "
"that's good enough" %
(tryMatchDist.maxMatchDist.asArcseconds(), self.config.minMatchDistanceArcSec))
"that's good enough",
tryMatchDist.maxMatchDist.asArcseconds(), self.config.minMatchDistanceArcSec)
break

self.log.info(
Expand Down Expand Up @@ -425,7 +425,7 @@ def _matchAndFitWcs(self, refCat, sourceCat, refFluxField, bbox, wcs, maxMatchDi
refFluxField=refFluxField,
maxMatchDist=maxMatchDist,
)
self.log.logdebug("Found %s matches" % (len(matchRes.matches),))
self.log.debug("Found %s matches", len(matchRes.matches))
if debug.display:
frame = int(debug.frame)
displayAstrometry(
Expand All @@ -438,7 +438,7 @@ def _matchAndFitWcs(self, refCat, sourceCat, refFluxField, bbox, wcs, maxMatchDi
title="Initial WCS",
)

self.log.logdebug("Fitting WCS")
self.log.debug("Fitting WCS")
fitRes = self.wcsFitter.fitWcs(
matches=matchRes.matches,
initWcs=wcs,
Expand Down