Night sky data: BSC5 naked-eye stars and constellation lines, packed by a committed generator; star placement by the sun's sidereal transform
2887 stars (Vmag <= 5.5) and 150 line chains, 21 KB packed. Placement precesses J2000 to the date and uses sun.js equatorialToHorizontal; tests hold five stars and the moon to astropy's altitude/azimuth within half a degree. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
18ad84aff5
commit
8c377b58ec
4 changed files with 629 additions and 0 deletions
121
scripts/ridge-sky/build-night-sky.py
Normal file
121
scripts/ridge-sky/build-night-sky.py
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
"""Pack the night sky's data into src/app/features/scene/ridge/nightSkyData.ts.
|
||||
|
||||
Usage (parse downloads with isolated mode):
|
||||
python -I scripts/ridge-sky/build-night-sky.py BSC5.DAT.GZ CONSTELLATIONS.LINES.JSON OUT.ts [MAX_MAG]
|
||||
|
||||
Inputs, each in its own directory, never run from inside it:
|
||||
bsc5.dat.gz Yale Bright Star Catalogue, 5th revised ed. (Hoffleit & Warren 1991), public domain; CDS/VizieR V/50.
|
||||
CDS was unreachable on 2026-11-20, so the file is the SAO Telescope Data Center's copy of the same
|
||||
catalogue: http://tdc-www.harvard.edu/catalogs/bsc5.dat.gz (fixed-width, CDS V/50 `catalog` layout).
|
||||
constellations.lines.json d3-celestial (Olaf Frohn), BSD-3-Clause:
|
||||
https://github.com/ofrohn/d3-celestial/blob/master/data/constellations.lines.json
|
||||
GeoJSON MultiLineStrings of [RA, Dec] degrees, J2000.
|
||||
|
||||
Stars (stars cut to Vmag <= MAX_MAG, default 5.5), 6 bytes each: RA uint16 (360 deg / 65536), Dec uint16 ((dec + 90) / 180 * 65535),
|
||||
Vmag uint8 ((V + 2) * 20), B-V uint8 ((B-V + 0.5) * 50; missing B-V stored as 0.65). Little endian, base64.
|
||||
Lines: per chain a uint8 vertex count then that many (RA uint16, Dec uint16) pairs, same scaling; chains concatenated; base64.
|
||||
"""
|
||||
import base64
|
||||
import gzip
|
||||
import hashlib
|
||||
import json
|
||||
import struct
|
||||
import sys
|
||||
|
||||
|
||||
def sha256(path):
|
||||
h = hashlib.sha256()
|
||||
with open(path, "rb") as f:
|
||||
h.update(f.read())
|
||||
return h.hexdigest()
|
||||
|
||||
|
||||
def ra16(deg):
|
||||
return int(round((deg % 360.0) / 360.0 * 65536.0)) % 65536
|
||||
|
||||
|
||||
def dec16(deg):
|
||||
return int(round((deg + 90.0) / 180.0 * 65535.0))
|
||||
|
||||
|
||||
def stars(path, max_mag):
|
||||
out = []
|
||||
for line in gzip.open(path, "rt", encoding="latin-1"):
|
||||
if len(line) < 114 or not line[75:77].strip():
|
||||
continue # entries struck from the catalogue carry no position
|
||||
try:
|
||||
ra = (int(line[75:77]) + int(line[77:79]) / 60.0 + float(line[79:83]) / 3600.0) * 15.0
|
||||
dec = int(line[84:86]) + int(line[86:88]) / 60.0 + int(line[88:90]) / 3600.0
|
||||
dec = -dec if line[83] == "-" else dec
|
||||
v = float(line[102:107])
|
||||
except ValueError:
|
||||
continue
|
||||
if v > max_mag:
|
||||
continue
|
||||
bv_text = line[109:114].strip()
|
||||
bv = float(bv_text) if bv_text else 0.65
|
||||
out.append((ra, dec, v, bv))
|
||||
out.sort(key=lambda s: s[2]) # brightest first: a prefix is the brighter stars
|
||||
return out
|
||||
|
||||
|
||||
def pack_stars(rows):
|
||||
buf = bytearray()
|
||||
for ra, dec, v, bv in rows:
|
||||
vq = min(255, max(0, int(round((v + 2.0) * 20.0))))
|
||||
bq = min(255, max(0, int(round((bv + 0.5) * 50.0))))
|
||||
buf += struct.pack("<HHBB", ra16(ra), dec16(dec), vq, bq)
|
||||
return bytes(buf)
|
||||
|
||||
|
||||
def pack_lines(path):
|
||||
with open(path, encoding="utf-8") as f:
|
||||
gj = json.load(f)
|
||||
buf = bytearray()
|
||||
chains = 0
|
||||
for feat in gj["features"]:
|
||||
geom = feat["geometry"]
|
||||
assert geom["type"] == "MultiLineString"
|
||||
for chain in geom["coordinates"]:
|
||||
assert 2 <= len(chain) < 256
|
||||
buf.append(len(chain))
|
||||
for lon, lat in chain:
|
||||
buf += struct.pack("<HH", ra16(lon), dec16(lat))
|
||||
chains += 1
|
||||
return bytes(buf), chains
|
||||
|
||||
|
||||
def wrap(b64, width=110):
|
||||
return "\n".join(b64[i : i + width] for i in range(0, len(b64), width))
|
||||
|
||||
|
||||
def main():
|
||||
bsc, lines, out = sys.argv[1:4]
|
||||
max_mag = float(sys.argv[4]) if len(sys.argv) > 4 else 5.5
|
||||
rows = stars(bsc, max_mag)
|
||||
star_bytes = pack_stars(rows)
|
||||
line_bytes, chains = pack_lines(lines)
|
||||
text = f"""/* eslint-disable */
|
||||
// GENERATED by scripts/ridge-sky/build-night-sky.py: do not edit. The night sky's data, J2000.
|
||||
// Stars: Yale Bright Star Catalogue, 5th revised ed. (Hoffleit & Warren 1991; public domain), Vmag <= {max_mag}, {len(rows)} stars.
|
||||
// source http://tdc-www.harvard.edu/catalogs/bsc5.dat.gz (copy of CDS/VizieR V/50), sha256 {sha256(bsc)}
|
||||
// Constellation lines: d3-celestial constellations.lines.json (Olaf Frohn, BSD-3-Clause), {chains} chains.
|
||||
// source https://github.com/ofrohn/d3-celestial/blob/master/data/constellations.lines.json, sha256 {sha256(lines)}
|
||||
// Layout: see the generator's docstring. Stars are sorted brightest first.
|
||||
|
||||
export const STAR_COUNT = {len(rows)};
|
||||
export const STARS_B64 = `
|
||||
{wrap(base64.b64encode(star_bytes).decode())}
|
||||
`;
|
||||
|
||||
export const LINE_CHAINS = {chains};
|
||||
export const LINES_B64 = `
|
||||
{wrap(base64.b64encode(line_bytes).decode())}
|
||||
`;
|
||||
"""
|
||||
with open(out, "w", encoding="utf-8", newline="\n") as f:
|
||||
f.write(text)
|
||||
print(f"{len(rows)} stars, {chains} chains, {len(star_bytes)} + {len(line_bytes)} bytes")
|
||||
|
||||
|
||||
main()
|
||||
Loading…
Reference in a new issue