Skip to content
4 changes: 4 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
PowerFlowData = "dd99e9e3-7471-40fc-b48d-a10501125371"
PowerFlowFileParser = "a1ee5d7c-0b6f-11f1-9fcb-79237b21bc78"
PowerTableDataParser = "2b750c0e-0b6f-11f1-9200-1befd75df6be"
PrettyTables = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d"
TimeSeries = "9e3dc215-6440-5c97-bce1-76c03772f85e"
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
Expand All @@ -33,6 +35,8 @@ JSON3 = "1"
LinearAlgebra = "1"
Logging = "1"
PowerFlowData = "^1.5"
PowerFlowFileParser = "0.1"
PowerTableDataParser = "1"
PrettyTables = "2.4, 3.1"
TimeSeries = "0.25"
UUIDs = "1"
Expand Down
11 changes: 8 additions & 3 deletions src/PowerSystems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ export Scenarios # scenarios.jl

export get_dynamic_components

export parse_file
# export parse_file
export open_time_series_store!
export add_time_series!
export bulk_add_time_series!
Expand Down Expand Up @@ -530,8 +530,8 @@ export clear_ext!
export convert_component!
export set_area!
export set_load_zone!
export PowerModelsData
export PowerSystemTableData
# export PowerModelsData
# export PowerSystemTableData
export add_dyn_injectors!
export get_machine
export get_shaft
Expand Down Expand Up @@ -626,6 +626,11 @@ import InteractiveUtils
import PrettyTables
import PowerFlowData

# Import parsers

import PowerFlowFileParser
import PowerTableDataParser

# Import InfrastructureSystems both as full module name (needed for internal macros like @forward)
# and with alias for convenient usage throughout the codebase
import InfrastructureSystems
Expand Down
4 changes: 2 additions & 2 deletions src/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ end
function system_via_power_models(file_path::AbstractString; kwargs...)
pm_kwargs = Dict(k => v for (k, v) in kwargs if !in(k, SYSTEM_KWARGS))
sys_kwargs = Dict(k => v for (k, v) in kwargs if in(k, SYSTEM_KWARGS))
return System(PowerModelsData(file_path; pm_kwargs...); sys_kwargs...)
return System(PowerFlowFileParser.PowerModelsData(file_path; pm_kwargs...); sys_kwargs...)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
return System(PowerFlowFileParser.PowerModelsData(file_path; pm_kwargs...); sys_kwargs...)
return System(
PowerFlowFileParser.PowerModelsData(file_path; pm_kwargs...);
sys_kwargs...,
)

end

