2024-03-18 21:13:37 +00:00
|
|
|
#!/usr/bin/env python
|
2024-04-21 16:23:40 +00:00
|
|
|
# ▄████████▄ + ███ + ▄█████████ ███ +
|
|
|
|
# ███▀ ▀███ + + ███ ███▀ + ███ + +
|
|
|
|
# ███ + ███ ███ ███ █████████ ███ ███ ███ ███
|
2024-04-21 17:34:00 +00:00
|
|
|
# ███ +███ ███ ███ ███ ███▐██████ ███ ███ ███
|
2024-04-21 16:23:40 +00:00
|
|
|
# ███ + ███ ███+ ███ +███ ███ + ███ ███ + ███
|
|
|
|
# ███▄ ▄███ ███▄ ███ ███ + ███ + ███ ███▄ ███
|
|
|
|
# ▀████████▀ + ▀███████ ███▄ ███▄ ▀████ ▀███████
|
|
|
|
# + + + ███
|
|
|
|
# + ▀████████████████████████████████████████████████████▀
|
|
|
|
#
|
2024-04-07 23:08:32 +00:00
|
|
|
# This script requires the following file in the extra/ directory:
|
2024-03-18 21:13:37 +00:00
|
|
|
# https://github.com/astronexus/HYG-Database/blob/cbd21013d2bb89732b893be357a6f41836dbe614/hyg/CURRENT/hygdata_v41.csv
|
|
|
|
|
|
|
|
import csv
|
|
|
|
import sys
|
|
|
|
import math
|
2024-04-07 23:08:32 +00:00
|
|
|
import re
|
|
|
|
|
|
|
|
PATH = "extra/hygdata_v41.csv"
|
2024-03-18 21:13:37 +00:00
|
|
|
|
2024-03-18 21:56:51 +00:00
|
|
|
#def entry(ra_hour, ra_min, ra_sec, dec_deg, dec_min, dec_sec, mag, name, color_index):
|
|
|
|
# return [
|
|
|
|
# ra_hour*15 + ra_min*0.25 + ra_sec*0.004166,
|
|
|
|
# dec_deg + dec_min/60 + dec_sec/3600,
|
|
|
|
# mag,
|
|
|
|
# name,
|
|
|
|
# color_index,
|
|
|
|
# ]
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#CUSTOM_ENTRIES = [
|
|
|
|
# entry(0, 42, 44.3, 41, 16, 9, 3.44-15, 0.63, "Andromeda Galaxy"),
|
|
|
|
#]
|
|
|
|
|
2024-03-18 21:13:37 +00:00
|
|
|
# Lower apparent magnitude = brighter.
|
|
|
|
# Sun = -26.7
|
|
|
|
# Sirius = -1.44
|
|
|
|
# Betelgeuse = 0.45
|
|
|
|
# Polaris (north star) = 1.97
|
|
|
|
# Meissa (orion's head, 8th brightest star in orion) = 3.33
|
|
|
|
MAX_APPARENT_MAGNITUDE = 7.0
|
|
|
|
|
2024-04-19 01:38:13 +00:00
|
|
|
SOL_ABSMAG = 4.83
|
|
|
|
SOL_RADIUS = 696.3e6
|
|
|
|
SOL_LUMINOSITY = 3.828e26
|
2024-04-19 01:39:12 +00:00
|
|
|
STEFAN_BOLTZMANN_CONSTANT = 5.670374419e-8
|
2024-04-19 01:38:13 +00:00
|
|
|
|
2024-04-07 23:08:32 +00:00
|
|
|
print("// This file was autogenerated by \"genrate_starchart.py\" using data from the")
|
|
|
|
print("// HYG database: https://github.com/astronexus/HYG-Database/tree/main/hyg")
|
2024-03-18 21:13:37 +00:00
|
|
|
print("// License: CC BY-SA 4.0: https://creativecommons.org/licenses/by-sa/4.0/")
|
2024-04-18 22:42:39 +00:00
|
|
|
print("// Each star's values: (x, y, z, magnitude, absolute magnitude, color index, name)")
|
2024-04-14 20:29:51 +00:00
|
|
|
print("[")
|
2024-03-18 21:13:37 +00:00
|
|
|
|
|
|
|
|
2024-04-19 01:39:12 +00:00
|
|
|
def render(i, x, y, z, ra, dec, mag, absmag, ci, dist, name):
|
2024-03-18 21:56:51 +00:00
|
|
|
# Takes ra/deg in degrees
|
2024-03-18 21:13:37 +00:00
|
|
|
ra = float(ra)
|
|
|
|
dec = float(dec)
|
|
|
|
mag = float(mag)
|
2024-04-18 22:42:39 +00:00
|
|
|
x, y, z = float(x), float(y), float(z)
|
2024-04-07 23:08:32 +00:00
|
|
|
name = re.sub(r'\s+', ' ', name)
|
2024-04-18 21:39:34 +00:00
|
|
|
if name == 'Sol':
|
|
|
|
return
|
2024-03-18 21:13:37 +00:00
|
|
|
|
2024-04-19 01:39:12 +00:00
|
|
|
#radius = star_radius(float(ci), float(absmag))
|
|
|
|
|
2024-04-18 22:42:39 +00:00
|
|
|
# distance = 1.0
|
|
|
|
# ra_radians = math.radians(ra * 15) # ra is in [0, 24], multiplying by 15 gives degrees in [0, 360]
|
|
|
|
# dec_radians = math.radians(dec)
|
|
|
|
# #print(f"ra_radians={ra_radians}, dec_radians={dec_radians}, dec={dec}, ra={ra}", file=sys.stderr)
|
|
|
|
# x = distance * math.cos(dec_radians) * math.cos(-ra_radians)
|
|
|
|
# y = distance * math.cos(dec_radians) * math.sin(-ra_radians)
|
|
|
|
# z = distance * math.sin(dec_radians)
|
|
|
|
#
|
|
|
|
# # Correct for differences in coordinate system axes
|
|
|
|
# x, y, z = x, z, y
|
2024-03-18 21:13:37 +00:00
|
|
|
|
2024-04-07 23:08:32 +00:00
|
|
|
#brightness = 2.512 ** (0 - mag)
|
|
|
|
|
2024-04-18 22:42:39 +00:00
|
|
|
print(f'({x:.04},{y:.04},{z:.04},{mag:.04},{absmag:.04},{ci},"{name}"),')
|
2024-03-18 21:13:37 +00:00
|
|
|
|
|
|
|
|
2024-04-07 23:08:32 +00:00
|
|
|
def clean_name(string):
|
|
|
|
return "".join([c for c in string if c.isalnum() or c in ' -_'])
|
2024-03-18 21:13:37 +00:00
|
|
|
|
|
|
|
|
2024-04-19 01:39:12 +00:00
|
|
|
def star_radius(color_index, absolute_magnitude):
|
|
|
|
# Convert color index to temperature (using Ballesteros' formula approximation for B-V)
|
|
|
|
temp = 4600 * ((1 / (0.92 * color_index + 1.7)) + (1 / (0.92 * color_index + 0.62)))
|
|
|
|
|
|
|
|
# Convert absolute magnitude to luminosity (in solar luminosities)
|
|
|
|
lum = 10 ** (0.4 * (SOL_ABSMAG - absolute_magnitude))
|
|
|
|
|
|
|
|
# Calculate the radius using Stefan-Boltzmann law (output should be in meters)
|
|
|
|
radius = math.sqrt(lum * SOL_LUMINOSITY / (4 * math.pi * STEFAN_BOLTZMANN_CONSTANT * temp ** 4)) # Luminosity in watts for the Sun ~ 3.828e26
|
|
|
|
|
|
|
|
# Convert radius from meters to solar radii (1 solar radius ≈ 6.96e8 meters)
|
|
|
|
radius_solar = radius / SOL_RADIUS
|
|
|
|
|
|
|
|
return radius_solar
|
|
|
|
|
|
|
|
|
2024-03-18 21:13:37 +00:00
|
|
|
total = 0
|
|
|
|
count = 0
|
2024-03-18 21:56:51 +00:00
|
|
|
count_extra = 0
|
2024-03-21 01:11:07 +00:00
|
|
|
entries = []
|
2024-04-07 23:08:32 +00:00
|
|
|
with open(PATH, "r", encoding="utf-8") as f:
|
2024-04-19 01:39:12 +00:00
|
|
|
for index, entry in enumerate(csv.DictReader(f)):
|
|
|
|
entries.append((index, entry))
|
2024-03-21 01:11:07 +00:00
|
|
|
|
2024-04-19 01:39:12 +00:00
|
|
|
entries.sort(key=lambda entry: float(entry[1]['mag']))
|
2024-03-21 01:11:07 +00:00
|
|
|
|
2024-04-19 01:39:12 +00:00
|
|
|
for index, entry in entries:
|
2024-03-21 01:11:07 +00:00
|
|
|
total += 1
|
|
|
|
ra = entry['ra']
|
|
|
|
dec = entry['dec']
|
2024-04-18 22:42:39 +00:00
|
|
|
x = entry['x']
|
|
|
|
y = entry['y']
|
|
|
|
z = entry['z']
|
2024-03-21 01:11:07 +00:00
|
|
|
mag = entry['mag']
|
2024-04-18 22:42:39 +00:00
|
|
|
absmag = entry['absmag']
|
2024-03-21 01:11:07 +00:00
|
|
|
ci = entry['ci']
|
2024-04-07 23:08:32 +00:00
|
|
|
dist = entry['dist']
|
|
|
|
name = clean_name(entry['proper'])
|
|
|
|
if not name:
|
|
|
|
name = clean_name(entry['bf'])
|
|
|
|
if not name:
|
|
|
|
name = clean_name(entry['gl'])
|
|
|
|
|
2024-03-21 01:11:07 +00:00
|
|
|
if not all([ra, dec, mag, ci]):
|
|
|
|
continue
|
|
|
|
if float(mag) > MAX_APPARENT_MAGNITUDE:
|
|
|
|
continue
|
2024-04-19 01:39:12 +00:00
|
|
|
render(index, x, y, z, ra, dec, mag, absmag, ci, dist, name)
|
2024-03-21 01:11:07 +00:00
|
|
|
count += 1
|
2024-03-18 21:56:51 +00:00
|
|
|
#for entry in CUSTOM_ENTRIES:
|
|
|
|
# render(entry[0], entry[1], entry[2], entry[3], entry[4])
|
|
|
|
# count_extra += 1
|
2024-03-18 21:13:37 +00:00
|
|
|
|
2024-04-14 20:29:51 +00:00
|
|
|
print("]")
|
2024-03-18 21:56:51 +00:00
|
|
|
print(f"Wrote {count} stars (total={total}) + {count_extra} extra entries.", file=sys.stderr)
|