"""Sandbox at NON-test points: exact P+ and r from the test-21 runner against Phi(kappa x), psi and the TWA."""
import sys, math, time, numpy as np
from scipy.stats import norm
sys.path.insert(0, sys.argv[1]); import mqg_test21_runner as R
pts = [(th, N, mu) for th in (0.012, 0.025) for N in (1000,) for mu in (1.5, 2.0, 2.5)]
for th, N, mu in pts:
    t0 = time.time()
    row, _ = R.compute_row(dict(row='SB', k=0, theta=th, N=N, mu=mu, seed=123), quiet=True)
    x = math.sin(2*th)*math.sqrt(N/2); kap = math.sqrt(2/mu)
    psi = math.degrees(math.atan2(math.sqrt(mu-1), 1-mu/2))
    r = complex(*row['r']); tw = row['twa']
    print(f"th={th} N={N} mu={mu}: t*={row['t_star']:.2f}  P={row['P']:.4f}  Phi(kx)={norm.cdf(kap*x):.4f}  Phi(x)={norm.cdf(x):.4f}  "
          f"TWA {tw['P']:.4f}+-{tw['se']:.4f}  |r|={abs(r):.4f} arg={math.degrees(math.atan2(r.imag,r.real)):.2f} psi={psi:.2f}  "
          f"TWA|r|={abs(complex(*tw['r'])):.4f}  {time.time()-t0:.0f}s")
