Exemplo n.º 1
0
 def testReadLsstSkyWcsStripMetadata(self):
     metadata = self.makeMetadata()
     self.assertEqual(len(metadata.toList()), 32)
     readLsstSkyWcs(metadata, strip=False)
     self.assertEqual(len(metadata.toList()), 32)
     readLsstSkyWcs(metadata, strip=True)
     self.assertEqual(len(metadata.toList()), 18)
Exemplo n.º 2
0
    def testReadLsstSkyWcsNormalizeFk5(self):
        """Test that readLsstSkyWcs correctly normalizes FK5 1975 to ICRS
        """
        equinox = 1975
        metadata = self.makeMetadata()
        metadata.set("RADESYS", "FK5")
        metadata.set("EQUINOX", equinox)
        crpix = self.getCrpix(metadata)
        # record the original CRVAL before reading and stripping metadata
        crvalFk5Deg = (metadata.get("CRVAL1"), metadata.get("CRVAL2"))

        # read frameSet and compute crval
        frameSet = readLsstSkyWcs(metadata, strip=True)
        crvalRadians = frameSet.applyForward(crpix)
        crvalPoint = SpherePoint(*[crvalRadians[i]*radians for i in range(2)])

        # compare crval to the value recorded as the skyRef property of the current frame
        skyFrame = frameSet.getFrame(ast.FrameSet.CURRENT)
        recordedCrvalRadians = skyFrame.getSkyRef()
        recordedCrvalPoint = SpherePoint(*[recordedCrvalRadians[i]*radians for i in range(2)])
        self.assertSpherePointsAlmostEqual(crvalPoint, recordedCrvalPoint)

        # get predicted crval by converting with astropy
        crvalFk5 = SkyCoord(crvalFk5Deg[0], crvalFk5Deg[1], frame="fk5",
                            equinox="J%f" % (equinox,), unit="deg")
        predictedCrvalIcrs = crvalFk5.icrs
        predictedCrvalPoint = SpherePoint(predictedCrvalIcrs.ra.radian*radians,
                                          predictedCrvalIcrs.dec.radian*radians)
        # AST and astropy disagree by 0.025 arcsec; it's not worth worrying about because
        # we will always use ICRS internally and almost always fit our own WCS.
        self.assertSpherePointsAlmostEqual(crvalPoint, predictedCrvalPoint, maxSep=0.05*arcseconds)
Exemplo n.º 3
0
    def testReadLsstSkyWcsNormalizeFk5(self):
        """Test that readLsstSkyWcs correctly normalizes FK5 1975 to ICRS
        """
        equinox = 1975
        metadata = self.makeMetadata()
        metadata.set("RADESYS", "FK5")
        metadata.set("EQUINOX", equinox)
        crpix = self.getCrpix(metadata)
        # record the original CRVAL before reading and stripping metadata
        crvalFk5Deg = (metadata.getScalar("CRVAL1"), metadata.getScalar("CRVAL2"))

        # read frameSet and compute crval
        frameSet = readLsstSkyWcs(metadata, strip=True)
        crvalRadians = frameSet.applyForward(crpix)
        crvalPoint = SpherePoint(*[crvalRadians[i]*radians for i in range(2)])

        # compare crval to the value recorded as the skyRef property of the current frame
        skyFrame = frameSet.getFrame(ast.FrameSet.CURRENT)
        recordedCrvalRadians = skyFrame.getSkyRef()
        recordedCrvalPoint = SpherePoint(*[recordedCrvalRadians[i]*radians for i in range(2)])
        self.assertSpherePointsAlmostEqual(crvalPoint, recordedCrvalPoint)

        # get predicted crval by converting with astropy
        crvalFk5 = SkyCoord(crvalFk5Deg[0], crvalFk5Deg[1], frame="fk5",
                            equinox="J%f" % (equinox,), unit="deg")
        predictedCrvalIcrs = crvalFk5.icrs
        predictedCrvalPoint = SpherePoint(predictedCrvalIcrs.ra.radian*radians,
                                          predictedCrvalIcrs.dec.radian*radians)
        # AST and astropy disagree by 0.025 arcsec; it's not worth worrying about because
        # we will always use ICRS internally and almost always fit our own WCS.
        self.assertSpherePointsAlmostEqual(crvalPoint, predictedCrvalPoint, maxSep=0.05*arcseconds)
