示例#1
0
    def testTractSeparation(self):
        """Confirm that each sky tract has the proper distance to other tracts
        """
        for numTracts in (2, 4, 25):
            for minDec in (-45, -2.5, 32):
                for deltaDec in (2, 17):
                    maxDec = minDec + deltaDec
                    config = EquatSkyMap.ConfigClass()
                    config.numTracts = numTracts
                    config.decRange = (minDec, maxDec)
                    skyMap = EquatSkyMap(config)
                    predDeltaRa = 360.0 / numTracts

                    for tractId, tractInfo in enumerate(skyMap):
                        self.assertEqual(tractInfo.getId(), tractId)

                        prevTract, nextTract = self.getNeighborTracts(
                            skyMap, tractId)

                        deltaRa = tractInfo.getCtrCoord().getRa(
                        ) - prevTract.getCtrCoord().getRa()
                        deltaRa = deltaRa.asDegrees()
                        raError = abs(deltaRa - predDeltaRa) % 180.0
                        self.assertAlmostEquals(raError, 0.0)

                        deltaRa = nextTract.getCtrCoord().getRa(
                        ) - tractInfo.getCtrCoord().getRa()
                        deltaRa = deltaRa.asDegrees()
                        raError = abs(deltaRa - predDeltaRa) % 180.0
                        self.assertAlmostEquals(raError, 0.0)
示例#2
0
    def testSymmetry(self):
        """Verify that the projection is symmetrical about the equator
        """
        for minDec in (-5.0, -1.0, 0.5):
            maxDec = minDec + 2.0
            config = EquatSkyMap.ConfigClass()
            config.decRange = minDec, maxDec
            skyMap = EquatSkyMap(config)
            for tractInfo in skyMap[0:1]:
                numPatches = tractInfo.getNumPatches()
                midXIndex = numPatches[0]//2
                minPixelPosList = []
                maxPixelPosList = []
                maxYInd = numPatches[1] - 1
                for xInd in (0, midXIndex, numPatches[0] - 1):
                    minDecPatchInfo = tractInfo.getPatchInfo((xInd, 0))
                    minDecPosBox = geom.Box2D(minDecPatchInfo.getOuterBBox())
                    minPixelPosList += [
                        minDecPosBox.getMin(),
                        geom.Point2D(minDecPosBox.getMaxX(), minDecPosBox.getMinY()),
                    ]

                    maxDecPatchInfo = tractInfo.getPatchInfo((xInd, maxYInd))
                    maxDecPosBox = geom.Box2D(maxDecPatchInfo.getOuterBBox())
                    maxPixelPosList += [
                        maxDecPosBox.getMax(),
                        geom.Point2D(maxDecPosBox.getMinX(), maxDecPosBox.getMaxY()),
                    ]
                wcs = tractInfo.getWcs()
                minDecList = [wcs.pixelToSky(pos).getPosition(geom.degrees)[1] for pos in minPixelPosList]
                maxDecList = [wcs.pixelToSky(pos).getPosition(geom.degrees)[1] for pos in maxPixelPosList]
                self.assertTrue(numpy.allclose(minDecList, minDecList[0]))
                self.assertTrue(numpy.allclose(maxDecList, maxDecList[0]))
                self.assertTrue(minDecList[0] <= minDec)
                self.assertTrue(maxDecList[0] >= maxDec)
    def testFindTract(self):
        """Test the SkyMap.findTract method
        """
        for numTracts in (2, 4):
            config = EquatSkyMap.ConfigClass()
            config.numTracts = numTracts
            skyMap = EquatSkyMap(config)
            decRange = skyMap.config.decRange
            decList = (
                (decRange[0] * 0.999) + (decRange[1] * 0.901),
                (decRange[0] * 0.500) + (decRange[1] * 0.500),
                (decRange[0] * 0.091) + (decRange[1] * 0.999),
            )
            for tractInfo0 in skyMap:
                tractId0 = tractInfo0.getId()
                ctrCoord0 = tractInfo0.getCtrCoord()

                for tractInfo1 in self.getNeighborTracts(skyMap, tractId0):

                    tractId1 = tractInfo1.getId()
                    ctrCoord1 = tractInfo1.getCtrCoord()

                    for deltaFrac in (-0.001, 0.001):
                        v0 = ctrCoord0.getVector() * (0.5 + deltaFrac)
                        v1 = ctrCoord1.getVector() * (0.5 - deltaFrac)
                        testVec = v0 + v1
                        testRa = afwGeom.SpherePoint(testVec).getRa()

                        if deltaFrac > 0.0:
                            expectedTractId = tractId0
                        else:
                            expectedTractId = tractId1

                        for testDecDeg in decList:
                            testDec = afwGeom.Angle(testDecDeg, afwGeom.degrees)
                            testCoord = afwGeom.SpherePoint(testRa, testDec)

                            nearestTractInfo = skyMap.findTract(testCoord)
                            nearestTractId = nearestTractInfo.getId()

                            self.assertEqual(nearestTractId, expectedTractId)

                            patchInfo = nearestTractInfo.findPatch(testCoord)
                            pixelInd = afwGeom.Point2I(nearestTractInfo.getWcs().skyToPixel(testCoord))
                            self.assertTrue(patchInfo.getInnerBBox().contains(pixelInd))

                # find a point outside the tract and make sure it fails
                tractInfo = tractInfo0
                wcs = tractInfo.getWcs()
                bbox = afwGeom.Box2D(tractInfo.getBBox())
                outerPixPosList = [
                    bbox.getMin() - afwGeom.Extent2D(1, 1),
                    afwGeom.Point2D(bbox.getMaxX(), bbox.getMinY()) - afwGeom.Extent2D(1, 1),
                    bbox.getMax() + afwGeom.Extent2D(1, 1),
                    afwGeom.Point2D(bbox.getMinX(), bbox.getMaxY()) + afwGeom.Extent2D(1, 1),
                ]
                for outerPixPos in outerPixPosList:
                    testCoord = wcs.pixelToSky(outerPixPos)
                    self.assertRaises(LookupError, tractInfo.findPatch, testCoord)
