コード例 #1
0
ファイル: constellations.py プロジェクト: rzinkstok/skymap
def build_constellation_boundary_database():
    print()
    print("Creating constellation boundary database")
    db = SkyMapDatabase()
    db.drop_table("skymap_constellation_boundaries")
    db.create_table(
        "skymap_constellation_boundaries",
        ["ra1", "dec1", "ra2", "dec2"],
        [float, float, float, float],
    )

    # Retrieve data from Vizier
    print()
    print("Retrieving data from Vizier")
    Vizier.ROW_LIMIT = -1
    catalog = Vizier.get_catalogs("VI/49")
    constbnd = catalog["VI/49/constbnd"]

    print()
    print("Building edges from {} points".format(len(constbnd)))
    prev_hash = None
    edges = []
    for row in constbnd:
        if not row["adj"]:
            prev_hash = None

        current_hash = point_hash(row["RAB1875"], row["DEB1875"])
        if prev_hash is not None:
            e = QuickEdge(prev_hash, current_hash)

            if e not in edges:
                edges.append(e)

        prev_hash = current_hash

    print()
    print("Connecting {} edges".format(len(edges)))
    for i, e1 in enumerate(edges):
        for e2 in edges[i + 1 :]:
            e1.connect(e2)

    print()
    print("Building extended edges")
    new_edges = []
    for i, e in enumerate(edges):
        new_edge = e.extended_edge
        if new_edge not in new_edges:
            new_edges.append(new_edge)

    print()
    print(f"Loading {len(new_edges)} edges to database")
    for i, e in enumerate(new_edges):
        db.insert_row(
            "skymap_constellation_boundaries",
            ["ra1", "dec1", "ra2", "dec2"],
            e.coordinates,
        )
コード例 #2
0
def build_constellation_boundary_database():
    print
    print "Building constellation boundary database"
    db = SkyMapDatabase()
    db.drop_table("skymap_constellation_boundaries")
    db.create_table("skymap_constellation_boundaries",
                    ["ra1", "dec1", "ra2", "dec2"],
                    [float, float, float, float])

    edges = []
    rows = db.query("""SELECT * FROM cst_bound_constbnd""")

    print "Creating raw edges"
    prev_point = None
    nrecords = len(rows)
    next_id = 1
    for i, row in enumerate(rows):
        sys.stdout.write("\r{0:.1f}%".format(i * 100.0 / (nrecords - 1)))
        sys.stdout.flush()

        if not row['adj']:
            prev_point = None

        ra = 15.0 * row['RAhr']
        dec = row['DEdeg']
        point = SphericalPoint(ra, dec)

        if prev_point is not None:
            e = BoundaryEdge(prev_point, point)
            if e not in edges:
                edges.append(e)
                next_id += 1

        prev_point = point

    print
    print "Connecting edges"
    n = 0
    nrecords = len(edges) * (len(edges) - 1) / 2
    for i, e1 in enumerate(edges):
        for e2 in edges[i + 1:]:
            sys.stdout.write("\r{0:.1f}%".format(n * 100.0 / (nrecords - 1)))
            sys.stdout.flush()
            n += 1
            if e1 == e2:
                continue

            e1.connect(e2)

    print
    print "Building extended edges"
    new_edges = []
    nrecords = len(edges)
    for i, e in enumerate(edges):
        sys.stdout.write("\r{0:.1f}%".format(i * 100.0 / (nrecords - 1)))
        sys.stdout.flush()
        new_edge = e.extended_edge
        if new_edge not in new_edges:
            new_edges.append(new_edge)
    print
    nrecords = len(new_edges)
    print "Loading {} edges to database".format(nrecords)

    for i, e in enumerate(new_edges):
        sys.stdout.write("\r{0:.1f}%".format(i * 100.0 / (nrecords - 1)))
        sys.stdout.flush()
        db.insert_row("skymap_constellation_boundaries",
                      ["ra1", "dec1", "ra2", "dec2"],
                      [e.p1.ra, e.p1.dec, e.p2.ra, e.p2.dec])