Esempio n. 1
0
    def testBasicFormat(self):
        """
        Test basic log output with default configuration but using
        the f variants.
        Since the default threshold is INFO, the DEBUG or TRACE
        message is not emitted.
        """
        with TestLog.StdoutCapture(self.outputFilename):
            log.configure()
            log.logf(log.getDefaultLoggerName(),
                     log.INFO,
                     "This is {{INFO}} Item 1: {item[1]}",
                     item=["a", "b", "c"])
            log.infof(u"This is {unicode} INFO")
            log.tracef("This is TRACE")
            log.debugf("This is DEBUG")
            log.warnf("This is WARN {city}", city="Tucson")
            log.errorf("This is ERROR {1}->{0}", 2, 1)
            log.fatalf("This is FATAL {1} out of {0} times for {place}",
                       4,
                       3,
                       place="LSST")
            log.warnf("Format {} {} {}", 3, 2.71828, "foo")
        self.check("""
root INFO: This is {INFO} Item 1: b
root INFO: This is {unicode} INFO
root WARN: This is WARN Tucson
root ERROR: This is ERROR 1->2
root FATAL: This is FATAL 3 out of 4 times for LSST
root WARN: Format 3 2.71828 foo
""")
Esempio n. 2
0
File: test_log.py Progetto: lsst/log
    def testBasicFormat(self):
        """
        Test basic log output with default configuration but using
        the f variants.
        Since the default threshold is INFO, the DEBUG or TRACE
        message is not emitted.
        """
        with TestLog.StdoutCapture(self.outputFilename):
            log.configure()
            log.logf(log.getDefaultLogger(), log.INFO,
                     "This is {{INFO}} Item 1: {item[1]}",
                     item=["a", "b", "c"])
            log.infof(u"This is {unicode} INFO")
            log.tracef("This is TRACE")
            log.debugf("This is DEBUG")
            log.warnf("This is WARN {city}", city="Tucson")
            log.errorf("This is ERROR {1}->{0}", 2, 1)
            log.fatalf("This is FATAL {1} out of {0} times for {place}",
                       4, 3, place="LSST")
            log.warnf("Format {} {} {}", 3, 2.71828, "foo")
        self.check("""
root INFO: This is {INFO} Item 1: b
root INFO: This is {unicode} INFO
root WARN: This is WARN Tucson
root ERROR: This is ERROR 1->2
root FATAL: This is FATAL 3 out of 4 times for LSST
root WARN: Format 3 2.71828 foo
""")
Esempio n. 3
0
    def makeDataRefList(self, namespace):
        """Make self.refList from self.idList
        """
        if self.datasetType is None:
            raise RuntimeError("Must call setDatasetType first")
        skymap = None
        log = lsst.log.Log.getLogger("jointcal.dataIds")
        visitTract = {}  # Set of tracts for each visit
        visitRefs = {}  # List of data references for each visit
        for dataId in self.idList:
            if "tract" not in dataId:
                # Discover which tracts the data overlaps
                log.infof("Reading WCS to determine tracts for components of dataId={}", dict(dataId))
                if skymap is None:
                    skymap = self.getSkymap(namespace)

                for ref in namespace.butler.subset("calexp", dataId=dataId):
                    if not ref.datasetExists("calexp"):
                        log.warnf("calexp with dataId: {} not found.", dict(dataId))
                        continue

                    # XXX fancier mechanism to select an individual exposure than just pulling out "visit"?
                    if "visit" in ref.dataId.keys():
                        visit = ref.dataId["visit"]
                    else:
                        # Fallback if visit is not in the dataId
                        visit = namespace.butler.queryMetadata("calexp", ("visit"), ref.dataId)[0]
                    if visit not in visitRefs:
                        visitRefs[visit] = list()
                    visitRefs[visit].append(ref)

                    wcs = ref.get("calexp_wcs", immediate=True)
                    box = lsst.afw.geom.Box2D(ref.get("calexp_bbox"))
                    # Going with just the nearest tract.  Since we're throwing all tracts for the visit
                    # together, this shouldn't be a problem unless the tracts are much smaller than a CCD.
                    tract = skymap.findTract(wcs.pixelToSky(box.getCenter()))
                    if lsst.meas.base.imageOverlapsTract(tract, wcs, box):
                        if visit not in visitTract:
                            visitTract[visit] = set()
                        visitTract[visit].add(tract.getId())
            else:
                tract = dataId.pop("tract")
                # making a DataRef for src fills out any missing keys and allows us to iterate
                for ref in namespace.butler.subset("src", dataId=dataId):
                    if ref.datasetExists():
                        self._addDataRef(namespace, ref.dataId, tract)

        # Ensure all components of a visit are kept together by putting them all in the same set of tracts
        # NOTE: sorted() here is to keep py2 and py3 dataRefs in the same order.
        # NOTE: see DM-9393 for details.
        for visit, tractSet in sorted(visitTract.items()):
            for ref in visitRefs[visit]:
                for tract in sorted(tractSet):
                    self._addDataRef(namespace, ref.dataId, tract)
        if visitTract:
            tractCounter = collections.Counter()
            for tractSet in visitTract.values():
                tractCounter.update(tractSet)
            log.infof("Number of visits per tract: {}", dict(tractCounter))