示例#4
0
    def testFindTract(self):
        """Test the SkyMap.findTract method
        """
        for numTracts in (2, 4):
            config = EquatSkyMap.ConfigClass()
            config.numTracts = numTracts
            skyMap = EquatSkyMap(config)
            decRange = skyMap.config.decRange
            decList = (
                (decRange[0] * 0.999) + (decRange[1] * 0.901),
                (decRange[0] * 0.500) + (decRange[1] * 0.500),
                (decRange[0] * 0.091) + (decRange[1] * 0.999),
            )
            for tractInfo0 in skyMap:
                tractId0 = tractInfo0.getId()
                ctrCoord0 = tractInfo0.getCtrCoord()

                for tractInfo1 in self.getNeighborTracts(skyMap, tractId0):

                    tractId1 = tractInfo1.getId()
                    ctrCoord1 = tractInfo1.getCtrCoord()

                    for deltaFrac in (-0.001, 0.001):
                        v0 = ctrCoord0.getVector() * (0.5 + deltaFrac)
                        v1 = ctrCoord1.getVector() * (0.5 - deltaFrac)
                        testVec = v0 + v1
                        testRa = geom.SpherePoint(testVec).getRa()

                        if deltaFrac > 0.0:
                            expectedTractId = tractId0
                        else:
                            expectedTractId = tractId1

                        for testDecDeg in decList:
                            testDec = geom.Angle(testDecDeg, geom.degrees)
                            testCoord = geom.SpherePoint(testRa, testDec)

                            nearestTractInfo = skyMap.findTract(testCoord)
                            nearestTractId = nearestTractInfo.getId()

                            self.assertEqual(nearestTractId, expectedTractId)

                            patchInfo = nearestTractInfo.findPatch(testCoord)
                            pixelInd = geom.Point2I(nearestTractInfo.getWcs().skyToPixel(testCoord))
                            self.assertTrue(patchInfo.getInnerBBox().contains(pixelInd))

                # find a point outside the tract and make sure it fails
                tractInfo = tractInfo0
                wcs = tractInfo.getWcs()
                bbox = geom.Box2D(tractInfo.getBBox())
                outerPixPosList = [
                    bbox.getMin() - geom.Extent2D(1, 1),
                    geom.Point2D(bbox.getMaxX(), bbox.getMinY()) - geom.Extent2D(1, 1),
                    bbox.getMax() + geom.Extent2D(1, 1),
                    geom.Point2D(bbox.getMinX(), bbox.getMaxY()) + geom.Extent2D(1, 1),
                ]
                for outerPixPos in outerPixPosList:
                    testCoord = wcs.pixelToSky(outerPixPos)
                    self.assertRaises(LookupError, tractInfo.findPatch, testCoord)
