roche_vega.py
roche_vega.py (PY)
| 1 | #!/usr/bin/env python3 |
| 2 | """ |
| 3 | Vega (alpha Lyrae) and the Pole-on Calibration Mirage |
| 4 | ===================================================== |
| 5 | First-principles Roche equipotential + gravity darkening (von Zeipel 1924 vs. |
| 6 | Espinosa Lara & Rieutord 2011) + Milne-Eddington wavelength-dependent gray |
| 7 | atmosphere integrator in pure Python (zero external dependencies). |
| 8 | |
| 9 | Generates all numerical tables reported in notes.md and writes vega_figures.svg. |
| 10 | """ |
| 11 | |
| 12 | from __future__ import annotations |
| 13 | |
| 14 | import math |
| 15 | from pathlib import Path |
| 16 | |
| 17 | # Physical constants (SI) |
| 18 | SIGMA_SB = 5.670374419e-8 |
| 19 | H_PLANCK = 6.62607015e-34 |
| 20 | C_LIGHT = 2.99792458e8 |
| 21 | K_BOLTZ = 1.380649e-23 |
| 22 | R_SUN = 6.957e8 |
| 23 | L_SUN = 3.828e26 |
| 24 | MAGIC_ANGLE_DEG = math.degrees(math.acos(1.0 / math.sqrt(3.0))) |
| 25 | |
| 26 | |
| 27 | # --------------------------------------------------------------------------- |
| 28 | # 1. Quadrature (Gauss-Laguerre for radiative transfer, Gauss-Legendre for phi) |
| 29 | # --------------------------------------------------------------------------- |
| 30 | def gauss_laguerre(n: int) -> tuple[list[float], list[float]]: |
| 31 | def L_and_dL(x: float, order: int) -> tuple[float, float, float]: |
| 32 | L0, L1 = 1.0, 1.0 - x |
| 33 | for k in range(2, order + 1): |
| 34 | L2 = ((2 * k - 1 - x) * L1 - (k - 1) * L0) / k |
| 35 | L0, L1 = L1, L2 |
| 36 | dL = order * (L1 - L0) / x |
| 37 | return L1, dL, L0 |
| 38 | |
| 39 | nodes: list[float] = [] |
| 40 | weights: list[float] = [] |
| 41 | for i in range(1, n + 1): |
| 42 | if i == 1: |
| 43 | z = 3.0 / (1.0 + 2.4 * n) |
| 44 | elif i == 2: |
| 45 | z = nodes[-1] + 15.0 / (1.0 + 2.5 * n) |
| 46 | else: |
| 47 | ai = i - 2 |
| 48 | z = nodes[-1] + ((1.0 + 2.55 * ai) / (1.9 * ai)) * (nodes[-1] - nodes[-2]) |
| 49 | for _ in range(40): |
| 50 | Ln, dLn, _ = L_and_dL(z, n) |
| 51 | dz = Ln / dLn |
| 52 | z -= dz |
| 53 | if abs(dz) < 1e-14 * max(1.0, z): |
| 54 | break |
| 55 | w = z / (((n + 1) ** 2) * (L_and_dL(z, n + 1)[0] ** 2)) |
| 56 | nodes.append(z) |
| 57 | weights.append(w) |
| 58 | return nodes, weights |
| 59 | |
| 60 | |
| 61 | def gauss_legendre(n: int) -> tuple[list[float], list[float]]: |
| 62 | nodes: list[float] = [] |
| 63 | weights: list[float] = [] |
| 64 | m = (n + 1) // 2 |
| 65 | for i in range(1, m + 1): |
| 66 | x = math.cos(math.pi * (i - 0.25) / (n + 0.5)) |
| 67 | dp = 1.0 |
| 68 | for _ in range(30): |
| 69 | p0, p1 = 1.0, x |
| 70 | for k in range(2, n + 1): |
| 71 | p0, p1 = p1, ((2 * k - 1) * x * p1 - (k - 1) * p0) / k |
| 72 | dp = n * (x * p1 - p0) / (x * x - 1.0) |
| 73 | dx = p1 / dp |
| 74 | x -= dx |
| 75 | if abs(dx) < 1e-15: |
| 76 | break |
| 77 | w = 2.0 / ((1.0 - x * x) * dp * dp) |
| 78 | nodes.append(-x) |
| 79 | weights.append(w) |
| 80 | if i != n + 1 - i: |
| 81 | nodes.append(x) |
| 82 | weights.append(w) |
| 83 | pairs = sorted(zip(nodes, weights)) |
| 84 | return [p[0] for p in pairs], [p[1] for p in pairs] |
| 85 | |
| 86 | |
| 87 | GL_T, GL_W = gauss_laguerre(12) |
| 88 | GP_X, GP_W = gauss_legendre(12) |
| 89 | |
| 90 | |
| 91 | # --------------------------------------------------------------------------- |
| 92 | # 2. Roche Equipotential & Gravity Darkening (von Zeipel & ELR 2011) |
| 93 | # --------------------------------------------------------------------------- |
| 94 | def omega_from_Om_ratio(Om_over_Omc: float) -> float: |
| 95 | """Invert Om/Om_c = w * (3 / (2 + w^2))^(3/2) for w = Om / Om_K(R_e) in [0, 1].""" |
| 96 | if Om_over_Omc <= 0.0: |
| 97 | return 0.0 |
| 98 | if Om_over_Omc >= 1.0: |
| 99 | return 1.0 |
| 100 | lo, hi = 0.0, 1.0 |
| 101 | for _ in range(80): |
| 102 | mid = 0.5 * (lo + hi) |
| 103 | val = mid * (3.0 / (2.0 + mid * mid)) ** 1.5 |
| 104 | if val < Om_over_Omc: |
| 105 | lo = mid |
| 106 | else: |
| 107 | hi = mid |
| 108 | return 0.5 * (lo + hi) |
| 109 | |
| 110 | |
| 111 | def roche_r(theta: float, w: float) -> float: |
| 112 | """Dimensionless radius r / R_e solving 1/(w^2 r) + (1/2) r^2 sin^2(theta) = 1/w^2 + 1/2.""" |
| 113 | if w == 0.0: |
| 114 | return 1.0 |
| 115 | s = math.sin(theta) |
| 116 | r_p = 2.0 / (2.0 + w * w) |
| 117 | if s < 1e-12: |
| 118 | return r_p |
| 119 | r = r_p + (1.0 - r_p) * s * s |
| 120 | c1 = 1.0 + 0.5 * w * w |
| 121 | a = 0.5 * (w * s) ** 2 |
| 122 | for _ in range(30): |
| 123 | f = a * r**3 - c1 * r + 1.0 |
| 124 | df = 3.0 * a * r**2 - c1 |
| 125 | step = f / df |
| 126 | r -= step |
| 127 | if abs(step) < 1e-15: |
| 128 | break |
| 129 | return r |
| 130 | |
| 131 | |
| 132 | def solve_vartheta(theta: float, r: float, w: float) -> float: |
| 133 | """Solve Espinosa Lara & Rieutord (2011) Eq. (24) for flux streamline angle vartheta.""" |
| 134 | if w == 0.0: |
| 135 | return theta |
| 136 | south = theta > 0.5 * math.pi |
| 137 | th = math.pi - theta if south else theta |
| 138 | if th <= 1e-10: |
| 139 | return math.pi if south else 0.0 |
| 140 | if th >= 0.5 * math.pi - 1e-10: |
| 141 | return 0.5 * math.pi |
| 142 | rhs = ( |
| 143 | (1.0 / 3.0) * (w**2) * (r**3) * (math.cos(th) ** 3) |
| 144 | + math.cos(th) |
| 145 | + math.log(math.tan(0.5 * th)) |
| 146 | ) |
| 147 | lo, hi = th, 0.5 * math.pi - 1e-15 |
| 148 | x = min(0.5 * (lo + hi), th + 0.05) |
| 149 | for _ in range(60): |
| 150 | fx = math.cos(x) + math.log(math.tan(0.5 * x)) - rhs |
| 151 | if fx < 0.0: |
| 152 | lo = x |
| 153 | else: |
| 154 | hi = x |
| 155 | if abs(fx) < 1e-14 or (hi - lo) < 1e-14: |
| 156 | break |
| 157 | dfx = (math.cos(x) ** 2) / math.sin(x) |
| 158 | xn = x - fx / max(dfx, 1e-15) |
| 159 | x = 0.5 * (lo + hi) if (xn <= lo or xn >= hi) else xn |
| 160 | return (math.pi - x) if south else x |
| 161 | |
| 162 | |
| 163 | def surface_point(theta: float, w: float, model: str = "elr", beta: float = 0.25): |
| 164 | r = roche_r(theta, w) |
| 165 | s, c = math.sin(theta), math.cos(theta) |
| 166 | g_r = -1.0 / (r * r) + w * w * r * s * s |
| 167 | g_th = w * w * r * s * c |
| 168 | g_mag = math.hypot(g_r, g_th) |
| 169 | n_r = -g_r / g_mag |
| 170 | n_th = -g_th / g_mag |
| 171 | n_rho = n_r * s + n_th * c |
| 172 | n_z = n_r * c - n_th * s |
| 173 | |
| 174 | r_p = 2.0 / (2.0 + w * w) |
| 175 | g_p = 1.0 / (r_p * r_p) |
| 176 | |
| 177 | if model == "elr": |
| 178 | th_f = math.pi - theta if theta > 0.5 * math.pi else theta |
| 179 | if th_f <= 1e-7: |
| 180 | F_w = math.exp((2.0 / 3.0) * w * w * r**3) |
| 181 | elif th_f >= 0.5 * math.pi - 1e-7: |
| 182 | F_w = (1.0 - w * w * r**3) ** (-2.0 / 3.0) |
| 183 | else: |
| 184 | vt = solve_vartheta(th_f, r, w) |
| 185 | F_w = (math.tan(vt) / math.tan(th_f)) ** 2 |
| 186 | F_w_p = math.exp((2.0 / 3.0) * w * w * r_p**3) |
| 187 | F_rel = (F_w * g_mag) / (F_w_p * g_p) |
| 188 | T_rel = F_rel**0.25 |
| 189 | elif model == "vz": |
| 190 | T_rel = (g_mag / g_p) ** beta |
| 191 | F_rel = T_rel**4 |
| 192 | elif model == "uniform": |
| 193 | T_rel = 1.0 |
| 194 | F_rel = 1.0 |
| 195 | else: |
| 196 | raise ValueError(f"Unknown model: {model}") |
| 197 | |
| 198 | return r, g_mag, n_r, n_rho, n_z, T_rel, F_rel |
| 199 | |
| 200 | |
| 201 | # --------------------------------------------------------------------------- |
| 202 | # 3. Radiative Transfer & Exact Axisymmetric Ring Integrals |
| 203 | # --------------------------------------------------------------------------- |
| 204 | def planck_lambda(lam_m: float, T: float) -> float: |
| 205 | x = (H_PLANCK * C_LIGHT) / (lam_m * K_BOLTZ * T) |
| 206 | if x > 700.0: |
| 207 | return 0.0 |
| 208 | return (2.0 * H_PLANCK * C_LIGHT * C_LIGHT) / ((lam_m**5) * math.expm1(x)) |
| 209 | |
| 210 | |
| 211 | def I_gray_lambda(lam_m: float, T_eff: float, mu: float) -> float: |
| 212 | """Emergent intensity of a Milne-Eddington gray atmosphere T^4(tau) = 3/4 T_eff^4 (tau + 2/3).""" |
| 213 | acc = 0.0 |
| 214 | for t, wt in zip(GL_T, GL_W): |
| 215 | T_tau = T_eff * ((0.75 * (mu * t + 2.0 / 3.0)) ** 0.25) |
| 216 | acc += wt * planck_lambda(lam_m, T_tau) |
| 217 | return acc |
| 218 | |
| 219 | |
| 220 | def ring_visibility_moments(n_rho: float, n_z: float, inc: float, u: float = 0.0) -> float: |
| 221 | """Exact analytic azimuthal integral int_{mu>0} mu * (1 - u + u*mu)/(1 - u/3) dphi.""" |
| 222 | A = n_z * math.cos(inc) |
| 223 | B = n_rho * math.sin(inc) |
| 224 | if B <= 1e-15: |
| 225 | if A <= 0.0: |
| 226 | return 0.0 |
| 227 | M1 = 2.0 * math.pi * A |
| 228 | M2 = 2.0 * math.pi * A * A |
| 229 | elif A >= B: |
| 230 | M1 = 2.0 * math.pi * A |
| 231 | M2 = 2.0 * math.pi * (A * A + 0.5 * B * B) |
| 232 | elif A <= -B: |
| 233 | return 0.0 |
| 234 | else: |
| 235 | c0 = max(-1.0, min(1.0, -A / B)) |
| 236 | phi0 = math.acos(c0) |
| 237 | s0 = math.sqrt(max(0.0, 1.0 - c0 * c0)) |
| 238 | M1 = 2.0 * (A * phi0 + B * s0) |
| 239 | M2 = 2.0 * ((A * A + 0.5 * B * B) * phi0 + 1.5 * A * B * s0) |
| 240 | return ((1.0 - u) * M1 + u * M2) / (1.0 - u / 3.0) |
| 241 | |
| 242 | |
| 243 | def build_star( |
| 244 | w: float, |
| 245 | R_e_rsun: float, |
| 246 | T_pole: float, |
| 247 | model: str = "elr", |
| 248 | beta: float = 0.25, |
| 249 | u: float = 0.6, |
| 250 | N_th: int = 240, |
| 251 | ): |
| 252 | R_e = R_e_rsun * R_SUN |
| 253 | dth = math.pi / N_th |
| 254 | rings = [] |
| 255 | L_bol = 0.0 |
| 256 | area = 0.0 |
| 257 | for k in range(N_th): |
| 258 | th = (k + 0.5) * dth |
| 259 | r, g_mag, n_r, n_rho, n_z, T_rel, _ = surface_point(th, w, model=model, beta=beta) |
| 260 | dA_dphi = (R_e**2) * (r * r) * math.sin(th) / n_r * dth |
| 261 | T = T_pole * T_rel |
| 262 | F = SIGMA_SB * (T**4) |
| 263 | L_bol += 2.0 * math.pi * dA_dphi * F |
| 264 | area += 2.0 * math.pi * dA_dphi |
| 265 | rings.append((th, r, n_r, n_rho, n_z, dA_dphi, T, F)) |
| 266 | |
| 267 | def L_app(inc_deg: float) -> float: |
| 268 | inc = math.radians(inc_deg) |
| 269 | tot = 0.0 |
| 270 | for (_, _, _, n_rho, n_z, dA_dphi, _, F) in rings: |
| 271 | tot += F * dA_dphi * ring_visibility_moments(n_rho, n_z, inc, u=u) |
| 272 | return 4.0 * tot |
| 273 | |
| 274 | return L_bol, area, rings, L_app |
| 275 | |
| 276 | |
| 277 | def monochromatic_flux(rings, lam_m: float, inc_deg: float, gray_atm: bool = True) -> float: |
| 278 | inc = math.radians(inc_deg) |
| 279 | ci, si = math.cos(inc), math.sin(inc) |
| 280 | tot = 0.0 |
| 281 | if not gray_atm: |
| 282 | for (_, _, _, n_rho, n_z, dA_dphi, T, _) in rings: |
| 283 | tot += dA_dphi * planck_lambda(lam_m, T) * ring_visibility_moments(n_rho, n_z, inc, u=0.0) |
| 284 | return 4.0 * tot |
| 285 | for (_, _, _, n_rho, n_z, dA_dphi, T, _) in rings: |
| 286 | A = n_z * ci |
| 287 | B = n_rho * si |
| 288 | if A <= -B: |
| 289 | continue |
| 290 | phi0 = math.pi if (B <= 1e-15 or A >= B) else math.acos(max(-1.0, min(1.0, -A / B))) |
| 291 | ring_acc = 0.0 |
| 292 | half = 0.5 * phi0 |
| 293 | for gx, gw in zip(GP_X, GP_W): |
| 294 | phi = half * (gx + 1.0) |
| 295 | mu = A + B * math.cos(phi) |
| 296 | if mu > 0.0: |
| 297 | ring_acc += gw * mu * I_gray_lambda(lam_m, T, mu) |
| 298 | tot += dA_dphi * (2.0 * half * ring_acc) |
| 299 | return 4.0 * math.pi * tot |
| 300 | |
| 301 | |
| 302 | def spherical_flux(lam_m: float, T_eff: float, R_rsun: float, gray_atm: bool = True) -> float: |
| 303 | R = R_rsun * R_SUN |
| 304 | if not gray_atm: |
| 305 | return 4.0 * (math.pi**2) * (R**2) * planck_lambda(lam_m, T_eff) |
| 306 | acc = 0.0 |
| 307 | for gx, gw in zip(GP_X, GP_W): |
| 308 | mu = 0.5 * (gx + 1.0) |
| 309 | acc += 0.5 * gw * mu * I_gray_lambda(lam_m, T_eff, mu) |
| 310 | return 8.0 * (math.pi**2) * (R**2) * acc |
| 311 | |
| 312 | |
| 313 | def fit_single_T(rings, inc_deg: float, opt_lams_nm: list[int], gray_atm: bool = True): |
| 314 | true_vals = [monochromatic_flux(rings, nm * 1e-9, inc_deg, gray_atm=gray_atm) for nm in opt_lams_nm] |
| 315 | |
| 316 | def loss(T: float) -> tuple[float, float]: |
| 317 | ratios = [ |
| 318 | math.log(tv / spherical_flux(nm * 1e-9, T, 1.0, gray_atm=gray_atm)) |
| 319 | for tv, nm in zip(true_vals, opt_lams_nm) |
| 320 | ] |
| 321 | ml = sum(ratios) / len(ratios) |
| 322 | return sum((r - ml) ** 2 for r in ratios), math.exp(0.5 * ml) |
| 323 | |
| 324 | a, b = 6000.0, 12000.0 |
| 325 | gr = (math.sqrt(5.0) - 1.0) / 2.0 |
| 326 | c, d = b - gr * (b - a), a + gr * (b - a) |
| 327 | fc, _ = loss(c) |
| 328 | fd, _ = loss(d) |
| 329 | for _ in range(55): |
| 330 | if fc < fd: |
| 331 | b, d, fd = d, c, fc |
| 332 | c = b - gr * (b - a) |
| 333 | fc, _ = loss(c) |
| 334 | else: |
| 335 | a, c, fc = c, d, fd |
| 336 | d = a + gr * (b - a) |
| 337 | fd, _ = loss(d) |
| 338 | Tb = 0.5 * (a + b) |
| 339 | _, Rb = loss(Tb) |
| 340 | return Tb, Rb |
| 341 | |
| 342 | |
| 343 | # --------------------------------------------------------------------------- |
| 344 | # 4. Gulliver-Hill-Adelman (1994) Spectral Line Profile Simulator |
| 345 | # --------------------------------------------------------------------------- |
| 346 | def saha_FeI_weight(T: float) -> float: |
| 347 | kT_eV = 8.617333262e-5 * T |
| 348 | return (T**-2.5) * math.exp(7.902 / kT_eV) |
| 349 | |
| 350 | |
| 351 | def boltzmann_HeI_weight(T: float) -> float: |
| 352 | kT_eV = 8.617333262e-5 * T |
| 353 | return math.exp(-20.96 / kT_eV) |
| 354 | |
| 355 | |
| 356 | def compute_line_profile( |
| 357 | rings, inc_deg: float, v_eq_kms: float, lam_m: float, weight_fn, v_grid: list[float], sigma_th: float = 2.0 |
| 358 | ): |
| 359 | inc = math.radians(inc_deg) |
| 360 | ci, si = math.cos(inc), math.sin(inc) |
| 361 | N_phi = 240 |
| 362 | dphi = 2.0 * math.pi / N_phi |
| 363 | prof = [0.0] * len(v_grid) |
| 364 | inv_2s2 = 0.5 / (sigma_th * sigma_th) |
| 365 | norm_g = 1.0 / (math.sqrt(2.0 * math.pi) * sigma_th) |
| 366 | u_v = 0.42 |
| 367 | |
| 368 | for (th, r, _, n_rho, n_z, dA_dphi, T, _) in rings: |
| 369 | A = n_z * ci |
| 370 | B = n_rho * si |
| 371 | if A <= -B: |
| 372 | continue |
| 373 | w_T = weight_fn(T) |
| 374 | v_ring_sini = v_eq_kms * r * math.sin(th) * si |
| 375 | B_cont = planck_lambda(lam_m, T) |
| 376 | for m in range(N_phi): |
| 377 | phi = (m + 0.5) * dphi |
| 378 | mu = A + B * math.cos(phi) |
| 379 | if mu <= 0.0: |
| 380 | continue |
| 381 | I_c = B_cont * (1.0 - u_v * (1.0 - mu)) |
| 382 | w_line = dA_dphi * dphi * mu * I_c * w_T |
| 383 | v_los = v_ring_sini * math.sin(phi) |
| 384 | for idx, vg in enumerate(v_grid): |
| 385 | dv = vg - v_los |
| 386 | if abs(dv) < 5.0 * sigma_th: |
| 387 | prof[idx] += w_line * norm_g * math.exp(-dv * dv * inv_2s2) |
| 388 | |
| 389 | dv_step = v_grid[1] - v_grid[0] |
| 390 | ew = sum(prof) * dv_step |
| 391 | return [val / ew for val in prof] |
| 392 | |
| 393 | |
| 394 | # --------------------------------------------------------------------------- |
| 395 | # 5. SVG Figure Generator (3-panel clean visual summary) |
| 396 | # --------------------------------------------------------------------------- |
| 397 | def write_svg(out_path: Path, w_mon: float, Lb_mon: float, Lfn_mon, c2_mon: float, v_grid, p_unif, p_fe1, p_he1, p_fe1_auf): |
| 398 | # Panel 1 (left): Meridional cross-section of Vega (Om/Omc=0.774) vs Sphere vs Breakup (1.0) |
| 399 | # Panel 2 (middle): L_app(i)/L_bol vs inclination i (exact vs pure P2) |
| 400 | # Panel 3 (right): Normalized absorption line profiles (Fe I vs Uniform vs He I vs Auf06 Fe I) |
| 401 | W, H = 1080, 380 |
| 402 | |
| 403 | def poly_roche(w: float, cx: float, cy: float, scale: float, n: int = 180) -> str: |
| 404 | pts = [] |
| 405 | # Scale so polar radius is fixed at R_p_px = scale (shows centrifugal equatorial bulge!) |
| 406 | r_p = 2.0 / (2.0 + w * w) |
| 407 | for k in range(n + 1): |
| 408 | ang = 2.0 * math.pi * k / n |
| 409 | th = ang if ang <= math.pi else 2.0 * math.pi - ang |
| 410 | r_norm = roche_r(th, w) / r_p # in units of R_pole |
| 411 | x = cx + scale * r_norm * math.sin(ang) |
| 412 | y = cy - scale * r_norm * math.cos(ang) |
| 413 | pts.append(f"{x:.1f},{y:.1f}") |
| 414 | return " ".join(pts) |
| 415 | |
| 416 | # Panel 1 coords |
| 417 | p1_cx, p1_cy, p1_rp = 175.0, 195.0, 86.0 |
| 418 | pts_sphere = poly_roche(0.0, p1_cx, p1_cy, p1_rp) |
| 419 | pts_vega = poly_roche(w_mon, p1_cx, p1_cy, p1_rp) |
| 420 | pts_crit = poly_roche(0.999, p1_cx, p1_cy, p1_rp) |
| 421 | |
| 422 | # Panel 2 coords: x in [390, 690] -> i in [0, 90], y in [65, 305] -> L_app/L_bol in [0.85, 1.25] |
| 423 | p2_x0, p2_x1, p2_y0, p2_y1 = 400.0, 695.0, 60.0, 305.0 |
| 424 | def p2_xy(inc_deg: float, ratio: float) -> tuple[float, float]: |
| 425 | x = p2_x0 + (inc_deg / 90.0) * (p2_x1 - p2_x0) |
| 426 | y = p2_y1 - ((ratio - 0.85) / 0.40) * (p2_y1 - p2_y0) |
| 427 | return x, y |
| 428 | |
| 429 | curve_exact = [] |
| 430 | curve_p2 = [] |
| 431 | for inc in range(0, 91, 2): |
| 432 | r_ex = Lfn_mon(float(inc)) / Lb_mon |
| 433 | mu = math.cos(math.radians(inc)) |
| 434 | r_p2 = 1.0 + c2_mon * 0.5 * (3 * mu * mu - 1.0) |
| 435 | x, y = p2_xy(inc, r_ex) |
| 436 | curve_exact.append(f"{x:.1f},{y:.1f}") |
| 437 | x2, y2 = p2_xy(inc, r_p2) |
| 438 | curve_p2.append(f"{x2:.1f},{y2:.1f}") |
| 439 | |
| 440 | x_earth, y_earth = p2_xy(6.2, Lfn_mon(6.2) / Lb_mon) |
| 441 | x_magic, y_magic = p2_xy(MAGIC_ANGLE_DEG, 1.0) |
| 442 | x_eq, y_eq = p2_xy(90.0, Lfn_mon(90.0) / Lb_mon) |
| 443 | _, y_one = p2_xy(0.0, 1.0) |
| 444 | |
| 445 | # Panel 3 coords: x in [765, 1055] -> v in [-26, 26], y in [60, 305] -> absorption depth 0..1.05 |
| 446 | p3_x0, p3_x1, p3_y0, p3_y1 = 765.0, 1055.0, 60.0, 305.0 |
| 447 | def line_pts(prof: list[float]) -> str: |
| 448 | pk = max(prof) |
| 449 | pts = [] |
| 450 | for v, val in zip(v_grid, prof): |
| 451 | if -26 <= v <= 26: |
| 452 | x = p3_x0 + ((v + 26.0) / 52.0) * (p3_x1 - p3_x0) |
| 453 | # Absorption line hangs downward from continuum y = p3_y0 + 18 |
| 454 | y = (p3_y0 + 18.0) + (val / pk) * (p3_y1 - p3_y0 - 32.0) |
| 455 | pts.append(f"{x:.1f},{y:.1f}") |
| 456 | return " ".join(pts) |
| 457 | |
| 458 | s_unif = line_pts(p_unif) |
| 459 | s_fe1 = line_pts(p_fe1) |
| 460 | s_he1 = line_pts(p_he1) |
| 461 | s_auf = line_pts(p_fe1_auf) |
| 462 | |
| 463 | svg = f'''<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 {W} {H}" font-family="ui-sans-serif, system-ui, sans-serif"> |
| 464 | <defs> |
| 465 | <radialGradient id="vegaGrad" cx="50%" cy="50%" r="55%" fx="50%" fy="15%"> |
| 466 | <stop offset="0%" stop-color="#dbeafe"/> |
| 467 | <stop offset="55%" stop-color="#93c5fd"/> |
| 468 | <stop offset="100%" stop-color="#f59e0b" stop-opacity="0.75"/> |
| 469 | </radialGradient> |
| 470 | </defs> |
| 471 | <rect width="{W}" height="{H}" fill="#0f172a"/> |
| 472 | |
| 473 | <!-- Title --> |
| 474 | <text x="24" y="30" fill="#f8fafc" font-size="16" font-weight="700">Vega (α Lyrae): Roche Shape, Quadrupole Luminosity Bias, and Flat-Bottomed Line Split</text> |
| 475 | |
| 476 | <!-- PANEL 1: Roche Cross-Section --> |
| 477 | <text x="{p1_cx}" y="55" fill="#cbd5e1" font-size="12.5" font-weight="600" text-anchor="middle">1. Meridional Roche Profile (fixed R_pole)</text> |
| 478 | <polygon points="{pts_crit}" fill="none" stroke="#475569" stroke-width="1.2" stroke-dasharray="4,4"/> |
| 479 | <polygon points="{pts_vega}" fill="url(#vegaGrad)" fill-opacity="0.35" stroke="#60a5fa" stroke-width="2.2"/> |
| 480 | <polygon points="{pts_sphere}" fill="none" stroke="#94a3b8" stroke-width="1.2" stroke-dasharray="2,3"/> |
| 481 | <!-- Spin axis & Earth line of sight (6.2 deg) --> |
| 482 | <line x1="{p1_cx}" y1="74" x2="{p1_cx}" y2="316" stroke="#64748b" stroke-width="1" stroke-dasharray="3,3"/> |
| 483 | <line x1="{p1_cx}" y1="{p1_cy}" x2="{p1_cx + 125*math.sin(math.radians(6.2)):.1f}" y2="{p1_cy - 125*math.cos(math.radians(6.2)):.1f}" stroke="#38bdf8" stroke-width="1.8"/> |
| 484 | <text x="{p1_cx + 20}" y="82" fill="#38bdf8" font-size="11">Earth (i = 6.2°)</text> |
| 485 | <text x="{p1_cx}" y="102" fill="#e0f2fe" font-size="11" text-anchor="middle">Pole: 10,070 K</text> |
| 486 | <text x="{p1_cx + 102}" y="{p1_cy + 14}" fill="#fbbf24" font-size="11">Eq: 8,984 K</text> |
| 487 | <text x="32" y="336" fill="#94a3b8" font-size="10.5">Solid blue: Vega (Ω/Ω_c = 0.774, R_e/R_p = 1.127)</text> |
| 488 | <text x="32" y="352" fill="#64748b" font-size="10.5">Outer dash: breakup limit (R_e/R_p = 1.500); Inner dot: sphere</text> |
| 489 | |
| 490 | <!-- PANEL 2: L_app(i) / L_bol --> |
| 491 | <text x="{0.5*(p2_x0+p2_x1):.1f}" y="50" fill="#cbd5e1" font-size="12.5" font-weight="600" text-anchor="middle">2. Apparent Luminosity Bias vs. Viewing Angle i</text> |
| 492 | <rect x="{p2_x0}" y="{p2_y0}" width="{p2_x1-p2_x0}" height="{p2_y1-p2_y0}" fill="#1e293b" stroke="#334155"/> |
| 493 | <line x1="{p2_x0}" y1="{y_one:.1f}" x2="{p2_x1}" y2="{y_one:.1f}" stroke="#475569" stroke-dasharray="4,4"/> |
| 494 | <line x1="{x_magic:.1f}" y1="{p2_y0}" x2="{x_magic:.1f}" y2="{p2_y1}" stroke="#475569" stroke-dasharray="3,4"/> |
| 495 | <polyline points="{' '.join(curve_exact)}" fill="none" stroke="#38bdf8" stroke-width="2.5"/> |
| 496 | <polyline points="{' '.join(curve_p2)}" fill="none" stroke="#f472b6" stroke-width="1.3" stroke-dasharray="4,3"/> |
| 497 | <circle cx="{x_earth:.1f}" cy="{y_earth:.1f}" r="4.5" fill="#38bdf8"/> |
| 498 | <circle cx="{x_magic:.1f}" cy="{y_magic:.1f}" r="4.5" fill="#a78bfa"/> |
| 499 | <circle cx="{x_eq:.1f}" cy="{y_eq:.1f}" r="4.5" fill="#fbbf24"/> |
| 500 | <text x="{x_earth + 8:.1f}" y="{y_earth + 4:.1f}" fill="#38bdf8" font-size="10.5">Earth 6.2° (+21.3%, V=+0.03)</text> |
| 501 | <text x="{x_magic - 4:.1f}" y="{y_magic - 10:.1f}" fill="#c4b5fd" font-size="10.5" text-anchor="end">i* = 54.75° (honest)</text> |
| 502 | <text x="{x_eq - 6:.1f}" y="{y_eq - 9:.1f}" fill="#fbbf24" font-size="10.5" text-anchor="end">Eq 90° (-10.9%, V=+0.30)</text> |
| 503 | <!-- Axis labels --> |
| 504 | <text x="{p2_x0 - 6}" y="{p2_y0 + 5}" fill="#94a3b8" font-size="10" text-anchor="end">1.25</text> |
| 505 | <text x="{p2_x0 - 6}" y="{y_one + 4:.1f}" fill="#94a3b8" font-size="10" text-anchor="end">1.00</text> |
| 506 | <text x="{p2_x0 - 6}" y="{p2_y1}" fill="#94a3b8" font-size="10" text-anchor="end">0.85</text> |
| 507 | <text x="{p2_x0}" y="{p2_y1 + 16}" fill="#94a3b8" font-size="10" text-anchor="middle">0°</text> |
| 508 | <text x="{0.5*(p2_x0+p2_x1):.1f}" y="{p2_y1 + 16}" fill="#94a3b8" font-size="10" text-anchor="middle">45° (inclination i)</text> |
| 509 | <text x="{p2_x1}" y="{p2_y1 + 16}" fill="#94a3b8" font-size="10" text-anchor="middle">90°</text> |
| 510 | <text x="{p2_x0}" y="352" fill="#94a3b8" font-size="10.5">Blue: exact ELR+LD | Pink dash: 1 + c₂P₂(cos i) (99.7% fit)</text> |
| 511 | |
| 512 | <!-- PANEL 3: Spectral Line Profiles --> |
| 513 | <text x="{0.5*(p3_x0+p3_x1):.1f}" y="50" fill="#cbd5e1" font-size="12.5" font-weight="600" text-anchor="middle">3. Weak Absorption Line Profiles (i = 6.2°)</text> |
| 514 | <rect x="{p3_x0}" y="{p3_y0}" width="{p3_x1-p3_x0}" height="{p3_y1-p3_y0}" fill="#1e293b" stroke="#334155"/> |
| 515 | <line x1="{p3_x0}" y1="{p3_y0+18}" x2="{p3_x1}" y2="{p3_y0+18}" stroke="#475569" stroke-dasharray="3,3"/> |
| 516 | <polyline points="{s_unif}" fill="none" stroke="#94a3b8" stroke-width="1.6" stroke-dasharray="4,3"/> |
| 517 | <polyline points="{s_he1}" fill="none" stroke="#38bdf8" stroke-width="2.2"/> |
| 518 | <polyline points="{s_fe1}" fill="none" stroke="#fbbf24" stroke-width="2.4"/> |
| 519 | <polyline points="{s_auf}" fill="none" stroke="#f87171" stroke-width="1.6" stroke-dasharray="2,2"/> |
| 520 | <text x="{p3_x0}" y="{p3_y1 + 16}" fill="#94a3b8" font-size="10" text-anchor="middle">-26</text> |
| 521 | <text x="{0.5*(p3_x0+p3_x1):.1f}" y="{p3_y1 + 16}" fill="#94a3b8" font-size="10" text-anchor="middle">0 (Δv km/s)</text> |
| 522 | <text x="{p3_x1}" y="{p3_y1 + 16}" fill="#94a3b8" font-size="10" text-anchor="middle">+26</text> |
| 523 | <!-- Legend --> |
| 524 | <text x="{p3_x0 + 6}" y="338" fill="#38bdf8" font-size="10.5">He I (hot pole, FWHM 20 km/s)</text> |
| 525 | <text x="{p3_x0 + 6}" y="354" fill="#fbbf24" font-size="10.5">Fe I (cool eq, flat-bottomed 38 km/s) | Red: Ω=0.916</text> |
| 526 | </svg> |
| 527 | ''' |
| 528 | out_path.write_text(svg, encoding="utf-8") |
| 529 | |
| 530 | |
| 531 | def main() -> None: |
| 532 | w_mon = omega_from_Om_ratio(0.774) |
| 533 | w_auf = omega_from_Om_ratio(0.916) |
| 534 | w_ext = omega_from_Om_ratio(0.990) |
| 535 | |
| 536 | print("=== 1. ELR (2011) vs. von Zeipel (beta=0.25) across rotation rates ===") |
| 537 | print(f"{'Om/Omc':>7} {'w':>7} {'Re/Rp':>7} {'v/vc':>7} {'Teq/Tp(vZ)':>11} {'Teq/Tp(ELR)':>12} {'beta_eff':>10}") |
| 538 | for Om_c in [0.01, 0.30, 0.50, 0.70, 0.774, 0.86, 0.916, 0.95, 0.99, 0.999]: |
| 539 | w = omega_from_Om_ratio(Om_c) |
| 540 | _, gp, *_ = surface_point(0.0, w, "elr") |
| 541 | _, ge, *_, t_elr, _ = surface_point(0.5 * math.pi, w, "elr") |
| 542 | *_, t_vz, _ = surface_point(0.5 * math.pi, w, "vz", beta=0.25) |
| 543 | re_rp = 1.0 + 0.5 * w * w |
| 544 | v_vc = w * math.sqrt(3.0 / (2.0 + w * w)) |
| 545 | beta_eff = math.log(t_elr) / math.log(ge / gp) |
| 546 | print(f"{Om_c:7.3f} {w:7.4f} {re_rp:7.4f} {v_vc:7.4f} {t_vz:11.5f} {t_elr:12.5f} {beta_eff:10.5f}") |
| 547 | |
| 548 | # 2. Monnier Model 3 vs ELR conservation & quadrupole lock |
| 549 | Lb_elr, area_elr, rings_elr, Lfn_elr = build_star(w_mon, 2.726, 10070.0, model="elr", u=0.6, N_th=240) |
| 550 | Lb_m3, area_m3, rings_m3, Lfn_m3 = build_star(w_mon, 2.726, 10070.0, model="vz", beta=0.231, u=0.6, N_th=240) |
| 551 | _, _, rings_auf, _ = build_star(w_auf, 2.818, 10150.0, model="elr", u=0.6, N_th=160) |
| 552 | |
| 553 | N_i = 180 |
| 554 | di = 0.5 * math.pi / N_i |
| 555 | sky_avg = sum(Lfn_elr(math.degrees((j + 0.5) * di)) * math.sin((j + 0.5) * di) * di for j in range(N_i)) |
| 556 | print(f"\n=== 2. Vega Conservation Check (ELR, Om/Omc=0.774, u=0.6) ===") |
| 557 | print(f"L_bol = {Lb_elr/L_SUN:.2f} Lsun (M3 beta=0.231: {Lb_m3/L_SUN:.2f}, Monnier 2012: 47.2 ± 2.0)") |
| 558 | print(f"L_sky_avg = {sky_avg/L_SUN:.2f} Lsun (rel err = {(sky_avg - Lb_elr)/Lb_elr:+.2e})") |
| 559 | print(f"L_app(6.2) = {Lfn_elr(6.2)/L_SUN:.2f} Lsun (ratio = {Lfn_elr(6.2)/Lb_elr:.4f}; Monnier: 58.4 ± 2.2)") |
| 560 | print(f"L_app(90) = {Lfn_elr(90.0)/L_SUN:.2f} Lsun (ratio = {Lfn_elr(90.0)/Lb_elr:.4f})") |
| 561 | |
| 562 | # Legendre c2, c4 |
| 563 | def P2(x: float) -> float: return 0.5 * (3 * x * x - 1.0) |
| 564 | def P4(x: float) -> float: return 0.125 * (35 * x**4 - 30 * x * x + 3.0) |
| 565 | N_mu = 120 |
| 566 | c2 = sum(5.0 * (Lfn_elr(math.degrees(math.acos((j + 0.5) / N_mu))) / Lb_elr) * P2((j + 0.5) / N_mu) / N_mu for j in range(N_mu)) |
| 567 | c4 = sum(9.0 * (Lfn_elr(math.degrees(math.acos((j + 0.5) / N_mu))) / Lb_elr) * P4((j + 0.5) / N_mu) / N_mu for j in range(N_mu)) |
| 568 | print(f"Legendre harmonics: c2 = {c2:+.5f}, c4 = {c4:+.6f} (|c4/c2| = {abs(c4/c2):.4f})") |
| 569 | |
| 570 | # 3. 3-way brightening decomposition & honest angle i* |
| 571 | def find_honest_angle(L_bol: float, Lfn) -> float: |
| 572 | lo, hi = 0.0, 90.0 |
| 573 | for _ in range(50): |
| 574 | mid = 0.5 * (lo + hi) |
| 575 | if Lfn(mid) > L_bol: |
| 576 | lo = mid |
| 577 | else: |
| 578 | hi = mid |
| 579 | return 0.5 * (lo + hi) |
| 580 | |
| 581 | print("\n=== 3. 3-Way Brightening Decomposition & Honest Angle i* ===") |
| 582 | print(f"{'Case':28s} {'L(0)/Lb':>8} {'L(90)/Lb':>9} {'dMag(90-0)':>11} {'i_honest':>9} {'i*-54.74':>9}") |
| 583 | for label, w, mod, beta, u in [ |
| 584 | ("Vega M3: Geom only (u=0)", w_mon, "uniform", 0.0, 0.0), |
| 585 | ("Vega M3: Geom + LD (u=0.6)", w_mon, "uniform", 0.0, 0.6), |
| 586 | ("Vega M3: Geom + ELR (u=0)", w_mon, "elr", 0.0, 0.0), |
| 587 | ("Vega M3: Geom + ELR + LD", w_mon, "elr", 0.0, 0.6), |
| 588 | ("Vega M3: Geom + vZ.231 + LD", w_mon, "vz", 0.231, 0.6), |
| 589 | ("Aufdenberg 06 (0.916) ELR+LD", w_auf, "elr", 0.0, 0.6), |
| 590 | ("Near-breakup (0.990) ELR+LD", w_ext, "elr", 0.0, 0.6), |
| 591 | ]: |
| 592 | Lb, _, _, Lfn = build_star(w, 2.726, 10070.0, model=mod, beta=beta, u=u, N_th=240) |
| 593 | r0, r90 = Lfn(0.0) / Lb, Lfn(90.0) / Lb |
| 594 | dmag = -2.5 * math.log10(r90 / r0) |
| 595 | ih = find_honest_angle(Lb, Lfn) |
| 596 | print(f"{label:28s} {r0:8.4f} {r90:9.4f} {dmag:+11.4f} {ih:8.3f}° {ih-MAGIC_ANGLE_DEG:+8.3f}°") |
| 597 | |
| 598 | # 4. Multiband magnitudes vs inclination (Monnier ELR, gray atmosphere) |
| 599 | _, _, rings_elr_120, _ = build_star(w_mon, 2.726, 10070.0, model="elr", u=0.6, N_th=120) |
| 600 | bands = [("UV250", 250e-9), ("U", 365e-9), ("B", 445e-9), ("V", 551e-9), ("K", 2190e-9)] |
| 601 | ref = {b: monochromatic_flux(rings_elr_120, lam, 6.2, gray_atm=True) for b, lam in bands} |
| 602 | print("\n=== 4. Multiband Photometry vs Inclination (Vega ELR, gray atmosphere) ===") |
| 603 | print(f"{'inc':>6} {'V':>7} {'dUV250':>8} {'dU':>7} {'dB':>7} {'dV':>7} {'dK':>7} {'B-V':>7} {'V-K':>7}") |
| 604 | for inc in [0.0, 6.2, 30.0, 54.74, 75.0, 90.0]: |
| 605 | dm = {b: -2.5 * math.log10(monochromatic_flux(rings_elr_120, lam, inc, gray_atm=True) / ref[b]) for b, lam in bands} |
| 606 | print(f"{inc:5.1f}° {0.03+dm['V']:+7.3f} {dm['UV250']:+8.3f} {dm['U']:+7.3f} {dm['B']:+7.3f} {dm['V']:+7.3f} {dm['K']:+7.3f} {dm['B']-dm['V']:+7.3f} {dm['V']-dm['K']:+7.3f}") |
| 607 | |
| 608 | # 5. Optical single-T SED mirage & depth-latitude interference |
| 609 | opt_grid = [380, 420, 460, 500, 550, 600, 650, 700, 750] |
| 610 | print("\n=== 5. Optical Single-T SED Residuals (Pure Planck vs Milne-Eddington Gray Atm) ===") |
| 611 | for inc in [6.2, 54.74, 90.0]: |
| 612 | Tp, Rp = fit_single_T(rings_elr_120, inc, opt_grid, gray_atm=False) |
| 613 | Tg, Rg = fit_single_T(rings_elr_120, inc, opt_grid, gray_atm=True) |
| 614 | rp = " | ".join( |
| 615 | f"{nm}nm:{100*(monochromatic_flux(rings_elr_120, nm*1e-9, inc, False)/spherical_flux(nm*1e-9, Tp, Rp, False)-1):+.2f}%" |
| 616 | for nm in [200, 551, 2190, 10000] |
| 617 | ) |
| 618 | rg = " | ".join( |
| 619 | f"{nm}nm:{100*(monochromatic_flux(rings_elr_120, nm*1e-9, inc, True)/spherical_flux(nm*1e-9, Tg, Rg, True)-1):+.2f}%" |
| 620 | for nm in [200, 551, 2190, 10000] |
| 621 | ) |
| 622 | print(f" i={inc:5.2f}° Planck (T={Tp:6.1f}K): {rp}") |
| 623 | print(f" i={inc:5.2f}° GrayAtm(T={Tg:6.1f}K): {rg}") |
| 624 | |
| 625 | # 6. Line profiles & SVG generation |
| 626 | v_eq_mon = (2.0 * math.pi * 2.726 * R_SUN) / (0.71 * 86400.0) / 1000.0 |
| 627 | v_grid = [float(v) for v in range(-30, 31)] |
| 628 | p_unif = compute_line_profile(rings_elr, 6.2, v_eq_mon, 500e-9, lambda T: 1.0, v_grid) |
| 629 | p_fe1 = compute_line_profile(rings_elr, 6.2, v_eq_mon, 500e-9, saha_FeI_weight, v_grid) |
| 630 | p_he1 = compute_line_profile(rings_elr, 6.2, v_eq_mon, 500e-9, boltzmann_HeI_weight, v_grid) |
| 631 | p_fe1_auf = compute_line_profile(rings_auf, 4.5, 274.0, 500e-9, saha_FeI_weight, v_grid) |
| 632 | |
| 633 | def fwhm(prof: list[float]) -> float: |
| 634 | half = 0.5 * max(prof) |
| 635 | above = [v for v, p in zip(v_grid, prof) if p >= half] |
| 636 | return above[-1] - above[0] |
| 637 | |
| 638 | print("\n=== 6. Gulliver-Hill-Adelman Weak Line Profile Split (i = 6.2°, v sin i = 21.0 km/s) ===") |
| 639 | for label, prof in [ |
| 640 | ("Uniform W(T)=const", p_unif), |
| 641 | ("Cool-eq Fe I (Monnier 0.774)", p_fe1), |
| 642 | ("Hot-pole He I (Monnier 0.774)", p_he1), |
| 643 | ("Cool-eq Fe I (Aufdenberg 0.916)", p_fe1_auf), |
| 644 | ]: |
| 645 | c0, pk = prof[v_grid.index(0.0)], max(prof) |
| 646 | print(f" {label:32s}: Center/Peak={c0/pk:.4f}, FWHM={fwhm(prof):4.1f} km/s") |
| 647 | |
| 648 | svg_path = Path(__file__).resolve().parent / "vega_figures.svg" |
| 649 | write_svg(svg_path, w_mon, Lb_elr, Lfn_elr, c2, v_grid, p_unif, p_fe1, p_he1, p_fe1_auf) |
| 650 | print(f"\nWrote {svg_path} ({svg_path.stat().st_size} bytes)") |
| 651 | |
| 652 | if __name__ == "__main__": |
| 653 | main() |
| 654 |