Skip to content

Commit

Permalink
Exporter: add round trip *bus* name remapping
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielKS committed Jul 23, 2024
1 parent 0cf2345 commit 62f3137
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
16 changes: 15 additions & 1 deletion src/psse_exporter/psse_exporter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,21 @@ function create_gen_ids(gens::Vector{<:PSY.Device})
return gen_ids
end

# TODO maybe we want a special System constructor that takes the JSON and does this internally
# TODO maybe we want a special System constructor that takes the JSON and handles these mappings internally
"""
Given a metadata dictionary parsed from a `raw_metadata_log.json`, yields a function that
can be passed as the `bus_name_formatter` kwarg to the `System` constructor to properly
restore Sienna bus names:
`System("filename.raw"; bus_name_formatter = PF.make_bus_name_formatter_from_metadata(md))`
"""
function make_bus_name_formatter_from_metadata(md::Dict)
bus_map = Dict(value => key for (key, value) in md["Bus_Name_Mapping"])
function md_bus_name_formatter(device_dict::Dict)::String
return bus_map[device_dict["name"]]
end
return md_bus_name_formatter
end

"""
Given a metadata dictionary parsed from a `raw_metadata_log.json`, yields a function that
can be passed as the `gen_name_formatter` kwarg to the `System` constructor to properly
Expand Down
14 changes: 4 additions & 10 deletions test/test_psse_export.jl
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,7 @@ end
# We currently have two imperfect methods of comparing systems. TODO at some point combine into one good method
function compare_systems_wrapper(sys1::System, sys2::System, sys2_metadata = nothing)
first_result = compare_component_values(sys1, sys2)
second_result = compare_systems_loosely(
sys1,
sys2;
bus_name_mapping = if isnothing(sys2_metadata)
Dict{String, String}()
else
sys2_metadata["Bus_Name_Mapping"]
end,
)
second_result = compare_systems_loosely(sys1, sys2)
return first_result && second_result
end

Expand All @@ -241,7 +233,9 @@ end
function read_system_and_metadata(raw_path, metadata_path)
md = PF.JSON.parsefile(metadata_path)
sys =
System(raw_path; gen_name_formatter = PF.make_gen_name_formatter_from_metadata(md))
System(raw_path;
bus_name_formatter = PF.make_bus_name_formatter_from_metadata(md),
gen_name_formatter = PF.make_gen_name_formatter_from_metadata(md))
return sys, md
end

Expand Down

0 comments on commit 62f3137

Please sign in to comment.