#!/usr/bin/env python3 """Base rates of orbital period, WD mass and light-curve class among novae (rules B1, B2). Usage: python -I base_rates.py Reads the arXiv TeX of Schaefer (2022b) and Schaefer (2025) as data. """ import json import math import os import re import sys def clean(cell): return re.sub(r"\s+", " ", cell.replace("$", "").replace("~", " ")).strip() def parse_2022(path): rows = [] text = open(path, encoding="utf-8", errors="replace").read().splitlines() active = False for line in text: if "All Reliable Orbital Periods for Novae" in line: active = True continue if active and "Critical periods from the histograms" in line: break if not active or "&" not in line or line.strip().startswith("%"): continue cells = [clean(c) for c in line.rstrip("\\ \t").split("&")] if len(cells) < 5 or not cells[0] or cells[0].startswith("Nova"): continue m = re.match(r"([0-9]*\.?[0-9]+)", cells[3]) if not m: continue cells[4] = cells[4].replace("\\\\", "").strip() digits = len(m.group(1).replace(".", "").lstrip("0")) rows.append({"name": cells[0], "year": cells[1], "lc": cells[2], "P": float(m.group(1)), "comments": cells[4], "cited": "[" in cells[3], "digits": digits}) return rows def parse_sed_names(path): """Names in the table of periods from SEDs (Table 2 of Schaefer 2022b).""" names = set() text = open(path, encoding="utf-8", errors="replace").read().splitlines() active = False for line in text: if "Orbital periods measured from SEDs" in line: active = True continue if active and "end{table" in line: break if active and "&" in line: n = clean(line.split("&")[0]) if n and not n.startswith("Nova"): names.add(n) return names def parse_2025(path): rows = [] text = open(path, encoding="utf-8", errors="replace").read().splitlines() active = False for line in text: if "startdata" in line: active = True continue if "enddata" in line and active: break if not active or "&" not in line or line.strip().startswith("%"): continue cells = [clean(c) for c in line.rstrip("\\ \t").split("&")] if len(cells) < 16: continue lc = cells[2] m = re.match(r"([A-Z])(?:\(([0-9.]+)\))?", lc) letter = m.group(1) if m else None t3 = float(m.group(2)) if m and m.group(2) else None P = None pm = re.match(r"([0-9]*\.?[0-9]+)", cells[8].replace(">", "").replace("\\", "")) if pm: P = float(pm.group(1)) M = None mm = re.match(r"([0-9]*\.?[0-9]+)", cells[9]) if mm: M = float(mm.group(1)) rows.append({"name": cells[0], "year": cells[1], "lc": lc, "letter": letter, "t3": t3, "P": P, "M": M, "pop": cells[10], "props": cells[15].replace("\\\\", "").strip()}) return rows def hyper_all(n_close, n_total, k=4): p = 1.0 for i in range(k): p *= (n_close - i) / (n_total - i) return p def main(): root = sys.argv[1] outdir = sys.argv[2] os.makedirs(outdir, exist_ok=True) p22 = os.path.join(root, "schaefer2022-periods", "src", "NovaPeriods_MNRAS.tex") p25 = os.path.join(root, "schaefer2025-wd-masses", "src", "Nova_WD_masses_ApJ.tex") r22 = parse_2022(p22) sed = parse_sed_names(p22) r25 = parse_2025(p25) out = {"n_2022": len(r22), "n_2025": len(r25), "n_sed_names": len(sed)} # B1 thr = [1, 2, 3, 5, 10] tab = {} for t in thr: n = sum(1 for r in r22 if r["P"] <= t) tab[str(t)] = {"n": n, "frac": n / len(r22), "all_four_close_p": hyper_all(n, len(r22))} out["B1_all"] = tab # Rule N9. Schaefer's Section 3: of the 25 names in his Table 2, 6 have previously known periods and 1 has his new photometric period; "this SED analysis produced 18 new P measures". # Those seven show in his master table with a literature reference or a period of six or more digits. The other 18 are the SED periods. in_table2 = [r for r in r22 if r["name"] in sed] measured = [r for r in in_table2 if r["cited"] or r["digits"] >= 6] sed_periods = [r for r in in_table2 if not (r["cited"] or r["digits"] >= 6)] if len(in_table2) != 25 or len(sed_periods) != 18: raise SystemExit("Table 2 count changed: %d names, %d SED periods" % (len(in_table2), len(sed_periods))) drop = set(r["name"] for r in sed_periods) nosed = [r for r in r22 if r["name"] not in drop] tab2 = {} for t in thr: n = sum(1 for r in nosed if r["P"] <= t) tab2[str(t)] = {"n": n, "frac": n / len(nosed), "all_four_close_p": hyper_all(n, len(nosed))} out["B1_without_SED_periods"] = { "n": len(nosed), "thresholds": tab2, "removed_18": sorted((r["P"], r["name"]) for r in sed_periods), "table2_names_kept_as_measured": sorted((r["P"], r["name"]) for r in measured), } # The earlier, wrong version of this count removed all 25 names. Kept so the change can be seen. no25 = [r for r in r22 if r["name"] not in sed] tab25 = {} for t in thr: n = sum(1 for r in no25 if r["P"] <= t) tab25[str(t)] = {"n": n, "frac": n / len(no25), "all_four_close_p": hyper_all(n, len(no25))} out["B1_without_all_25_names_superseded"] = {"n": len(no25), "thresholds": tab25} # Their four, in his list out["B1_members"] = [r for r in r22 if r["name"] in ("HR Del", "V723 Cas", "V5558 Sgr", "V1405 Cas", "Gaia22alz", "KT Eri", "U Sco")] # J class in 2022 list j22 = [r for r in r22 if r["lc"].startswith("J")] out["B1_J_class_2022"] = { "n": len(j22), "P_le3": sum(1 for r in j22 if r["P"] <= 3), "P_gt3": [(r["name"], r["P"]) for r in j22 if r["P"] > 3], "sorted": sorted((r["P"], r["name"], r["lc"]) for r in j22), } # slow novae of every class, t3 >= 100 d def t3(r): m = re.match(r"[A-Z]\(([0-9.]+)\)", r["lc"]) return float(m.group(1)) if m else None slow = [r for r in r22 if t3(r) and t3(r) >= 100] out["B1_slow_t3ge100"] = {"n": len(slow), "P_le3": sum(1 for r in slow if r["P"] <= 3), "list": sorted((r["P"], r["name"], r["lc"]) for r in slow)} # B2 J = [r for r in r25 if r["letter"] == "J"] Jp = [r for r in J if r["P"] is not None] Jm = [r for r in J if r["M"] is not None] letters = sorted(set(r["letter"] for r in r25 if r["letter"])) out["B2_class_counts"] = {l: sum(1 for r in r25 if r["letter"] == l) for l in letters} out["B2_J"] = { "n": len(J), "with_P": len(Jp), "P_le3": sum(1 for r in Jp if r["P"] <= 3), "P_gt3": [(r["name"], r["P"]) for r in Jp if r["P"] > 3], "with_M": len(Jm), "M_le_0.70": sum(1 for r in Jm if r["M"] <= 0.70), "M_gt_0.70": sum(1 for r in Jm if r["M"] > 0.70), "M_median": sorted(r["M"] for r in Jm)[len(Jm) // 2] if Jm else None, "M_range": [min(r["M"] for r in Jm), max(r["M"] for r in Jm)] if Jm else None, "M_sorted": sorted((r["M"], r["name"], r["lc"], r["P"]) for r in Jm), } box = [r for r in r25 if r["M"] is not None and r["M"] <= 0.70 and r["P"] is not None and r["P"] <= 3] cnt = {} for r in box: cnt[r["letter"] or "none"] = cnt.get(r["letter"] or "none", 0) + 1 out["B2_lowmass_close"] = { "n": len(box), "by_class": cnt, "list": sorted((r["M"], r["name"], r["lc"], r["P"]) for r in box), } box2 = [r for r in r25 if r["M"] is not None and r["M"] <= 0.70] out["B2_lowmass_any_P"] = {"n": len(box2), "with_P": sum(1 for r in box2 if r["P"] is not None), "P_le3": sum(1 for r in box2 if r["P"] is not None and r["P"] <= 3), "P_gt10": [(r["name"], r["P"], r["lc"], r["M"]) for r in box2 if r["P"] is not None and r["P"] > 10]} narrow = [r for r in r25 if r["M"] is not None and 0.5 <= r["M"] <= 0.7 and r["P"] is not None and r["P"] <= 3] cnt2 = {} for r in narrow: cnt2[r["letter"] or "none"] = cnt2.get(r["letter"] or "none", 0) + 1 out["B2_0p5_0p7_close"] = {"n": len(narrow), "by_class": cnt2} # Rising-phase comparison: the named novae out["B2_named"] = [r for r in r25 if r["name"] in ("HR Del", "V723 Cas", "V5558 Sgr", "V1405 Cas", "PU Vul", "CN Cha", "T Pyx", "V1548 Aql", "V1280 Sco", "Gaia22alz")] out["B2_any_Gaia22"] = [r["name"] for r in r25 if "Gaia" in r["name"]] with open(os.path.join(outdir, "base_rates.json"), "w", encoding="utf-8", newline="\n") as fh: json.dump(out, fh, indent=1) # short print print("2022 list n =", len(r22), " SED names", len(sed)) for t in thr: print(" P<=%d d: %d (%.1f%%) ; all four close p=%.3f" % (t, tab[str(t)]["n"], 100 * tab[str(t)]["frac"], tab[str(t)]["all_four_close_p"])) print("without SED periods n =", len(nosed)) for t in thr: print(" P<=%d d: %d (%.1f%%) ; all four close p=%.3f" % (t, tab2[str(t)]["n"], 100 * tab2[str(t)]["frac"], tab2[str(t)]["all_four_close_p"])) print("J class in 2022 list:", len(j22), "P<=3:", out["B1_J_class_2022"]["P_le3"], "P>3:", out["B1_J_class_2022"]["P_gt3"]) print("slow t3>=100 in 2022 list:", len(slow), "P<=3:", out["B1_slow_t3ge100"]["P_le3"]) print("2025 table n =", len(r25), out["B2_class_counts"]) print("J:", {k: v for k, v in out["B2_J"].items() if k != "M_sorted"}) print("low mass close:", out["B2_lowmass_close"]["n"], out["B2_lowmass_close"]["by_class"]) print(" 0.5-0.7 close:", out["B2_0p5_0p7_close"]) print("low mass any P:", {k: v for k, v in out["B2_lowmass_any_P"].items()}) print("named:", [(r["name"], r["lc"], r["P"], r["M"]) for r in out["B2_named"]]) print("gaia names:", out["B2_any_Gaia22"]) if __name__ == "__main__": main()