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.
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:
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:
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:
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.
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.)
over 1 year ago