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-31801: Prepend lsst to logger names and switch to python logging #259

Merged
merged 6 commits into from
Nov 11, 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
10 changes: 7 additions & 3 deletions bin.src/convert_refcat_to_nJy.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"""
import os.path
import glob
import logging

import concurrent.futures
import itertools
Expand All @@ -48,7 +49,11 @@
from lsst.meas.algorithms import DatasetConfig
from lsst.meas.algorithms.loadReferenceObjects import convertToNanojansky, hasNanojanskyFluxUnits
from lsst.meas.algorithms.ingestIndexReferenceTask import addRefCatMetadata
import lsst.log


# Set up logging
logging.basicConfig(level=logging.INFO)
log = logging.getLogger("lsst.convert_refcat_to_nJy")


def is_old_schema(config, filename):
Expand All @@ -69,9 +74,8 @@ def process_one(filename, write=False, quiet=False):
quiet : `bool`, optional
Do not print messages about files read/written or fields found?
"""
log = lsst.log.Log()
if quiet:
log.setLevel(lsst.log.WARN)
logging.getLogger().setLevel(logging.WARNING)

log.info("Reading: %s", filename)
catalog = lsst.afw.table.SimpleCatalog.readFits(filename)
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/meas/algorithms/convertRefcatManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class ConvertRefcatManager:
The start and end HTM pixel ids.
addRefCatMetadata : callable
A function called to add extra metadata to each output Catalog.
log : `lsst.log.Log`
log : `lsst.log.Log` or `logging.Logger`
The log to send messages to.
"""
_flags = ['photometric', 'resolved', 'variable']
Expand Down
24 changes: 12 additions & 12 deletions python/lsst/meas/algorithms/loadReferenceObjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import abc
import itertools
import logging

import astropy.time
import astropy.units
Expand All @@ -35,7 +36,6 @@
import lsst.afw.table as afwTable
import lsst.pex.config as pexConfig
import lsst.pipe.base as pipeBase
import lsst.log
from lsst import sphgeom
from lsst.daf.base import PropertyList
from lsst.utils.timer import timeMethod
Expand Down Expand Up @@ -91,7 +91,7 @@ def convertToNanojansky(catalog, log, doConvert=True):
----------
catalog : `lsst.afw.table.SimpleCatalog`
The catalog to convert.
log : `lsst.log.Log`
log : `lsst.log.Log` or `logging.Logger`
Log to send messages to.
doConvert : `bool`, optional
Return a converted catalog, or just identify the fields that need to be converted?
Expand All @@ -110,8 +110,8 @@ def convertToNanojansky(catalog, log, doConvert=True):
"""
# Do not share the AliasMap: for refcats, that gets created when the
# catalog is read from disk and should not be propagated.
mapper = lsst.afw.table.SchemaMapper(catalog.schema, shareAliasMap=False)
mapper.addMinimalSchema(lsst.afw.table.SimpleTable.makeMinimalSchema())
mapper = afwTable.SchemaMapper(catalog.schema, shareAliasMap=False)
mapper.addMinimalSchema(afwTable.SimpleTable.makeMinimalSchema())
input_fields = []
output_fields = []
for field in catalog.schema:
Expand All @@ -124,7 +124,7 @@ def convertToNanojansky(catalog, log, doConvert=True):
name = oldName.replace('_fluxSigma', '_fluxErr')
else:
name = oldName
newField = lsst.afw.table.Field[field.dtype](name, field.field.getDoc(), units)
newField = afwTable.Field[field.dtype](name, field.field.getDoc(), units)
mapper.addMapping(field.getKey(), newField)
input_fields.append(field.field)
output_fields.append(newField)
Expand All @@ -135,7 +135,7 @@ def convertToNanojansky(catalog, log, doConvert=True):

