コード例 #1
0
    def testNaive(self):
        positions = [
            lsst.geom.Point2D(60.0, -60.0),
            lsst.geom.Point2D(60.5, -60.0),
            lsst.geom.Point2D(60.0, -60.5),
            lsst.geom.Point2D(60.5, -60.5)
        ]
        radii = [12.0, 17.0]
        for position in positions:
            for radius in radii:
                ellipse = lsst.afw.geom.Ellipse(
                    lsst.afw.geom.ellipses.Axes(radius, radius, 0.0), position)
                area = self.computeNaiveArea(position, radius)
                # test that this isn't the same as the sinc instFlux
                self.assertFloatsNotEqual(
                    ApertureFluxAlgorithm.computeSincFlux(
                        self.exposure.getMaskedImage().getImage(), ellipse,
                        self.ctrl).instFlux, area)

                def check(method, image):
                    """Test that all instFlux measurement invocations work.

                    That is, that they return the expected value.
                    """
                    result = method(image, ellipse, self.ctrl)
                    self.assertFloatsAlmostEqual(result.instFlux, area)
                    self.assertFalse(
                        result.getFlag(
                            ApertureFluxAlgorithm.APERTURE_TRUNCATED.number))
                    self.assertFalse(
                        result.getFlag(ApertureFluxAlgorithm.
                                       SINC_COEFFS_TRUNCATED.number))
                    if hasattr(image, "getVariance"):
                        self.assertFloatsAlmostEqual(result.instFluxErr,
                                                     (area * 0.25)**0.5)
                    else:
                        self.assertTrue(np.isnan(result.instFluxErr))

                check(ApertureFluxAlgorithm.computeNaiveFlux,
                      self.exposure.getMaskedImage())
                check(ApertureFluxAlgorithm.computeNaiveFlux,
                      self.exposure.getMaskedImage().getImage())
                check(ApertureFluxAlgorithm.computeFlux,
                      self.exposure.getMaskedImage())
                check(ApertureFluxAlgorithm.computeFlux,
                      self.exposure.getMaskedImage().getImage())
        # test failure conditions when the aperture itself is truncated
        invalid = ApertureFluxAlgorithm.computeNaiveFlux(
            self.exposure.getMaskedImage().getImage(),
            lsst.afw.geom.Ellipse(lsst.afw.geom.ellipses.Axes(12.0, 12.0),
                                  lsst.geom.Point2D(25.0, -60.0)), self.ctrl)
        self.assertTrue(
            invalid.getFlag(ApertureFluxAlgorithm.APERTURE_TRUNCATED.number))
        self.assertFalse(
            invalid.getFlag(
                ApertureFluxAlgorithm.SINC_COEFFS_TRUNCATED.number))
        self.assertTrue(np.isnan(invalid.instFlux))
コード例 #2
0
ファイル: testApertureFlux.py プロジェクト: mjuric/meas_base
    def testNaive(self):
        positions = [
            lsst.afw.geom.Point2D(60.0, -60.0),
            lsst.afw.geom.Point2D(60.5, -60.0),
            lsst.afw.geom.Point2D(60.0, -60.5),
            lsst.afw.geom.Point2D(60.5, -60.5)
        ]
        radii = [12.0, 17.0]
        for position in positions:
            for radius in radii:
                ellipse = lsst.afw.geom.ellipses.Ellipse(
                    lsst.afw.geom.ellipses.Axes(radius, radius, 0.0), position)
                area = self.computeNaiveArea(position, radius)
                # test that this isn't the same as the sinc flux
                self.assertNotClose(
                    ApertureFluxAlgorithm.computeSincFlux(
                        self.exposure.getMaskedImage().getImage(), ellipse,
                        self.ctrl).flux, area)

                # test that all the ways we could invoke naive flux measurement produce the expected result
                def check(method, image):
                    result = method(image, ellipse, self.ctrl)
                    self.assertClose(result.flux, area)
                    self.assertFalse(
                        result.getFlag(
                            ApertureFluxAlgorithm.APERTURE_TRUNCATED))
                    self.assertFalse(
                        result.getFlag(
                            ApertureFluxAlgorithm.SINC_COEFFS_TRUNCATED))
                    if hasattr(image, "getVariance"):
                        self.assertClose(result.fluxSigma, (area * 0.25)**0.5)
                    else:
                        self.assertTrue(numpy.isnan(result.fluxSigma))

                check(ApertureFluxAlgorithm.computeNaiveFlux,
                      self.exposure.getMaskedImage())
                check(ApertureFluxAlgorithm.computeNaiveFlux,
                      self.exposure.getMaskedImage().getImage())
                check(ApertureFluxAlgorithm.computeFlux,
                      self.exposure.getMaskedImage())
                check(ApertureFluxAlgorithm.computeFlux,
                      self.exposure.getMaskedImage().getImage())
        # test failure conditions when the aperture itself is truncated
        invalid = ApertureFluxAlgorithm.computeNaiveFlux(
            self.exposure.getMaskedImage().getImage(),
            lsst.afw.geom.ellipses.Ellipse(
                lsst.afw.geom.ellipses.Axes(12.0, 12.0),
                lsst.afw.geom.Point2D(25.0, -60.0)), self.ctrl)
        self.assertTrue(
            invalid.getFlag(ApertureFluxAlgorithm.APERTURE_TRUNCATED))
        self.assertFalse(
            invalid.getFlag(ApertureFluxAlgorithm.SINC_COEFFS_TRUNCATED))
        self.assertTrue(numpy.isnan(invalid.flux))
