Fix zodiac traces using Stellarium modern lines

This commit is contained in:
vini 2026-07-19 14:07:54 -03:00
parent 03692a0398
commit 3df13f9a0c
2 changed files with 47 additions and 31 deletions

View file

@ -1,8 +1,9 @@
#!/usr/bin/env python3
"""Gera constellations.js com os signos zodiacais em coordenadas J2000.
Fonte: d3-celestial, de Olaf Frohn, licença BSD-3-Clause.
Os dados são compactados para uso offline pelo wallpaper.
Os traçados são da cultura ``modern`` do Stellarium. As coordenadas J2000
dos respectivos identificadores Hipparcos vêm do d3-celestial. Os dados são
compactados para uso offline pelo wallpaper.
"""
import json
@ -10,7 +11,11 @@ import urllib.request
from pathlib import Path
BASE = "https://raw.githubusercontent.com/ofrohn/d3-celestial/master/data/"
STELLARIUM_URL = (
"https://raw.githubusercontent.com/Stellarium/stellarium/master/"
"skycultures/modern/index.json"
)
D3_BASE = "https://raw.githubusercontent.com/ofrohn/d3-celestial/master/data/"
OUT = Path(__file__).resolve().parent.parent / "plugin/contents/ui/constellations.js"
ZODIAC = {
@ -28,7 +33,11 @@ ZODIAC = {
"Psc": "Peixes",
}
LICENSE = """Copyright (c) 2015, Olaf Frohn
LICENSE = """Constellation lines: Stellarium Modern sky culture, CC BY-SA 4.0.
https://github.com/Stellarium/stellarium/tree/master/skycultures/modern
Hipparcos J2000 coordinates: d3-celestial.
Copyright (c) 2015, Olaf Frohn
All rights reserved.
Redistribution and use in source and binary forms, with or without
@ -48,8 +57,8 @@ OUT OF THE USE OF THIS SOFTWARE.
"""
def fetch(name: str) -> dict:
req = urllib.request.Request(BASE + name, headers={"User-Agent": "skeledance-build/1.0"})
def fetch(url: str) -> dict:
req = urllib.request.Request(url, headers={"User-Agent": "skeledance-build/1.0"})
return json.loads(urllib.request.urlopen(req, timeout=30).read())
@ -58,8 +67,13 @@ def rounded_point(point: list[float]) -> list[float]:
def main() -> None:
line_data = fetch("constellations.lines.json")["features"]
name_data = fetch("constellations.json")["features"]
sky_culture = fetch(STELLARIUM_URL)
star_data = fetch(D3_BASE + "stars.6.json")["features"]
name_data = fetch(D3_BASE + "constellations.json")["features"]
stars = {
int(feature["id"]): rounded_point(feature["geometry"]["coordinates"])
for feature in star_data
}
metadata = {
feature["id"]: {
"name": feature["properties"].get("name", feature["id"]),
@ -69,25 +83,23 @@ def main() -> None:
}
merged: dict[str, dict] = {}
for feature in line_data:
ident = feature["id"]
for constellation in sky_culture["constellations"]:
ident = constellation["id"].split()[-1]
if ident not in ZODIAC:
continue
item = merged.setdefault(
ident,
{
"id": ident,
"name": ZODIAC[ident],
"rank": int(feature["properties"].get("rank", 3)),
"label": metadata.get(ident, {}).get("label"),
"lines": [],
},
)
item["rank"] = min(item["rank"], int(feature["properties"].get("rank", 3)))
item["lines"].extend(
[[rounded_point(point) for point in line]
for line in feature["geometry"]["coordinates"]]
)
lines = []
for hip_line in constellation.get("lines", []):
missing = [hip for hip in hip_line if hip not in stars]
if missing:
raise RuntimeError(f"{ident}: HIP ausente no catálogo: {missing}")
lines.append([stars[hip] for hip in hip_line])
merged[ident] = {
"id": ident,
"name": ZODIAC[ident],
"rank": 1 if ident in {"Ari", "Tau", "Gem", "Leo", "Vir", "Sco", "Sgr"} else 2,
"label": metadata.get(ident, {}).get("label"),
"lines": lines,
}
payload = json.dumps(
[merged[ident] for ident in ZODIAC],
@ -96,8 +108,8 @@ def main() -> None:
)
OUT.write_text(
"/* Gerado por tools/build_constellations.py.\n"
" d3-celestial constellation lines, coordenadas equatoriais J2000.\n\n"
+ "\n".join(" " + line for line in LICENSE.rstrip().splitlines())
" Stellarium Modern constellation lines, coordenadas Hipparcos J2000.\n\n"
+ "\n".join((" " + line) if line else "" for line in LICENSE.rstrip().splitlines())
+ " */\nconst CONSTELLATIONS=" + payload + ";\n",
encoding="utf-8",
)