"""digitize_check.py -- combines Readings A and B and runs checks T1-T19 of RULES_digitize.txt. py -3.12 -I digitize_check.py Writes out/fig4_points.csv, out/fig5_points.csv, out/fig6_points.csv, out/digitize.json, out/digitize_log.txt. """ import csv import hashlib import json import math import os import sys out_dir, rules_dir, img_dir = sys.argv[1], sys.argv[2], sys.argv[3] CREDIT = ("Values read from Wang, M., et al. (2026), ApJ 1012:79, doi:10.3847/1538-4357/aeb6ab, Figures 4-6 " "(CC BY 4.0); digitized by Fact-Checked Science, two independent readings; not the authors' data.") def sha(path): with open(path, "rb") as f: return hashlib.sha256(f.read()).hexdigest() A = json.load(open(os.path.join(out_dir, "reading_a.json"), encoding="utf-8")) B = json.load(open(os.path.join(out_dir, "reading_b.json"), encoding="utf-8")) NOMINAL = { "fig4": [("D=1e-4", 1e-4), ("D=1e-3", 1e-3), ("D=1e-2", 1e-2), ("D=0.1", 0.1), ("D=1", 1.0), ("D=10", 10.0)], "fig5": [("tilt %d" % t, t) for t in range(0, 181, 30)], } LOGY = {"fig4": True, "fig5": False, "fig6": True} def match(points_a, points_b, series): pa = sorted([p for p in points_a if p["series"] == series], key=lambda p: p["x"]) pb = sorted([p for p in points_b if p["series"] == series], key=lambda p: p["x"]) assert len(pa) == len(pb), (series, len(pa), len(pb)) return list(zip(pa, pb)) combined = {} agreement = [] for fig in ("fig4", "fig5", "fig6"): rows = [] for series in (("black", "blue") if fig == "fig6" else ("black",)): for pa, pb in match(A[fig]["points"], B[fig]["points"], series): ya, yb = pa["y"], pb["y"] dlog = math.log10(ya) - math.log10(yb) dlin = ya - yb mean = math.sqrt(ya * yb) if LOGY[fig] else (ya + yb) / 2 u = max(abs(dlog) / 2, 0.02) xa, xb = pa["x"], pb["x"] row = {"figure": fig, "series": series, "x_A": xa, "x_B": xb, "y_A": ya, "y_B": yb, "dlog10_A_minus_B": dlog, "d_axis_units_A_minus_B": dlin, "y_mean": mean, "u_dex": u, "agree_0.05dex": abs(dlog) <= 0.05} rows.append(row) agreement.append(abs(dlog)) rows.sort(key=lambda r: (r["series"], r["x_A"])) combined[fig] = rows # nominal labels for fig, rows in combined.items(): for r in rows: if fig == "fig4": r["nominal"] = min(NOMINAL["fig4"], key=lambda n: abs(math.log10(n[1]) - math.log10(r["x_A"])))[0] else: t = 30 * round(r["x_A"] / 30) r["nominal"] = "tilt %d" % t if r["series"] == "blue": r["nominal"] += " / " + {0: "1.0D", 30: "0.7D", 60: "0.4D", 90: "0.1D"}[t] def get(fig, nominal, series="black"): for r in combined[fig]: if r["nominal"].startswith(nominal) and r["series"] == series: return r raise KeyError((fig, nominal, series)) def cls_sigfig1(v, u, m, N): lo, hi = (m - 0.5) * 10 ** N, (m + 0.5) * 10 ** N if lo * 10 ** -u <= v < hi * 10 ** u: return "agrees" return loose(v, lo, hi) def cls_sigfig2(v, u, stated, approaching=False): d = abs(math.log10(v / stated)) if d <= 0.02 + u: return "agrees" if approaching and stated * 0.95 * 10 ** -(0.02 + u) <= v <= stated: return "agrees" return loose(v, stated, stated) def cls_order(v, N): if abs(math.log10(v) - N) <= 0.5: return "agrees" return loose(v, 10 ** N, 10 ** N) def cls_range(v, u, N, M): lv = math.log10(v) if N - u <= lv <= M + u: return "agrees" return loose(v, 10 ** N, 10 ** M) def loose(v, lo, hi): lv = math.log10(v) if math.log10(lo) - 0.18 <= lv <= math.log10(hi) + 0.18: return "loose" return "disagrees" checks = [] def add(tid, text, locator, digitized, verdict, note=""): checks.append({"id": tid, "text": text, "locator": locator, "digitized": digitized, "class": verdict, "note": note}) f4 = {r["nominal"]: r for r in combined["fig4"]} f5 = {r["nominal"]: r for r in combined["fig5"]} f6k = {r["nominal"]: r for r in combined["fig6"] if r["series"] == "black"} f6b = {r["nominal"].split(" / ")[0]: r for r in combined["fig6"] if r["series"] == "blue"} for name, r in (("Fig. 4 D=1", f4["D=1"]), ("Fig. 5 0 deg", f5["tilt 0"]), ("Fig. 6 black 0 deg", f6k["tilt 0"]), ("Fig. 6 blue 0 deg (1.0D)", f6b["tilt 0"])): add("T1", "5.76e21 s^-1 at D = 1, tilt 0", "Sec. 3 para 5; App. B", {name: r["y_mean"]}, cls_sigfig2(r["y_mean"], r["u_dex"], 5.76e21)) add("T2a", "approximately 6e21 at 0 deg", "Sec. 4.2 para 1", {"Fig. 5 0 deg": f5["tilt 0"]["y_mean"]}, cls_sigfig1(f5["tilt 0"]["y_mean"], f5["tilt 0"]["u_dex"], 6, 21)) add("T2b", "approximately 7e21 at 180 deg", "Sec. 4.2 para 1", {"Fig. 5 180 deg": f5["tilt 180"]["y_mean"]}, cls_sigfig1(f5["tilt 180"]["y_mean"], f5["tilt 180"]["u_dex"], 7, 21)) add("T3", "maximum at 150 deg, approaching 2.0e22", "Sec. 4.2 para 1", {"Fig. 5 150 deg": f5["tilt 150"]["y_mean"], "is_max": max(f5, key=lambda k: f5[k]["y_mean"]) == "tilt 150"}, cls_sigfig2(f5["tilt 150"]["y_mean"], f5["tilt 150"]["u_dex"], 2.0e22, approaching=True) if max(f5, key=lambda k: f5[k]["y_mean"]) == "tilt 150" else "disagrees") mn = min(f5, key=lambda k: f5[k]["y_mean"]) add("T4", "minimum at 0 or 180 deg", "Sec. 4.2 para 1", {"minimum at": mn}, "agrees" if mn in ("tilt 0", "tilt 180") else "disagrees") loc90 = f5["tilt 90"]["y_mean"] < min(f5["tilt 60"]["y_mean"], f5["tilt 120"]["y_mean"]) add("T5", "90 deg a local decrease compared with 60 and 120 deg", "Sec. 4.2 para 1", {"60": f5["tilt 60"]["y_mean"], "90": f5["tilt 90"]["y_mean"], "120": f5["tilt 120"]["y_mean"]}, "agrees" if loc90 else "disagrees") ratio = max(r["y_mean"] for r in f5.values()) / min(r["y_mean"] for r in f5.values()) add("T6a", "more than 3 times the minimum", "Sec. 4.2 para 1; Abstract (2)", {"max/min": ratio}, "agrees" if ratio > 3 else ("loose" if ratio > 2 else "disagrees")) add("T6b", "a factor of ~3.5", "Sec. 4.2 para 1", {"max/min": ratio}, "agrees" if 3.25 <= ratio < 3.75 else ("loose" if 3.5 / 1.5 <= ratio <= 3.5 * 1.5 else "disagrees")) kmin = min(r["y_mean"] for r in f6k.values()) kmax = max(r["y_mean"] for r in f6k.values()) c_lo = cls_sigfig1(kmin, 0.02, 6, 21) c_hi = cls_sigfig1(kmax, 0.02, 2, 22) add("T7", "black circles within (0.6-2) x 10^22", "Sec. 4.3 para 2", {"min": kmin, "max": kmax}, "agrees" if (c_lo == c_hi == "agrees") else (c_lo if c_lo != "agrees" else c_hi)) t8 = {} for k, r in f6k.items(): d = math.log10(r["y_mean"]) - math.log10(f5[k]["y_mean"]) t8[k] = d add("T8", "Fig. 6 black circles same as Fig. 5", "Fig. 6 caption", {"dlog10 Fig6-Fig5": t8}, "agrees" if all(abs(v) <= 0.05 for v in t8.values()) else "disagrees") b90 = f6b["tilt 90"] add("T9", "nearly 2e23 at 90 deg / 0.1D", "Sec. 4.3 para 2", {"Fig. 6 blue 90": b90["y_mean"]}, cls_sigfig1(b90["y_mean"], b90["u_dex"], 2, 23), "'nearly' read as just below 2e23; the plotted value is above it" if b90["y_mean"] > 2e23 else "") r10 = b90["y_mean"] / f6k["tilt 90"]["y_mean"] add("T10", "approximately 10 times higher than at the same tilt with today's field", "Sec. 4.3 para 2", {"blue90/black90": r10, "dex": math.log10(r10)}, "agrees" if 7.5 <= r10 < 15 else ("loose" if 10 / 1.5 <= r10 <= 15 else "disagrees")) add("T11", "~1e24 at D = 0.1, tilt 0 (Fig. 4)", "Sec. 4.3 para 3", {"Fig. 4 D=0.1": f4["D=0.1"]["y_mean"]}, cls_order(f4["D=0.1"]["y_mean"], 24)) add("T12", "~1e19 at D = 10", "Sec. 4.1 para 2", {"Fig. 4 D=10": f4["D=10"]["y_mean"]}, cls_order(f4["D=10"]["y_mean"], 19)) for k in ("D=1e-4", "D=1e-3", "D=1e-2"): add("T13", "~10^25-10^26 for D <= 1e-2", "Abstract (1); Sec. 4.1 para 2; Sec. 5 (1)", {"Fig. 4 " + k: f4[k]["y_mean"]}, cls_range(f4[k]["y_mean"], f4[k]["u_dex"], 25, 26)) add("T14", "D = 1: ~10^21-10^22", "Sec. 4.1 para 2", {"Fig. 4 D=1": f4["D=1"]["y_mean"]}, cls_range(f4["D=1"]["y_mean"], f4["D=1"]["u_dex"], 21, 22)) dex15 = math.log10(f4["D=0.1"]["y_mean"] / f4["D=1"]["y_mean"]) add("T15a", "D = 1 -> 0.1: nearly 2 to 3 orders of magnitude", "Sec. 4.1 para 2", {"dex": dex15}, "agrees" if 1.8 <= dex15 <= 3.0 else "disagrees") add("T15b", "At 10^-1 the escape rate increases by 2 to 3 orders of magnitude", "Abstract (1); Sec. 5 (1)", {"dex": dex15}, "agrees" if 2.0 <= dex15 <= 3.0 else "disagrees") span = math.log10(max(r["y_mean"] for r in f4.values()) / min(r["y_mean"] for r in f4.values())) add("T16", "spans more than 6 orders of magnitude", "Sec. 4.1 para 2", {"dex": span}, "agrees" if span > 6 else ("loose" if span > 6 - 0.18 else "disagrees"), "margin above 6 is within the reading uncertainty" if span - 6 < 0.05 else "") bmax = max(r["y_mean"] for r in f6b.values()) for ref_name, ref in (("5.76e21 (text)", 5.76e21), ("Fig. 4 D=1", f4["D=1"]["y_mean"])): d17 = math.log10(bmax / ref) add("T17", "reversal: 1 to 2 orders of magnitude relative to the present-day value", "Abstract (3); Sec. 5 (3)", {"blue max / " + ref_name: bmax / ref, "dex": d17}, "agrees" if 1 <= d17 <= 2 else "disagrees") add("T18", "at D = 0.1, higher at 0 deg (Fig. 4) than at 90 deg (Fig. 6)", "Sec. 4.3 para 3", {"Fig4 D=0.1": f4["D=0.1"]["y_mean"], "Fig6 blue 90": b90["y_mean"], "ratio": f4["D=0.1"]["y_mean"] / b90["y_mean"]}, "agrees" if f4["D=0.1"]["y_mean"] > b90["y_mean"] else "disagrees") sat = [f4[k]["y_mean"] for k in ("D=1e-4", "D=1e-3", "D=1e-2")] add("T19", "monotonic decrease for D >= 1; saturation for D <= 1e-2", "Sec. 4.1 para 2", {"D=1 > D=10": f4["D=1"]["y_mean"] > f4["D=10"]["y_mean"], "saturation spread (dex)": math.log10(max(sat) / min(sat))}, "described (no threshold pre-registered)", "only two points at D >= 1; the three saturated points differ by %.2f dex" % math.log10(max(sat) / min(sat))) # derived, for the page (not checks) derived = { "path_blue": {k: r["y_mean"] for k, r in f6b.items()}, "moment_effect_at_fixed_tilt": { "tilt 30: 0.7D / 1D": f6b["tilt 30"]["y_mean"] / f6k["tilt 30"]["y_mean"], "tilt 60: 0.4D / 1D": f6b["tilt 60"]["y_mean"] / f6k["tilt 60"]["y_mean"], "tilt 90: 0.1D / 1D": f6b["tilt 90"]["y_mean"] / f6k["tilt 90"]["y_mean"], "tilt 0: 0.1D / 1D (Fig. 4)": f4["D=0.1"]["y_mean"] / f4["D=1"]["y_mean"]}, "log_slopes_fig4": { "D 0.1-1": math.log10(f4["D=1"]["y_mean"] / f4["D=0.1"]["y_mean"]), "D 1-10": math.log10(f4["D=10"]["y_mean"] / f4["D=1"]["y_mean"]), "D 0.01-0.1": math.log10(f4["D=0.1"]["y_mean"] / f4["D=1e-2"]["y_mean"])}, "log_slope_fig6_tilt30_0.7D_to_1D": math.log10(f6k["tilt 30"]["y_mean"] / f6b["tilt 30"]["y_mean"]) / math.log10(1 / 0.7), "tilt_0_to_30_ratio_fig5": f5["tilt 30"]["y_mean"] / f5["tilt 0"]["y_mean"], "tilt_ratio_150_over_180": f5["tilt 150"]["y_mean"] / f5["tilt 180"]["y_mean"], "tilt_ratio_30_over_150": f5["tilt 30"]["y_mean"] / f5["tilt 150"]["y_mean"], } # CSVs for fig in ("fig4", "fig5", "fig6"): path = os.path.join(out_dir, "%s_points.csv" % fig) with open(path, "w", encoding="utf-8", newline="\n") as f: f.write("# " + CREDIT + "\n") f.write("# Figure %s. Columns: point, series, x (reading A), x (reading B), escape rate in O+ ions per " "second (reading A), (reading B), mean, A-B in dex, reading uncertainty in dex.\n" % fig[-1]) w = csv.writer(f, lineterminator="\n") w.writerow(["point", "series", "x_A", "x_B", "rate_A_per_s", "rate_B_per_s", "rate_mean_per_s", "dlog10_A_minus_B", "u_dex"]) for r in combined[fig]: w.writerow([r["nominal"], r["series"], "%.4g" % r["x_A"], "%.4g" % r["x_B"], "%.4g" % r["y_A"], "%.4g" % r["y_B"], "%.4g" % r["y_mean"], "%.4f" % r["dlog10_A_minus_B"], "%.3f" % r["u_dex"]]) summary = { "credit": CREDIT, "agreement": {"n_points": len(agreement), "max_abs_dlog10": max(agreement), "median_abs_dlog10": sorted(agreement)[len(agreement) // 2], "all_within_0.05_dex": all(a <= 0.05 for a in agreement)}, "calibration": {fig: {"A_x_pass": A[fig]["calibration"]["x"]["pass"], "A_y_pass": A[fig]["calibration"]["y"]["pass"], "A_max_frac": [A[fig]["calibration"]["x"]["max_frac"], A[fig]["calibration"]["y"]["max_frac"]], "B_x_pass": B[fig]["axes"]["x"]["check_pass"], "B_y_pass": B[fig]["axes"]["y"]["check_pass"], "B_max_frac": [B[fig]["axes"]["x"]["max_residual_frac"], B[fig]["axes"]["y"]["max_residual_frac"]]} for fig in ("fig4", "fig5", "fig6")}, "fig6_minor_tick_check": {"A_max_abs_residual_px": max(abs(m["residual_px"]) for m in A["fig6"]["minor_check"]), "B_max_abs_residual_px": max(abs(v["residual_px"]) for v in B["fig6"]["minor_tick_check"].values())}, "points": combined, "checks": checks, "derived": derived, } with open(os.path.join(out_dir, "digitize.json"), "w", encoding="utf-8", newline="\n") as f: json.dump(summary, f, indent=1) log = ["digitize_check.py log", CREDIT, ""] for name in ("RULES_digitize.txt", "RULES_digitize_layout.txt"): log.append("%s %s" % (sha(os.path.join(rules_dir, name)), name)) for name in ("apjaeb6abf4_hr.jpg", "apjaeb6abf5_hr.jpg", "apjaeb6abf6_hr.jpg"): log.append("%s %s" % (sha(os.path.join(img_dir, name)), name)) for name in ("digitize_a.py", "digitize_b.py", "digitize_check.py"): cp = os.path.join(rules_dir, "code", name) cp = cp if os.path.exists(cp) else os.path.join(rules_dir, name) log.append("%s %s" % (sha(cp), name)) for name in ("reading_a.json", "reading_b.json", "reading_b_pixels.json"): cp = os.path.join(out_dir, name) cp = cp if os.path.exists(cp) else os.path.join(rules_dir, name) log.append("%s %s" % (sha(cp), name)) log.append("") log.append("Agreement A vs B: %d points, max |dlog10| %.4f, median %.4f" % ( len(agreement), max(agreement), sorted(agreement)[len(agreement) // 2])) for c in checks: log.append("%-5s %-10s %s | %s | %s %s" % (c["id"], c["class"], c["text"], c["locator"], json.dumps(c["digitized"], default=lambda o: o), ("| " + c["note"]) if c["note"] else "")) log.append("") log.append("Derived: " + json.dumps(derived, indent=1)) with open(os.path.join(out_dir, "digitize_log.txt"), "w", encoding="utf-8", newline="\n") as f: f.write("\n".join(log) + "\n") print("\n".join(log))