67 lines
3.4 KiB
Python
67 lines
3.4 KiB
Python
|
|
"""Régénère public/assets/js/ciel-donnees.js (le ciel du planisphère).
|
||
|
|
|
||
|
|
Usage :
|
||
|
|
mkdir -p /tmp/ciel && cd /tmp/ciel && for f in stars.6.json constellations.lines.json constellations.json starnames.json; do
|
||
|
|
curl -sSfLO "https://cdn.jsdelivr.net/npm/d3-celestial@0.7.35/data/$f"; done
|
||
|
|
python3 -I outils/ciel.py /tmp/ciel ../../Set-OPS-public/scripts/etoiles.py public/assets/js/ciel-donnees.js
|
||
|
|
|
||
|
|
Sources : d3-celestial (BSD-3, O. Frohn) pour les positions Hipparcos et les tracés ;
|
||
|
|
table figée des étoiles de Set-OPS pour l ordre des 70 circumpolaires."""
|
||
|
|
import json, re, sys, unicodedata
|
||
|
|
src, etoiles_py, sortie = sys.argv[1], sys.argv[2], sys.argv[3]
|
||
|
|
DEC_MIN, MAG_MAX = -16, 5.6
|
||
|
|
stars = json.load(open(f"{src}/stars.6.json"))["features"]
|
||
|
|
noms = json.load(open(f"{src}/starnames.json"))
|
||
|
|
lignes = json.load(open(f"{src}/constellations.lines.json"))["features"]
|
||
|
|
consts = {c["id"]: c for c in json.load(open(f"{src}/constellations.json"))["features"]}
|
||
|
|
|
||
|
|
def ra(x): return round(x % 360, 2)
|
||
|
|
pos = {}
|
||
|
|
E = []
|
||
|
|
for s in stars:
|
||
|
|
lon, dec = s["geometry"]["coordinates"]
|
||
|
|
m = s["properties"]["mag"]
|
||
|
|
pos[str(s["id"])] = (ra(lon), round(dec, 2), m)
|
||
|
|
if dec >= DEC_MIN and m <= MAG_MAX:
|
||
|
|
try: bv = round(float(s["properties"]["bv"]), 2)
|
||
|
|
except Exception: bv = 0.6
|
||
|
|
E.append([ra(lon), round(dec, 2), m, bv])
|
||
|
|
E.sort(key=lambda e: -e[2]) # faibles d'abord, brillantes dessinées par-dessus
|
||
|
|
|
||
|
|
C = []
|
||
|
|
for f in lignes:
|
||
|
|
segs = [[[ra(p[0]), round(p[1], 2)] for p in seg] for seg in f["geometry"]["coordinates"]]
|
||
|
|
if max(p[1] for seg in segs for p in seg) < DEC_MIN: continue
|
||
|
|
p = consts[f["id"]]["properties"]
|
||
|
|
d = p.get("display", [0, 0, 0])
|
||
|
|
C.append({"id": f["id"], "nom": p.get("fr") or p["name"], "l": [ra(d[0]), d[1]], "s": segs})
|
||
|
|
|
||
|
|
def ascii(n): return re.sub(r"[^a-z]", "", unicodedata.normalize("NFKD", n).encode("ascii", "ignore").decode().lower())
|
||
|
|
par_ascii = {ascii(v["name"]): (hip, v) for hip, v in noms.items() if v.get("name")}
|
||
|
|
if "shedar" in par_ascii: h, v = par_ascii["shedar"]; par_ascii["schedar"] = (h, dict(v, name="Schedar"))
|
||
|
|
|
||
|
|
table = re.search(r"ETOILES[^=]*=\s*\((.*?)\)\n", open(etoiles_py).read(), re.S).group(1)
|
||
|
|
table = re.findall(r'"([a-z]+)"', table)
|
||
|
|
CIRC = []
|
||
|
|
for n in table[:70]:
|
||
|
|
hip, v = par_ascii.get(n, (None, {}))
|
||
|
|
p = pos.get(hip) if hip else None
|
||
|
|
CIRC.append({"n": v.get("name") or n.capitalize(), "c": v.get("c", ""), "b": v.get("desig", ""),
|
||
|
|
"p": [p[0], p[1], p[2]] if p else None})
|
||
|
|
|
||
|
|
BRILLANTES = []
|
||
|
|
for hip, v in noms.items():
|
||
|
|
p = pos.get(hip)
|
||
|
|
if p and p[1] >= DEC_MIN and (p[2] < 1.4 or v.get("name") == "Polaris"):
|
||
|
|
BRILLANTES.append({"n": v.get("fr") or v["name"], "p": [p[0], p[1], p[2]]})
|
||
|
|
|
||
|
|
out = {"etoiles": E, "constellations": C, "circumpolaires": CIRC, "brillantes": BRILLANTES}
|
||
|
|
js = ("/* GÉNÉRÉ — positions : catalogue Hipparcos via d3-celestial (BSD-3, O. Frohn) ;\n"
|
||
|
|
" noms : Union astronomique internationale (IAU-CSN) ; ordre des 70 circumpolaires :\n"
|
||
|
|
" table figée de Set-OPS (scripts/etoiles.py). Ne pas éditer à la main. */\n"
|
||
|
|
"window.CIEL = " + json.dumps(out, ensure_ascii=False, separators=(",", ":")) + ";\n")
|
||
|
|
open(sortie, "w").write(js)
|
||
|
|
print(len(E), "étoiles ;", len(C), "constellations ;", sum(1 for c in CIRC if c["p"]), "/ 70 circumpolaires placées ;", len(BRILLANTES), "brillantes ;", len(js)//1024, "Kio")
|
||
|
|
print([c["n"] for c in CIRC if not c["p"]])
|
||
|
|
print([c for c in CIRC if c["n"] in ("Miram", "Achird")])
|