示例#5
0
 def test_gettingPatchInfo(self):
     skyMap = EquatSkyMap(EquatSkyMap.ConfigClass())
     tract = skyMap[0]
     # Look up patchInfo with a coordinate pair
     patchIndex = (3, 5)
     pairPatchInfo = tract.getPatchInfo(patchIndex)
     # Fetch the sequential index
     sequentialPatchIndex = tract.getSequentialPatchIndex(pairPatchInfo)
     # Turn the sequential index back into a pair
     returnedPatchIndex = tract.getPatchIndexPair(sequentialPatchIndex)
     # Test that the different indexes match
     self.assertEqual(patchIndex, returnedPatchIndex)
     # verify patch info can be retrieved with both indexes
     sequentialPatchInfo = tract.getPatchInfo(sequentialPatchIndex)
     self.assertEqual(pairPatchInfo, sequentialPatchInfo)
示例#6
0
    def testMoreBasicAttributes(self):
        """Confirm that constructor attributes are available.
        """
        defaultSkyMap = self.getSkyMap()
        for numTracts in (1, 2, 4, 25):
            config = EquatSkyMap.ConfigClass()
            config.numTracts = numTracts
            skyMap = EquatSkyMap(config)
            self.assertEqual(len(skyMap), numTracts)
            if numTracts == defaultSkyMap.config.numTracts:
                self.assertEqual(skyMap, defaultSkyMap)
            else:
                self.assertNotEqual(skyMap, defaultSkyMap)

        for decRange in ([-1.3, 0.5], [6.1, 6.8]):
            config = EquatSkyMap.ConfigClass()
            config.decRange = decRange
            skyMap = EquatSkyMap(config)
            self.assertNotEqual(skyMap, defaultSkyMap)
示例#7
0
    def testBasicAttributes(self):
        """Confirm that constructor attributes are available
        """
        for numTracts in (1, 2, 4, 25):
            config = EquatSkyMap.ConfigClass()
            config.numTracts = numTracts
            skyMap = EquatSkyMap(config)
            self.assertEqual(len(skyMap), numTracts)

        for tractOverlap in (0.0, 0.01, 0.1):  # degrees
            config = EquatSkyMap.ConfigClass()
            config.tractOverlap = tractOverlap
            skyMap = EquatSkyMap(config)
            for tractInfo in skyMap:
                self.assertAlmostEqual(tractInfo.getTractOverlap().asDegrees(),
                                       tractOverlap)
            self.assertEqual(len(skyMap), skyMap.config.numTracts)

        for patchBorder in (0, 101):
            config = EquatSkyMap.ConfigClass()
            config.patchBorder = patchBorder
            skyMap = EquatSkyMap(config)
            for tractInfo in skyMap:
                self.assertEqual(tractInfo.getPatchBorder(), patchBorder)
            self.assertEqual(len(skyMap), skyMap.config.numTracts)

        skyMapClass = skyMapRegistry["equat"]
        for xInnerDim in (1005, 5062):
            for yInnerDim in (2032, 5431):
                config = skyMapClass.ConfigClass()
                config.patchInnerDimensions = (xInnerDim, yInnerDim)
                skyMap = EquatSkyMap(config)
                for tractInfo in skyMap:
                    self.assertEqual(
                        tuple(tractInfo.getPatchInnerDimensions()),
                        (xInnerDim, yInnerDim))
                self.assertEqual(len(skyMap), skyMap.config.numTracts)
 def testPickle(self):
     """Test that pickling and unpickling restores the original exactly
     """
     skyMap = EquatSkyMap()
     pickleStr = pickle.dumps(skyMap)
     unpickledSkyMap = pickle.loads(pickleStr)
     self.assertEqual(skyMap.getVersion(), unpickledSkyMap.getVersion())
     self.assertEqual(len(skyMap), len(unpickledSkyMap))
     for configName in (
         "patchInnerDimensions",
         "patchBorder",
         "projection",
         "pixelScale",
         "tractOverlap",
         "numTracts",
         "decRange",
     ):
         self.assertEqual(getattr(skyMap.config, configName), getattr(unpickledSkyMap.config, configName))
     for tractInfo, unpickledTractInfo in itertools.izip(skyMap, unpickledSkyMap):
         for getterName in (
             "getBBox",
             "getCtrCoord",
             "getId",
             "getNumPatches",
             "getPatchBorder",
             "getPatchInnerDimensions",
             "getTractOverlap",
             "getVertexList",
             "getWcs",
         ):
             self.assertEqual(getattr(tractInfo, getterName)(), getattr(unpickledTractInfo, getterName)())
         
         # test WCS at a few locations
         wcs = tractInfo.getWcs()
         unpickledWcs = unpickledTractInfo.getWcs()
         for x in (-1000.0, 0.0, 1000.0):
             for y in (-532.5, 0.5, 532.5):
                 pixelPos = afwGeom.Point2D(x, y)
                 skyPos = wcs.pixelToSky(pixelPos)
                 unpickledSkyPos = unpickledWcs.pixelToSky(pixelPos)
                 self.assertEqual(skyPos, unpickledSkyPos)
         
         # compare a few patches
         numPatches = tractInfo.getNumPatches()
         patchBorder = skyMap.config.patchBorder
         for xInd in (0, 1, numPatches[0]/2, numPatches[0]-2, numPatches[0]-1):
             for yInd in (0, 1, numPatches[1]/2, numPatches[1]-2, numPatches[1]-1):
                 patchInfo = tractInfo.getPatchInfo((xInd, yInd))
                 unpickledPatchInfo = unpickledTractInfo.getPatchInfo((xInd, yInd))
                 self.assertEqual(patchInfo, unpickledPatchInfo)
                 
                 # check inner and outer bbox (nothing to do with pickle,
                 # but a convenient place for the test)
                 innerBBox = patchInfo.getInnerBBox()
                 outerBBox = patchInfo.getOuterBBox()
                 
                 if xInd == 0:
                     self.assertEqual(innerBBox.getMinX(), outerBBox.getMinX())
                 else:
                     self.assertEqual(innerBBox.getMinX() - patchBorder, outerBBox.getMinX())
                 if yInd == 0:
                     self.assertEqual(innerBBox.getMinY(), outerBBox.getMinY())
                 else:
                     self.assertEqual(innerBBox.getMinY() - patchBorder, outerBBox.getMinY())
                     
                 if xInd == numPatches[0] - 1:
                     self.assertEqual(innerBBox.getMaxX(), outerBBox.getMaxX())
                 else:
                     self.assertEqual(innerBBox.getMaxX() + patchBorder, outerBBox.getMaxX())
                 if yInd == numPatches[1] - 1:
                     self.assertEqual(innerBBox.getMaxY(), outerBBox.getMaxY())
                 else:
                     self.assertEqual(innerBBox.getMaxY() + patchBorder, outerBBox.getMaxY())
