hostcap-screen 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hostcap_screen/__init__.py +5 -0
- hostcap_screen/cli.py +67 -0
- hostcap_screen/criteria.py +123 -0
- hostcap_screen/dashboard.py +596 -0
- hostcap_screen/data/__init__.py +0 -0
- hostcap_screen/data/layout_ieee39.yaml +53 -0
- hostcap_screen/engine.py +514 -0
- hostcap_screen/errors.py +5 -0
- hostcap_screen/network.py +166 -0
- hostcap_screen/psse.py +659 -0
- hostcap_screen/redispatch.py +85 -0
- hostcap_screen/report.py +135 -0
- hostcap_screen-0.1.0.dist-info/METADATA +249 -0
- hostcap_screen-0.1.0.dist-info/RECORD +18 -0
- hostcap_screen-0.1.0.dist-info/WHEEL +5 -0
- hostcap_screen-0.1.0.dist-info/entry_points.txt +2 -0
- hostcap_screen-0.1.0.dist-info/licenses/LICENSE +674 -0
- hostcap_screen-0.1.0.dist-info/top_level.txt +1 -0
hostcap_screen/cli.py
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"""Command-line interface: hostcap-screen run ..."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import sys
|
|
7
|
+
import time
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
from . import __version__
|
|
11
|
+
from .criteria import load_criteria
|
|
12
|
+
from .engine import Screener
|
|
13
|
+
from .network import load_network
|
|
14
|
+
from .dashboard import write_dashboard
|
|
15
|
+
from .report import write_csv, write_html, write_json
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
19
|
+
p = argparse.ArgumentParser(prog="hostcap-screen", description="Transmission injection capability screening")
|
|
20
|
+
p.add_argument("--version", action="version", version=f"%(prog)s {__version__}")
|
|
21
|
+
sub = p.add_subparsers(dest="command", required=True)
|
|
22
|
+
r = sub.add_parser("run", help="Screen one or more buses")
|
|
23
|
+
r.add_argument("--case", default="ieee39", help="'ieee39', a PSS/E .raw file (v32, v33, v35), or a pandapower .json file")
|
|
24
|
+
r.add_argument("--criteria", default=None, help="YAML criteria file (defaults used if omitted)")
|
|
25
|
+
r.add_argument("--buses", default=None, help="Comma-separated bus labels, e.g. 4,16,26 (default: all)")
|
|
26
|
+
r.add_argument("--pmax", type=float, default=2000.0, help="Search maximum in MW (default 2000)")
|
|
27
|
+
r.add_argument("--tol", type=float, default=1.0, help="Search tolerance in MW (default 1)")
|
|
28
|
+
r.add_argument("--redispatch", choices=["proportional", "slack"], default="proportional")
|
|
29
|
+
r.add_argument("--reactive", choices=["voltage", "unity"], default="voltage",
|
|
30
|
+
help="voltage: plant regulates its bus within the power factor limit; unity: Q = 0")
|
|
31
|
+
r.add_argument("--pf", type=float, default=0.95, help="Power factor limit for voltage mode (default 0.95)")
|
|
32
|
+
r.add_argument("--workers", type=int, default=1, help="Parallel processes (default 1)")
|
|
33
|
+
r.add_argument("--no-gen-outages", action="store_true", help="Do not study generator outages")
|
|
34
|
+
r.add_argument("--no-next-limit", action="store_true", help="Skip the upgrade (next limit) search (faster)")
|
|
35
|
+
r.add_argument("--out", default="hostcap_results", help="Output folder")
|
|
36
|
+
return p
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def main(argv=None) -> int:
|
|
40
|
+
args = build_parser().parse_args(argv)
|
|
41
|
+
t0 = time.time()
|
|
42
|
+
net = load_network(args.case)
|
|
43
|
+
crit = load_criteria(args.criteria)
|
|
44
|
+
s = Screener(net, crit, redispatch=args.redispatch, reactive=args.reactive,
|
|
45
|
+
pf_limit=args.pf, pmax_mw=args.pmax, tol_mw=args.tol,
|
|
46
|
+
include_gen_outages=not args.no_gen_outages, next_limit=not args.no_next_limit)
|
|
47
|
+
labels = [b.strip() for b in args.buses.split(",")] if args.buses else None
|
|
48
|
+
print(f"HostCap-Screen {__version__}: {len(s.contingencies)} outages studied, {len(s.skipped)} skipped")
|
|
49
|
+
for note in net.get("hostcap_notes", []) or []:
|
|
50
|
+
print(f" note: {note}")
|
|
51
|
+
|
|
52
|
+
def progress(n, total, r):
|
|
53
|
+
print(f" [{n}/{total}] bus {r.bus}: {r.capability_mw:.0f} MW ({r.status})", flush=True)
|
|
54
|
+
|
|
55
|
+
results = s.screen(labels, progress=progress, workers=args.workers)
|
|
56
|
+
out = Path(args.out)
|
|
57
|
+
out.mkdir(parents=True, exist_ok=True)
|
|
58
|
+
write_csv(results, out / "hostcap_results.csv")
|
|
59
|
+
write_json(results, s, out / "hostcap_results.json")
|
|
60
|
+
write_html(results, s, out / "hostcap_report.html")
|
|
61
|
+
write_dashboard(out / "hostcap_dashboard.html", s, results)
|
|
62
|
+
print(f"Done in {time.time() - t0:.0f} s. Outputs in {out.resolve()}")
|
|
63
|
+
return 0
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
if __name__ == "__main__":
|
|
67
|
+
sys.exit(main())
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"""Planning criteria for HostCap-Screen.
|
|
2
|
+
|
|
3
|
+
Criteria are user-editable through a YAML file. The defaults are common
|
|
4
|
+
steady-state screening values. They are NOT the official planning criteria
|
|
5
|
+
of any ISO, RTO, or utility. NERC TPL-001 leaves the specific limits to each
|
|
6
|
+
Transmission Planner and Planning Coordinator, so users should replace these
|
|
7
|
+
values with the criteria that apply to their system.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
from dataclasses import dataclass, field, asdict
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
from typing import Optional
|
|
15
|
+
|
|
16
|
+
import yaml
|
|
17
|
+
|
|
18
|
+
PROFILE_NAME_DEFAULT = "Generic planning screen (not an ISO/utility criterion)"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@dataclass
|
|
22
|
+
class VoltageBand:
|
|
23
|
+
"""Voltage limits (per unit) for buses within a nominal-kV range."""
|
|
24
|
+
|
|
25
|
+
kv_min: float = 0.0 # inclusive
|
|
26
|
+
kv_max: float = 1.0e9 # inclusive
|
|
27
|
+
v_min_normal: float = 0.95
|
|
28
|
+
v_max_normal: float = 1.05
|
|
29
|
+
v_min_contingency: float = 0.90
|
|
30
|
+
v_max_contingency: float = 1.10
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@dataclass
|
|
34
|
+
class Criteria:
|
|
35
|
+
profile_name: str = PROFILE_NAME_DEFAULT
|
|
36
|
+
|
|
37
|
+
# Default voltage limits (used when no kV band or bus override applies)
|
|
38
|
+
v_min_normal: float = 0.95
|
|
39
|
+
v_max_normal: float = 1.05
|
|
40
|
+
v_min_contingency: float = 0.90
|
|
41
|
+
v_max_contingency: float = 1.10
|
|
42
|
+
|
|
43
|
+
# Thermal limits, percent of the rating used for each condition
|
|
44
|
+
thermal_normal_pct: float = 100.0
|
|
45
|
+
thermal_contingency_pct: float = 100.0
|
|
46
|
+
# Emergency rating as a percent of the normal rating. Used only when the
|
|
47
|
+
# network data carries a single rating (as the IEEE 39-bus case does).
|
|
48
|
+
emergency_rating_pct_of_normal: float = 100.0
|
|
49
|
+
|
|
50
|
+
# Only buses at or above this nominal voltage are monitored for voltage
|
|
51
|
+
monitor_min_kv: float = 0.0
|
|
52
|
+
|
|
53
|
+
# A violation that already exists with 0 MW injected is reported only if
|
|
54
|
+
# the new plant worsens it by more than these tolerances.
|
|
55
|
+
preexisting_tol_pu: float = 0.005
|
|
56
|
+
preexisting_tol_pct: float = 1.0
|
|
57
|
+
# "worsen": pre-existing violations count only if worsened beyond tolerance
|
|
58
|
+
# "ignore": pre-existing violations never limit the plant (they are still reported)
|
|
59
|
+
preexisting_policy: str = "worsen"
|
|
60
|
+
|
|
61
|
+
voltage_bands: list[VoltageBand] = field(default_factory=list)
|
|
62
|
+
# Per-bus overrides, keyed by bus label: {label: {v_min_normal: ..., ...}}
|
|
63
|
+
bus_overrides: dict = field(default_factory=dict)
|
|
64
|
+
|
|
65
|
+
# ---------------------------------------------------------------
|
|
66
|
+
def voltage_limits(self, bus_label, vn_kv: float, contingency: bool) -> tuple[float, float]:
|
|
67
|
+
"""Return (v_min, v_max) in per unit for a bus and system condition."""
|
|
68
|
+
vmin = self.v_min_contingency if contingency else self.v_min_normal
|
|
69
|
+
vmax = self.v_max_contingency if contingency else self.v_max_normal
|
|
70
|
+
for band in self.voltage_bands:
|
|
71
|
+
if band.kv_min <= vn_kv <= band.kv_max:
|
|
72
|
+
vmin = band.v_min_contingency if contingency else band.v_min_normal
|
|
73
|
+
vmax = band.v_max_contingency if contingency else band.v_max_normal
|
|
74
|
+
break
|
|
75
|
+
ov = self.bus_overrides.get(str(bus_label))
|
|
76
|
+
if ov:
|
|
77
|
+
key_min = "v_min_contingency" if contingency else "v_min_normal"
|
|
78
|
+
key_max = "v_max_contingency" if contingency else "v_max_normal"
|
|
79
|
+
vmin = float(ov.get(key_min, vmin))
|
|
80
|
+
vmax = float(ov.get(key_max, vmax))
|
|
81
|
+
return vmin, vmax
|
|
82
|
+
|
|
83
|
+
def thermal_limit_pct(self, contingency: bool) -> float:
|
|
84
|
+
"""Loading limit in percent of the NORMAL rating carried by the model."""
|
|
85
|
+
if contingency:
|
|
86
|
+
return self.thermal_contingency_pct * self.emergency_rating_pct_of_normal / 100.0
|
|
87
|
+
return self.thermal_normal_pct
|
|
88
|
+
|
|
89
|
+
def validate(self) -> None:
|
|
90
|
+
pairs = [(self.v_min_normal, self.v_max_normal), (self.v_min_contingency, self.v_max_contingency)]
|
|
91
|
+
pairs += [(b.v_min_normal, b.v_max_normal) for b in self.voltage_bands]
|
|
92
|
+
pairs += [(b.v_min_contingency, b.v_max_contingency) for b in self.voltage_bands]
|
|
93
|
+
for lo, hi in pairs:
|
|
94
|
+
if not (0.5 < lo < hi < 1.5):
|
|
95
|
+
raise ValueError(f"Invalid voltage limits: min={lo}, max={hi} (per unit)")
|
|
96
|
+
for name in ("thermal_normal_pct", "thermal_contingency_pct", "emergency_rating_pct_of_normal"):
|
|
97
|
+
if getattr(self, name) <= 0:
|
|
98
|
+
raise ValueError(f"{name} must be positive")
|
|
99
|
+
if self.preexisting_policy not in ("worsen", "ignore"):
|
|
100
|
+
raise ValueError("preexisting_policy must be 'worsen' or 'ignore'")
|
|
101
|
+
if self.preexisting_tol_pu < 0 or self.preexisting_tol_pct < 0:
|
|
102
|
+
raise ValueError("Pre-existing violation tolerances must be zero or positive")
|
|
103
|
+
|
|
104
|
+
def to_dict(self) -> dict:
|
|
105
|
+
return asdict(self)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def load_criteria(path: Optional[str | Path] = None) -> Criteria:
|
|
109
|
+
"""Load criteria from YAML. Missing keys keep their default values."""
|
|
110
|
+
if path is None:
|
|
111
|
+
crit = Criteria()
|
|
112
|
+
crit.validate()
|
|
113
|
+
return crit
|
|
114
|
+
data = yaml.safe_load(Path(path).read_text(encoding="utf-8")) or {}
|
|
115
|
+
known = set(Criteria.__dataclass_fields__)
|
|
116
|
+
unknown = set(data) - known
|
|
117
|
+
if unknown:
|
|
118
|
+
raise ValueError(f"Unknown criteria keys in {path}: {sorted(unknown)}")
|
|
119
|
+
bands = [VoltageBand(**b) for b in data.pop("voltage_bands", []) or []]
|
|
120
|
+
overrides = {str(k): v for k, v in (data.pop("bus_overrides", {}) or {}).items()}
|
|
121
|
+
crit = Criteria(**data, voltage_bands=bands, bus_overrides=overrides)
|
|
122
|
+
crit.validate()
|
|
123
|
+
return crit
|