"""Site calibration of the factory maps (residual offsets measured on this lot with component solves). `site_calibration.json` (next to this file) holds additive offsets in each map's own output units, measured by solving the real components at the lot's planned operating point. Missing file or key = no offset. """ from __future__ import annotations import json import os _PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "site_calibration.json") KEYS = ("kappa_log", "vm_mpa", "lambda_log", "surge_c7_log", "nadir_hz", "cell_polar_v", "bus_drop_v") def _load() -> dict[str, float]: try: with open(_PATH, "r", encoding="utf-8") as fh: doc = json.load(fh) except (OSError, ValueError): return {} return {k: float(doc[k]) for k in KEYS if isinstance(doc.get(k), (int, float)) and not isinstance(doc.get(k), bool)} CAL = _load() def get(key: str) -> float: return CAL.get(key, 0.0)