Skip to content

Commit

Permalink
fix merge issues, simplify results code
Browse files Browse the repository at this point in the history
  • Loading branch information
adfarth committed Jan 24, 2025
1 parent 06e4366 commit 0653de3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
16 changes: 8 additions & 8 deletions src/core/electric_utility.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
### Cambium Emissions and Clean Energy Inputs ###
cambium_scenario::String = "Mid-case", # Cambium Scenario for evolution of electricity sector (see Cambium documentation for descriptions).
## Options: ["Mid-case", "Mid-case with tax credit expiration", "Low renewable energy cost", "Low renewable energy cost with tax credit expiration", "High renewable energy cost", "High electrification", "Low natural gas prices", "High natural gas prices", "Mid-case with 95% decarbonization by 2050", "Mid-case with 100% decarbonization by 2035"]
cambium_location_type::String = "GEA Regions", # Geographic boundary at which emissions and clean energy fraction are calculated. Options: ["Nations", "GEA Regions", "States"]
cambium_start_year::Int = 2025, # First year of operation of system. Emissions and clean energy fraction will be levelized starting in this year for the duration of cambium_levelization_years. # Options: any year 2023 through 2050. # TODO: update options with Cambium 2023
## Options: ["Mid-case", "Low renewable energy cost", "High renewable energy cost", "High demand growth", "Low natural gas prices", "High natural gas prices", "Mid-case with 95% decarbonization by 2050", "Mid-case with 100% decarbonization by 2035"]
cambium_location_type::String = "GEA Regions 2023", # Geographic boundary at which emissions and clean energy fraction are calculated. Options: ["Nations", "GEA Regions 2023"]
cambium_start_year::Int = 2025, # First year of operation of system. Emissions and clean energy fraction will be levelized starting in this year for the duration of cambium_levelization_years. # Options: any year 2025 through 2050.
cambium_levelization_years::Int = analysis_years, # Expected lifetime or analysis period of the intervention being studied. Emissions and clean energy fraction will be averaged over this period.
cambium_grid_level::String = "enduse", # Options: ["enduse", "busbar"]. Busbar refers to point where bulk generating stations connect to grid; enduse refers to point of consumption (includes distribution loss rate).
Expand Down Expand Up @@ -173,8 +173,8 @@ struct ElectricUtility

### Cambium Emissions and Clean Energy Inputs ###
cambium_scenario::String = "Mid-case", # Cambium Scenario for evolution of electricity sector (see Cambium documentation for descriptions).
cambium_location_type::String = "GEA Regions", # Geographic boundary at which emissions and clean energy fraction are calculated. Options: ["Nations", "GEA Regions", "States"]
cambium_start_year::Int = 2025, # First year of operation of system. Emissions and clean energy fraction will be levelized starting in this year for the duration of cambium_levelization_years. # Options: any year 2023 through 2050.
cambium_location_type::String = "GEA Regions 2023", # Geographic boundary at which emissions and clean energy fraction are calculated.
cambium_start_year::Int = 2025, # First year of operation of system. Emissions and clean energy fraction will be levelized starting in this year for the duration of cambium_levelization_years.
cambium_levelization_years::Int = analysis_years, # Expected lifetime or analysis period of the intervention being studied. Emissions and clean energy fraction will be averaged over this period.
cambium_grid_level::String = "enduse", # Options: ["enduse", "busbar"]. Busbar refers to point where bulk generating stations connect to grid; enduse refers to point of consumption (includes distribution loss rate).

Expand All @@ -195,7 +195,7 @@ struct ElectricUtility

### Grid Clean Energy Fraction Inputs ###
cambium_cef_metric::String = "cef_load", # Options = ["cef_load", "cef_gen"] # cef_load is the fraction of generation that is clean, for the generation that is allocated to a region’s end-use load; cef_gen is the fraction of generation that is clean within a region
renewable_energy_fraction_series::Union{Real,Array{<:Real,1}} = Float64[], # Utilities renewable energy fraction. Can be scalar or timeseries (aligned with time_steps_per_hour)
renewable_energy_fraction_series::Union{Real,Array{<:Real,1}} = Float64[], # Fraction of energy supplied by the grid that is renewable. Can be scalar or timeseries (aligned with time_steps_per_hour)
)

is_MPC = isnothing(latitude) || isnothing(longitude)
Expand All @@ -204,9 +204,9 @@ struct ElectricUtility
if !is_MPC
# Check some inputs
error_if_series_vals_not_0_to_1(renewable_energy_fraction_series, "ElectricUtility", "renewable_energy_fraction_series")
if cambium_start_year < 2023 || cambium_start_year > 2050 # TODO: update?
if cambium_start_year < 2025 || cambium_start_year > 2050
cambium_start_year = 2025 # Must update annually
@warn("The cambium_start_year must be between 2023 and 2050. Setting cambium_start_year to $(cambium_start_year).")
@warn("The cambium_start_year must be between 2025 and 2050. Setting cambium_start_year to $(cambium_start_year).")
end

