def build_tile(params):
    hparts, vparts, zoom, x, y = params

    hparts_size = 24.0 / hparts
    vparts_size = 180.0 / vparts

    v1 = azalt_to_vector(0, 0)
    v2 = azalt_to_vector(hparts_size, vparts_size)

    min_distance = vector3_distance(v1, v2)
    hour = ((x * hparts_size + hparts_size / 2.0) + 12) % 24
    deg = 90 - y * vparts_size - vparts_size / 2.0
    mid_v = azalt_to_vector(hour, deg)

    tile_coords = get_tile_coords((hour, deg), zoom)
    assert tile_coords == (x, y + vparts / 2), (tile_coords, (x, y + vparts / 2))

    tile_id = "%s-%s-%s" % (zoom, x, y + vparts / 2)
    tile_objects = []

    for star in get_stars():
        object_v = azalt_to_vector(star.ra, star.dec)
        if vector3_distance(mid_v, object_v) <= min_distance:
            obj = (star.id, star.ra, star.dec, star.mag)

            # Some stars that are part of our constellations do not have
            # B/F designation. Need to make sure they're shown at all zoom levels
            if star.id in EXEMPTIONS and zoom >= EXEMPTIONS[star.id]:
                tile_objects.append(obj)
                continue

            # Always show stars if they have a proper name or part of a constellation
            # excluding Gliese designation
            if star.bayer_flamsteed or star.proper_name:
                tile_objects.append(obj)
                continue

            # All stars visible by zoom 7
            if zoom >= 7:
                tile_objects.append(obj)
                continue

            if star.mag <= 6 + (zoom - 5):
                tile_objects.append(obj)

    tile_objects.sort(key=lambda o: o[3], reverse=True)

    print "Tile: %s Objects: %d" % (tile_id, len(tile_objects))

    zpath = os.path.join("../indexes", str(zoom))
    try:
        os.mkdir(zpath)
    except:
        pass

    f = open(os.path.join(zpath, "%s.dat"%tile_id), "wb")
    try:
        pickle.dump(tile_objects, f)
    finally:
        f.close()
def get_named_stars():
    global NAMED_STARS
    if not NAMED_STARS:
        NAMED_STARS = [star for star in get_stars() if star.proper_name]

    return NAMED_STARS