Does light charge the quons? › Files cited on the page › check_section12_fable/
nist_fit_v2.py
#!/usr/bin/env python3
"""r28: trial 24's intercepts from NIST's n(p,T) data (Egan and Yang 2023 supplement), own code.
Per isotherm: straight line (deg 1) and the lock's polynomial (cubic N2/Ar, quadratic He) in refractivity against pressure,
weighted by sigma_p = sqrt(0.05^2 + (1e-6 p)^2) carried into refractivity by the slope. Intercepts in units of refractivity.
Then the inverse-variance mean of the polynomial intercepts over the isotherms, and of the straight-line intercepts (the author's 'means')."""
import sys, math
import numpy as np
ROOT = sys.argv[1] if len(sys.argv) > 1 else '/home/doug/aetherscience.org/aspden-investigation/sources/slow_light_2026-11-23/nist_npT/unzipped'
FILES = {'nitrogen': 'nitrogen/data-nitrogen-2062.csv', 'argon': 'argon/data-argon-2062.csv', 'helium': 'helium/data-helium-2062.csv'}
C = 299792458.0
def read(path):
rows = []
with open(path, encoding='utf-8', errors='replace') as fh:
for line in fh:
parts = line.strip().split(',')
if len(parts) != 3:
continue
try:
rows.append((float(parts[0]), float(parts[1]), float(parts[2]) * 1e-8))
except ValueError:
continue
a = np.array(rows)
return a[:, 0], a[:, 1], a[:, 2]
def wfit(p, r, deg):
slope = np.polyfit(p, r, 1)[0]
sig = np.sqrt(0.05**2 + (1e-6 * p)**2) * abs(slope)
w = 1 / sig
X = np.vander(p / 1e5, deg + 1) # scaled pressure for conditioning
Xw = X * w[:, None]; yw = r * w
beta, res, rank, sv = np.linalg.lstsq(Xw, yw, rcond=None)
cov = np.linalg.inv(Xw.T @ Xw)
resid = (yw - Xw @ beta)
chi2 = float(resid @ resid); dof = len(p) - (deg + 1)
scale = max(1.0, chi2 / dof) # inflate by chi2/dof when the fit is bad (Birge)
return beta[-1], math.sqrt(cov[-1, -1] * scale), chi2 / dof
total = 0
for gas, rel in FILES.items():
T, p, r = read(f'{ROOT}/{rel}')
total += len(p) if gas != 'helium' else 0
print(f'\n=== {gas}: {len(p)} readings; T from {T.min():.2f} to {T.max():.2f} C; p from {p.min():.0f} to {p.max():.0f} Pa')
deg = 2 if gas == 'helium' else 3
iso = np.round(T, 0)
# r28 fix: readings within an isotherm sit at slightly different temperatures; bring each to the nominal one (density ~ p/T at fixed p)
r = r * (T + 273.15) / (iso + 273.15)
polys, lines = [], []
for tC in sorted(set(iso)):
m = iso == tC
if m.sum() < deg + 3:
continue
b1, s1, c1 = wfit(p[m], r[m], 1)
bp, sp, cp = wfit(p[m], r[m], deg)
polys.append((bp, sp)); lines.append((b1, s1))
print(f' {tC:5.0f} C (nominal): n={m.sum():3d} line intercept {b1:+.2e} (chi2/dof {c1:.1e}) deg-{deg} intercept {bp:+.2e} +- {sp:.1e} (chi2/dof {cp:.2f})')
def comb(v):
v = np.array(v); w = 1 / v[:, 1]**2
mu = (w * v[:, 0]).sum() / w.sum(); s = 1 / math.sqrt(w.sum())
return mu, s
mu, s = comb(polys); ml, sl = comb(lines)
print(f' combined deg-{deg} intercept: {mu:+.2e} +- {s:.1e} -> 2-sigma limit on a positive slowing {mu + 2*s:.2e} ({C*(mu+2*s):.3f} m/s); |mu|+2s = {abs(mu)+2*s:.2e}')
print(f' combined straight-line intercept (the author\'s first "mean"): {ml:+.2e}; per-isotherm at 20 C: {lines[0][0]:+.2e}')
print(f'\nnitrogen + argon readings: {total}')