Skip to content

Commit

Permalink
Merge pull request #443 from lanl-ansi/im-v0.13
Browse files Browse the repository at this point in the history
* use row-to-dict from im, updated print summary from im
* update infrastructure models require
* update changelog for next release
  • Loading branch information
ccoffrin authored Jan 1, 2019
2 parents 2fb7327 + 6beeb2a commit fd298a9
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 43 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ PowerModels.jl Change Log
=========================

### Staged
- nothing

### v0.9.2
- Added tracking of modifications in check_network_data
- Added validate option to parse_file
- Added silence() function to suppress info and warn messages
- Improved support for storage units in summary function

### v0.9.1
- Fixed print_summary in Julia v1.0
Expand Down
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
julia 0.6
JSON 0.6
InfrastructureModels 0.0.11 0.2-
InfrastructureModels 0.0.13 0.2-
MathProgBase 0.5.4
JuMP 0.17 0.19-
Compat 1.0
Expand Down
2 changes: 0 additions & 2 deletions docs/src/parser.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ We also provide the following (internal) helper methods:
parse_matpower_file
parse_matpower_string
matpower_to_powermodels
row_to_typed_dict
row_to_dict
mp_cost_data
split_loads_shunts
standardize_cost_terms
Expand Down
50 changes: 48 additions & 2 deletions src/core/data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,60 @@ end
"prints the text summary for a data file to IO"
function summary(io::IO, file::String; kwargs...)
data = parse_file(file)
InfrastructureModels.summary(io, data; kwargs...)
summary(io, data; kwargs...)
return data
end


pm_component_types_order = Dict(
"bus" => 1.0, "load" => 2.0, "shunt" => 3.0, "gen" => 4.0, "storage" => 5.0,
"branch" => 6.0, "dcline" => 7.0
)

pm_component_parameter_order = Dict(
"bus_i" => 1.0, "load_bus" => 2.0, "shunt_bus" => 3.0, "gen_bus" => 4.0,
"storage_bus" => 5.0, "f_bus" => 6.0, "t_bus" => 7.0,

"bus_name" => 9.1, "base_kv" => 9.2, "bus_type" => 9.3,

"vm" => 10.0, "va" => 11.0,
"pd" => 20.0, "qd" => 21.0,
"gs" => 30.0, "bs" => 31.0,
"pg" => 40.0, "qg" => 41.0, "vg" => 42.0, "mbase" => 43.0,
"energy" => 44.0,
"br_r" => 50.0, "br_x" => 51.0, "g_fr" => 52.0, "b_fr" => 53.0,
"g_to" => 54.0, "b_to" => 55.0, "tap" => 56.0, "shift" => 57.0,
"vf" => 58.1, "pf" => 58.2, "qf" => 58.3,
"vt" => 58.4, "pt" => 58.5, "qt" => 58.6,
"loss0" => 58.7, "loss1" => 59.8,

"vmin" => 60.0, "vmax" => 61.0,
"pmin" => 62.0, "pmax" => 63.0,
"qmin" => 64.0, "qmax" => 65.0,
"rate_a" => 66.0, "rate_b" => 67.0, "rate_c" => 68.0,
"pminf" => 69.0, "pmaxf" => 70.0, "qminf" => 71.0, "qmaxf" => 72.0,
"pmint" => 73.0, "pmaxt" => 74.0, "qmint" => 75.0, "qmaxt" => 76.0,
"energy_rating" => 77.01, "charge_rating" => 77.02,
"discharge_rating" => 77.03, "charge_efficiency" => 77.04,
"discharge_efficiency" => 77.05, "thermal_rating" => 77.06,
"qmin" => 77.07, "qmax" => 77.08, "qmin" => 77.09, "qmax" => 77.10,
"r" => 77.11, "x" => 77.12, "standby_loss" => 77.13,

"status" => 80.0, "gen_status" => 81.0, "br_status" => 82.0,

"model" => 90.0, "ncost" => 91.0, "cost" => 92.0, "startup" => 93.0, "shutdown" => 94.0
)

pm_component_status_parameters = Set(["status", "gen_status", "br_status"])


"prints the text summary for a data dictionary to IO"
function summary(io::IO, data::Dict{String,Any}; kwargs...)
InfrastructureModels.summary(io, data; kwargs...)
InfrastructureModels.summary(io, data;
component_types_order = pm_component_types_order,
component_parameter_order = pm_component_parameter_order,
component_status_parameters = pm_component_status_parameters,
kwargs...)
end


