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

Error when non standard value for "units" field in "energyratestructure" of URDB response #398

Merged
merged 10 commits into from
May 23, 2024
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Classify the change according to the following categories:
### Removed

## Develop
### Changed
- When the URDB response `energyratestructure` has a "unit" value that is not "kWh", throw an error instead of averaging rates in each energy tier.
### Fixed
- Convert `max_electric_load_kw` to _Float64_ before passing to function `get_chp_defaults_prime_mover_size_class`

Expand Down
17 changes: 2 additions & 15 deletions src/core/urdb.jl
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,7 @@ function parse_urdb_energy_costs(d::Dict, year::Int; time_steps_per_hour=1, bigM
period_with_max_tiers = findall(energy_tiers .== maximum(energy_tiers))[1]
n_energy_tiers = Int(maximum(energy_tier_set))

rates = Float64[]
energy_tier_limits_kwh = Float64[]
non_kwh_units = false

for energy_tier in d["energyratestructure"][period_with_max_tiers]
# energy_tier is a dictionary, eg. {'max': 1000, 'rate': 0.07531, 'adj': 0.0119, 'unit': 'kWh'}
Expand All @@ -233,17 +231,8 @@ function parse_urdb_energy_costs(d::Dict, year::Int; time_steps_per_hour=1, bigM
end

if "unit" in keys(energy_tier) && string(energy_tier["unit"]) != "kWh"
@warn "Using average rate in tier due to exotic units of " energy_tier["unit"]
non_kwh_units = true
throw(@error("URDB energy tiers have exotic units of " * energy_tier["unit"]))
end

append!(rates, get(energy_tier, "rate", 0) + get(energy_tier, "adj", 0))
end

if non_kwh_units
rate_average = sum(rates) / maximum([length(rates), 1])
n_energy_tiers = 1
energy_tier_limits_kwh = Float64[bigM]
end

energy_cost_vector = Float64[]
Expand Down Expand Up @@ -276,9 +265,7 @@ function parse_urdb_energy_costs(d::Dict, year::Int; time_steps_per_hour=1, bigM
else
tier_use = tier
end
total_rate = non_kwh_units ?
rate_average :
(get(d["energyratestructure"][period][tier_use], "rate", 0) +
total_rate = (get(d["energyratestructure"][period][tier_use], "rate", 0) +
get(d["energyratestructure"][period][tier_use], "adj", 0))
sell = get(d["energyratestructure"][period][tier_use], "sell", 0)

Expand Down
10 changes: 10 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1206,6 +1206,16 @@ else # run HiGHS tests
# inputs = REoptInputs(s)
# results = run_reopt(m, inputs)

@testset "Exotic Units for Energy Rates" begin
d = JSON.parsefile("./scenarios/no_techs.json")
d["ElectricTariff"] = Dict(
"urdb_label" => "6272e4ae7eb76766c247d469"
)
m = Model(optimizer_with_attributes(HiGHS.Optimizer, "output_flag" => false, "log_to_console" => false))
results = run_reopt(m, d)
@test occursin("URDB energy tiers have exotic units of", string(results["Messages"]))
end

end

@testset "EASIUR" begin
Expand Down
Loading