"""Constructs a System from a file path ending with .m, .raw, or .json
Expand Down Expand Up @@ -377,7 +377,7 @@ function System(sys_file::AbstractString, dyr_file::AbstractString; kwargs...)
ext = splitext(sys_file)[2]
if lowercase(ext) in [".raw"]
pm_kwargs = Dict(k => v for (k, v) in kwargs if !in(k, SYSTEM_KWARGS))
sys = System(PowerModelsData(sys_file; pm_kwargs...); kwargs...)
sys = System(PowerFlowFileParser.PowerModelsData(sys_file; pm_kwargs...); kwargs...)
else
throw(DataFormatError("$sys_file is not a .raw file type"))
end
Expand Down
2 changes: 1 addition & 1 deletion src/definitions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ IS.@scoped_enum(
)

const PS_MAX_LOG = parse(Int, get(ENV, "PS_MAX_LOG", "50"))
const DEFAULT_BASE_MVA = 100.0
# const DEFAULT_BASE_MVA = 100.0; only used in PSTD parser

const POWER_SYSTEM_STRUCT_DESCRIPTOR_FILE =
joinpath(dirname(pathof(PowerSystems)), "descriptors", "power_system_structs.json")
Expand Down
19 changes: 17 additions & 2 deletions src/parsers/common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ merge!(
),
)

# get_generator_mapping is only used in two places: to create a
# PowerSystemTableData object, where mappings is type String which has been
# extracted to the parser repo; to create a System from a
# PowerFlowFileParser.PowerModelsData object, where mappings is type DataType.
# Thus get_generator_mapping still needs to stay in this repo
"""Return a dict where keys are a tuple of input parameters (fuel, unit_type) and values are
generator types."""
function get_generator_mapping(filename::String)
Expand Down Expand Up @@ -75,8 +80,13 @@ function get_generator_mapping(filename::String)
return mappings
end

# mappings is now a union of type String and DataType because when
# get_generator_type is called in power_system_table_data.jl, mappings is of
# type String (see above function and comment), and when the function is called
# in power_models_data.jl, mappings is of type DataType

"""Return the PowerSystems generator type for this fuel and unit_type."""
function get_generator_type(fuel, unit_type, mappings::Dict{NamedTuple, DataType})
function get_generator_type(fuel, unit_type, mappings::Union{Dict{NamedTuple, String}, Dict{NamedTuple, DataType}})
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
function get_generator_type(fuel, unit_type, mappings::Union{Dict{NamedTuple, String}, Dict{NamedTuple, DataType}})
function get_generator_type(
fuel,
unit_type,
mappings::Union{Dict{NamedTuple, String}, Dict{NamedTuple, DataType}},
)

fuel = isnothing(fuel) ? "" : uppercase(fuel)
unit_type = uppercase(unit_type)
generator = nothing
Expand All @@ -85,7 +95,12 @@ function get_generator_type(fuel, unit_type, mappings::Dict{NamedTuple, DataType
for ut in (unit_type, nothing), fu in (fuel, nothing)
key = (fuel = fu, unit_type = ut)
if haskey(mappings, key)
generator = mappings[key]
if typeof(mappings[key]) == DataType
generator = mappings[key]
elseif typeof(mappings[key]) == String
gen_type = mappings[key]
generator = getfield(PowerSystems, Symbol(gen_type))
end
break
end
end
Expand Down
4 changes: 3 additions & 1 deletion src/parsers/enums.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

# this is the only place IS.@scoped_enum(InputCategory) is defined
# InputCategory is used only in power_system_table_data.jl but is
# needed by both PowerSystemTableData() and System()
IS.@scoped_enum(
InputCategory,
BRANCH = 1,
Expand Down
17 changes: 9 additions & 8 deletions src/parsers/power_models_data.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#=
"""Container for data parsed by PowerModels"""
struct PowerModelsData
data::Dict{String, Any}
Expand All @@ -21,13 +22,13 @@ function PowerModelsData(file::Union{String, IO}; kwargs...)
correct_pm_transformer_status!(pm_data)
return pm_data
end

=#
"""
Constructs a System from PowerModelsData.
Constructs a System from PowerFlowFileParser.PowerModelsData.

# Arguments
- `pm_data::Union{PowerModelsData, Union{String, IO}}`: PowerModels data object or supported
load flow case (*.m, *.raw)
- `pm_data::Union{PowerFlowFileParser.PowerModelsData, Union{String, IO}}`: PowerFlowFileParser.PowerModels
data object or supported load flow case (*.m, *.raw)

# Keyword arguments
- `ext::Dict`: Contains user-defined parameters. Should only contain standard types.
Expand All @@ -47,7 +48,7 @@ sys = System(
)
```
"""
function System(pm_data::PowerModelsData; kwargs...)
function System(pm_data::PowerFlowFileParser.PowerModelsData; kwargs...)
runchecks = get(kwargs, :runchecks, true)
data = pm_data.data
if length(data["bus"]) < 1
Expand Down Expand Up @@ -83,8 +84,8 @@ function System(pm_data::PowerModelsData; kwargs...)

return sys
end

function correct_pm_transformer_status!(pm_data::PowerModelsData)
#= this function only used in PowerModelsData function, not System
function correct_pm_transformer_status!(pm_data::PowerFlowFileParser.PowerModelsData)
for (k, branch) in pm_data.data["branch"]
f_bus_bvolt = pm_data.data["bus"][branch["f_bus"]]["base_kv"]
t_bus_bvolt = pm_data.data["bus"][branch["t_bus"]]["base_kv"]
Expand All @@ -103,7 +104,7 @@ function correct_pm_transformer_status!(pm_data::PowerModelsData)
end
end
end

=#
"""
Internal component name retrieval from pm2ps_dict
"""
Expand Down
Loading
Loading