Skip to content

Commit

Permalink
add test to test_with_xpress
Browse files Browse the repository at this point in the history
  • Loading branch information
adfarth committed Oct 3, 2023
1 parent 8c0ffe6 commit 3e4fdab
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/core/electric_utility.jl
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,15 @@ struct ElectricUtility
end
# Warnings
if co2_from_avert && length(emissions_factor_series_lb_CO2_per_kwh) > 0
@warn("You set co2_from_avert = true and provided values for emissions_factor_series_lb_CO2_per_kwh. REopt will use provided values for emissions_factor_series_lb_CO2_per_kwh.")
@warn("You set co2_from_avert = true and provided values for emissions_factor_series_lb_CO2_per_kwh. REopt will use the provided values for emissions_factor_series_lb_CO2_per_kwh.")
elseif !co2_from_avert && region_abbr ["AKGD","HIMS","HIOA"] && length(emissions_factor_series_lb_CO2_per_kwh) == 0
co2_from_avert = true # Must use "avert" data (actually eGRID) because AK and HI are not in Cambium
if isnothing(emissions_factor_CO2_decrease_fraction)
emissions_factor_CO2_decrease_fraction = 0.02163
@warn("Using eGRID data for region $(region_abbr) for all grid emissions factors and setting emissions_factor_CO2_decrease_fraction = $(emissions_factor_CO2_decrease_fraction).")
else
@warn("Using eGRID data for region $(region_abbr) for all grid emissions factors.")
end
@warn("Using $(region_abbr) eGRID data for all grid emissions factors and emissions_factor_CO2_decrease_fraction = $(emissions_factor_CO2_decrease_fraction).")
elseif isnothing(emissions_factor_CO2_decrease_fraction)
emissions_factor_CO2_decrease_fraction = 0.0 # For Cambium data and if not user-provided
end
Expand Down Expand Up @@ -556,11 +558,8 @@ function cambium_emissions_profile(; scenario::String,
)

try
print("\n\n***CALLING CAMBIUM API***\n\n")

r = HTTP.get(url; query=payload)
response = JSON.parse(String(r.body))
# print("\n", response["status"], "\n")
response = JSON.parse(String(r.body)) # contains response["status"]
output = response["message"]
co2_emissions = output["values"] ./ 1000 # [lb / MWh] --> [lb / kWh]

Expand Down
61 changes: 61 additions & 0 deletions test/test_with_xpress.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1309,6 +1309,67 @@ end
@test calculated_ghp_capex reopt_ghp_capex atol=300
end

@testset "Cambium Emissions" begin
"""
1) Location in contiguous US
- Correct data from Cambium (returned location and values)
- Adjusted for load year vs. Cambium year (which starts on Sunday) vs. AVERT year (2021 currently)
- co2 pct increase should be zero
2) HI and AK locations
- Should use AVERT data and give an "info" message
- Adjust for load year vs. AVERT year
- co2 pct increase should be the default value unless user provided value
3) International
- all emissions should be zero unless provided
"""
m1 = Model(Xpress.Optimizer)
m2 = Model(Xpress.Optimizer)

post_name = "cambium.json"
post = JSON.parsefile("./scenarios/$post_name")

cities = Dict(
"Denver" => (39.7413753050447, -104.99965032911328),
"Fairbanks" => (64.84053664406181, -147.71913656313163),
"Santiago" => (-33.44485437650408, -70.69031905547853)
)

# 1) Location in contiguous US
city = "Denver"
post["Site"]["latitude"] = cities[city][1]
post["Site"]["longitude"] = cities[city][2]
post["ElectricLoad"]["loads_kw"] = [20 for i in range(1,8760)]
post["ElectricLoad"]["year"] = 2021 # 2021 First day is Fri
scen = Scenario(post)

@test scen.electric_utility.cambium_emissions_region == "Colorado"
@test mean(scen.electric_utility.emissions_factor_series_lb_CO2_per_kwh) 0.38046 rtol=1e-5
@test scen.electric_utility.emissions_factor_series_lb_CO2_per_kwh[1] 0.66672 rtol=1e-5 # Should start on Friday
@test scen.electric_utility.emissions_factor_series_lb_CO2_per_kwh[8760] 0.64833465 rtol=1e-5 # Should end on Friday
@test mean(scen.electric_utility.emissions_factor_series_lb_SO2_per_kwh) 0.000592455 rtol=1e-5 # check avg from AVERT data for RM region
@test scen.electric_utility.emissions_factor_CO2_decrease_fraction 0 atol=1e-5
@test scen.electric_utility.emissions_factor_SO2_decrease_fraction 0.02163

# 2) AK location
city = "Fairbanks"
post["Site"]["latitude"] = cities[city][1]
post["Site"]["longitude"] = cities[city][2]
scen = Scenario(post)

@test mean(scen.electric_utility.emissions_factor_series_lb_CO2_per_kwh) 1.40636 rtol=1e-5 # check data from eGRID (AVERT data file) usd
@test scen.electric_utility.emissions_factor_CO2_decrease_fraction 0.02163 # should get updated

# 3) International location
city = "Santiago"
post["Site"]["latitude"] = cities[city][1]
post["Site"]["longitude"] = cities[city][2]
scen = Scenario(post)

@test sum(scen.electric_utility.emissions_factor_series_lb_CO2_per_kwh) 0
@test sum(scen.electric_utility.emissions_factor_series_lb_NOx_per_kwh) 0

end

@testset "Emissions and Renewable Energy Percent" begin
#renewable energy and emissions reduction targets
include_exported_RE_in_total = [true,false,true]
Expand Down

0 comments on commit 3e4fdab

Please sign in to comment.