#!/usr/bin/env python3 """Write chart_data.json: the numbers behind the page's charts. Figure 5 of Kato & Hachisu (2026), CC BY 4.0, is read from the vector EPS in the arXiv source: points and model curves as the paper plotted them. The engulfment curves come from radius_curves.json (rule N8), one for each model. Usage: python -I chart_data.py """ import importlib.util import json 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 # Aydi et al. (2023), t0 = HJD 2459604.522 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 main(): src, out = sys.argv[1:3] segs, marks = rf.parse(os.path.join(src, "f5.eps")) res = {"note": "Figure 5 read from the arXiv EPS, CC BY 4.0: t = HJD - 2459604.522, magnitude from the left axis. Engulfment: radius_curves.json, from the plotted curves of each model, and Kepler's law."} models = {} for s in segs: xs = [p[0] for p in s["pts"]] ys = [p[1] for p in s["pts"]] col = tuple(s["color"]) if len(s["pts"]) >= 7 and max(xs) - min(xs) > 1000 and min(ys) < 1700 and max(ys) > 4000: key = {(0.0, 1.0, 0.0): "M06.Ne.047", (1.0, 0.5, 0.0): "M06.Ne.25", (0.0, 0.0, 0.0): "M06.Ne.11"}.get(col) if key and key not in models: models[key] = [[round(x2t(p[0]), 1), round(y2m(p[1]), 3)] for p in s["pts"]] res["models"] = models res["asassn_g_as_plotted"] = sorted([round(x2t(m["x"]), 1), round(y2m(m["y"]), 3)] for m in marks if m["name"] == "M17" and m["color"][0] > 0.9 and -80 < x2t(m["x"]) < 210) res["aavso_as_plotted"] = sorted([round(x2t(m["x"]), 1), round(y2m(m["y"]), 3)] for m in marks if m["name"] == "M21" and -80 < x2t(m["x"]) < 210) res["M06.Ne.11_points_A_B_C"] = [[12.1, 18.32], [48.6, 14.72], [105.0, 12.33]] radii = json.load(open(os.path.join(out, "radius_curves.json"), encoding="utf-8")) res["engulfment_curves"] = radii["engulfment_curves"] res["engulfment_days"] = radii["days"] with open(os.path.join(out, "chart_data.json"), "w", encoding="utf-8", newline="\n") as fh: json.dump(res, fh, indent=0) print("wrote chart_data.json") if __name__ == "__main__": main()