Exemplo n.º 4
0
    def testReadLsstSkyWcsStripMetadata(self):
        metadata = self.makeMetadata()
        nKeys = len(metadata.toList())
        nToStrip = 12 + 6  # WCS "A" is also stripped
        frameSet1 = readLsstSkyWcs(metadata, strip=False)
        self.assertEqual(len(metadata.toList()), nKeys)

        crval = SpherePoint(metadata.get("CRVAL1")*degrees, metadata.get("CRVAL2")*degrees)
        crvalRad = crval.getPosition(radians)
        desiredCrpix = self.getCrpix(metadata)
        computedCrpix = frameSet1.applyInverse(crvalRad)
        self.assertPairsAlmostEqual(desiredCrpix, computedCrpix)

        # read again, this time stripping metadata
        frameSet2 = readLsstSkyWcs(metadata, strip=True)
        self.assertEqual(len(metadata.toList()), nKeys - nToStrip)
        self.assertEqual(frameSet1, frameSet2)

        # having stripped the WCS keywords, we should not be able to generate
        # a WCS from what's left
        with self.assertRaises(lsst.pex.exceptions.TypeError):
            readLsstSkyWcs(metadata, strip=False)

        # try a full WCS with just CRPIX1 or 2 missing
        for i in (1, 2):
            metadata = self.makeMetadata()
            metadata.remove("CRPIX%d" % (i,))
            with self.assertRaises(lsst.pex.exceptions.TypeError):
                readLsstSkyWcs(metadata, strip=False)
Exemplo n.º 5
0
    def testReadLsstSkyWcsStripMetadata(self):
        metadata = self.makeMetadata()
        nKeys = len(metadata.toList())
        nToStrip = 12 + 6  # WCS "A" is also stripped
        frameSet1 = readLsstSkyWcs(metadata, strip=False)
        self.assertEqual(len(metadata.toList()), nKeys)

        crval = SpherePoint(metadata.getScalar("CRVAL1"), metadata.getScalar("CRVAL2"), degrees)
        crvalRad = crval.getPosition(radians)
        desiredCrpix = self.getCrpix(metadata)
        computedCrpix = frameSet1.applyInverse(crvalRad)
        self.assertPairsAlmostEqual(desiredCrpix, computedCrpix)

        # read again, this time stripping metadata
        frameSet2 = readLsstSkyWcs(metadata, strip=True)
        self.assertEqual(len(metadata.toList()), nKeys - nToStrip)
        self.assertEqual(frameSet1, frameSet2)

        # having stripped the WCS keywords, we should not be able to generate
        # a WCS from what's left
        with self.assertRaises(lsst.pex.exceptions.TypeError):
            readLsstSkyWcs(metadata, strip=False)

        # try a full WCS with just CRPIX1 or 2 missing
        for i in (1, 2):
            metadata = self.makeMetadata()
            metadata.remove("CRPIX%d" % (i,))
            with self.assertRaises(lsst.pex.exceptions.TypeError):
                readLsstSkyWcs(metadata, strip=False)
Exemplo n.º 6
0
    def testReadLsstSkyWcsNormalizeRaDec(self):
        """Test that a Dec, RA WCS frame set is normalized to RA, Dec
        """
        metadata = self.makeMetadata()

        crpix = self.getCrpix(metadata)

        # swap RA, Decaxes in metadata
        crvalIn = SpherePoint(metadata.get("CRVAL1")*degrees, metadata.get("CRVAL2")*degrees)
        metadata.set("CRVAL1", crvalIn[1].asDegrees())
        metadata.set("CRVAL2", crvalIn[0].asDegrees())
        metadata.set("CTYPE1", "DEC--TAN")
        metadata.set("CTYPE2", "RA---TAN")

        # create the wcs
        frameSet = readLsstSkyWcs(metadata)

        # compute pixel origin and compare to input crval
        computedCrvalRadians = frameSet.applyForward(crpix)
        computedCrval = SpherePoint(*[computedCrvalRadians[i]*radians for i in range(2)])
        self.assertSpherePointsAlmostEqual(crvalIn, computedCrval)
Exemplo n.º 7
0
    def testReadLsstSkyWcsNormalizeRaDec(self):
        """Test that a Dec, RA WCS frame set is normalized to RA, Dec
        """
        metadata = self.makeMetadata()

        crpix = self.getCrpix(metadata)

        # swap RA, Decaxes in metadata
        crvalIn = SpherePoint(metadata.getScalar("CRVAL1"), metadata.getScalar("CRVAL2"), degrees)
        metadata.set("CRVAL1", crvalIn[1].asDegrees())
        metadata.set("CRVAL2", crvalIn[0].asDegrees())
        metadata.set("CTYPE1", "DEC--TAN")
        metadata.set("CTYPE2", "RA---TAN")

        # create the wcs
        frameSet = readLsstSkyWcs(metadata)

        # compute pixel origin and compare to input crval
        computedCrvalRadians = frameSet.applyForward(crpix)
        computedCrval = SpherePoint(*[computedCrvalRadians[i]*radians for i in range(2)])
        self.assertSpherePointsAlmostEqual(crvalIn, computedCrval)