コード例 #3
0
 def testSinc(self):
     positions = [lsst.afw.geom.Point2D(60.0, -60.0),
                  lsst.afw.geom.Point2D(60.5, -60.0),
                  lsst.afw.geom.Point2D(60.0, -60.5),
                  lsst.afw.geom.Point2D(60.5, -60.5)]
     radii = [7.0, 9.0]
     for position in positions:
         for radius in radii:
             ellipse = lsst.afw.geom.ellipses.Ellipse(lsst.afw.geom.ellipses.Axes(radius, radius, 0.0),
                                                      position)
             area = ellipse.getCore().getArea()
             # test that this isn't the same as the naive flux
             self.assertNotClose(
                 ApertureFluxAlgorithm.computeNaiveFlux(self.exposure.getMaskedImage().getImage(),
                                                        ellipse, self.ctrl).flux,
                 area
             )
             # test that all the ways we could invoke sinc flux measurement produce the expected result
             def check(method, image):
                 result = method(image, ellipse, self.ctrl)
                 self.assertClose(result.flux, area, rtol=1E-3)
                 self.assertFalse(result.getFlag(ApertureFluxAlgorithm.APERTURE_TRUNCATED))
                 self.assertFalse(result.getFlag(ApertureFluxAlgorithm.SINC_COEFFS_TRUNCATED))
                 if hasattr(image, "getVariance"):
                     self.assertFalse(numpy.isnan(result.fluxSigma))
                 else:
                     self.assertTrue(numpy.isnan(result.fluxSigma))
             check(ApertureFluxAlgorithm.computeSincFlux, self.exposure.getMaskedImage())
             check(ApertureFluxAlgorithm.computeSincFlux, self.exposure.getMaskedImage().getImage())
             check(ApertureFluxAlgorithm.computeFlux, self.exposure.getMaskedImage())
             check(ApertureFluxAlgorithm.computeFlux, self.exposure.getMaskedImage().getImage())
     # test failure conditions when the aperture itself is truncated
     invalid1 = ApertureFluxAlgorithm.computeSincFlux(
         self.exposure.getMaskedImage().getImage(),
         lsst.afw.geom.ellipses.Ellipse(lsst.afw.geom.ellipses.Axes(9.0, 9.0),
                                        lsst.afw.geom.Point2D(25.0, -60.0)),
         self.ctrl
         )
     self.assertTrue(invalid1.getFlag(ApertureFluxAlgorithm.APERTURE_TRUNCATED))
     self.assertTrue(invalid1.getFlag(ApertureFluxAlgorithm.SINC_COEFFS_TRUNCATED))
     self.assertTrue(numpy.isnan(invalid1.flux))
     # test failure conditions when the aperture is not truncated, but the sinc coeffs are
     invalid2 = ApertureFluxAlgorithm.computeSincFlux(
         self.exposure.getMaskedImage().getImage(),
         lsst.afw.geom.ellipses.Ellipse(lsst.afw.geom.ellipses.Axes(9.0, 9.0),
                                        lsst.afw.geom.Point2D(30.0, -60.0)),
         self.ctrl
         )
     self.assertFalse(invalid2.getFlag(ApertureFluxAlgorithm.APERTURE_TRUNCATED))
     self.assertTrue(invalid2.getFlag(ApertureFluxAlgorithm.SINC_COEFFS_TRUNCATED))
     self.assertFalse(numpy.isnan(invalid2.flux))
