"""Reproduce the summer 2029 audit. Run python replay.py L.xlsx cohort.csv.""" import csv import hashlib import math import sys from collections import Counter from pathlib import Path from openpyxl import load_workbook workbook_path, cohort_path = (Path(arg) for arg in sys.argv[1:]) expected_hashes = { "6b01fcc181f10b46856f697c8c136e141899c91a0a649172d2056da21c2bcc5d", # Public ICC download "97bde8f00f621ce3d73b715eb4dbedb36352352efa1dddc64a47898a8129f7d3", # Stored ZIP in compute } assert hashlib.sha256(workbook_path.read_bytes()).hexdigest() in expected_hashes, "Appendix L vintage differs" workbook = load_workbook(workbook_path, read_only=True, data_only=True) region = workbook["MISO"] zone = workbook["MISO LRZ 4"] with cohort_path.open(newline="", encoding="utf-8") as cohort_file: rows = list(csv.DictReader(cohort_file)) assert [int(row["order"]) for row in rows] == list(range(1, 79)) assert len({r["application_id"] for r in rows}) == 78 assert Counter(row["audit_group"] for row in rows) == { "withdrawn": 13, "south_baseline": 13, "phase1_candidate": 30, "phase2_candidate": 15, "unassigned": 7, } by_id = {row["project_id"]: row for row in rows if row["project_id"]} # Gas and Gas/Storage requests in each block, including only incremental NRIS on uprates. phase12 = [2, 10, 12, 16, 23, 26, 28, 37, 38, 42, 46, 49, 50, 54, 63, 67, 69] phase3 = [60, 71, 72] late = [12, 16, 49, 50] def request(number): return float(by_id[f"E{number:04d}"]["requested_nris_mw"]) assert all(by_id[f"E{i:04d}"]["audit_group"].startswith(("phase1_", "phase2_")) for i in phase12) assert all(by_id[f"E{i:04d}"]["audit_group"] == "unassigned" for i in phase3) req12 = sum(map(request, phase12)) req3 = sum(map(request, phase3)) assert math.isclose(req12, 10714.06) and req3 == 1086 for col in ("H", "I"): implied_rate = region[col + "76"].value / req3 published = region[col + "67"].value predicted = req12 * implied_rate assert math.isclose(predicted, published, abs_tol=1e-6, rel_tol=0) print("phase 1+2 gas cross-check", region[col+"4"].value, implied_rate, predicted, published) rate = region["H76"].value / req3 regional_margin = region["H21"].value - region["H24"].value assert region["H20"].value == 0 allowance = zone["H20"].value local_supply = zone["H21"].value - allowance import_need = zone["H24"].value - local_supply outside = import_need + regional_margin debit = sum(map(request, late)) * rate cap_others = sum(request(i) for i in phase12 if i not in late) debit_floor = max(0, region["H67"].value - cap_others) phase3_total = region["H19"].value print("Accredited MW, positive margin = surplus") print("regional supply, requirement, margin", region["H21"].value, region["H24"].value, regional_margin) print("Zone 4 local supply, requirement, import need, allowance", local_supply, zone["H24"].value, import_need, allowance) print("outside residual at common reserve allocation", outside) for number in late: print(f"E{number:04d}", "requested, estimated credited", request(number), request(number) * rate) cases = { "draft": 0, "only Phase 3 missing": phase3_total, "Wisconsin two, common rate": (request(12) + request(16)) * rate, "four sites, common rate": debit, "Morgan limited to announced 720 MW": debit - (request(50) - 720) * rate, "four sites, minimum credit under request caps": debit_floor, } for label, loss in cases.items(): print(label, "credit removed / regional margin", round(loss, 3), round(regional_margin - loss, 3)) print("four-site floor/common outside upper bounds", outside-debit_floor, outside-debit) print("requirement relief to balance, floor/common", debit_floor-regional_margin, debit-regional_margin) for south in (2000, 5000): north_except_zone = outside - south available = min(outside, north_except_zone + 2500, allowance) print("illustrative South surplus / on-time import upper bound", south, available) print("2030 on-time regional margin", region["I21"].value - region["I24"].value)