#!/usr/bin/env python3 """Rule J: where a hot blackbody's energy falls, for the bands used by Hillman et al. (2014) and Kato & Hachisu (2026). Standard library only. Usage: python -I band_shares.py """ import json import math import os import sys K_EV = 8.617333e-5 HC_EV_NM = 1239.84193 def planck_share(temp, e_lo, e_hi, n=20000): """Fraction of the bolometric energy of a blackbody between photon energies e_lo and e_hi, in eV.""" kt = K_EV * temp x0, x1 = e_lo / kt, e_hi / kt x1 = min(x1, 700.0) if x0 >= x1: return 0.0 a, b = math.log(x0), math.log(x1) h = (b - a) / n s = 0.0 for i in range(n + 1): x = math.exp(a + i * h) f = x**4 / math.expm1(x) if x < 700 else 0.0 w = 1 if i in (0, n) else (4 if i % 2 else 2) s += w * f return s * h / 3 / (math.pi**4 / 15) def nm(lam): return HC_EV_NM / lam def main(): out = sys.argv[1] bands = { "V_507_595nm": (nm(595), nm(507)), "NUV_175_280nm": (nm(280), nm(175)), "FUV_91_175nm": (nm(175), nm(91.2)), "EUV_13p6_300eV": (13.6, 300.0), "X_0p3_1keV": (300.0, 1000.0), "X_0p3_10keV": (300.0, 10000.0), } res = {"note": "Shares of a blackbody's bolometric energy. Rule J.", "shares": {}} for logt in (4.48, 5.0, 5.37, 5.46): t = 10**logt res["shares"]["logT=%.2f" % logt] = {k: float("%.3g" % planck_share(t, *v)) for k, v in bands.items()} c = 2.99792458e17 # nm/s dnu_nuv = c / 175 - c / 280 dnu_v = c / 507 - c / 595 res["band_width_ratio_NUV_over_V_in_frequency"] = round(dnu_nuv / dnu_v, 2) with open(os.path.join(out, "band_shares.json"), "w", encoding="utf-8", newline="\n") as fh: json.dump(res, fh, indent=1) print(json.dumps(res, indent=0)) if __name__ == "__main__": main()