if doConvert:
newSchema = mapper.getOutputSchema()
output = lsst.afw.table.SimpleCatalog(newSchema)
output = afwTable.SimpleCatalog(newSchema)
output.extend(catalog, mapper=mapper)
for field in output_fields:
output[field.getName()] *= 1e9
Expand Down Expand Up @@ -236,7 +236,7 @@ def applyProperMotions(self, catalog, epoch):

# Warn/raise for a catalog in an incorrect format, if epoch was specified.
if ("pm_ra" in catalog.schema
and not isinstance(catalog.schema["pm_ra"].asKey(), lsst.afw.table.KeyAngle)):
and not isinstance(catalog.schema["pm_ra"].asKey(), afwTable.KeyAngle)):
if self.config.requireProperMotion:
raise RuntimeError("requireProperMotion=True but refcat pm_ra field is not an Angle.")
else:
Expand Down Expand Up @@ -275,13 +275,13 @@ def __init__(self, dataIds, refCats, config, log=None):
Handles to load refCats on demand
config : `lsst.pex.config.configurableField`
Configuration for the loader.
log : `lsst.log.Log` or `None`, optional
Logger object used to write out messages. If `None` the default
lsst logger will be used.
log : `lsst.log.Log`, `logging.Logger` or `None`, optional
Logger object used to write out messages. If `None` a default
logger will be used.
"""
self.dataIds = dataIds
self.refCats = refCats
self.log = log or lsst.log.Log.getDefaultLogger()
self.log = log or logging.getLogger(__name__).getChild("ReferenceObjectLoader")
self.config = config

@staticmethod
Expand Down Expand Up @@ -1461,7 +1461,7 @@ def applyProperMotionsImpl(log, catalog, epoch):

Parameters
----------
log : `lsst.log.Log`
log : `lsst.log.Log` or `logging.getLogger`
Log object to write to.
catalog : `lsst.afw.table.SimpleCatalog`
Catalog of positions, containing:
Expand Down
8 changes: 5 additions & 3 deletions python/lsst/meas/algorithms/objectSizeStarSelector.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import warnings
from functools import reduce

from lsst.log import Log
from lsst.utils.logging import getLogger
from lsst.pipe.base import Struct
import lsst.geom
from lsst.afw.cameraGeom import PIXELS, TAN_PIXELS
Expand All @@ -38,6 +38,8 @@

afwDisplay.setDefaultMaskTransparency(75)

_LOG = getLogger(__name__)


class ObjectSizeStarSelectorConfig(BaseSourceSelectorTask.ConfigClass):
doFluxLimit = pexConfig.Field(
Expand Down Expand Up @@ -165,7 +167,7 @@ def _assignClusters(yvec, centers):
minDist = numpy.nan*numpy.ones_like(yvec)
clusterId = numpy.empty_like(yvec)
clusterId.dtype = int # zeros_like(..., dtype=int) isn't in numpy 1.5
dbl = Log.getLogger("objectSizeStarSelector._assignClusters")
dbl = _LOG.getChild("_assignClusters")
dbl.setLevel(dbl.INFO)

# Make sure we are logging aall numpy warnings...
Expand Down Expand Up @@ -269,7 +271,7 @@ def _improveCluster(yvec, centers, clusterId, nsigma=2.0, nIteration=10, cluster
def plot(mag, width, centers, clusterId, marker="o", markersize=2, markeredgewidth=0, ltype='-',
magType="model", clear=True):

log = Log.getLogger("objectSizeStarSelector.plot")
log = _LOG.getChild("plot")
try:
import matplotlib.pyplot as plt
except ImportError as e:
Expand Down
8 changes: 5 additions & 3 deletions python/lsst/meas/algorithms/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@

import math
import numpy
import logging

import lsst.log
import lsst.pex.exceptions as pexExcept
import lsst.daf.base as dafBase
import lsst.geom
Expand All @@ -46,6 +46,8 @@

afwDisplay.setDefaultMaskTransparency(75)

_LOG = logging.getLogger(__name__)


def splitId(oid, asDict=True):

Expand Down Expand Up @@ -382,7 +384,7 @@ def makeSubplots(fig, nx=2, ny=2, Nx=1, Ny=1, plottingArea=(0.1, 0.1, 0.85, 0.80
Colour of border around panels
"""