示例#9
0
 def testDefaults(self):
     """Test important default values
     """
     config = EquatSkyMap.ConfigClass()
     skyMap = EquatSkyMap(config)
     self.assertEqual(skyMap.config.projection, "CEA")
示例#10
0
    def testFindTract(self):
        """Test the findTract method
        """
        for numTracts in (2, 4):
            config = EquatSkyMap.ConfigClass()
            config.numTracts = numTracts
            skyMap = EquatSkyMap(config)
            decRange = skyMap.config.decRange
            decList = (
                (decRange[0] * 0.999) + (decRange[1] * 0.901),
                (decRange[0] * 0.500) + (decRange[1] * 0.500),
                (decRange[0] * 0.091) + (decRange[1] * 0.999),
            )
            for tractInfo0 in skyMap:
                tractId0 = tractInfo0.getId()
                ctrCoord0 = tractInfo0.getCtrCoord()
                vector0 = numpy.array(ctrCoord0.getVector())

                for tractInfo1 in self.getNeighborTracts(skyMap, tractId0):

                    tractId1 = tractInfo1.getId()
                    ctrCoord1 = tractInfo1.getCtrCoord()
                    vector1 = numpy.array(ctrCoord1.getVector())

                    for deltaFrac in (-0.001, 0.001):
                        # this fuss is because Point3D does not support * float
                        v0 = [
                            v * (0.5 + deltaFrac)
                            for v in ctrCoord0.getVector()
                        ]
                        v1 = [
                            v * (0.5 - deltaFrac)
                            for v in ctrCoord1.getVector()
                        ]
                        testVec = afwGeom.Point3D(*(v0[i] + v1[i]
                                                    for i in range(3)))
                        testRa = afwCoord.IcrsCoord(testVec).getRa()

                        if deltaFrac > 0.0:
                            expectedTractId = tractId0
                        else:
                            expectedTractId = tractId1

                        for testDecDeg in decList:
                            testDec = afwGeom.Angle(testDecDeg,
                                                    afwGeom.degrees)
                            testCoord = afwCoord.IcrsCoord(testRa, testDec)

                            nearestTractInfo = skyMap.findTract(testCoord)
                            nearestTractId = nearestTractInfo.getId()

                            self.assertEqual(nearestTractId, expectedTractId)

                            patchInfo = nearestTractInfo.findPatch(testCoord)
                            pixelInd = afwGeom.Point2I(
                                nearestTractInfo.getWcs().skyToPixel(
                                    testCoord.toIcrs()))
                            self.assertTrue(
                                patchInfo.getInnerBBox().contains(pixelInd))

                # find a point outside the tract and make sure it fails
                tractInfo = tractInfo0
                wcs = tractInfo.getWcs()
                bbox = afwGeom.Box2D(tractInfo.getBBox())
                outerPixPosList = [
                    bbox.getMin() - afwGeom.Extent2D(1, 1),
                    afwGeom.Point2D(bbox.getMaxX(), bbox.getMinY()) -
                    afwGeom.Extent2D(1, 1),
                    bbox.getMax() + afwGeom.Extent2D(1, 1),
                    afwGeom.Point2D(bbox.getMinX(), bbox.getMaxY()) +
                    afwGeom.Extent2D(1, 1),
                ]
                for outerPixPos in outerPixPosList:
                    testCoord = wcs.pixelToSky(outerPixPos)
                    self.assertRaises(LookupError, tractInfo.findPatch,
                                      testCoord)
