drs-endplate / ground_truth /dev_summary.py
TraceHaus's picture
Upload 16 files
068e868 verified
Raw History Blame Contribute Delete
2.12 kB
import json, numpy as np, matplotlib
matplotlib.use("Agg"); import matplotlib.pyplot as plt
def stats(d):
return {"n": int(len(d)), "rms": round(float(np.sqrt((d**2).mean())), 3), "p50": round(float(np.median(d)), 3),
"p95": round(float(np.percentile(d, 95)), 3), "p99": round(float(np.percentile(d, 99)), 3), "max": round(float(d.max()), 2)}
out = {}
for key, files in [("original_to_rebuild", ["out/dev_ab_7.npz", "out/dev_ab_8.npz"]),
("rebuild_to_original", ["out/dev_ba_7.npz", "out/dev_ba_8.npz"])]:
zs = [np.load(f) for f in files]
d = np.concatenate([z["dist"] for z in zs]); P = np.concatenate([z["pts"] for z in zs]); s = np.concatenate([z["sign"] for z in zs])
r = {"all": stats(d), "fallback_queries": int(sum(int(z["fallback"]) for z in zs))}
regions = { # coarse geometric regions in the design frame (mm)
"flange_and_lip (z < -2.5)": P[:, 2] < -2.5,
"blade (z >= 20)": P[:, 2] >= 20,
"blade_tip (z >= 185)": P[:, 2] >= 185,
"ramp_ducts_bosses (-2.5 <= z < 20)": (P[:, 2] >= -2.5) & (P[:, 2] < 20),
}
r["regions"] = {k: stats(d[m]) for k, m in regions.items() if m.sum() > 50}
worst = np.argsort(d)[-5:][::-1]
r["worst_points_mm"] = [{"xyz": P[i].round(2).tolist(), "dist": round(float(d[i]), 3)} for i in worst]
out[key] = r
if key == "original_to_rebuild":
sd = d * np.where(s == 0, 1, s)
fig, ax = plt.subplots(1, 2, figsize=(14, 5.2))
for a, (i, j, lab) in zip(ax, [(0, 1, "plan (X-Y)"), (0, 2, "side (X-Z)")]):
o = np.argsort(np.abs(sd))
sc = a.scatter(P[o, i], P[o, j], c=sd[o], s=2, cmap="coolwarm", vmin=-0.5, vmax=0.5)
a.set_aspect("equal"); a.set_title(f"original → rebuild, signed deviation, {lab}"); a.set_xlabel("mm")
fig.colorbar(sc, ax=ax, label="mm (fixed ±0.5)", shrink=0.8)
fig.savefig("out/deviation_map_vs_step.png", dpi=150, bbox_inches="tight")
json.dump(out, open("out/deviation_vs_step.json", "w"), indent=2)
print(json.dumps({k: (v["all"], v["regions"]) for k, v in out.items()}, indent=1))