PowerModels Dictionary to DataFrame Conversion
VegaLite uses tabular data when creating a plot, and this requires converting the PowerModels dictionary data into a DataFrame. A struct is used for all of the supported components of the base power plot, where each component type is a DataFrame. This struct is created when powerplot()
is called. Multi-network dictionaries are supported.
mutable struct PowerModelsDataFrame
metadata::DataFrames.DataFrame
components::Dict{Symbol, DataFrames.DataFrame}
Top level data (non-components) is stored in a the meta data field. The components are stored as DataFrames in a dictionary, where the keys are the component types. By default any components that are in the supported components list are added.
Using tabular data can be convenient for a statistical analysis of the components. To create this data struct, call the constructor on a powermodels dictionary.
using PowerModels
using PowerPlots
case = parse_file("case14.m")
case_PMDF = PowerModelsDataFrame(case)
PowerModelsDataFrame(1×5 DataFrame
Row │ source_version per_unit source_type name baseMVA
│ SubString… Bool String SubString… Float64
─────┼───────────────────────────────────────────────────────────────────────
1 │ 2 true matpower pglib_opf_case14_ieee 100.0, Dict{Symbol, DataFrames.DataFrame}(:branch => 20×20 DataFrame
Row │ br_r rate_a shift rate_b br_x rate_c g_to Componen ⋯
│ Float64 Float64 Float64 Float64 Float64 Float64 Float64 Symbol ⋯
─────┼──────────────────────────────────────────────────────────────────────────
1 │ 0.05811 1.58 0.0 1.58 0.17632 1.58 0.0 branch ⋯
2 │ 0.01938 4.72 0.0 4.72 0.05917 4.72 0.0 branch
3 │ 0.12291 1.04 0.0 1.04 0.25581 1.04 0.0 branch
4 │ 0.17093 0.76 0.0 0.76 0.34802 0.76 0.0 branch
5 │ 0.05403 1.28 0.0 1.28 0.22304 1.28 0.0 branch ⋯
6 │ 0.06701 1.6 0.0 1.6 0.17103 1.6 0.0 branch
7 │ 0.09498 1.34 0.0 1.34 0.1989 1.34 0.0 branch
8 │ 0.06615 2.01 0.0 2.01 0.13027 2.01 0.0 branch
⋮ │ ⋮ ⋮ ⋮ ⋮ ⋮ ⋮ ⋮ ⋮ ⋱
14 │ 0.0 1.41 0.0 1.41 0.20912 1.41 0.0 branch ⋯
15 │ 0.12711 0.99 0.0 0.99 0.27038 0.99 0.0 branch
16 │ 0.0 1.17 0.0 1.17 0.25202 1.17 0.0 branch
17 │ 0.22092 0.99 0.0 0.99 0.19988 0.99 0.0 branch
18 │ 0.0 0.53 0.0 0.53 0.55618 0.53 0.0 branch ⋯
19 │ 0.08205 1.41 0.0 1.41 0.19207 1.41 0.0 branch
20 │ 0.04699 1.45 0.0 1.45 0.19797 1.45 0.0 branch
13 columns and 5 rows omitted, :voltage_source => 0×0 DataFrame, :switch => 0×0 DataFrame, :gen => 5×18 DataFrame
Row │ pg model shutdown startup qg gen_bus pmax Component ⋯
│ Float64 Int64 Float64 Float64 Float64 Int64 Float64 Symbol ⋯
─────┼──────────────────────────────────────────────────────────────────────────
1 │ 0.0 2 0.0 0.0 0.09 6 0.0 gen ⋯
2 │ 1.7 2 0.0 0.0 0.05 1 3.4 gen
3 │ 0.0 2 0.0 0.0 0.09 8 0.0 gen
4 │ 0.295 2 0.0 0.0 0.0 2 0.59 gen
5 │ 0.0 2 0.0 0.0 0.2 3 0.0 gen ⋯
11 columns omitted, :bus => 14×12 DataFrame
Row │ zone bus_i bus_type vmax ComponentType source_id area ⋯
│ Int64 Int64 Int64 Float64 Symbol String Int64 ⋯
─────┼──────────────────────────────────────────────────────────────────────────
1 │ 1 4 1 1.06 bus Any["bus", 4] 1 ⋯
2 │ 1 1 3 1.06 bus Any["bus", 1] 1
3 │ 1 12 1 1.06 bus Any["bus", 12] 1
4 │ 1 2 2 1.06 bus Any["bus", 2] 1
5 │ 1 6 2 1.06 bus Any["bus", 6] 1 ⋯
6 │ 1 11 1 1.06 bus Any["bus", 11] 1
7 │ 1 13 1 1.06 bus Any["bus", 13] 1
8 │ 1 5 1 1.06 bus Any["bus", 5] 1
9 │ 1 14 1 1.06 bus Any["bus", 14] 1 ⋯
10 │ 1 7 1 1.06 bus Any["bus", 7] 1
11 │ 1 8 2 1.06 bus Any["bus", 8] 1
12 │ 1 10 1 1.06 bus Any["bus", 10] 1
13 │ 1 9 1 1.06 bus Any["bus", 9] 1 ⋯
14 │ 1 3 2 1.06 bus Any["bus", 3] 1
5 columns omitted, :dcline => 0×0 DataFrame, :shunt => 1×7 DataFrame
Row │ source_id shunt_bus status gs bs index ComponentTyp ⋯
│ String Int64 Int8 Float64 Float64 Int64 Symbol ⋯
─────┼──────────────────────────────────────────────────────────────────────────
1 │ Any["bus", 9] 9 1 0.0 0.19 1 shunt ⋯
1 column omitted, :load => 11×7 DataFrame
Row │ source_id ComponentType load_bus status qd pd inde ⋯
│ String Symbol Int64 Int8 Float64 Float64 Int6 ⋯
─────┼──────────────────────────────────────────────────────────────────────────
1 │ Any["bus", 5] load 5 1 0.016 0.076 ⋯
2 │ Any["bus", 2] load 2 1 0.127 0.217
3 │ Any["bus", 3] load 3 1 0.19 0.942
4 │ Any["bus", 9] load 9 1 0.166 0.295
5 │ Any["bus", 14] load 14 1 0.05 0.149 1 ⋯
6 │ Any["bus", 6] load 6 1 0.075 0.112
7 │ Any["bus", 10] load 10 1 0.058 0.09
8 │ Any["bus", 11] load 11 1 0.018 0.035
9 │ Any["bus", 13] load 13 1 0.058 0.135 1 ⋯
10 │ Any["bus", 12] load 12 1 0.016 0.061
11 │ Any["bus", 4] load 4 1 -0.039 0.478
1 column omitted, :line => 0×0 DataFrame, :storage => 0×0 DataFrame…))
You can specify a subset of the default components, or new components not in the default list by passing in an argument.
case_PMDF = PowerModelsDataFrame(case, components=["bus", "branch"])
PowerModelsDataFrame(1×5 DataFrame
Row │ source_version per_unit source_type name baseMVA
│ SubString… Bool String SubString… Float64
─────┼───────────────────────────────────────────────────────────────────────
1 │ 2 true matpower pglib_opf_case14_ieee 100.0, Dict{Symbol, DataFrames.DataFrame}(:branch => 20×20 DataFrame
Row │ br_r rate_a shift rate_b br_x rate_c g_to Componen ⋯
│ Float64 Float64 Float64 Float64 Float64 Float64 Float64 Symbol ⋯
─────┼──────────────────────────────────────────────────────────────────────────
1 │ 0.05811 1.58 0.0 1.58 0.17632 1.58 0.0 branch ⋯
2 │ 0.01938 4.72 0.0 4.72 0.05917 4.72 0.0 branch
3 │ 0.12291 1.04 0.0 1.04 0.25581 1.04 0.0 branch
4 │ 0.17093 0.76 0.0 0.76 0.34802 0.76 0.0 branch
5 │ 0.05403 1.28 0.0 1.28 0.22304 1.28 0.0 branch ⋯
6 │ 0.06701 1.6 0.0 1.6 0.17103 1.6 0.0 branch
7 │ 0.09498 1.34 0.0 1.34 0.1989 1.34 0.0 branch
8 │ 0.06615 2.01 0.0 2.01 0.13027 2.01 0.0 branch
⋮ │ ⋮ ⋮ ⋮ ⋮ ⋮ ⋮ ⋮ ⋮ ⋱
14 │ 0.0 1.41 0.0 1.41 0.20912 1.41 0.0 branch ⋯
15 │ 0.12711 0.99 0.0 0.99 0.27038 0.99 0.0 branch
16 │ 0.0 1.17 0.0 1.17 0.25202 1.17 0.0 branch
17 │ 0.22092 0.99 0.0 0.99 0.19988 0.99 0.0 branch
18 │ 0.0 0.53 0.0 0.53 0.55618 0.53 0.0 branch ⋯
19 │ 0.08205 1.41 0.0 1.41 0.19207 1.41 0.0 branch
20 │ 0.04699 1.45 0.0 1.45 0.19797 1.45 0.0 branch
13 columns and 5 rows omitted, :bus => 14×12 DataFrame
Row │ zone bus_i bus_type vmax ComponentType source_id area ⋯
│ Int64 Int64 Int64 Float64 Symbol String Int64 ⋯
─────┼──────────────────────────────────────────────────────────────────────────
1 │ 1 4 1 1.06 bus Any["bus", 4] 1 ⋯
2 │ 1 1 3 1.06 bus Any["bus", 1] 1
3 │ 1 12 1 1.06 bus Any["bus", 12] 1
4 │ 1 2 2 1.06 bus Any["bus", 2] 1
5 │ 1 6 2 1.06 bus Any["bus", 6] 1 ⋯
6 │ 1 11 1 1.06 bus Any["bus", 11] 1
7 │ 1 13 1 1.06 bus Any["bus", 13] 1
8 │ 1 5 1 1.06 bus Any["bus", 5] 1
9 │ 1 14 1 1.06 bus Any["bus", 14] 1 ⋯
10 │ 1 7 1 1.06 bus Any["bus", 7] 1
11 │ 1 8 2 1.06 bus Any["bus", 8] 1
12 │ 1 10 1 1.06 bus Any["bus", 10] 1
13 │ 1 9 1 1.06 bus Any["bus", 9] 1 ⋯
14 │ 1 3 2 1.06 bus Any["bus", 3] 1
5 columns omitted, :connector => 0×0 DataFrame))
To create an individual component dictionary, use the comp_dict_to_dataframe
function.
case_PMDF = comp_dict_to_dataframe(case["bus"])
Row | zone | bus_i | bus_type | vmax | source_id | area | vmin | index | va | vm | base_kv |
---|---|---|---|---|---|---|---|---|---|---|---|
Int64 | Int64 | Int64 | Float64 | String | Int64 | Float64 | Int64 | Float64 | Float64 | Float64 | |
1 | 1 | 4 | 1 | 1.06 | Any["bus", 4] | 1 | 0.94 | 4 | 0.0 | 1.0 | 1.0 |
2 | 1 | 1 | 3 | 1.06 | Any["bus", 1] | 1 | 0.94 | 1 | 0.0 | 1.0 | 1.0 |
3 | 1 | 12 | 1 | 1.06 | Any["bus", 12] | 1 | 0.94 | 12 | 0.0 | 1.0 | 1.0 |
4 | 1 | 2 | 2 | 1.06 | Any["bus", 2] | 1 | 0.94 | 2 | 0.0 | 1.0 | 1.0 |
5 | 1 | 6 | 2 | 1.06 | Any["bus", 6] | 1 | 0.94 | 6 | 0.0 | 1.0 | 1.0 |
6 | 1 | 11 | 1 | 1.06 | Any["bus", 11] | 1 | 0.94 | 11 | 0.0 | 1.0 | 1.0 |
7 | 1 | 13 | 1 | 1.06 | Any["bus", 13] | 1 | 0.94 | 13 | 0.0 | 1.0 | 1.0 |
8 | 1 | 5 | 1 | 1.06 | Any["bus", 5] | 1 | 0.94 | 5 | 0.0 | 1.0 | 1.0 |
9 | 1 | 14 | 1 | 1.06 | Any["bus", 14] | 1 | 0.94 | 14 | 0.0 | 1.0 | 1.0 |
10 | 1 | 7 | 1 | 1.06 | Any["bus", 7] | 1 | 0.94 | 7 | 0.0 | 1.0 | 1.0 |
11 | 1 | 8 | 2 | 1.06 | Any["bus", 8] | 1 | 0.94 | 8 | 0.0 | 1.0 | 1.0 |
12 | 1 | 10 | 1 | 1.06 | Any["bus", 10] | 1 | 0.94 | 10 | 0.0 | 1.0 | 1.0 |
13 | 1 | 9 | 1 | 1.06 | Any["bus", 9] | 1 | 0.94 | 9 | 0.0 | 1.0 | 1.0 |
14 | 1 | 3 | 2 | 1.06 | Any["bus", 3] | 1 | 0.94 | 3 | 0.0 | 1.0 | 1.0 |