#!/usr/bin/env python3 # Packs the Yale Bright Star Catalog (5th ed.) into public/assets/sky/stars.bin # for the sky component: four little-endian float32s per star, right ascension # and declination (J2000, radians), V magnitude and B-V colour index. # # curl -O http://tdc-www.harvard.edu/catalogs/bsc5.dat.gz # python3 tools/sky/build-stars.py bsc5.dat.gz public/assets/sky/stars.bin # # Byte columns follow the catalog's ReadMe (CDS V/50). import gzip import math import struct import sys def main(src, dst): opener = gzip.open if src.endswith('.gz') else open stars = [] with opener(src, 'rt', encoding='ascii', errors='replace') as f: for line in f: line = line.rstrip('\n').ljust(197) if not line[75:77].strip() or not line[102:107].strip(): continue # the 14 entries that turned out not to be stars ra = (int(line[75:77]) + int(line[77:79]) / 60 + float(line[79:83]) / 3600) * 15 dec = int(line[84:86]) + int(line[86:88]) / 60 + int(line[88:90]) / 3600 if line[83] == '-': dec = -dec vmag = float(line[102:107]) bv = float(line[109:114]) if line[109:114].strip() else 0.6 stars.append((math.radians(ra), math.radians(dec), vmag, bv)) with open(dst, 'wb') as out: for s in stars: out.write(struct.pack('<4f', *s)) print(f'{len(stars)} stars, {min(s[2] for s in stars):.2f} to {max(s[2] for s in stars):.2f} mag -> {dst}') if __name__ == '__main__': main(sys.argv[1], sys.argv[2])