Power Flow Data Guide
Network data follows the MATPOWER format, a standard for power system test cases. The data comes from the PGLib-OPF benchmark library (github.com/power-grid-lib/pglib-opf).
Required First Step
Before any network parsing, complete the loader setup described in LOADER_SETUP.md (same directory as this file). Every workflow that uses power-flow-data starts there; the examples below assume the loader from that document is installed and importable.
⚠️ Important: Handling Large Network Files
Network JSON files can be very large (100K+ lines for realistic grids). Never read line-by-line with sed, head, or similar tools — this wastes time and context.
Always use Python's JSON parser directly (after the LOADER_SETUP.md step):
import json
with open('network.json') as f:
data = json.load(f)
print(f"Buses: {len(data['bus'])}")
print(f"Generators: {len(data['gen'])}")
print(f"Branches: {len(data['branch'])}")
Network Topology Concepts
Bus Types
| Type | Code | Specified | Solved | Description |
|---|---|---|---|---|
| Slack | 3 | V, θ=0 | P, Q | Reference bus, balances power |
| PV | 2 | P, V | Q, θ | Generator bus with voltage control |
| PQ | 1 | P, Q | V, θ | Load bus |
Per-Unit System
baseMVA = 100
P_pu = P_MW / baseMVA
Loading Network Data
import json, numpy as np
def load_network(filepath):
with open(filepath) as f:
data = json.load(f)
return {
'baseMVA': data['baseMVA'],
'bus': np.array(data['bus']),
'gen': np.array(data['gen']),
'branch': np.array(data['branch']),
'gencost': np.array(data['gencost']),
'reserve_capacity': np.array(data['reserve_capacity']),
'reserve_requirement': data['reserve_requirement']
}
Reserve Data
| Field | Type | Description |
|---|---|---|
| reserve_capacity | array | Maximum reserve each generator can provide (MW) |
| reserve_requirement | float | Minimum total system reserves required (MW) |
Bus Number Mapping
bus_num_to_idx = {int(buses[i, 0]): i for i in range(n_bus)}
Branch Data Interpretation
def get_branch_info(branch, bus_num_to_idx):
return {
'from_bus': bus_num_to_idx[int(branch[0])],
'to_bus': bus_num_to_idx[int(branch[1])],
'rating': branch[5],
'in_service': branch[10] == 1
}
Computing Total Load
def total_load(buses):
return sum(bus[2] for bus in buses)