Flexible graph visualization tool for power systems



Flexible graph visualization tool for power systems

This package specifies a few power grid visualizations, and has tools for mapping any data you like onto a particular visualization. It works well with PowerModels.jl, so you can iterate and explore as you work on new algorithms and relaxations for power flow analysis.

Usage example

using PowerGrid3, PowerModels, Ipopt

casepath = joinpath(Pkg.dir("PowerGrid3"), "test", "data", "pglib_opf_case14_ieee.m")
solver = IpoptSolver()
jsonpath = joinpath(Pkg.dir("PowerGrid3"), "html", "graphdata.json")
htmlpath = joinpath(Pkg.dir("PowerGrid3"), "html", "index.html")

pm = build_generic_model(casepath, ACPPowerModel, PowerModels.post_opf)
result = solve_generic_model(pm, solver)

gd = GraphData(pm)

# dictionary with bus_id keys and vmag values
vmag = mapbuspropertysol(pm, result, "vm")

# encode vmin as color in JSON data
setnodeproperty!(gd, "color", vmag)

# set lower and upper extrema to blue and red, resp.
nodeColor = ContinuousScale(vmag, ["blue", "red"])

savegraphdata(jsonpath, gd)
savehtml(htmlpath, nodeColor=nodeColor)

Effective power system graph visualizations include:

  • Force-directed layouts
    • Applying uniform forces reveals basic structure of the unweighted graph
    • Letting forces vary with some system property can provide additional insight. Each node's attractive force can be related to generation capacity, for example.
  • Layouts with fixed edge lengths
    • Use Thevenin impedance or injection shift factors to obtain pairwise distances, then perform multi-dimensional scaling to embed the graph in a plane without relying on a force-directed layout. Distances in this plane are "electrical distances".
  • Color and size
    • Each generator can be represented by a smaller circle, while buses are drawn as larger circles.
    • Each edge may be colored according to line flow, in relation to all flows across the network or as a fraction of individual line capacity.
    • Hovering over a node or edge can show more information.

D3 and force simulations

Styling nodes or edges requires each element to be assigned a value; it also requires a "scale" to determine how each value is mapped to some visual feature (size, color). D3 has excellent scaling tools, so this package focuses on assigning data values (continuous or categorical) to buses and lines, and lets D3 handle the conversion to sizes/colors/etc.

D3's force simulation makes it easy to generate force-directed graphs from appropriately-formatted JSON files. PowerGrid3 uses Julia to write these files. Let's say we want to color a line according to flow, as a fraction of capacity. PowerGrid3 does the following:

  • Compute the fraction of capacity for each line
  • Store each value as a property of the corresponding edge
  • Write a graphdata.json containing this data
  • Generate a scale that maps from the extrema (or maybe the range 0-100%) to colors (i.e. blue-red)
  • Write Javascript code containing this scale, telling D3 to connect the line flow values to colors by way of the scale

This informs the type structure. One object would be NodeStyle, with a field for encoding the domain and range, and another field with the dictionary that maps each node ID (bus ID) to a value

For more information on D3 force simulations:

Other planar embedding techniques

D3's force simulations embed a graph using only its adjacency information, but power grids have much more data available. Research has identified appropriate distance metrics based on electrical information: rather than simulating some physical force, you can compute pairwise electrical distances between nodes, use multi-dimensional scaling to then lay out the graph directly.

Seeing the visualizations

Planar embeddings may be generated by Plots.jl, just like any other plot. Force simulations, however, require D3. There is an Atom package that allows you to preview an HTML file from within Atom. Thus, if you use PowerGrid3 to save JSON and .html files in some directory, then preview the HTML file using the Atom package's command, you will be able to see graph visualizations within Atom. (There is even an option to have the graph update any time you save.)

First Commit


Last Touched

over 1 year ago


11 commits

Used By: