def testBasic(self): """ Test basic log output with default configuration. Since the default threshold is INFO, the DEBUG or TRACE message is not emitted. """ with TestLog.StdoutCapture(self.outputFilename): log.configure() log.log(log.getDefaultLogger(), log.INFO, "This is INFO") log.info(u"This is unicode INFO") log.trace("This is TRACE") log.debug("This is DEBUG") log.warn("This is WARN") log.error("This is ERROR") log.fatal("This is FATAL") log.critical("This is CRITICAL") log.warning("Format %d %g %s", 3, 2.71828, "foo") self.check(""" root INFO: This is INFO root INFO: This is unicode INFO root WARN: This is WARN root ERROR: This is ERROR root FATAL: This is FATAL root FATAL: This is CRITICAL root WARN: Format 3 2.71828 foo """)
def getCcdImage(self, ccd, imageFactory=afwImage.ImageF, binSize=1, asMaskedImage=False): """Return an image of the specified ccd, and also the (possibly updated) ccd""" log = _LOG.getChild("ButlerImage") if self.isTrimmed: bbox = ccd.getBBox() else: bbox = calcRawCcdBBox(ccd) im = None if self.butler is not None: err = None for dataId in [dict(detector=ccd.getId()), dict(ccd=ccd.getId()), dict(ccd=ccd.getName())]: try: im = self.butler.get(self.type, dataId, **self.kwargs) except FitsError as e: # no point trying another dataId err = IOError(e.args[0].split('\n')[0]) # It's a very chatty error break except Exception as e: # try a different dataId if err is None: err = e continue else: ccd = im.getDetector() # possibly modified by assembleCcdTask break if im: if asMaskedImage: im = im.getMaskedImage() else: im = im.getMaskedImage().getImage() else: if self.verbose: # Lost by jupyterlab. print(f"Reading {ccd.getId()}: {err}") log.warning("Reading %s: %s", ccd.getId(), err) if im is None: return self._prepareImage(ccd, imageFactory(*bbox.getDimensions()), binSize), ccd if self.type == "raw": if hasattr(im, 'convertF'): im = im.convertF() if False and self.callback is None: # we need to trim the raw image self.callback = rawCallback allowRotate = True if self.callback: try: im = self.callback(im, ccd, imageSource=self) except Exception as e: if self.verbose: log.error("callback failed: %s", e) im = imageFactory(*bbox.getDimensions()) else: allowRotate = False # the callback was responsible for any rotations return self._prepareImage(ccd, im, binSize, allowRotate=allowRotate), ccd
def run(self, parsedCmd): """Run the task on all targets. Parameters ---------- parsedCmd : `argparse.Namespace` Parsed command `argparse.Namespace`. Returns ------- resultList : `list` A list of results returned by `TaskRunner.__call__`, or an empty list if `TaskRunner.__call__` is not called (e.g. if `TaskRunner.precall` returns `False`). See `TaskRunner.__call__` for details. Notes ----- The task is run under multiprocessing if `TaskRunner.numProcesses` is more than 1; otherwise processing is serial. """ resultList = [] disableImplicitThreading() # To prevent thread contention if self.numProcesses > 1: import multiprocessing self.prepareForMultiProcessing() pool = multiprocessing.Pool(processes=self.numProcesses, maxtasksperchild=1) mapFunc = functools.partial(_runPool, pool, self.timeout) else: pool = None mapFunc = map if self.precall(parsedCmd): profileName = parsedCmd.profile if hasattr(parsedCmd, "profile") else None log = parsedCmd.log targetList = self.getTargetList(parsedCmd) if len(targetList) > 0: with profile(profileName, log): # Run the task using self.__call__ resultList = list(mapFunc(self, targetList)) else: log.warning( "Not running the task because there is no data to process; " 'you may preview data using "--show data"') if pool is not None: pool.close() pool.join() return resultList
def runCrosstalkAlone(self): """Utility for crosstalk correction directly on a DECam MEF file. """ log = lsst.log.Log.getLogger('obs.decam.DecamCrosstalkIO') parsed = self.parseCrosstalkIOArgs() filename = parsed['filename'] outfile = parsed['outfile'] mef = fits.open(filename) sources, coeffs = self.config.getSourcesAndCoeffs() corrected = subtractCrosstalkIO(mef, sources, coeffs) if outfile: corrected.writeto(outfile, overwrite=True) else: log.warning( 'No outfile specified, not writing corrected image to disk')
def makeWcs(self, visitInfo, detector): """Create a SkyWcs from information about the exposure. Overide the default which uses visit info Return the metadata-based SkyWcs (always created, so that the relevant metadata keywords are stripped). Is geometry based WCS superior? Parameters ---------- visitInfo : `~lsst.afw.image.VisitInfo` The information about the telescope boresight and camera orientation angle for this exposure. detector : `~lsst.afw.cameraGeom.Detector` The detector used to acquire this exposure. Returns ------- skyWcs : `~lsst.afw.geom.SkyWcs` Reversible mapping from pixel coordinates to sky coordinates. Raises ------ InitialSkyWcsError Raised if there is an error generating the SkyWcs, chained from the lower-level exception if available. """ #Setting this to True improves the WCS but is very slow due to downloading objs useMetadataWcs=False if not self.isOnSky(): # This is not an on-sky observation return None skyWcs = self._createSkyWcsFromMetadata() if useMetadataWcs: msg = "VIRCAM camera geom not used. Defaulting to metadata-based SkyWcs." log.warning(msg) if skyWcs is None: raise InitialSkyWcsError("Failed to create both metadata and boresight-based SkyWcs." "See warnings in log messages for details.") return skyWcs else: return self.makeRawSkyWcsFromBoresight(visitInfo.getBoresightRaDec(), visitInfo.getBoresightRotAngle(), detector)
def testForwardToPythonContextManager(self): """Test that `lsst.log` log messages can be forwarded to `logging` using context manager""" log.configure() # Without forwarding we only get python logger messages captured with self.assertLogs(level="WARNING") as cm: log.warning("lsst.log: not forwarded") logging.warning("Python logging: captured") self.assertEqual(len(cm.output), 1) # Temporarily turn on forwarding with log.UsePythonLogging(): with self.assertLogs(level="WARNING") as cm: log.warn("lsst.log: forwarded") logging.warning("Python logging: also captured") self.assertEqual(len(cm.output), 2) # Verify that forwarding is disabled self.assertFalse(log.Log.UsePythonLogging)
def testBasic(self): """ Test basic log output with default configuration. Since the default threshold is INFO, the DEBUG or TRACE message is not emitted. """ with TestLog.StdoutCapture(self.outputFilename): log.configure() log.log(log.getDefaultLogger(), log.INFO, "This is INFO") log.info(u"This is unicode INFO") log.trace("This is TRACE") log.debug("This is DEBUG") log.warn("This is WARN") log.error("This is ERROR") log.fatal("This is FATAL") log.warning("Format %d %g %s", 3, 2.71828, "foo") self.check(""" root INFO: This is INFO root INFO: This is unicode INFO root WARN: This is WARN root ERROR: This is ERROR root FATAL: This is FATAL root WARN: Format 3 2.71828 foo """)