"""Gate for the overnight chain (2026-11-01): exit 1 unless the one-glacier smoke test of the area_min_h calibration (out_test_minh/) is sound.""" import sys import numpy as np import xarray as xr f = '/home/www/fmaussion/runs/lmr_2025/adapbs/out_test_minh/RGI60-11.00804_test_minh.nc' try: ds = xr.open_dataset(f) except Exception as e: sys.exit(f'FAIL: no test output ({e})') ok_runs = ds.error.values == '' i04 = list(ds.time.values).index(2004) checks = { 'area_var is min_h': ds.attrs.get('opt_area_var') == 'min_h', 'vol_err is 0.1': ds.attrs.get('opt_vol_err') == '0.1', 'most runs ok': ok_runs.sum() >= 0.8 * len(ok_runs), 'area target == stored area_min_h series at 2004': np.allclose(ds.pred.values[ok_runs, 1], ds.area_km2.values[ok_runs, i04].astype(float), rtol=1e-5), 'weights sum to 1': abs(float(np.nansum(ds.weight.values)) - 1) < 1e-6, } for k, v in checks.items(): print(f'{k:50s} {"OK" if v else "FAIL"}') sys.exit(0 if all(checks.values()) else 1)