diff --git a/Project.toml b/Project.toml index b2d9deb..6ca42ad 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "PowerSystemsMaps" uuid = "e146f72c-d4f8-45d3-b3ca-12a16cb68a38" authors = ["cbarrows "] -version = "0.1.3" +version = "0.1.4" [deps] Colors = "5ae59095-9a9b-59fe-a467-6f913c188581" @@ -20,6 +20,6 @@ Graphs = "1.4" MetaGraphs = "0.7" NetworkLayout = "0.4" Plots = "1" -PowerSystems = "1, 2" +PowerSystems = "2" Shapefile = "0.7, 0.8" julia = "^1.6" diff --git a/README.md b/README.md index 039d179..dcead6a 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ using Pkg; Pkg.add("PowerSystemsMaps") ```julia using PowerSystems -using PowerSystemsMaps +using PowerSystemsMaps PSM = PowerSystemsMaps PSM.Plots.plotlyjs() # load the PlotlyJS backend @@ -53,6 +53,6 @@ p = plot_net!( shownodelegend = true, size = (1500,800), buffer = 0.4e4 -) +) ``` diff --git a/src/plot_network.jl b/src/plot_network.jl index 473f77e..0a825bc 100644 --- a/src/plot_network.jl +++ b/src/plot_network.jl @@ -29,17 +29,18 @@ end function color_nodes!(g, sys, color_by::Type{T}) where {T <: AggregationTopology} # Generate n maximally distinguishable colors in LCHab space. - areas = get_components(color_by, sys) + accessor = get_aggregation_topology_accessor(color_by) + agg_top = get_components(color_by, sys) buses = get_components(Bus, sys) area_colors = Dict( zip( - get_name.(areas), - Colors.distinguishable_colors(length(areas), Colors.colorant"blue"), + get_name.(agg_top), + Colors.distinguishable_colors(length(agg_top), Colors.colorant"blue"), ), ) - node_colors = getindex.(Ref(area_colors), get_name.(get_area.(buses))) + node_colors = getindex.(Ref(area_colors), get_name.(accessor.(buses))) color_nodes!(g, sys, node_colors) - set_prop!(g, :group, get_name.(get_area.(buses))) + set_prop!(g, :group, get_name.(accessor.(buses))) end function color_nodes!(g, sys, color_by) @@ -135,6 +136,38 @@ function make_graph(sys::PowerSystems.System; kwargs...) return g end + + +function plot_lines!(p, sys, line_width) + components = collect(get_components(Branch, sys)) + fr_lat_lon = get_ext.(get_from.(get_arc.(components))) + to_lat_lon = get_ext.(get_to.(get_arc.(components))) + fr_xy = [PSM.lonlat_to_webmercator((PSM.get_longitude(p), PSM.get_latitude(p))) for p in fr_lat_lon] + to_xy = [PSM.lonlat_to_webmercator((PSM.get_longitude(p), PSM.get_latitude(p))) for p in to_lat_lon] + + xy = [] + groups = [] + labels = [] + for (i, c) in enumerate(components) + push!(xy, [fr_xy[i][1] fr_xy[i][2]; to_xy[i][1] to_xy[i][2]; NaN NaN]) + for _ in 1:3 + push!(groups, get_base_voltage(get_from(get_arc(c)))) + push!(labels, get_name(c)) + end + end + xy = vcat(xy...) + + p = plot!( + p, + xy[:,1], xy[:,2]; + linewidth = line_width, + hover = labels, + group = groups, + legend = true + ) + return p +end + """ plot a network from a graph