Skip to content

Commit

Permalink
Minor refactor of write_esr_revenue (#593)
Browse files Browse the repository at this point in the history
* remove a defunct comment
* add new column directly rather than use hcat and a rename!
* 'price' as variable rather than multiple df accesses
  • Loading branch information
cfe316 authored Dec 5, 2023
1 parent 54ef23a commit dcb98a3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
36 changes: 19 additions & 17 deletions src/write_outputs/energy_share_requirement/write_esr_revenue.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ function write_esr_revenue(path::AbstractString, inputs::Dict, setup::Dict, dfPo
dfGen = inputs["dfGen"]
dfESRRev = DataFrame(region = dfGen[!,:region], Resource = inputs["RESOURCES"], zone = dfGen[!,:Zone], Cluster = dfGen[!,:cluster], R_ID = dfGen[!,:R_ID])
G = inputs["G"]
nESR = inputs["nESR"]
weight = inputs["omega"]
VRE_STOR = inputs["VRE_STOR"]
dfVRE_STOR = inputs["dfVRE_STOR"]
if !isempty(VRE_STOR)
Expand All @@ -16,48 +18,48 @@ function write_esr_revenue(path::AbstractString, inputs::Dict, setup::Dict, dfPo
WIND_ONLY = setdiff(WIND, SOLAR)
SOLAR_WIND = intersect(SOLAR, WIND)
end

by_rid(rid, sym) = by_rid_df(rid, sym, dfVRE_STOR)
for i in 1:inputs["nESR"]
for i in 1:nESR
esr_col = Symbol("ESR_$i")
dfESRRev = hcat(dfESRRev, dfPower[1:G,:AnnualSum] .* dfGen[!,esr_col] * dfESR[i,:ESR_Price])
# dfpower is in MWh already, price is in $/MWh already, no need to scale
# if setup["ParameterScale"] == 1
# #dfESRRev[!,:x1] = dfESRRev[!,:x1] * (1e+3) # MillionUS$ to US$
# dfESRRev[!,:x1] = dfESRRev[!,:x1] * ModelScalingFactor # MillionUS$ to US$ # Is this right? -Jack 4/29/2021
# end
rename!(dfESRRev, Dict(:x1 => esr_col))
price = dfESR[i, :ESR_Price]
derated_annual_net_generation = dfPower[1:G,:AnnualSum] .* dfGen[!,esr_col]
revenue = derated_annual_net_generation * price
dfESRRev[!, esr_col] = revenue

if !isempty(VRE_STOR)
esr_vrestor_col = Symbol("ESRVreStor_$i")
if !isempty(SOLAR_ONLY)
solar_resources = ((dfVRE_STOR.WIND.==0) .& (dfVRE_STOR.SOLAR.!=0))
dfESRRev[SOLAR, esr_col] = (
value.(EP[:vP_SOLAR][SOLAR, :]).data
.* dfVRE_STOR[solar_resources, :EtaInverter] * inputs["omega"]
) .* dfVRE_STOR[solar_resources,esr_vrestor_col] * dfESR[i,:ESR_Price]
.* dfVRE_STOR[solar_resources, :EtaInverter] * weight
) .* dfVRE_STOR[solar_resources,esr_vrestor_col] * price
end
if !isempty(WIND_ONLY)
wind_resources = ((dfVRE_STOR.WIND.!=0) .& (dfVRE_STOR.SOLAR.==0))
dfESRRev[WIND, esr_col] = (
value.(EP[:vP_WIND][WIND, :]).data
* inputs["omega"]
) .* dfVRE_STOR[wind_resources,esr_vrestor_col] * dfESR[i,:ESR_Price]
* weight
) .* dfVRE_STOR[wind_resources,esr_vrestor_col] * price
end
if !isempty(SOLAR_WIND)
solar_and_wind_resources = ((dfVRE_STOR.WIND.!=0) .& (dfVRE_STOR.SOLAR.!=0))
dfESRRev[SOLAR_WIND, esr_col] = (
(
(value.(EP[:vP_WIND][SOLAR_WIND, :]).data * inputs["omega"])
.* dfVRE_STOR[solar_and_wind_resources,esr_vrestor_col] * dfESR[i,:ESR_Price]
(value.(EP[:vP_WIND][SOLAR_WIND, :]).data * weight)
.* dfVRE_STOR[solar_and_wind_resources,esr_vrestor_col] * price
) + (
value.(EP[:vP_SOLAR][SOLAR_WIND, :]).data
.* dfVRE_STOR[solar_and_wind_resources, :EtaInverter]
* inputs["omega"]
) .* dfVRE_STOR[solar_and_wind_resources,esr_vrestor_col] * dfESR[i,:ESR_Price]
* weight
) .* dfVRE_STOR[solar_and_wind_resources,esr_vrestor_col] * price
)
end
end
end
dfESRRev.AnnualSum = sum(eachcol(dfESRRev[:,6:inputs["nESR"]+5]))
dfESRRev.Total = sum(eachcol(dfESRRev[:, 6:nESR + 5]))
CSV.write(joinpath(path, "ESR_Revenue.csv"), dfESRRev)
return dfESRRev
end

2 changes: 1 addition & 1 deletion src/write_outputs/write_net_revenue.jl
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ function write_net_revenue(path::AbstractString, inputs::Dict, setup::Dict, EP::
# Add RPS/CES revenue to the dataframe
dfNetRevenue.ESRRevenue = zeros(nrow(dfNetRevenue))
if setup["EnergyShareRequirement"] > 0 && has_duals(EP) == 1 # The unit is confirmed to be $
dfNetRevenue.ESRRevenue = dfESRRev[1:G,:AnnualSum]
dfNetRevenue.ESRRevenue = dfESRRev[1:G,:Total]
end

# Calculate emissions cost
Expand Down

0 comments on commit dcb98a3

Please sign in to comment.