Beispiel #1
0
    def testLinearRamp(self):
        """Fit a ramp"""

        binsize = 1
        ramp, rampCoeffs, xVec, yVec = self.makeRamp(binsize)
        # Add a (labelled) bad value
        ramp.set(ramp.getWidth()//2, ramp.getHeight()//2, (0, 0x1, np.nan))

        if display:
            ds9.mtv(ramp, title="Input", frame=0)
        # Here's the range that the approximation should be valid (and also the
        # bbox of the image returned by getImage)
        bbox = afwGeom.BoxI(afwGeom.PointI(0, 0),
                            afwGeom.PointI(binsize*ramp.getWidth() - 1,
                                           binsize*ramp.getHeight() - 1))

        order = 3                       # 1 would be enough to fit the ramp
        actrl = afwMath.ApproximateControl(
            afwMath.ApproximateControl.CHEBYSHEV, order)
        approx = afwMath.makeApproximate(xVec, yVec, ramp, bbox, actrl)

        for i, aim in enumerate([approx.getImage(),
                                 approx.getMaskedImage().getImage(),
                                 ]):
            if i == 0 and display:
                ds9.mtv(aim, title="interpolated", frame=1)
                with ds9.Buffering():
                    for x in xVec:
                        for y in yVec:
                            ds9.dot('+', x, y, size=0.4, frame=1)

            for x, y in aim.getBBox().getCorners():
                self.assertEqual(
                    aim.get(x, y), rampCoeffs[0] + rampCoeffs[1]*x + rampCoeffs[1]*y)
Beispiel #2
0
    def testLinearRamp(self):
        """Fit a ramp"""

        binsize = 1
        ramp, rampCoeffs, xVec, yVec = self.makeRamp(binsize)
        #
        # Add a (labelled) bad value
        #
        ramp.set(ramp.getWidth() // 2, ramp.getHeight() // 2, (0, 0x1, np.nan))

        if display:
            ds9.mtv(ramp, title="Input", frame=0)
        #
        # Here's the range that the approximation should be valid (and also the
        # bbox of the image returned by getImage)
        #
        bbox = afwGeom.BoxI(
            afwGeom.PointI(0, 0), afwGeom.PointI(binsize * ramp.getWidth() - 1, binsize * ramp.getHeight() - 1)
        )

        order = 3  # 1 would be enough to fit the ramp
        actrl = afwMath.ApproximateControl(afwMath.ApproximateControl.CHEBYSHEV, order)
        approx = afwMath.makeApproximate(xVec, yVec, ramp, bbox, actrl)

        for i, aim in enumerate([approx.getImage(), approx.getMaskedImage().getImage()]):
            if i == 0 and display:
                ds9.mtv(aim, title="interpolated", frame=1)
                with ds9.Buffering():
                    for x in xVec:
                        for y in yVec:
                            ds9.dot("+", x, y, size=0.4, frame=1)

            for x, y in aim.getBBox().getCorners():
                self.assertEqual(aim.get(x, y), rampCoeffs[0] + rampCoeffs[1] * x + rampCoeffs[1] * y)
    def testLinearRamp(self):
        """Fit a ramp"""

        binsize = 1
        ramp, rampCoeffs, xVec, yVec = self.makeRamp(binsize)
        # Add a (labelled) bad value
        ramp[ramp.getWidth()//2, ramp.getHeight()//2, afwImage.LOCAL] = (0, 0x1, np.nan)

        if display:
            afwDisplay.Display(frame=0).mtv(ramp, title=self._testMethodName + ": Input")
        # Here's the range that the approximation should be valid (and also the
        # bbox of the image returned by getImage)
        bbox = lsst.geom.BoxI(lsst.geom.PointI(0, 0),
                              lsst.geom.PointI(binsize*ramp.getWidth() - 1,
                                               binsize*ramp.getHeight() - 1))

        order = 3                       # 1 would be enough to fit the ramp
        actrl = afwMath.ApproximateControl(
            afwMath.ApproximateControl.CHEBYSHEV, order)
        approx = afwMath.makeApproximate(xVec, yVec, ramp, bbox, actrl)

        for i, aim in enumerate([approx.getImage(),
                                 approx.getMaskedImage().getImage(),
                                 ]):
            if i == 0 and display:
                disp = afwDisplay.Display(frame=1)
                disp.mtv(aim, title=self._testMethodName + ": Interpolated")
                with disp.Buffering():
                    for x in xVec:
                        for y in yVec:
                            disp.dot('+', x, y, size=0.4)

            for x, y in aim.getBBox().getCorners():
                self.assertEqual(
                    aim[x, y, afwImage.LOCAL], rampCoeffs[0] + rampCoeffs[1]*x + rampCoeffs[1]*y)
Beispiel #4
0
 def testNoFinitePoints(self):
     """Check that makeApproximate throws a RuntimeError if grid has no finite points and weights to fit
     """
     binsize = 1
     for badValue in [(3, 0x1, 0), (np.nan, 0x1, 1)]:
         ramp, rampCoeffs, xVec, yVec = self.makeRamp(binsize)
         ramp.set(badValue)
         bbox = afwGeom.BoxI(afwGeom.PointI(0, 0), afwGeom.PointI(binsize*ramp.getWidth()  - 1,
                                                                  binsize*ramp.getHeight() - 1))
         order = 2
         actrl = afwMath.ApproximateControl(afwMath.ApproximateControl.CHEBYSHEV, order)
         self.assertRaises(pexExcept.RuntimeError,
                           lambda : afwMath.makeApproximate(xVec, yVec, ramp, bbox, actrl))
Beispiel #5
0
 def testNoFinitePoints(self):
     """Check that makeApproximate throws a RuntimeError if grid has no finite points and weights to fit
     """
     binsize = 1
     for badValue in [(3, 0x1, 0), (np.nan, 0x1, 1)]:
         ramp, rampCoeffs, xVec, yVec = self.makeRamp(binsize)
         ramp.set(badValue)
         bbox = afwGeom.BoxI(afwGeom.PointI(0, 0), afwGeom.PointI(binsize*ramp.getWidth() - 1,
                                                                  binsize*ramp.getHeight() - 1))
         order = 2
         actrl = afwMath.ApproximateControl(
             afwMath.ApproximateControl.CHEBYSHEV, order)
         self.assertRaises(pexExcept.RuntimeError,
                           lambda: afwMath.makeApproximate(xVec, yVec, ramp, bbox, actrl))