コード例 #1
0
    def do_testAstrometry(self, control, bkgd):
        """Test that we can instantiate and play with a centroiding algorithms"""

        x0, y0 = 12345, 54321
        for imageFactory in (
                afwImage.MaskedImageF,
                afwImage.MaskedImageD,
        ):

            im = imageFactory(afwGeom.ExtentI(100, 100))
            im.setXY0(afwGeom.Point2I(x0, y0))
            psf = testLib.makeTestPsf(im)

            exp = afwImage.makeExposure(im)
            exp.setPsf(psf)
            schema = afwTable.SourceTable.makeMinimalSchema()
            centroider = algorithms.MeasureSourcesBuilder().addAlgorithm(
                control).build(schema)

            #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

            im.set(bkgd)
            x, y = 30, 20
            im.set(x, y, (1010, ))

            table = afwTable.SourceTable.make(schema)
            table.defineCentroid(control.name)
            source = table.makeRecord()
            foot = afwDetection.Footprint(exp.getBBox())
            source.setFootprint(foot)

            centroider.apply(source, exp, afwGeom.Point2D(x + x0, y + y0))

            self.assertEqual(x + x0, source.getX())
            self.assertEqual(y + y0, source.getY())
            self.assertFalse(source.get(control.name + ".flags"))

            #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

            im.set(bkgd)
            im.set(10, 20, (1010, ))
            im.set(10, 21, (1010, ))
            im.set(11, 20, (1010, ))
            im.set(11, 21, (1010, ))

            x, y = 10.5 + x0, 20.5 + y0
            centroider.apply(source, exp,
                             afwGeom.Point2D(x + 0.123, y - 0.123))

            self.assertEqual(x, source.getX())
            self.assertEqual(y, source.getY())
            self.assertFalse(source.get(control.name + ".flags"))
コード例 #2
0
ファイル: centroid.py プロジェクト: mjuric/meas_base
    def do_testAstrometry(self, alg, bkgd, control):
        """Test that we can instantiate and play with a centroiding algorithms"""

        schema = afwTable.SourceTable.makeMinimalSchema()
        schema.getAliasMap().set("slot_Centroid", "test")
        centroider = alg(control, "test", schema)
        table = afwTable.SourceCatalog(schema)

        x0, y0 = 12345, 54321
        for imageFactory in (afwImage.MaskedImageF, ):

            im = imageFactory(afwGeom.ExtentI(100, 100))
            im.setXY0(afwGeom.Point2I(x0, y0))

            #   This fixed DoubleGaussianPsf replaces a computer generated one.
            #   The values are not anything in particular, just a reasonable size.
            psf = lsst.afw.detection.GaussianPsf(15, 15, 3.0)
            exp = afwImage.makeExposure(im)
            exp.setPsf(psf)
            #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

            im.set(bkgd)
            x, y = 30, 20
            im.set(x, y, (1010, ))

            source = table.addNew()
            foot = afwDetection.Footprint(exp.getBBox(afwImage.LOCAL))
            foot.addPeak(x + x0, y + y0, 1010)
            source.setFootprint(foot)

            centroider.measure(source, exp)

            self.assertClose(x + x0, source.getX(), rtol=.00001)
            self.assertClose(y + y0, source.getY(), rtol=.00001)
            self.assertFalse(source.get("test_flag"))

            #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

            im.set(bkgd)
            im.set(10, 20, (1010, ))
            im.set(10, 21, (1010, ))
            im.set(11, 20, (1010, ))
            im.set(11, 21, (1010, ))

            x, y = 10.5 + x0, 20.5 + y0
            source = table.addNew()
            source.set('test_x', x)
            source.set('test_y', y)
            centroider.measure(source, exp)
            self.assertClose(x, source.getX(), rtol=.00001)
            self.assertClose(y, source.getY(), rtol=.00001)
            self.assertFalse(source.get("test_flag"))