# Get AVERT emissions region
Expand Down
8 changes: 4 additions & 4 deletions src/results/electric_utility.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ function add_electric_utility_results(m::JuMP.AbstractModel, p::AbstractInputs,
r["electric_to_storage_series_kw"] = round.(value.(GridToBatt), digits=3)

if _n=="" #only output emissions and RE results if not a multinode model
r["lifecycle_emissions_tonnes_CO2"] = round(value(m[:yr1_emissions_from_elec_grid_net_if_selected_lbs_CO2]*TONNE_PER_LB*p.pwf_grid_emissions["CO2"]), digits=2)
r["lifecycle_emissions_tonnes_NOx"] = round(value(m[:yr1_emissions_from_elec_grid_net_if_selected_lbs_NOx]*TONNE_PER_LB*p.pwf_grid_emissions["NOx"]), digits=2)
r["lifecycle_emissions_tonnes_SO2"] = round(value(m[:yr1_emissions_from_elec_grid_net_if_selected_lbs_SO2]*TONNE_PER_LB*p.pwf_grid_emissions["SO2"]), digits=2)
r["lifecycle_emissions_tonnes_PM25"] = round(value(m[:yr1_emissions_from_elec_grid_net_if_selected_lbs_PM25]*TONNE_PER_LB*p.pwf_grid_emissions["PM25"]), digits=2)
r["lifecycle_emissions_tonnes_CO2"] = round(value(m[:Lifecycle_Emissions_Lbs_CO2_grid_net_if_selected]*TONNE_PER_LB), digits=2)
r["lifecycle_emissions_tonnes_NOx"] = round(value(m[:Lifecycle_Emissions_Lbs_NOx_grid_net_if_selected]*TONNE_PER_LB), digits=2)
r["lifecycle_emissions_tonnes_SO2"] = round(value(m[:Lifecycle_Emissions_Lbs_SO2_grid_net_if_selected]*TONNE_PER_LB), digits=2)
r["lifecycle_emissions_tonnes_PM25"] = round(value(m[:Lifecycle_Emissions_Lbs_PM25_grid_net_if_selected]*TONNE_PER_LB), digits=2)
r["annual_emissions_tonnes_CO2"] = r["lifecycle_emissions_tonnes_CO2"] / p.s.financial.analysis_years
r["annual_emissions_tonnes_NOx"] = r["lifecycle_emissions_tonnes_NOx"] / p.s.financial.analysis_years
r["annual_emissions_tonnes_SO2"] = r["lifecycle_emissions_tonnes_SO2"] / p.s.financial.analysis_years
Expand Down
3 changes: 1 addition & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2192,7 +2192,6 @@ else # run HiGHS tests
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
post["ElectricUtility"]["cambium_start_year"] = 2024
scen = Scenario(post)

@test scen.electric_utility.avert_emissions_region == "Rocky Mountains"
Expand Down Expand Up @@ -2370,7 +2369,7 @@ else # run HiGHS tests
@test results["Site"]["annual_emissions_from_fuelburn_tonnes_PM25"] nat_gas_emissions_lb_per_mmbtu["PM25"] * yr1_nat_gas_mmbtu * TONNE_PER_LB atol=1e-2
@test results["Site"]["lifecycle_emissions_tonnes_CO2"] results["Site"]["lifecycle_emissions_from_fuelburn_tonnes_CO2"] + results["ElectricUtility"]["lifecycle_emissions_tonnes_CO2"] rtol=0.001
@test results["Site"]["lifecycle_emissions_tonnes_NOx"] results["Site"]["lifecycle_emissions_from_fuelburn_tonnes_NOx"] + results["ElectricUtility"]["lifecycle_emissions_tonnes_NOx"] rtol=0.001
@test results["Site"]["lifecycle_emissions_tonnes_SO2"] results["Site"]["lifecycle_emissions_from_fuelburn_tonnes_SO2"] + results["ElectricUtility"]["lifecycle_emissions_tonnes_SO2"] rtol=0.001
@test results["Site"]["lifecycle_emissions_tonnes_SO2"] results["Site"]["lifecycle_emissions_from_fuelburn_tonnes_SO2"] + results["ElectricUtility"]["lifecycle_emissions_tonnes_SO2"] rtol=0.01 # rounding causes difference
@test results["Site"]["lifecycle_emissions_tonnes_PM25"] results["Site"]["lifecycle_emissions_from_fuelburn_tonnes_PM25"] + results["ElectricUtility"]["lifecycle_emissions_tonnes_PM25"] rtol=0.001
@test results["Site"]["annual_onsite_renewable_electricity_kwh"] results["PV"]["annual_energy_produced_kwh"] + inputs["CHP"]["fuel_renewable_energy_fraction"] * results["CHP"]["annual_electric_production_kwh"] atol=1
@test results["Site"]["onsite_renewable_electricity_fraction_of_elec_load"] results["Site"]["annual_onsite_renewable_electricity_kwh"] / results["ElectricLoad"]["annual_calculated_kwh"] rtol=0.001 #0.044285 atol=1e-4
Expand Down

0 comments on commit 0653de3

Please sign in to comment.