#!/usr/bin/env python3 """Rule N8: photospheric radius against time from the paper's plotted curves, for each model, and the days that follow from it. Usage: python -I radius_curves.py M06.Ne.11 comes from f5.eps and M06.sol.11 from f6.eps, read as vector data. At each node the V offset from the model's own point B gives a temperature, through the blackbody share of the light in the V band at constant luminosity. R = 3.78 Rsun x (T_B / T)^2, where 3.78 Rsun and log T_B = 4.48 are the paper's values at B (section 4.3). This is our approximation to the paper's model, checked against its radii at A and C. Writes radius_curves.json. """ import importlib.util import json import math import os import sys HERE = os.path.dirname(os.path.abspath(__file__)) spec = importlib.util.spec_from_file_location("read_figures", os.path.join(HERE, "read_figures.py")) rf = importlib.util.module_from_spec(spec) spec.loader.exec_module(rf) X_9600, X_9800 = 1716.0, 2808.0 Y_18, Y_10 = 1799.0, 5066.0 T0_HJD = 9604.522 G, MSUN, RSUN, DAY = 6.674e-8, 1.989e33, 6.957e10, 86400.0 HC_K_NM = 1.438777e7 # hc/k in nm K LOGT_B = 4.48 R_B = 3.78 def x2t(x): return 9600.0 + (x - X_9600) * 200.0 / (X_9800 - X_9600) - T0_HJD def y2m(y): return 18.0 - (y - Y_18) * 8.0 / (Y_10 - Y_18) def v_share(temp, n=400): """Share of a blackbody's energy in 507-595 nm.""" x1, x2 = HC_K_NM / (595.0 * temp), HC_K_NM / (507.0 * temp) h = (x2 - x1) / n s = 0.0 for i in range(n + 1): x = x1 + i * h w = 1 if i in (0, n) else (4 if i % 2 else 2) s += w * x**3 / math.expm1(x) return s * h / 3 / (math.pi**4 / 15) def temp_of_offset(dm, ref): """Temperature whose V share is brighter than ref by -dm magnitudes, on the hot side of the V peak. Bisection in log T.""" target = ref * 10 ** (-0.4 * dm) lo, hi = 3.95, 6.0 if v_share(10**lo) < target: return None for _ in range(60): mid = (lo + hi) / 2 if v_share(10**mid) > target: lo = mid else: hi = mid return 10 ** ((lo + hi) / 2) def radius_curve(nodes, tb, mb): ref = v_share(10**LOGT_B) out = [] for t, m in nodes: T = temp_of_offset(m - mb, ref) if T is None: continue out.append((t, R_B * (10**LOGT_B / T) ** 2, math.log10(T))) return out def day_at(curve, r): pts = [(t, R) for t, R, _ in curve] if r < pts[0][1]: return None for (t1, r1), (t2, r2) in zip(pts[:-1], pts[1:]): if r1 <= r <= r2: return t1 + (math.log(r) - math.log(r1)) / (math.log(r2) - math.log(r1)) * (t2 - t1) return None def radius_on_day(curve, day): pts = [(t, R) for t, R, _ in curve] for (t1, r1), (t2, r2) in zip(pts[:-1], pts[1:]): if t1 <= day <= t2: return math.exp(math.log(r1) + (day - t1) / (t2 - t1) * (math.log(r2) - math.log(r1))) return None def kepler(p, m1=0.6, m2=0.2): return (G * (m1 + m2) * MSUN * (p * DAY) ** 2 / (4 * math.pi**2)) ** (1 / 3) / RSUN def eggleton(q): return 0.49 * q ** (2 / 3) / (0.6 * q ** (2 / 3) + math.log(1 + q ** (1 / 3))) def pick_polyline(segs, xstart, min_pts): best = None for s in segs: p = s["pts"] if len(p) >= min_pts and abs(p[0][1] - 1575) < 3 and abs(p[0][0] - xstart) < 15 and tuple(s["color"]) == (0.0, 0.0, 0.0): if best is None or len(p) > len(best): best = p return best def main(): src, out = sys.argv[1:3] s5, m5 = rf.parse(os.path.join(src, "f5.eps")) s6, m6 = rf.parse(os.path.join(src, "f6.eps")) ne = pick_polyline(s5, 1804, 8) sol = pick_polyline(s6, 1503, 8) models = {} for name, poly, tb, mb, A, C in (("M06.Ne.11", ne, 48.6, 14.72, (12.1, 18.32), (105.0, 12.33)), ("M06.sol.11", sol, 42.9, 14.85, (-39.1, 18.47), (99.9, 12.45))): nodes = [(round(x2t(x), 2), round(y2m(y), 3)) for x, y in poly] # keep the rise, up to the turn into the flat part rising = [n for n in nodes if n[0] <= C[0] + 3] curve = radius_curve(rising, tb, mb) check = {} for lab, (t, m) in (("A", A), ("C", C)): T = temp_of_offset(m - mb, v_share(10**LOGT_B)) check[lab] = {"t": t, "log_T_from_offset": round(math.log10(T), 2) if T else None, "R_Rsun": round(R_B * (10**LOGT_B / T) ** 2, 2) if T else None} models[name] = {"B": [tb, mb], "check_against_paper": check, "paper_R_at_A_C": [0.335, 34.8], "curve_t_R_logT": [[round(a, 2), round(b, 3), round(c, 3)] for a, b, c in curve]} P0 = 0.2676 rows = {} for name, m in models.items(): c = m["curve_t_R_logT"] row = {} for lab, p in (("P0.2676", P0), ("P0.5352", 2 * P0), ("P1.437", 1.437)): days = {} for m2 in (0.2, 0.8): a = kepler(p, 0.6, m2) d = day_at(c, a) e = {"a_Rsun": round(a, 2), "day": round(d, 1) if d is not None else None} if d is not None: e["revolutions_by_day_49"] = round(max(0.0, 49 - d) / p, 0) e["revolutions_by_day_68"] = round(max(0.0, 68 - d) / p, 0) e["day_of_84_revolutions"] = round(d + 84 * p, 1) days["m2=%.1f" % m2] = e row[lab] = days a02 = kepler(1.437, 0.6, 0.2) r1 = eggleton(3.0) * a02 r2 = eggleton(1 / 3.0) * a02 row["WD_Roche_radius"] = {"R": round(r1, 2), "day": round(day_at(c, r1), 1)} row["donor_near_side"] = {"R": round(a02 - r2, 2), "day": round(day_at(c, a02 - r2), 1)} # Which periods reach the orbit inside the gap between the spectra, days 49 and 68 gap = {} for m2 in (0.2, 0.8): ends = [] for day in (49.0, 68.0): r = radius_on_day(c, day) ends.append(round((4 * math.pi**2 * (r * RSUN) ** 3 / (G * (0.6 + m2) * MSUN)) ** 0.5 / DAY, 2)) gap["m2=%.1f" % m2] = ends row["periods_reaching_orbit_in_gap_49_68"] = gap rows[name] = row curves = {} for name, m in models.items(): c = m["curve_t_R_logT"] for m2 in (0.2, 0.8): pts = [] p = 0.1 while p <= 3.0001: d = day_at(c, kepler(p, 0.6, m2)) if d is not None: pts.append([round(p, 4), round(d, 2)]) p *= 1.03 curves["%s_m2=%.1f" % (name, m2)] = pts res = {"note": "Rule N8. Radii are our approximation to the paper's models, from its plotted curves; blackbody V share at constant luminosity, anchored at each model's point B.", "models": models, "days": rows, "engulfment_curves": curves} with open(os.path.join(out, "radius_curves.json"), "w", encoding="utf-8", newline="\n") as fh: json.dump(res, fh, indent=0) print(json.dumps({"check": {k: v["check_against_paper"] for k, v in models.items()}, "days": rows}, indent=0)) if __name__ == "__main__": main()