"""The two charts on the factchecked.science page on Matthews et al. (2026). Usage: python3 -I chart_data.py [] 1. Figure 13 of the paper, redrawn: the 13 plotted points as read from the figure's vector paths (extract_fig13.py), marked by observing campaign. Adapted from Fig. 13 of Matthews et al. (2026), AJ 172, 184, CC BY 4.0. 2. Our own analysis, added after the first run of analysis.py (post hoc): the primary test P1 (Pearson r of campaign-mean ellipticity against sin^2(2 pi phase), exact permutation of the six campaign phases, one-sided) repeated with a common shift delta added to every phase, delta from -0.15 to +0.15 in steps of 0.01. Writes the numbers as JSON and, if a folder is given, fig13.svg and strip.svg, which the page inlines. Standard library only. """ import itertools import json import math import os import sys CREDIT = "Adapted from Fig. 13 of Matthews et al. (2026), AJ 172, 184, doi:10.3847/1538-3881/ae953d, CC BY 4.0" GROUPS = (("22 GHz", lambda nu: nu < 30), ("44 GHz", lambda nu: 30 <= nu < 60), ("107–485 GHz", lambda nu: nu >= 60)) SOURCE = {"E2015": "O’Gorman et al. (2017)", "E2019": "Matthews & Dupree (2022)"} def frac(x): return x - math.floor(x) def T1(p): return math.sin(2 * math.pi * p) ** 2 def pearson(x, y): n = len(x) mx, my = sum(x) / n, sum(y) / n sxy = sum((a - mx) * (b - my) for a, b in zip(x, y)) sxx = sum((a - mx) ** 2 for a in x) syy = sum((b - my) ** 2 for b in y) return sxy / math.sqrt(sxx * syy) def exact_p(e, ph, delta): t = [T1(frac(p + delta)) for p in ph] r0 = pearson(e, t) ge = sum(1 for perm in itertools.permutations(range(len(t))) if pearson(e, [t[i] for i in perm]) >= r0 - 1e-12) n = math.factorial(len(t)) return r0, ge / n def group(nu): for name, test in GROUPS: if test(nu): return name raise ValueError(nu) def fmt(v): return f"{v:.1f}".rstrip("0").rstrip(".") if abs(v - round(v)) > 1e-9 else str(int(round(v))) def minus(s): return s.replace("-", "−") def fig13_svg(points): W, Hh = 640, 382 x0, x1, y0, y1 = 74, 618, 318, 44 X = lambda ph: x0 + ph * (x1 - x0) Y = lambda e: y0 - e / 0.12 * (y0 - y1) o = [] o.append(f'') desc = ("Scatter chart, adapted from the paper’s Figure 13: ellipticity of Betelgeuse’s radio disk, from 0 to 0.12, " "against the companion’s orbital phase, from 0 to 1. The five 2023 points, at phases 0.08 to 0.11, just after the " "companion passed in front, have ellipticities 0.023 to 0.035. The two 2024 points, at 0.29, near greatest " "separation, are at 0.103 and 0.105. The two 2019 points, at 0.41, are at 0.040 and 0.043. The 2026 point, at 0.54, " "just after the companion passed behind, is at 0.016. The 2015 point, at 0.74, near the other greatest separation, " "is at 0.080, and the two 2021 points, at 0.76, are at 0.066 and 0.068.") o.append(f'{desc}') for a, b in ((0.2, 0.3), (0.7, 0.8)): o.append(f'') for k in range(7): e = 0.02 * k y = Y(e) o.append(f'') o.append(f'{"0" if k == 0 else f"{e:.2f}"}') for ph, lab in ((0, "0"), (0.25, "0.25"), (0.5, "0.5"), (0.75, "0.75"), (1, "1")): x = X(ph) cls = "f13-conj" if ph in (0, 0.5, 1) else "f13-grid" o.append(f'') o.append(f'{lab}') tops = ((0, "in front", "start"), (0.25, "greatest separation", "middle"), (0.5, "behind", "middle"), (0.75, "greatest separation", "middle"), (1, "in front", "end")) for ph, lab, anchor in tops: o.append(f'{lab}') # points, with small sideways offsets where two of one campaign coincide (as noted in the caption) pts = sorted(points, key=lambda p: (p["campaign"], p["phase"], p["e"])) placed = [] for p in pts: x, y = X(p["phase"]), Y(p["e"]) twins = [q for q in placed if q["campaign"] == p["campaign"] and abs(q["phase"] - p["phase"]) < 1e-9 and abs(q["e"] - p["e"]) < 0.006] if twins: x += 4.5 for q in twins: q["_x"] -= 4.5 p["_x"], p["_y"] = x, y placed.append(p) for p in placed: x, y = p["_x"], p["_y"] if p["group"] == "22 GHz": o.append(f'') elif p["group"] == "44 GHz": o.append(f'') else: o.append(f'') # campaign labels where = {"E2015": "above", "E2019": "above", "E2021": "below", "E2023": "above", "E2024": "above", "E2026": "above"} for camp in sorted({p["campaign"] for p in placed}): mine = [p for p in placed if p["campaign"] == camp] xm = sum(p["_x"] for p in mine) / len(mine) if where[camp] == "above": y = min(p["_y"] for p in mine) - 13 else: y = max(p["_y"] for p in mine) + 22 star = "*" if camp in SOURCE else "" o.append(f'{camp[1:]}{star}') o.append(f'Orbital phase of the companion, in fractions of its 5.8-year orbit') o.append(f'Ellipticity') o.append("") return "\n".join(o) def strip_svg(strip): W, Hh = 640, 262 x0, x1, top, bot = 74, 618, 34, 196 X = lambda d: x0 + (d + 0.15) / 0.30 * (x1 - x0) Y = lambda p: top + (-math.log10(p)) / 3 * (bot - top) o = [] o.append(f'') lo = [s for s in strip if s["p"] < 0.05] desc = ("Line chart of our exact test’s p, on a log scale from 1 down to 0.001, against a shift added to every " "campaign’s orbital phase, from minus 0.15 to plus 0.15 of an orbit. With no shift, the timing the paper uses, " f"p is {next(s['p'] for s in strip if abs(s['delta']) < 1e-9):.3f}. p stays below 0.05 for shifts from " f"{minus(f'{min(s['delta'] for s in lo):+.2f}')} to {minus(f'{max(s['delta'] for s in lo):+.2f}')}, reaches its " f"lowest, {min(s['p'] for s in strip):.4f}, near minus 0.05, and rises to 0.16 at plus 0.06, the edge of the timing’s " "one-standard-error range, which is shaded from minus 0.06 to plus 0.06.") o.append(f'{desc}') o.append(f'') o.append(f'± one standard error of the orbit’s timing') for p, lab in ((1, "1"), (0.1, "0.1"), (0.01, "0.01"), (0.001, "0.001")): y = Y(p) o.append(f'') o.append(f'{lab}') y05 = Y(0.05) o.append(f'') o.append(f'p = 0.05') o.append(f'') for d in (-0.15, -0.10, -0.05, 0.0, 0.05, 0.10, 0.15): lab = "0" if abs(d) < 1e-9 else minus(f"{d:+.2f}") o.append(f'{lab}') pts = " ".join(f"{X(s['delta']):.1f},{Y(s['p']):.1f}" for s in strip) o.append(f'') for s in strip: cls = "st-dot" if s["p"] < 0.05 else "st-dot is-open" o.append(f'') o.append(f'Shift added to every campaign’s phase, as a fraction of an orbit') o.append(f'0 is the timing the paper uses; lower p is stronger evidence') o.append(f'p, log scale') o.append("") return "\n".join(o) def main(): src, dst = sys.argv[1], sys.argv[2] svgdir = sys.argv[3] if len(sys.argv) > 3 else None A = json.load(open(src, encoding="utf-8"))["A"] points = [] for p in A["points"]: points.append({"campaign": p["epoch"], "group": group(p["nu"]), "phase": p["phase_fig"], "e": p["e_fig"], "from": SOURCE.get(p["epoch"], "this paper")}) points.sort(key=lambda p: (p["campaign"], p["group"], p["phase"], p["e"])) eps = A["epochs_Dfig"] e = [x["e_mean"] for x in eps] ph = [x["phase"] for x in eps] strip = [] for k in range(-15, 16): d = k / 100 r, p = exact_p(e, ph, d) strip.append({"delta": d, "r": round(r, 4), "p": round(p, 4)}) out = { "fig13": {"credit": CREDIT, "note": "Points as plotted in the paper's Fig. 13, read from its vector paths; 2015 and 2019 come " "from earlier papers, as the paper says.", "points": points}, "strip": {"credit": "Our analysis (Fact-Checked Science), added after the first run of analysis.py", "test": "P1 of RULES_analysis.txt with a common shift added to every campaign's phase", "rows": strip}, } with open(dst, "w", encoding="utf-8", newline="\n") as f: json.dump(out, f, indent=1, ensure_ascii=False) f.write("\n") if svgdir: os.makedirs(svgdir, exist_ok=True) for name, svg in (("fig13.svg", fig13_svg([dict(p) for p in points])), ("strip.svg", strip_svg(strip))): with open(os.path.join(svgdir, name), "w", encoding="utf-8", newline="\n") as f: f.write(svg + "\n") print("wrote", dst, "| strip p at 0:", next(s["p"] for s in strip if s["delta"] == 0)) if __name__ == "__main__": main()