Expand Down
45 changes: 7 additions & 38 deletions src/io/matpower.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,6 @@ function parse_matpower(file::Union{IO, String}; validate=true)
end


### very generic helper functions ###

"takes a row from a matrix and assigns the values names and types"
function row_to_typed_dict(row_data, columns)
dict_data = Dict{String,Any}()
for (i,v) in enumerate(row_data)
if i <= length(columns)
name, typ = columns[i]
dict_data[name] = InfrastructureModels.check_type(typ, v)
else
dict_data["col_$(i)"] = v
end
end
return dict_data
end

"takes a row from a matrix and assigns the values names"
function row_to_dict(row_data, columns)
dict_data = Dict{String,Any}()
for (i,v) in enumerate(row_data)
if i <= length(columns)
dict_data[columns[i]] = v
else
dict_data["col_$(i)"] = v
end
end
return dict_data
end



### Data and functions specific to Matpower format ###

mp_data_names = ["mpc.version", "mpc.baseMVA", "mpc.bus", "mpc.gen",
Expand Down Expand Up @@ -189,7 +158,7 @@ function parse_matpower_string(data_string::String)
if haskey(matlab_data, "mpc.bus")
buses = []
for bus_row in matlab_data["mpc.bus"]
bus_data = row_to_typed_dict(bus_row, mp_bus_columns)
bus_data = InfrastructureModels.row_to_typed_dict(bus_row, mp_bus_columns)
bus_data["index"] = InfrastructureModels.check_type(Int, bus_row[1])
push!(buses, bus_data)
end
Expand All @@ -201,7 +170,7 @@ function parse_matpower_string(data_string::String)
if haskey(matlab_data, "mpc.gen")
gens = []
for (i, gen_row) in enumerate(matlab_data["mpc.gen"])
gen_data = row_to_typed_dict(gen_row, mp_gen_columns)
gen_data = InfrastructureModels.row_to_typed_dict(gen_row, mp_gen_columns)
gen_data["index"] = i
push!(gens, gen_data)
end
Expand All @@ -213,7 +182,7 @@ function parse_matpower_string(data_string::String)
if haskey(matlab_data, "mpc.branch")
branches = []
for (i, branch_row) in enumerate(matlab_data["mpc.branch"])
branch_data = row_to_typed_dict(branch_row, mp_branch_columns)
branch_data = InfrastructureModels.row_to_typed_dict(branch_row, mp_branch_columns)
branch_data["index"] = i
push!(branches, branch_data)
end
Expand All @@ -225,7 +194,7 @@ function parse_matpower_string(data_string::String)
if haskey(matlab_data, "mpc.dcline")
dclines = []
for (i, dcline_row) in enumerate(matlab_data["mpc.dcline"])
dcline_data = row_to_typed_dict(dcline_row, mp_dcline_columns)
dcline_data = InfrastructureModels.row_to_typed_dict(dcline_row, mp_dcline_columns)
dcline_data["index"] = i
push!(dclines, dcline_data)
end
Expand All @@ -235,7 +204,7 @@ function parse_matpower_string(data_string::String)
if haskey(matlab_data, "mpc.storage")
storage = []
for (i, storage_row) in enumerate(matlab_data["mpc.storage"])
storage_data = row_to_typed_dict(storage_row, mp_storage_columns)
storage_data = InfrastructureModels.row_to_typed_dict(storage_row, mp_storage_columns)
storage_data["index"] = i
push!(storage, storage_data)
end
Expand All @@ -246,7 +215,7 @@ function parse_matpower_string(data_string::String)
if haskey(matlab_data, "mpc.bus_name")
bus_names = []
for (i, bus_name_row) in enumerate(matlab_data["mpc.bus_name"])
bus_name_data = row_to_typed_dict(bus_name_row, mp_bus_name_columns)
bus_name_data = InfrastructureModels.row_to_typed_dict(bus_name_row, mp_bus_name_columns)
bus_name_data["index"] = i
push!(bus_names, bus_name_data)
end
Expand Down Expand Up @@ -296,7 +265,7 @@ function parse_matpower_string(data_string::String)
end
tbl = []
for (i, row) in enumerate(matlab_data[k])
row_data = row_to_dict(row, column_names)
row_data = InfrastructureModels.row_to_dict(row, column_names)
row_data["index"] = i
push!(tbl, row_data)
end
Expand Down

0 comments on commit fd298a9

Please sign in to comment.