Esempio n. 4
0
    def makeDataRefList(self, namespace):
        """Make self.refList from self.idList
        """
        if self.datasetType is None:
            raise RuntimeError("Must call setDatasetType first")
        skymap = None
        log = lsst.log.Log.getLogger("jointcal.dataIds")
        visitTract = {}  # Set of tracts for each visit
        visitRefs = {}  # List of data references for each visit
        for dataId in self.idList:
            if "tract" not in dataId:
                # Discover which tracts the data overlaps
                log.infof("Reading WCS to determine tracts for components of dataId={}", dict(dataId))
                if skymap is None:
                    skymap = self.getSkymap(namespace)

                for ref in namespace.butler.subset("calexp", dataId=dataId):
                    if not ref.datasetExists("calexp"):
                        log.warnf("calexp with dataId: {} not found.", dict(dataId))
                        continue

                    # XXX fancier mechanism to select an individual exposure than just pulling out "visit"?
                    if "visit" in ref.dataId.keys():
                        visit = ref.dataId["visit"]
                    else:
                        # Fallback if visit is not in the dataId
                        visit = namespace.butler.queryMetadata("calexp", ("visit"), ref.dataId)[0]
                    if visit not in visitRefs:
                        visitRefs[visit] = list()
                    visitRefs[visit].append(ref)

                    wcs = ref.get("calexp_wcs", immediate=True)
                    box = lsst.afw.geom.Box2D(ref.get("calexp_bbox"))
                    # Going with just the nearest tract.  Since we're throwing all tracts for the visit
                    # together, this shouldn't be a problem unless the tracts are much smaller than a CCD.
                    tract = skymap.findTract(wcs.pixelToSky(box.getCenter()))
                    if lsst.meas.base.imageOverlapsTract(tract, wcs, box):
                        if visit not in visitTract:
                            visitTract[visit] = set()
                        visitTract[visit].add(tract.getId())
            else:
                tract = dataId.pop("tract")
                # making a DataRef for src fills out any missing keys and allows us to iterate
                for ref in namespace.butler.subset("src", dataId=dataId):
                    if ref.datasetExists():
                        self._addDataRef(namespace, ref.dataId, tract)

        # Ensure all components of a visit are kept together by putting them all in the same set of tracts
        # NOTE: sorted() here is to keep py2 and py3 dataRefs in the same order.
        # NOTE: see DM-9393 for details.
        for visit, tractSet in sorted(visitTract.items()):
            for ref in visitRefs[visit]:
                for tract in sorted(tractSet):
                    self._addDataRef(namespace, ref.dataId, tract)
        if visitTract:
            tractCounter = collections.Counter()
            for tractSet in visitTract.values():
                tractCounter.update(tractSet)
            log.infof("Number of visits per tract: {}", dict(tractCounter))