diff --git a/src/psse_exporter/psse_exporter.jl b/src/psse_exporter/psse_exporter.jl index 326c14d7..cdec0367 100644 --- a/src/psse_exporter/psse_exporter.jl +++ b/src/psse_exporter/psse_exporter.jl @@ -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 diff --git a/test/test_psse_export.jl b/test/test_psse_export.jl index 9d1d390c..6b06ca23 100644 --- a/test/test_psse_export.jl +++ b/test/test_psse_export.jl @@ -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 @@ -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