コード例 #3
0
    def mySetup(self, runCentroider=True):
        msConfig = algorithms.SourceMeasurementConfig()
        if not runCentroider:
            msConfig.centroider = None
            msConfig.slots.centroid = None

        schema = afwTable.SourceTable.makeMinimalSchema()
        ms = msConfig.makeMeasureSources(schema)

        table = afwTable.SourceTable.make(schema)
        msConfig.slots.setupTable(table)
        source = table.makeRecord()

        fp = afwDetection.Footprint(self.exp.getBBox())
        source.setFootprint(fp)
        ms.apply(source, self.exp, afwGeom.Point2D(self.xcen, self.ycen))

        return source
コード例 #4
0
ファイル: centroid.py プロジェクト: mjuric/meas_base
    def mySetup(self):
        msConfig = measBase.SingleFrameMeasurementConfig()
        msConfig.algorithms.names = ["base_SdssCentroid"]
        msConfig.slots.centroid = "base_SdssCentroid"
        msConfig.slots.shape = None
        msConfig.slots.apFlux = None
        msConfig.slots.modelFlux = None
        msConfig.slots.psfFlux = None
        msConfig.slots.instFlux = None
        msConfig.slots.calibFlux = None
        schema = afwTable.SourceTable.makeMinimalSchema()
        task = measBase.SingleFrameMeasurementTask(schema, config=msConfig)
        measCat = afwTable.SourceCatalog(schema)

        source = measCat.addNew()
        fp = afwDetection.Footprint(self.exp.getBBox(afwImage.LOCAL))
        fp.addPeak(50, 50, 1000.0)
        source.setFootprint(fp)
        # Then run the default SFM task.  Results not checked
        task.run(measCat, self.exp)
        return source
コード例 #5
0
ファイル: testAlgorithms.py プロジェクト: dr-guangtou/hs_hsc
    def testAlgorithms(self):
        """Test that we can instantiate and use algorithms"""

        config = measAlg.SourceMeasurementConfig()
        config.algorithms.names = measAlg.AlgorithmRegistry.all.keys()
        config.algorithms.names.discard(config.centroider.name)
        config.doReplaceWithNoise = False

        config.algorithms.names.discard("flux.peakLikelihood")

        if False:
            log = pexLog.getDefaultLog()
            log.setThreshold(log.DEBUG)

        schema = afwTable.SourceTable.makeMinimalSchema()
        task = measAlg.SourceMeasurementTask(schema, config=config)
        catalog = afwTable.SourceCatalog(schema)
        source = catalog.addNew()
        source.set("id", 12345)

        size = 256
        xStar, yStar = 65.432, 76.543
        width = 3.21
        x0, y0 = 12345, 54321
        x, y = numpy.indices((size, size))
        im = afwImage.MaskedImageF(afwGeom.ExtentI(size, size))
        im.setXY0(afwGeom.Point2I(x0, y0))
        im.getVariance().set(1.0)
        arr = im.getImage().getArray()
        arr[y,
            x] = numpy.exp(-0.5 * ((x - xStar)**2 + (y - yStar)**2) / width**2)
        psf = testLib.makeTestPsf(im)
        exp = afwImage.makeExposure(im)
        exp.setPsf(psf)
        exp.setXY0(afwGeom.Point2I(x0, y0))
        scale = 1.0e-5
        wcs = afwImage.makeWcs(
            afwCoord.Coord(0.0 * afwGeom.degrees, 0.0 * afwGeom.degrees),
            afwGeom.Point2D(0.0, 0.0), scale, 0.0, 0.0, scale)
        exp.setWcs(wcs)

        point = afwGeom.Point2I(int(xStar + x0), int(yStar + y0))
        bbox = im.getBBox()
        bbox.shift(afwGeom.Extent2I(x0, y0))
        foot = afwDetection.Footprint(point, width, bbox)
        foot.addPeak(point.getX(), point.getY(), 1.0)
        afwDetection.setMaskFromFootprint(exp.getMaskedImage().getMask(), foot,
                                          1)
        source.setFootprint(foot)

        if display:
            ds9.mtv(exp, frame=1)

        task.run(exp, catalog)

        for alg in config.algorithms:
            flagName = alg + ".flags"
            if False:
                print(alg,
                      source.get(flagName) if flagName in schema else None,
                      source.get(alg) if alg in schema else None)
            elif flagName in schema:
                self.assertFalse(source.get(alg + ".flags"))