def testIntersect(self): """Tests polygon sky-pixel intersection. """ qs1 = skypix.QuadSpherePixelization(3, 0.0) polygons = [qs1.getGeometry(qs1.id(r, 1, 1), True) for r in range(6)] qs2 = skypix.QuadSpherePixelization(4, 0.0) results = [ set([ qs2.id(r, 1, 1), qs2.id(r, 2, 1), qs2.id(r, 1, 2), qs2.id(r, 2, 2) ]) for r in range(6) ] for poly, res in zip(polygons, results): self.assertEqual(set(qs2.intersect(poly)), res)
def testIdAndCoord(self): for R in (3, 4, 16, 17): qs = skypix.QuadSpherePixelization(R, 0.0) self.assertEqual(len(qs), 6 * R**2) for i in range(6 * R**2): root, x, y = qs.coords(i) self.assertEqual(qs.id(root, x, y), i)
def testPixel(self): """Verifies that the center of pixel P is mapped back to P. """ for R in (64, 65): qs = skypix.QuadSpherePixelization(R, 0.0) for i in qs: c = geom.sphericalCoords(qs.getCenter(i)) pixelId = qs.pixel(math.radians(c[0]), math.radians(c[1])) self.assertEqual(i, pixelId)
def testGeometry(self): """Verifies that pixels are contained in their padded selves. """ for R in (4, 5): qs = skypix.QuadSpherePixelization(R, math.radians(1.0)) for i in range(6 * R**2): pixel = qs.getGeometry(i, True) paddedPixel = qs.getGeometry(i, False) self.assertTrue(paddedPixel.contains(pixel))
def testPrune1(self): coords = [] for ra, dec in [(0.0, 0.0), (0.1, 0.1), (0.0, 90.0), (0.0, -90.0)]: coords.append(afwCoord.IcrsCoord(ra * degrees, dec * degrees)) res = 3 qs = skypix.QuadSpherePixelization(res, 0.0) root, x, y = 1, 1, 1 skyTileId = qs.id(root, x, y) skyTile = utils.PT1SkyTile(res, root, x, y, skyTileId) numContained = sum(skyTile.contains(s) for s in coords) self.assertEqual(numContained, 2)
def testSpiral(self): """Tests that pixels are ordered in an approximate spiral. """ for R in (17, 32): qs = skypix.QuadSpherePixelization(R, 0.0) lag = 8 * R for i in qs: neighbors = qs.getNeighbors(i) maxN = max(neighbors) minN = min(neighbors) self.assertTrue(maxN - i < lag) self.assertTrue(i - minN < lag)
def testPrune2(self): coarseRes = 3 subdiv = 6 fineRes = coarseRes * subdiv coarseQs = skypix.QuadSpherePixelization(coarseRes, 0.0) fineQs = skypix.QuadSpherePixelization(fineRes, 0.0) for skyTileId in coarseQs: root, cx, cy = coarseQs.coords(skyTileId) skyTile = utils.PT1SkyTile(coarseRes, root, cx, cy, skyTileId) for cid in coarseQs: root2, cx2, cy2 = coarseQs.coords(cid) for x in xrange(cx2 * subdiv, (cx2 + 1) * subdiv): for y in xrange(cy2 * subdiv, (cy2 + 1) * subdiv): pixelCenter = geom.sphericalCoords( fineQs.getCenter(fineQs.id(root2, x, y))) s = afwCoord.IcrsCoord(pixelCenter[0] * degrees, pixelCenter[1] * degrees) if root == root2 and cx == cx2 and cy == cy2: self.assertEqual(skyTile.contains(s), True) else: self.assertEqual(skyTile.contains(s), False)
def testNeighborCommutativity(self): """Tests that if pixel P1 is a neighbor of pixel P2, then P2 is a neighbor of P1. """ for R in (16, 17): qs = skypix.QuadSpherePixelization(R, 0.0) for root in range(6): # test root pixel edges and corners for i in range(R - 1): self._checkNeighborCommutativity(qs, root, i, 0) self._checkNeighborCommutativity(qs, root, 0, i) self._checkNeighborCommutativity(qs, root, i, R - 1) self._checkNeighborCommutativity(qs, root, R - 1, i) # test root pixel centers self._checkNeighborCommutativity(qs, root, R // 2, R // 2)
def testNeighborProximity(self): """Tests that neighbors of a pixel P are close to P. """ tolerance = 1.0 for R in (180, 181): qs = skypix.QuadSpherePixelization(R, 0.0) for root in range(6): # test root pixel edges and corners for i in range(R - 1): self._checkNeighbors(qs, root, i, 0, tolerance) self._checkNeighbors(qs, root, 0, i, tolerance) self._checkNeighbors(qs, root, i, R - 1, tolerance) self._checkNeighbors(qs, root, R - 1, i, tolerance) # test root pixel centers self._checkNeighbors(qs, root, R // 2, R // 2, tolerance)
def run( rerun, # Rerun name stack, # Stack identifier filter, # Filter name field, # Field name scale, # Scale, arcsec/pix ): io = pipReadWrite.ReadWrite(hsc.HscSimMapper(rerun=rerun), ['visit', 'ccd']) skyPolicy = io.inButler.get('skypolicy') print skyPolicy.toString() sky = skypix.QuadSpherePixelization( skyPolicy.get('resolutionPix'), skyPolicy.get('paddingArcsec') / 3600.0) dataId = {'filter': filter} if field is not None: dataId['field'] = field skytiles = io.inButler.queryMetadata('calexp', None, 'skyTile', dataId) for tile in skytiles: dataId['skyTile'] = tile visits = io.inButler.queryMetadata('calexp', None, 'visit', dataId) if len(visits) == 0: continue geom = sky.getGeometry(tile) bbox = geom.getBoundingBox() ra, dec = bbox.getCenter() # Degrees theta = bbox.getThetaExtent() # Width, degrees size = int(theta * 3600.0 / scale) # Size, pixels cmd = "hsc_stack.py --rerun " + rerun cmd += " --stack %d" % stack cmd += " --patch %d" % tile cmd += " --filter %s" % filter cmd += " --coords %f %f" % (ra, dec) cmd += " --scale %f" % scale cmd += " --sizes %d %d" % (size, size) cmd += " --frames %s" % ":".join(map(str, visits)) cmd += " --ignore" print cmd