示例#11
0
    def testPickle(self):
        """Test that pickling and unpickling restores the original exactly
        """
        skyMap = EquatSkyMap()
        pickleStr = pickle.dumps(skyMap)
        unpickledSkyMap = pickle.loads(pickleStr)
        self.assertEqual(skyMap.getVersion(), unpickledSkyMap.getVersion())
        self.assertEqual(len(skyMap), len(unpickledSkyMap))
        for configName in (
                "patchInnerDimensions",
                "patchBorder",
                "projection",
                "pixelScale",
                "tractOverlap",
                "numTracts",
                "decRange",
        ):
            self.assertEqual(getattr(skyMap.config, configName),
                             getattr(unpickledSkyMap.config, configName))
        for tractInfo, unpickledTractInfo in zip(skyMap, unpickledSkyMap):
            for getterName in (
                    "getBBox",
                    "getCtrCoord",
                    "getId",
                    "getNumPatches",
                    "getPatchBorder",
                    "getPatchInnerDimensions",
                    "getTractOverlap",
                    "getVertexList",
                    "getWcs",
            ):
                self.assertEqual(
                    getattr(tractInfo, getterName)(),
                    getattr(unpickledTractInfo, getterName)())

            # test WCS at a few locations
            wcs = tractInfo.getWcs()
            unpickledWcs = unpickledTractInfo.getWcs()
            for x in (-1000.0, 0.0, 1000.0):
                for y in (-532.5, 0.5, 532.5):
                    pixelPos = afwGeom.Point2D(x, y)
                    skyPos = wcs.pixelToSky(pixelPos)
                    unpickledSkyPos = unpickledWcs.pixelToSky(pixelPos)
                    self.assertEqual(skyPos, unpickledSkyPos)

            # compare a few patches
            numPatches = tractInfo.getNumPatches()
            patchBorder = skyMap.config.patchBorder
            for xInd in (0, 1, numPatches[0] // 2, numPatches[0] - 2,
                         numPatches[0] - 1):
                for yInd in (0, 1, numPatches[1] // 2, numPatches[1] - 2,
                             numPatches[1] - 1):
                    patchInfo = tractInfo.getPatchInfo((xInd, yInd))
                    unpickledPatchInfo = unpickledTractInfo.getPatchInfo(
                        (xInd, yInd))
                    self.assertEqual(patchInfo, unpickledPatchInfo)

                    # check inner and outer bbox (nothing to do with pickle,
                    # but a convenient place for the test)
                    innerBBox = patchInfo.getInnerBBox()
                    outerBBox = patchInfo.getOuterBBox()

                    if xInd == 0:
                        self.assertEqual(innerBBox.getMinX(),
                                         outerBBox.getMinX())
                    else:
                        self.assertEqual(innerBBox.getMinX() - patchBorder,
                                         outerBBox.getMinX())
                    if yInd == 0:
                        self.assertEqual(innerBBox.getMinY(),
                                         outerBBox.getMinY())
                    else:
                        self.assertEqual(innerBBox.getMinY() - patchBorder,
                                         outerBBox.getMinY())

                    if xInd == numPatches[0] - 1:
                        self.assertEqual(innerBBox.getMaxX(),
                                         outerBBox.getMaxX())
                    else:
                        self.assertEqual(innerBBox.getMaxX() + patchBorder,
                                         outerBBox.getMaxX())
                    if yInd == numPatches[1] - 1:
                        self.assertEqual(innerBBox.getMaxY(),
                                         outerBBox.getMaxY())
                    else:
                        self.assertEqual(innerBBox.getMaxY() + patchBorder,
                                         outerBBox.getMaxY())