log = lsst.log.Log.getLogger("utils.makeSubplots")
log = _LOG.getChild("makeSubplots")
try:
import matplotlib.pyplot as plt
except ImportError as e:
Expand Down Expand Up @@ -474,7 +476,7 @@ def plotPsfSpatialModel(exposure, psf, psfCellSet, showBadCandidates=True, numSa
matchKernelAmplitudes=False, keepPlots=True):
"""Plot the PSF spatial model."""

log = lsst.log.Log.getLogger("utils.plotPsfSpatialModel")
log = _LOG.getChild("plotPsfSpatialModel")
try:
import matplotlib.pyplot as plt
import matplotlib as mpl
Expand Down
12 changes: 6 additions & 6 deletions src/CR.cc
Original file line number Diff line number Diff line change
Expand Up @@ -574,10 +574,10 @@ std::vector<std::shared_ptr<afw::detection::Footprint>> findCosmicRays(
// find the sum of pixel values within the CR
(*cr)->getSpans()->applyFunctor(CountDN, *mimage.getImage());

LOGL_DEBUG("TRACE4.algorithms.CR", "CR at (%d, %d) has %g DN", (*cr)->getBBox().getMinX(),
LOGL_DEBUG("TRACE4.lsst.algorithms.CR", "CR at (%d, %d) has %g DN", (*cr)->getBBox().getMinX(),
(*cr)->getBBox().getMinY(), CountDN.getCounts());
if (CountDN.getCounts() < minDn) { /* not bright enough */
LOGL_DEBUG("TRACE5.algorithms.CR", "Erasing CR");
LOGL_DEBUG("TRACE5.lsst.algorithms.CR", "Erasing CR");

cr = CRs.erase(cr);
--cr; // back up to previous CR (we're going to increment it)
Expand All @@ -591,7 +591,7 @@ std::vector<std::shared_ptr<afw::detection::Footprint>> findCosmicRays(
*/
bool const debias_values = true;
bool grow = false;
LOGL_DEBUG("TRACE2.algorithms.CR", "Removing initial list of CRs");
LOGL_DEBUG("TRACE2.lsst.algorithms.CR", "Removing initial list of CRs");
removeCR(mimage, CRs, bkgd, crBit, saturBit, badMask, debias_values, grow);
#if 0 // Useful to see phase 2 in display; debugging only
(void)setMaskFromFootprintList(mimage.getMask().get(), CRs,
Expand All @@ -607,7 +607,7 @@ std::vector<std::shared_ptr<afw::detection::Footprint>> findCosmicRays(
bool too_many_crs = false; // we've seen too many CR pixels
int nextra = 0; // number of pixels added to list of CRs
for (int i = 0; i != niteration && !too_many_crs; ++i) {
LOGL_DEBUG("TRACE1.algorithms.CR", "Starting iteration %d", i);
LOGL_DEBUG("TRACE1.lsst.algorithms.CR", "Starting iteration %d", i);
for (std::vector<std::shared_ptr<afw::detection::Footprint>>::iterator fiter = CRs.begin();
fiter != CRs.end(); fiter++) {
std::shared_ptr<afw::detection::Footprint> cr = *fiter;
Expand Down Expand Up @@ -709,7 +709,7 @@ std::vector<std::shared_ptr<afw::detection::Footprint>> findCosmicRays(
} else {
if (true || nextra > 0) {
grow = true;
LOGL_DEBUG("TRACE2.algorithms.CR", "Removing final list of CRs, grow = %d", grow);
LOGL_DEBUG("TRACE2.lsst.algorithms.CR", "Removing final list of CRs, grow = %d", grow);
removeCR(mimage, CRs, bkgd, crBit, saturBit, badMask, debias_values, grow);
}
/*
Expand Down Expand Up @@ -919,7 +919,7 @@ class RemoveCR {
* estimate
*/
if (ngood > 0) {
LOGL_DEBUG("TRACE3.algorithms.CR", "Adopted min==%g at (%d, %d) (ngood=%d)",
LOGL_DEBUG("TRACE3.lsst.algorithms.CR", "Adopted min==%g at (%d, %d) (ngood=%d)",
static_cast<double>(min), x, y, ngood);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/nopytest_ingestIndexReferenceCatalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def runTest(withRaDecErr):
# (otherwise it logs to `root`); only show WARN logs because each
# loadRegion (called once per source) in the check below will log
# twice to INFO.
log = lsst.log.Log.getLogger('ReferenceObjectLoader')
log = lsst.log.Log.getLogger('lsst.ReferenceObjectLoader')
log.setLevel(lsst.log.WARN)
loader = ReferenceObjectLoader([dataRef.dataId for dataRef in datasetRefs],
handlers,
Expand All @@ -130,7 +130,7 @@ def setUp(self):
np.random.seed(10)

tempPath = tempfile.mkdtemp()
self.log = lsst.log.Log.getLogger("TestIngestIndexManager")
self.log = lsst.log.Log.getLogger("lsst.TestIngestIndexManager")
self.config = ingestIndexTestBase.makeConvertConfig(withRaDecErr=True)
self.config.id_name = 'id'
self.depth = 2 # very small depth, for as few pixels as possible.
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cr.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import lsst.utils.tests

# Increase the number for more verbose messages
logUtils.traceSetAt("algorithms.CR", 3)
logUtils.traceSetAt("lsst.algorithms.CR", 3)

try:
display
Expand Down
4 changes: 2 additions & 2 deletions tests/test_htmIndex.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,10 +363,10 @@ def testRequireProperMotion(self):
config.anyFilterMapsToThis = "g" # to use a catalog not made for obs_test
loader = LoadIndexedReferenceObjectsTask(butler=self.testButler, config=config)
with unittest.mock.patch.object(self.testButler, 'get', return_value=refcatData):
with lsst.log.UsePythonLogging(), self.assertLogs(level="WARNING") as cm:
with self.assertLogs("lsst.LoadIndexedReferenceObjectsTask", level="WARNING") as cm:
loader.loadSkyCircle(center, self.searchRadius, epoch=epoch)
warnLog1 = "Reference catalog pm_ra field is not an Angle; cannot apply proper motion."
self.assertEqual(cm.output, [f"WARNING:LoadIndexedReferenceObjectsTask:{warnLog1}"])
self.assertEqual(cm.records[0].message, warnLog1)

def testLoadVersion0(self):
"""Test reading a pre-written format_version=0 (Jy flux) catalog.
Expand Down
2 changes: 1 addition & 1 deletion tests/test_measure.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import lsst.utils.tests

# Change the level to Log.DEBUG or Log.TRACE to see debug messages
Log.getLogger("measurement").setLevel(Log.INFO)
Log.getLogger("lsst.measurement").setLevel(Log.INFO)

try:
type(display)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_psfDetermination.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
afwDisplay.setDefaultMaskTransparency(75)

# Change the level to Log.DEBUG or Log.TRACE to see debug messages
Log.getLogger("measurement").setLevel(Log.INFO)
Log.getLogger("psfDeterminer").setLevel(Log.TRACE)
Log.getLogger("lsst.measurement").setLevel(Log.INFO)
Log.getLogger("lsst.psfDeterminer").setLevel(Log.TRACE)


def psfVal(ix, iy, x, y, sigma1, sigma2, b):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_psfIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
afwDisplay.setDefaultMaskTransparency(75)

# Change the level to Log.DEBUG or Log.TRACE to see debug messages
Log.getLogger("measurement").setLevel(Log.INFO)
Log.getLogger("lsst.measurement").setLevel(Log.INFO)


def roundTripPsf(key, psf):
Expand Down