diff --git a/docs/src/examples/basic examples.md b/docs/src/examples/basic examples.md index a7f5976..73112ed 100644 --- a/docs/src/examples/basic examples.md +++ b/docs/src/examples/basic examples.md @@ -87,6 +87,18 @@ powerplot(data; ) ``` +# Specify components for plotting +Supported components for plotting are specified as: +```@example power_data +supported_component_types +``` + +By default, all of these components found in the data dictionary will be plotted. However, it is possible to plot a subset of the components using the `components` keyword. + +```@example power_data +powerplot(data; components=["bus","branch"], width=300, height=300) +``` + # Power Flow If the variables `pf` (power from) and `pt` (power to) exist in the data, power flow directions can be visualized using the `show_flow` boolean toggle (true by default). diff --git a/docs/src/parameters.md b/docs/src/parameters.md index a664738..de77c69 100644 --- a/docs/src/parameters.md +++ b/docs/src/parameters.md @@ -10,6 +10,7 @@ These paramters modify the entire plot. | `layout_algorithim` | algorithm for generating network layout (see [Layouts](@ref)) | `kamada_kawai` | | `fixed` | use fixed coordinates from network model | `false` | | `parallel_edge_offset` | offset distance between parallel edges | `0.05` | +| `components` | string array of components to plot | `supported_component_types`| diff --git a/src/core/types.jl b/src/core/types.jl index ab96472..ddde72f 100644 --- a/src/core/types.jl +++ b/src/core/types.jl @@ -1,5 +1,8 @@ -const supported_component_types = ["bus","gen","branch","dcline","load", "connector", "nw"] +const supported_component_types = ["bus","gen","branch","dcline","load", "connector"] +const supported_node_types = ["bus","gen","load"] +const supported_edge_types = ["branch","dcline","connector"] + """ PowerModelsGraph diff --git a/src/experimental/experimental.jl b/src/experimental/experimental.jl index b754ce9..cb4b595 100644 --- a/src/experimental/experimental.jl +++ b/src/experimental/experimental.jl @@ -83,7 +83,6 @@ module Experimental end function _set_geo_coords!(plot_layer::AbstractDict{<:Any,<:Any}) - println("running_branch") # create lat/lon channels from x/y channels for i in keys(plot_layer["layer"]) if haskey(plot_layer["layer"][i],"layer") diff --git a/src/layouts/common.jl b/src/layouts/common.jl index b32afd0..466c1af 100644 --- a/src/layouts/common.jl +++ b/src/layouts/common.jl @@ -37,8 +37,8 @@ components is returned. function layout_network(case::Dict{String,<:Any}; fixed = false, layout_algorithm = kamada_kawai, - node_types::Array{String,1}=["bus","gen","storage","load"], - edge_types::Array{String,1}=["switch","branch","dcline","transformer"], + node_types::Array{String,1}=supported_node_types, + edge_types::Array{String,1}=supported_edge_types, connector_weight=0.5, edge_weight=1.0, kwargs... diff --git a/src/plots/plot.jl b/src/plots/plot.jl index 1c551d4..63172d9 100644 --- a/src/plots/plot.jl +++ b/src/plots/plot.jl @@ -14,6 +14,7 @@ Create a plower plot. Check github repo for documentation on kwarg options. function powerplot( case::Dict{String,<:Any}; layout_algorithm=kamada_kawai, + components=supported_component_types, fixed=false, invalid_keys = Dict("branch" => ["mu_angmin", "mu_angmax", "mu_sf", "shift", "rate_b", "rate_c", "g_to", "g_fr", "mu_st", "source_id", "f_bus", "t_bus", "qf", "angmin", "angmax", "qt", "tap"],#["b_fr","b_to", "xcoord_1", "xcoord_2", "ycoord_1", "ycoord_2", "pf", "src","dst","rate_a","br_r","br_x","index","br_status"], "bus" => ["mu_vmax", "lam_q", "mu_vmin", "source_id","lam_p"],#["xcoord_1", "ycoord_1", "bus_type", "name", "vmax", "vmin", "index", "va", "vm", "base_kv"], @@ -24,15 +25,26 @@ function powerplot( return _powerplot_mn(case; layout_algorithm=layout_algorithm, fixed=fixed, invalid_keys=invalid_keys, kwargs...) end + # copy data for modification by plots + data = deepcopy(case) + + # remove components that are not to be plotted + for component_type in supported_component_types + if !(component_type in components) && haskey(data, component_type) + delete!(data, component_type) + end + end + + # modify case dictionary for distribution grid data - if haskey(case, "is_kron_reduced") - case = distr_data(case) + if haskey(data, "is_kron_reduced") + data = distr_data(data) end @prepare_plot_attributes(kwargs) # creates the plot_attributes dictionary _validate_plot_attributes!(plot_attributes) # check the attributes for valid input types - data = layout_network(case; layout_algorithm=layout_algorithm, fixed=fixed, kwargs...) + data = layout_network(data; layout_algorithm=layout_algorithm, fixed=fixed, kwargs...) # fix parallel branch coordinates offset_parallel_edges!(data,plot_attributes[:parallel_edge_offset]) @@ -42,7 +54,7 @@ function powerplot( # validate data-related attributes _validate_data_type(plot_attributes, :gen_data_type) - _validate_data(PMD.gen, plot_attributes[:gen_data], "generator") + _validate_data(PMD.gen, plot_attributes[:gen_data], "gen") _validate_data_type(plot_attributes, :bus_data_type) _validate_data(PMD.bus, plot_attributes[:bus_data], "bus") _validate_data_type(plot_attributes, :branch_data_type) @@ -116,7 +128,7 @@ function powerplot!(plt_layer::VegaLite.VLSpec, case::Dict{String,<:Any}; # validate data-related attributes _validate_data_type(plot_attributes, :gen_data_type) - _validate_data(PMD.gen, plot_attributes[:gen_data], "generator") + _validate_data(PMD.gen, plot_attributes[:gen_data], "gen") _validate_data_type(plot_attributes, :bus_data_type) _validate_data(PMD.bus, plot_attributes[:bus_data], "bus") _validate_data_type(plot_attributes, :branch_data_type) @@ -184,7 +196,7 @@ function _powerplot_mn(case::Dict{String,<:Any}; # validate data-related attributes PowerPlots._validate_data_type(plot_attributes, :gen_data_type) - PowerPlots._validate_data(PMD.gen, plot_attributes[:gen_data], "generator") + PowerPlots._validate_data(PMD.gen, plot_attributes[:gen_data], "gen") PowerPlots._validate_data_type(plot_attributes, :bus_data_type) PowerPlots._validate_data(PMD.bus, plot_attributes[:bus_data], "bus") PowerPlots._validate_data_type(plot_attributes, :branch_data_type) @@ -251,7 +263,7 @@ function _powerplot_mn!(plt_layer::VegaLite.VLSpec, case::Dict{String,<:Any}; # validate data-related attributes PowerPlots._validate_data_type(plot_attributes, :gen_data_type) - PowerPlots._validate_data(PMD.gen, plot_attributes[:gen_data], "generator") + PowerPlots._validate_data(PMD.gen, plot_attributes[:gen_data], "gen") PowerPlots._validate_data_type(plot_attributes, :bus_data_type) PowerPlots._validate_data(PMD.bus, plot_attributes[:bus_data], "bus") PowerPlots._validate_data_type(plot_attributes, :branch_data_type) diff --git a/test/runtests.jl b/test/runtests.jl index f454c42..d2fc845 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -147,6 +147,12 @@ data = PowerModels.parse_file("$(joinpath(dirname(pathof(PowerModels)), ".."))/t end end + @testset "filter plot components" begin + case = PowerModels.parse_file("$(joinpath(dirname(pathof(PowerModels)), ".."))/test/data/matpower/case5.m") + p=powerplot(case, components=["bus","branch"]) + @test length(keys(p.layer))==2 + + end @testset "Experimental" begin using PowerPlots.Experimental @@ -204,6 +210,28 @@ data = PowerModels.parse_file("$(joinpath(dirname(pathof(PowerModels)), ".."))/t end + @testset "Verify new components are fully supported" begin + + # set of nodes and edges is equivalent to all supported components + @test Set(union(supported_node_types,supported_edge_types))==Set(supported_component_types) + + for comp_type in supported_component_types + Memento.info(PowerPlots._LOGGER, "checking support for: $comp_type") + + # check that all components have a plot function + @test isdefined(PowerPlots, Symbol("plot_$comp_type")) + + # check that all components have kwargs + @test haskey(default_plot_attributes, Symbol("$(comp_type)_size")) + @test haskey(default_plot_attributes, Symbol("$(comp_type)_color")) + # skip connector + if comp_type != "connector" + @test haskey(default_plot_attributes, Symbol("$(comp_type)_data")) + @test haskey(default_plot_attributes, Symbol("$(comp_type)_data_type")) + end + end + end + end PowerModels.logger_config!(prev_level); # reset PowerModels logger to previous level