Workbench Quick Reference
Beyond the indexable interface, PowerWorld provides convenience methods that wrap common workflows into single calls. These cover data retrieval shortcuts, power flow, voltage analysis, matrix extraction, sensitivity factors, and case control - so you spend less time assembling field lists and more time on analysis.
from esapp import PowerWorld
from esapp.components import *
pw = PowerWorld("path/to/case.pwb")
Data Shortcuts
These methods return DataFrames of common object types with their most useful fields pre-selected. They’re thin wrappers around the indexable interface - pw.gens() is equivalent to pw[Gen, ["GenMW", "GenMVR", "GenStatus"]] but shorter to type.
Method |
Returns |
|---|---|
|
Generator MW, Mvar, and status |
|
Load MW, Mvar, and status |
|
Switched shunt MW, Mvar, and status |
|
All transmission lines |
|
All transformers |
|
All areas |
|
All zones |
In [9]:
pw.gens().head()
Out[9]:
| BusNum | GenID | GenMVR | GenMW | GenStatus | |
|---|---|---|---|---|---|
| 0 | 2 | 1 | 0.80000 | 2.500000 | Closed |
| 1 | 2 | 2 | 0.80000 | 2.500000 | Closed |
| 2 | 2 | 3 | 0.80000 | 2.500000 | Closed |
| 3 | 2 | 4 | 0.80000 | 2.500000 | Closed |
| 4 | 23 | 1 | 0.04408 | 69.274741 | Closed |
In [10]:
pw.loads().head()
Out[10]:
| BusNum | LoadID | LoadMVR | LoadMW | LoadStatus | |
|---|---|---|---|---|---|
| 0 | 2 | 1 | 0.0 | 60.699999 | Closed |
| 1 | 3 | 1 | 0.0 | 59.390002 | Closed |
| 2 | 4 | 1 | 0.0 | 22.470000 | Closed |
| 3 | 6 | 1 | 0.0 | 27.460000 | Closed |
| 4 | 7 | 1 | 0.0 | 37.009999 | Closed |
Power Flow & Voltage Analysis
pflow() solves the AC power flow and returns complex bus voltages. After solving, all data accessed through the indexable interface reflects the updated system state. You can specify the solution method explicitly or use the default (Polar Newton-Raphson).
V = pw.pflow() # default: Polar Newton-Raphson
V = pw.pflow(method="POLARNEWT") # explicit method selection
Several methods provide quick access to voltage and power data without having to assemble field lists manually:
Method |
Returns |
|---|---|
|
Complex bus voltages (per-unit) |
|
Magnitude and angle as separate Series |
|
Set bus voltages from a complex array |
|
Bus active/reactive power mismatches |
|
Net power injection at each bus |
|
Buses outside a voltage band |
In [11]:
V = pw.voltage()
np.abs(V).describe()
Out[11]:
count 37.000000
mean 0.988868
std 0.008708
min 0.974911
25% 0.980583
50% 0.991217
75% 0.995798
max 1.003416
dtype: float64
Matrices & Topology
System matrices are returned as scipy sparse arrays by default, with an option for dense numpy arrays. The bus map provides the mapping between PowerWorld bus numbers and matrix row/column indices.
Method |
Returns |
|---|---|
|
System admittance matrix (sparse) |
|
Dense admittance matrix |
|
Power flow Jacobian |
|
Polar-form Jacobian |
|
DC Jacobian |
|
Bus number to matrix index mapping |
|
Bus latitude/longitude from substation data |
In [12]:
Y = pw.ybus()
Y.shape
Out[12]:
(37, 37)
In [13]:
J = pw.jacobian()
J.shape
Out[13]:
(74, 74)
Case Control & Solver Options
Basic case management methods handle saving, closing, and resetting the case state. Solver options are exposed as Python descriptors on PowerWorld, letting you read and write simulation settings as regular attributes rather than calling dedicated getter/setter methods.
Method |
Purpose |
|---|---|
|
Save the case |
|
Save to a new file |
|
Close the current case |
|
Reset to 1.0 pu / 0 deg |
|
Enter edit mode |
|
Enter run mode |
|
Add a message to the PowerWorld log |
Solver settings are accessed directly as attributes:
pw.max_iterations = 250 # set max Newton iterations
pw.flat_start = True # enable flat start
pw.convergence_tol = 1e-5 # set convergence tolerance
pw.do_one_iteration = True # single iteration mode
pw.dc_mode = True # DC approximation
See the API Reference for the full list of solver option descriptors.
Convenience Features
Several methods wrap multi-step workflows into single calls.
Branch flows and overloads - flows() retrieves MW, MVR, MVA, and percent loading for every branch. overloads() filters to branches exceeding a threshold.
Method |
Returns |
|---|---|
|
Branch MW, MVR, MVA, and % loading |
|
Branches exceeding a loading threshold |
Sensitivity factors - ptdf() and lodf() compute Power Transfer Distribution Factors and Line Outage Distribution Factors, respectively. Both call the underlying SAW sensitivity commands and return the results as a DataFrame.
Method |
Returns |
|---|---|
|
Power Transfer Distribution Factors |
|
Line Outage Distribution Factors |
Snapshot - a context manager that saves the current case state on entry and restores it on exit, even if an exception occurs. Useful for “what-if” analyses where you want to modify the case temporarily without losing the original state.
with pw.snapshot():
pw[Gen, "GenMW"] = modified_gen
pw.pflow()
v = pw.voltage()
# state automatically restored here
Quick properties provide case-level counts and the system MVA base without having to query and count manually. summary() aggregates these into a single dict along with generation/load totals and the voltage range.
Property / Method |
Returns |
|---|---|
|
Number of buses |
|
Number of branches |
|
Number of generators |
|
System MVA base (float) |
|
Dict with counts, totals, and voltage range |
Utility Modules
PowerWorld embeds specialized analysis modules as attributes. These provide domain-specific functionality built on top of the indexable interface and SAW commands.
Attribute |
Module |
Capabilities |
|---|---|---|
|
Network topology |
Incidence matrices, Laplacians, bus coordinates |
|
GIC analysis |
G-matrix, E-field Jacobians, storm simulation |
Like the solver options on PowerWorld, GIC analysis options are also exposed as descriptors on pw.gic:
pw.gic.pf_include = True # enable GIC in power flow
pw.gic.calc_mode = 'SnapShot' # set calculation mode
pw.gic.configure() # apply sensible defaults
See the API Reference for full documentation of each module.