EVE-Obstruction-Tomography / experiments /make_nonlinear_figures.py
PureOne's picture
Publish EVE Obstruction Tomography v2.0.0 research release
b6abf2d verified
Raw History Blame Contribute Delete
2.8 kB
#!/usr/bin/env python3
"""Scientific figure from saved data and explicitly labeled analytic geometry."""
from pathlib import Path
import csv
import numpy as np
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
ROOT=Path(__file__).resolve().parents[1]
with (ROOT/"data/nonlinear/distance_grid_queries.csv").open() as f:
grid=list(csv.DictReader(f))
with (ROOT/"results/nonlinear_drift_summary.csv").open() as f:
drift=list(csv.DictReader(f))
plt.rcParams.update({"font.size":10,"axes.spines.top":False,"axes.spines.right":False,
"axes.titlesize":11,"figure.dpi":160,"pdf.fonttype":42})
fig,axs=plt.subplots(2,2,figsize=(10.2,7.8),layout="constrained")
blue,red,orange="#216785","#B64842","#C07819"
t=np.linspace(0,2*np.pi,501)
ax=axs[0,0]
ax.fill(np.cos(t),np.sin(t),color=blue,alpha=.15,label="Disk: all interior points")
ax.plot(np.cos(t),np.sin(t),color=red,lw=2,label="Circle: boundary only")
ax.scatter([0],[0],s=30,color=blue)
ax.set(aspect="equal",xlabel="Output 1",ylabel="Output 2",
title="A Identical linear supports, different sets")
ax.legend(loc="upper right",fontsize=8)
ax=axs[0,1];r=np.linspace(0,1.5,401)
ax.plot(r,(r-1)**2,color=red,label="Circle")
ax.plot(r,np.maximum(r-1,0)**2,color=blue,label="Disk")
ax.plot(r,np.maximum.reduce([np.sqrt(.02)-r,r-1,np.zeros_like(r)])**2,
"--",color=orange,label="Annulus, hole radius 0.141")
ax.set(xlabel="Target distance from center",ylabel="Minimum squared mismatch",
title="B Quadratic probes reveal missing points")
ax.legend(fontsize=8)
ax=axs[1,0]
sel=[x for x in grid if x["shape"]=="circle" and float(x["delta"])==.001 and x["selected"]=="1"]
ax.scatter([float(x["u"]) for x in sel],[float(x["v"]) for x in sel],s=2,color=blue,alpha=.5,label="Recovered grid points")
ax.plot(np.cos(t),np.sin(t),color=red,lw=1,label="True circle")
ax.set(aspect="equal",xlabel="Output 1",ylabel="Output 2",
title="C Finite grid with loss noise bound 0.001")
ax.legend(loc="upper right",fontsize=8)
ax=axs[1,1]
rows=sorted([x for x in drift if x["kind"]=="drift" and float(x["delta"])==.0001
and float(x["timing_bound"])==.00001],key=lambda x:float(x["h"]))
h=[float(x["h"]) for x in rows]
ax.loglog(h,[float(x["drift_error_max"]) for x in rows],"o-",color=blue,label="Largest observed drift error")
ax.loglog(h,[float(x["drift_bound"]) for x in rows],"s--",color=orange,label="Certified upper bound")
ax.set(xlabel="Finite difference step h",ylabel="Euclidean drift error",
title="D Noise and time resolution tradeoff")
ax.grid(True,which="both",alpha=.16);ax.legend(fontsize=8)
fig.savefig(ROOT/"figures/05_nonlinear_geometry.pdf")
fig.savefig(ROOT/"figures/05_nonlinear_geometry.png")
plt.close(fig)
print("Saved nonlinear geometry figure.")