Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix case sensitivity in enum parsers #1045

Merged
merged 4 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "PowerSystems"
uuid = "bcd98974-b02a-5e2f-9ee0-a103f5c450dd"
authors = ["Jose Daniel Lara", "Daniel Thom", "Dheepak Krishnamurthy", "Clayton Barrows", "Sourabh Dalvi"]
version = "3.2.1"
version = "3.2.2"

[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
Expand Down
61 changes: 31 additions & 30 deletions src/parsers/common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,44 @@ const GENERATOR_MAPPING_FILE =
const PSSE_DYR_MAPPING_FILE =
joinpath(dirname(pathof(PowerSystems)), "parsers", "psse_dynamic_mapping.yaml")

const STRING2FUEL = Dict((string(x) => x) for x in instances(ThermalFuels))
const STRING2FUEL =
Dict((normalize(string(x); casefold = true) => x) for x in instances(ThermalFuels))
merge!(
STRING2FUEL,
Dict(
"NG" => ThermalFuels.NATURAL_GAS,
"NUC" => ThermalFuels.NUCLEAR,
"GAS" => ThermalFuels.NATURAL_GAS,
"OIL" => ThermalFuels.DISTILLATE_FUEL_OIL,
"DFO" => ThermalFuels.DISTILLATE_FUEL_OIL,
"SYNC_COND" => ThermalFuels.OTHER,
"GEOTHERMAL " => ThermalFuels.GEOTHERMAL,
"AG_BIPRODUCT" => ThermalFuels.AG_BIPRODUCT,
"ng" => ThermalFuels.NATURAL_GAS,
"nuc" => ThermalFuels.NUCLEAR,
"gas" => ThermalFuels.NATURAL_GAS,
"oil" => ThermalFuels.DISTILLATE_FUEL_OIL,
"dfo" => ThermalFuels.DISTILLATE_FUEL_OIL,
"sync_cond" => ThermalFuels.OTHER,
"geothermal " => ThermalFuels.GEOTHERMAL,
"ag_biproduct" => ThermalFuels.AG_BIPRODUCT,
),
)

const STRING2PRIMEMOVER = Dict((string(x) => x) for x in instances(PrimeMovers))
const STRING2PRIMEMOVER =
GabrielKS marked this conversation as resolved.
Show resolved Hide resolved
Dict((normalize(string(x); casefold = true) => x) for x in instances(PrimeMovers))
merge!(
STRING2PRIMEMOVER,
Dict(
"W2" => PrimeMovers.WT,
"WIND" => PrimeMovers.WT,
"PV" => PrimeMovers.PVe,
"PVe" => PrimeMovers.PVe,
"SOLAR" => PrimeMovers.PVe,
"RTPV" => PrimeMovers.PVe,
"NB" => PrimeMovers.ST,
"STEAM" => PrimeMovers.ST,
"HYDRO" => PrimeMovers.HY,
"ROR" => PrimeMovers.HY,
"PUMP" => PrimeMovers.PS,
"PUMPED_HYDRO" => PrimeMovers.PS,
"NUCLEAR" => PrimeMovers.ST,
"SYNC_COND" => PrimeMovers.OT,
"CSP" => PrimeMovers.CP,
"UN" => PrimeMovers.OT,
"STORAGE" => PrimeMovers.BA,
"ICE" => PrimeMovers.IC,
"w2" => PrimeMovers.WT,
"wind" => PrimeMovers.WT,
"pv" => PrimeMovers.PVe,
"solar" => PrimeMovers.PVe,
"rtpv" => PrimeMovers.PVe,
"nb" => PrimeMovers.ST,
"steam" => PrimeMovers.ST,
"hydro" => PrimeMovers.HY,
"ror" => PrimeMovers.HY,
"pump" => PrimeMovers.PS,
"pumped_hydro" => PrimeMovers.PS,
"nuclear" => PrimeMovers.ST,
"sync_cond" => PrimeMovers.OT,
"csp" => PrimeMovers.CP,
"un" => PrimeMovers.OT,
"storage" => PrimeMovers.BA,
"ice" => PrimeMovers.IC,
),
)

Expand Down Expand Up @@ -201,15 +202,15 @@ function convert_units!(
end

function parse_enum_mapping(::Type{ThermalFuels}, fuel::AbstractString)
return STRING2FUEL[uppercase(fuel)]
return STRING2FUEL[normalize(fuel; casefold = true)]
end

function parse_enum_mapping(::Type{ThermalFuels}, fuel::Symbol)
return parse_enum_mapping(ThermalFuels, string(fuel))
end

function parse_enum_mapping(::Type{PrimeMovers}, prime_mover::AbstractString)
return STRING2PRIMEMOVER[uppercase(prime_mover)]
return STRING2PRIMEMOVER[normalize(prime_mover; casefold = true)]
end

function parse_enum_mapping(::Type{PrimeMovers}, prime_mover::Symbol)
Expand Down
Loading