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

Minor refactor of write_esr_revenue #593

Merged
merged 3 commits into from
Dec 5, 2023
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
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 @@
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"]

Check warning on line 11 in src/write_outputs/energy_share_requirement/write_esr_revenue.jl

View check run for this annotation

Codecov / codecov/patch

src/write_outputs/energy_share_requirement/write_esr_revenue.jl#L10-L11

Added lines #L10 - L11 were not covered by tests
VRE_STOR = inputs["VRE_STOR"]
dfVRE_STOR = inputs["dfVRE_STOR"]
if !isempty(VRE_STOR)
Expand All @@ -16,48 +18,48 @@
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

Check warning on line 23 in src/write_outputs/energy_share_requirement/write_esr_revenue.jl

View check run for this annotation

Codecov / codecov/patch

src/write_outputs/energy_share_requirement/write_esr_revenue.jl#L23

Added line #L23 was not covered by tests
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

Check warning on line 28 in src/write_outputs/energy_share_requirement/write_esr_revenue.jl

View check run for this annotation

Codecov / codecov/patch

src/write_outputs/energy_share_requirement/write_esr_revenue.jl#L25-L28

Added lines #L25 - L28 were not covered by tests

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]))

Check warning on line 61 in src/write_outputs/energy_share_requirement/write_esr_revenue.jl

View check run for this annotation

Codecov / codecov/patch

src/write_outputs/energy_share_requirement/write_esr_revenue.jl#L61

Added line #L61 was not covered by tests
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 @@
# 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]

Check warning on line 135 in src/write_outputs/write_net_revenue.jl

View check run for this annotation

Codecov / codecov/patch

src/write_outputs/write_net_revenue.jl#L135

Added line #L135 was not covered by tests
end

# Calculate emissions cost
Expand Down
Loading