예제 #1
0
 def test_construction(self):
     with self.assertRaises(ValueError):
         Q3cPixelization(-1)
     with self.assertRaises(ValueError):
         Q3cPixelization(Q3cPixelization.MAX_LEVEL + 1)
     q1 = Q3cPixelization(0)
     self.assertEqual(q1.getLevel(), 0)
     q2 = Q3cPixelization(1)
     q3 = Q3cPixelization(q2)
     self.assertNotEqual(q1, q2)
     self.assertEqual(q2, q3)
예제 #2
0
 def test_index_to_string(self):
     strings = ['+X', '+Y', '+Z', '-X', '-Y', '-Z']
     for i in range(6):
         s = strings[i]
         components = [0.0] * 3
         components[i % 3] = 1.0 if i < 3 else -1.0
         v = UnitVector3d(*components)
         f = Q3cPixelization(0).index(v)
         self.assertEqual(Q3cPixelization(0).toString(f), s)
         for j in range(4):
             self.assertEqual(
                 Q3cPixelization(1).toString(f * 4 + j), s + str(j))
예제 #3
0
 def test_envelope_and_interior(self):
     pixelization = Q3cPixelization(1)
     c = Circle(UnitVector3d(1.0, -0.5, -0.5), Angle.fromDegrees(0.1))
     rs = pixelization.envelope(c)
     self.assertTrue(rs == RangeSet(4))
     rs = pixelization.envelope(c, 1)
     self.assertTrue(rs == RangeSet(4))
     self.assertTrue(rs.isWithin(pixelization.universe()))
     rs = pixelization.interior(c)
     self.assertTrue(rs.empty())
예제 #4
0
def main():

    descr = 'Quick and dirty simulation of sky partitioning and CCD overlaps.'
    parser = ArgumentParser(description=descr)
    parser.add_argument('-v', '--verbose', action='count', default=0,
                        help='More verbose output, can use several times.')
    parser.add_argument('-m', '--mode', default='htm',
                        choices=["htm", "q3c", "mq3c"],
                        help='Partitioning mode, def: %(default)s')
    parser.add_argument('--level', type=int, default=8,
                        help='Pixelization level, def: %(default)s')
    parser.add_argument('-n', '--counts', type=int, default=1000,
                        help='Number of visits, def: %(default)s')
    parser.add_argument('--pixels-per-tile', default=None,
                        help='Output file name for pixels-per-tile')
    parser.add_argument('--tiles-per-pixel', default=None,
                        help='Output file name for pixels-per-tile')
    args = parser.parse_args()

    # configure logging
    _configLogger(args.verbose)

    if args.mode == 'htm':
        pixelator = HtmPixelization(args.level)
        lvlchk = pixelator.level
        poly = pixelator.triangle
    elif args.mode == 'q3c':
        pixelator = Q3cPixelization(args.level)
        lvlchk = None
        poly = pixelator.quad
    elif args.mode == 'mq3c':
        pixelator = Mq3cPixelization(args.level)
        lvlchk = pixelator.level
        poly = pixelator.quad

    pixels_per_tile = []
    area_per_tile = []
    tiles_per_pixel = []

    for i in range(args.counts):

        pointing_xyz = generators.rand_sphere_xyz(1, -1)[0]
        pointing_v = UnitVector3d(pointing_xyz[0], pointing_xyz[1], pointing_xyz[2])

        rot_ang = random.uniform(0., 2*math.pi)

        tiles = geom.make_square_tiles(FOV_rad, 15, 15, pointing_v, rot_rad=rot_ang)

        # for each tile find all pixels that overlap it
        pixel_tiles = dict()
        for ix, iy, tile in tiles:
            ranges = pixelator.envelope(tile, 1000000)

            tile_pixels = 0
            tile_area = 0.
            for i0, i1 in ranges:
                for pixId in range(i0, i1):
                    if lvlchk is not None and lvlchk(pixId) != args.level:
                        logging.warning("tile %dx%d not fully pixelized: %d-%d", ix, iy, i0, i1)
                    else:
                        tile_pixels += 1
                        pixel_tiles.setdefault(pixId, 0)
                        pixel_tiles[pixId] += 1
                        if poly:
                            tile_area += geom.poly_area(poly(pixId)) * (180/math.pi)**2

            pixels_per_tile.append(tile_pixels)
            area_per_tile.append(tile_area)

        for count in pixel_tiles.values():
            tiles_per_pixel.append(count)

    avg_area = sum(area_per_tile) / len(area_per_tile)

    print("pixels_per_tile: {:.2f}".format(sum(pixels_per_tile)/len(pixels_per_tile)))
    print("area_per_tile: {:.6f} deg^2".format(avg_area))
    print("tiles_per_pixel: {:.2f}".format(sum(tiles_per_pixel)/len(tiles_per_pixel)))

    if args.pixels_per_tile:
        with open(args.pixels_per_tile, 'w') as f:
            print("pixels,area_deg_sq", file=f)
            for pix, area in zip(pixels_per_tile, area_per_tile):
                print(f"{pix},{area}", file=f)

    if args.tiles_per_pixel:
        with open(args.tiles_per_pixel, 'w') as f:
            print("tiles", file=f)
            for num in tiles_per_pixel:
                print(num, file=f)
예제 #5
0
 def test_pickle(self):
     a = Q3cPixelization(20)
     b = pickle.loads(pickle.dumps(a))
     self.assertEqual(a, b)
예제 #6
0
 def test_string(self):
     p = Q3cPixelization(3)
     self.assertEqual(str(p), 'Q3cPixelization(3)')
     self.assertEqual(str(p), repr(p))
     self.assertEqual(p, eval(repr(p),
                              dict(Q3cPixelization=Q3cPixelization)))
예제 #7
0
 def test_indexing(self):
     pixelization = Q3cPixelization(1)
     self.assertEqual(pixelization.index(UnitVector3d(0.5, -0.5, 1.0)), 0)
예제 #8
0
 def test_yaml(self):
     a = Q3cPixelization(20)
     b = yaml.safe_load(yaml.dump(a))
     self.assertEqual(a, b)
예제 #9
0
 def test_pixel(self):
     h = Q3cPixelization(1)
     self.assertIsInstance(h.pixel(10), ConvexPolygon)