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)
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)
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)