コード例 #4
0
    def testSinc(self):
        positions = [lsst.afw.geom.Point2D(60.0, -60.0),
                     lsst.afw.geom.Point2D(60.5, -60.0),
                     lsst.afw.geom.Point2D(60.0, -60.5),
                     lsst.afw.geom.Point2D(60.5, -60.5)]
        radii = [7.0, 9.0]
        for position in positions:
            for radius in radii:
                ellipse = lsst.afw.geom.ellipses.Ellipse(lsst.afw.geom.ellipses.Axes(radius, radius, 0.0),
                                                         position)
                area = ellipse.getCore().getArea()
                # test that this isn't the same as the naive flux
                self.assertFloatsNotEqual(
                    ApertureFluxAlgorithm.computeNaiveFlux(self.exposure.getMaskedImage().getImage(),
                                                           ellipse, self.ctrl).flux, area)

                def check(method, image):
                    # test that all the ways we could invoke sinc flux measurement produce the expected result
                    result = method(image, ellipse, self.ctrl)
                    self.assertFloatsAlmostEqual(result.flux, area, rtol=1E-3)
                    self.assertFalse(result.getFlag(ApertureFluxAlgorithm.APERTURE_TRUNCATED.number))
                    self.assertFalse(result.getFlag(ApertureFluxAlgorithm.SINC_COEFFS_TRUNCATED.number))
                    if hasattr(image, "getVariance"):
                        self.assertFalse(np.isnan(result.fluxSigma))
                    else:
                        self.assertTrue(np.isnan(result.fluxSigma))
                check(ApertureFluxAlgorithm.computeSincFlux, self.exposure.getMaskedImage())
                check(ApertureFluxAlgorithm.computeSincFlux, self.exposure.getMaskedImage().getImage())
                check(ApertureFluxAlgorithm.computeFlux, self.exposure.getMaskedImage())
                check(ApertureFluxAlgorithm.computeFlux, self.exposure.getMaskedImage().getImage())
        # test failure conditions when the aperture itself is truncated
        invalid1 = ApertureFluxAlgorithm.computeSincFlux(
            self.exposure.getMaskedImage().getImage(),
            lsst.afw.geom.ellipses.Ellipse(lsst.afw.geom.ellipses.Axes(9.0, 9.0),
                                           lsst.afw.geom.Point2D(25.0, -60.0)),
            self.ctrl)
        self.assertTrue(invalid1.getFlag(ApertureFluxAlgorithm.APERTURE_TRUNCATED.number))
        self.assertTrue(invalid1.getFlag(ApertureFluxAlgorithm.SINC_COEFFS_TRUNCATED.number))
        self.assertTrue(np.isnan(invalid1.flux))
        # test failure conditions when the aperture is not truncated, but the sinc coeffs are
        invalid2 = ApertureFluxAlgorithm.computeSincFlux(
            self.exposure.getMaskedImage().getImage(),
            lsst.afw.geom.ellipses.Ellipse(lsst.afw.geom.ellipses.Axes(9.0, 9.0),
                                           lsst.afw.geom.Point2D(30.0, -60.0)),
            self.ctrl)
        self.assertFalse(invalid2.getFlag(ApertureFluxAlgorithm.APERTURE_TRUNCATED.number))
        self.assertTrue(invalid2.getFlag(ApertureFluxAlgorithm.SINC_COEFFS_TRUNCATED.number))
        self.assertFalse(np.isnan(invalid2.flux))
コード例 #5
0
ファイル: test_ApertureFlux.py プロジェクト: lsst/meas_base
    def testNaive(self):
        positions = [lsst.geom.Point2D(60.0, -60.0),
                     lsst.geom.Point2D(60.5, -60.0),
                     lsst.geom.Point2D(60.0, -60.5),
                     lsst.geom.Point2D(60.5, -60.5)]
        radii = [12.0, 17.0]
        for position in positions:
            for radius in radii:
                ellipse = lsst.afw.geom.Ellipse(lsst.afw.geom.ellipses.Axes(radius, radius, 0.0), position)
                area = self.computeNaiveArea(position, radius)
                # test that this isn't the same as the sinc instFlux
                self.assertFloatsNotEqual(
                    ApertureFluxAlgorithm.computeSincFlux(self.exposure.getMaskedImage().getImage(),
                                                          ellipse, self.ctrl).instFlux, area)

                def check(method, image):
                    """Test that all instFlux measurement invocations work.

                    That is, that they return the expected value.
                    """
                    result = method(image, ellipse, self.ctrl)
                    self.assertFloatsAlmostEqual(result.instFlux, area)
                    self.assertFalse(result.getFlag(ApertureFluxAlgorithm.APERTURE_TRUNCATED.number))
                    self.assertFalse(result.getFlag(ApertureFluxAlgorithm.SINC_COEFFS_TRUNCATED.number))
                    if hasattr(image, "getVariance"):
                        self.assertFloatsAlmostEqual(result.instFluxErr, (area*0.25)**0.5)
                    else:
                        self.assertTrue(np.isnan(result.instFluxErr))
                check(ApertureFluxAlgorithm.computeNaiveFlux, self.exposure.getMaskedImage())
                check(ApertureFluxAlgorithm.computeNaiveFlux, self.exposure.getMaskedImage().getImage())
                check(ApertureFluxAlgorithm.computeFlux, self.exposure.getMaskedImage())
                check(ApertureFluxAlgorithm.computeFlux, self.exposure.getMaskedImage().getImage())
        # test failure conditions when the aperture itself is truncated
        invalid = ApertureFluxAlgorithm.computeNaiveFlux(
            self.exposure.getMaskedImage().getImage(),
            lsst.afw.geom.Ellipse(lsst.afw.geom.ellipses.Axes(12.0, 12.0),
                                  lsst.geom.Point2D(25.0, -60.0)),
            self.ctrl)
        self.assertTrue(invalid.getFlag(ApertureFluxAlgorithm.APERTURE_TRUNCATED.number))
        self.assertFalse(invalid.getFlag(ApertureFluxAlgorithm.SINC_COEFFS_TRUNCATED.number))
        self.assertTrue(np.isnan(invalid.instFlux))