Skip to content

Commit

Permalink
Polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
cfe316 committed Nov 22, 2023
1 parent 138b2ed commit 264258a
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions src/write_outputs/capacity_reserve_margin/write_capacity_value.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ function write_capacity_value(path::AbstractString, inputs::Dict, setup::Dict, E
MUST_RUN = inputs["MUST_RUN"]
VRE_STOR = inputs["VRE_STOR"]

minimum_plant_size = 1 # MW
minimum_crm_price = 1 # $/MW
scale_factor = setup["ParameterScale"] == 1 ? ModelScalingFactor : 1
eTotalCap = value.(EP[:eTotalCap])

Check warning on line 14 in src/write_outputs/capacity_reserve_margin/write_capacity_value.jl

View check run for this annotation

Codecov / codecov/patch

src/write_outputs/capacity_reserve_margin/write_capacity_value.jl#L13-L14

Added lines #L13 - L14 were not covered by tests

minimum_plant_size = 1 # MW
large_plants = findall(>=(minimum_plant_size), eTotalCap * scale_factor)

Check warning on line 17 in src/write_outputs/capacity_reserve_margin/write_capacity_value.jl

View check run for this annotation

Codecov / codecov/patch

src/write_outputs/capacity_reserve_margin/write_capacity_value.jl#L16-L17

Added lines #L16 - L17 were not covered by tests

THERM_ALL_EX = intersect(THERM_ALL, large_plants)
Expand Down Expand Up @@ -41,63 +41,65 @@ function write_capacity_value(path::AbstractString, inputs::Dict, setup::Dict, E

dfCapValue = DataFrame()
for i in 1:inputs["NCapacityReserveMargin"]
temp_dfCapValue = DataFrame(Resource = inputs["RESOURCES"], Zone = dfGen[!, :Zone], Reserve = fill(Symbol("CapRes_$i"), G))
capvalue = zeros(T, G)
riskyhour = findall(>=(minimum_crm_price), capacity_reserve_margin_price(EP, inputs, setup, i))
capvalue = zeros(T, G)

Check warning on line 44 in src/write_outputs/capacity_reserve_margin/write_capacity_value.jl

View check run for this annotation

Codecov / codecov/patch

src/write_outputs/capacity_reserve_margin/write_capacity_value.jl#L44

Added line #L44 was not covered by tests

minimum_crm_price = 1 # $/MW
riskyhour = findall(>=(minimum_crm_price), capacity_reserve_margin_price(EP, inputs, setup, i))

Check warning on line 47 in src/write_outputs/capacity_reserve_margin/write_capacity_value.jl

View check run for this annotation

Codecov / codecov/patch

src/write_outputs/capacity_reserve_margin/write_capacity_value.jl#L46-L47

Added lines #L46 - L47 were not covered by tests

power(y) = value.(EP[:vP][y, riskyhour])'

Check warning on line 49 in src/write_outputs/capacity_reserve_margin/write_capacity_value.jl

View check run for this annotation

Codecov / codecov/patch

src/write_outputs/capacity_reserve_margin/write_capacity_value.jl#L49

Added line #L49 was not covered by tests

capvalue[riskyhour, THERM_ALL_EX] .= crm_derate(i, THERM_ALL_EX)
capvalue[riskyhour, THERM_ALL_EX] = crm_derate(i, THERM_ALL_EX)

Check warning on line 51 in src/write_outputs/capacity_reserve_margin/write_capacity_value.jl

View check run for this annotation

Codecov / codecov/patch

src/write_outputs/capacity_reserve_margin/write_capacity_value.jl#L51

Added line #L51 was not covered by tests

capvalue[riskyhour, VRE_EX] .= crm_derate(i, VRE_EX) .* max_power(riskyhour, VRE_EX)
capvalue[riskyhour, VRE_EX] = crm_derate(i, VRE_EX) .* max_power(riskyhour, VRE_EX)

Check warning on line 53 in src/write_outputs/capacity_reserve_margin/write_capacity_value.jl

View check run for this annotation

Codecov / codecov/patch

src/write_outputs/capacity_reserve_margin/write_capacity_value.jl#L53

Added line #L53 was not covered by tests

capvalue[riskyhour, MUST_RUN_EX] .= crm_derate(i, MUST_RUN_EX) .* max_power(riskyhour, MUST_RUN_EX)
capvalue[riskyhour, MUST_RUN_EX] = crm_derate(i, MUST_RUN_EX) .* max_power(riskyhour, MUST_RUN_EX)

Check warning on line 55 in src/write_outputs/capacity_reserve_margin/write_capacity_value.jl

View check run for this annotation

Codecov / codecov/patch

src/write_outputs/capacity_reserve_margin/write_capacity_value.jl#L55

Added line #L55 was not covered by tests

capvalue[riskyhour, HYDRO_RES_EX] .= crm_derate(i, HYDRO_RES_EX) .* power(HYDRO_RES_EX) ./ total_cap(HYDRO_RES_EX)
capvalue[riskyhour, HYDRO_RES_EX] = crm_derate(i, HYDRO_RES_EX) .* power(HYDRO_RES_EX) ./ total_cap(HYDRO_RES_EX)

Check warning on line 57 in src/write_outputs/capacity_reserve_margin/write_capacity_value.jl

View check run for this annotation

Codecov / codecov/patch

src/write_outputs/capacity_reserve_margin/write_capacity_value.jl#L57

Added line #L57 was not covered by tests

if !isempty(STOR_ALL_EX)
charge = value.(EP[:vCHARGE][STOR_ALL_EX, riskyhour].data)'
capres_discharge = value.(EP[:vCAPRES_discharge][STOR_ALL_EX, riskyhour].data)'
capres_charge = value.(EP[:vCAPRES_charge][STOR_ALL_EX, riskyhour].data)'

Check warning on line 62 in src/write_outputs/capacity_reserve_margin/write_capacity_value.jl

View check run for this annotation

Codecov / codecov/patch

src/write_outputs/capacity_reserve_margin/write_capacity_value.jl#L60-L62

Added lines #L60 - L62 were not covered by tests

capvalue[riskyhour, STOR_ALL_EX] .= crm_derate(i, STOR_ALL_EX) .* (power(STOR_ALL_EX) - charge + capres_discharge - capres_charge) ./ total_cap(STOR_ALL_EX)
capvalue[riskyhour, STOR_ALL_EX] = crm_derate(i, STOR_ALL_EX) .* (power(STOR_ALL_EX) - charge + capres_discharge - capres_charge) ./ total_cap(STOR_ALL_EX)

Check warning on line 64 in src/write_outputs/capacity_reserve_margin/write_capacity_value.jl

View check run for this annotation

Codecov / codecov/patch

src/write_outputs/capacity_reserve_margin/write_capacity_value.jl#L64

Added line #L64 was not covered by tests
end

if !isempty(FLEX_EX)
charge = value.(EP[:vCHARGE_FLEX][FLEX_EX, riskyhour].data)'
capvalue[riskyhour, FLEX_EX] .= crm_derate(i, FLEX_EX) .* (charge - power(FLEX_EX)) ./ total_cap(FLEX_EX)
capvalue[riskyhour, FLEX_EX] = crm_derate(i, FLEX_EX) .* (charge - power(FLEX_EX)) ./ total_cap(FLEX_EX)

Check warning on line 69 in src/write_outputs/capacity_reserve_margin/write_capacity_value.jl

View check run for this annotation

Codecov / codecov/patch

src/write_outputs/capacity_reserve_margin/write_capacity_value.jl#L68-L69

Added lines #L68 - L69 were not covered by tests
end
if !isempty(VRE_STOR_EX)
capres_dc_discharge = value.(EP[:vCAPRES_DC_DISCHARGE][DC_DISCHARGE, riskyhour].data)'
discharge_eff = dfVRE_STOR[dfVRE_STOR.STOR_DC_DISCHARGE .!= 0, :EtaInverter]'
capvalue_dc_discharge = zeros(T, G)
capvalue_dc_discharge[riskyhour, DC_DISCHARGE] .= capres_dc_discharge .* discharge_eff
capvalue_dc_discharge[riskyhour, DC_DISCHARGE] = capres_dc_discharge .* discharge_eff

Check warning on line 75 in src/write_outputs/capacity_reserve_margin/write_capacity_value.jl

View check run for this annotation

Codecov / codecov/patch

src/write_outputs/capacity_reserve_margin/write_capacity_value.jl#L72-L75

Added lines #L72 - L75 were not covered by tests

capres_dc_charge = value.(EP[:vCAPRES_DC_CHARGE][DC_CHARGE, riskyhour].data)'
charge_eff = dfVRE_STOR[dfVRE_STOR.STOR_DC_CHARGE .!= 0, :EtaInverter]'
capvalue_dc_charge = zeros(T, G)
capvalue_dc_charge[riskyhour, DC_CHARGE] .= capres_dc_charge ./ charge_eff
capvalue_dc_charge[riskyhour, DC_CHARGE] = capres_dc_charge ./ charge_eff

Check warning on line 80 in src/write_outputs/capacity_reserve_margin/write_capacity_value.jl

View check run for this annotation

Codecov / codecov/patch

src/write_outputs/capacity_reserve_margin/write_capacity_value.jl#L77-L80

Added lines #L77 - L80 were not covered by tests

capvalue[riskyhour, VRE_STOR_EX] .= crm_derate(i, VRE_STOR_EX) .* power(VRE_STOR_EX) ./ total_cap(VRE_STOR_EX)
capvalue[riskyhour, VRE_STOR_EX] = crm_derate(i, VRE_STOR_EX) .* power(VRE_STOR_EX) ./ total_cap(VRE_STOR_EX)

Check warning on line 82 in src/write_outputs/capacity_reserve_margin/write_capacity_value.jl

View check run for this annotation

Codecov / codecov/patch

src/write_outputs/capacity_reserve_margin/write_capacity_value.jl#L82

Added line #L82 was not covered by tests

charge_vre_stor = value.(EP[:vCHARGE_VRE_STOR][VRE_STOR_STOR_EX, :].data)'
capvalue[riskyhour, VRE_STOR_STOR_EX] .-= crm_derate(i, VRE_STOR_STOR_EX) .* charge_vre_stor ./ total_cap(VRE_STOR_STOR_EX)
charge_vre_stor = value.(EP[:vCHARGE_VRE_STOR][VRE_STOR_STOR_EX, riskyhour].data)'
capvalue[riskyhour, VRE_STOR_STOR_EX] -= crm_derate(i, VRE_STOR_STOR_EX) .* charge_vre_stor ./ total_cap(VRE_STOR_STOR_EX)

Check warning on line 85 in src/write_outputs/capacity_reserve_margin/write_capacity_value.jl

View check run for this annotation

Codecov / codecov/patch

src/write_outputs/capacity_reserve_margin/write_capacity_value.jl#L84-L85

Added lines #L84 - L85 were not covered by tests

capvalue[riskyhour, DC_DISCHARGE_EX] .+= crm_derate(i, DC_DISCHARGE_EX) .* capvalue_dc_discharge[riskyhour, DC_DISCHARGE_EX] ./ total_cap(DC_DISCHARGE_EX)
capres_ac_discharge = value.(EP[:vCAPRES_AC_DISCHARGE][AC_DISCHARGE_EX, :].data)'
capvalue[riskyhour, AC_DISCHARGE_EX] .+= crm_derate(i, AC_DISCHARGE_EX) .* capres_ac_discharge ./ total_cap(AC_DISCHARGE_EX)
capvalue[riskyhour, DC_DISCHARGE_EX] += crm_derate(i, DC_DISCHARGE_EX) .* capvalue_dc_discharge[riskyhour, DC_DISCHARGE_EX] ./ total_cap(DC_DISCHARGE_EX)
capres_ac_discharge = value.(EP[:vCAPRES_AC_DISCHARGE][AC_DISCHARGE_EX, riskyhour].data)'
capvalue[riskyhour, AC_DISCHARGE_EX] += crm_derate(i, AC_DISCHARGE_EX) .* capres_ac_discharge ./ total_cap(AC_DISCHARGE_EX)

Check warning on line 89 in src/write_outputs/capacity_reserve_margin/write_capacity_value.jl

View check run for this annotation

Codecov / codecov/patch

src/write_outputs/capacity_reserve_margin/write_capacity_value.jl#L87-L89

Added lines #L87 - L89 were not covered by tests

capvalue[riskyhour, DC_CHARGE_EX] .-= crm_derate(i, DC_CHARGE_EX) .* capvalue_dc_charge[riskyhour, DC_CHARGE_EX] ./ total_cap(DC_CHARGE_EX)
capres_ac_charge = value.(EP[:vCAPRES_AC_CHARGE][AC_CHARGE_EX, :].data)'
capvalue[riskyhour, AC_CHARGE_EX] .-= crm_derate(i, AC_CHARGE_EX) .* capres_ac_charge ./ total_cap(AC_CHARGE_EX)
capvalue[riskyhour, DC_CHARGE_EX] -= crm_derate(i, DC_CHARGE_EX) .* capvalue_dc_charge[riskyhour, DC_CHARGE_EX] ./ total_cap(DC_CHARGE_EX)
capres_ac_charge = value.(EP[:vCAPRES_AC_CHARGE][AC_CHARGE_EX, riskyhour].data)'
capvalue[riskyhour, AC_CHARGE_EX] -= crm_derate(i, AC_CHARGE_EX) .* capres_ac_charge ./ total_cap(AC_CHARGE_EX)

Check warning on line 93 in src/write_outputs/capacity_reserve_margin/write_capacity_value.jl

View check run for this annotation

Codecov / codecov/patch

src/write_outputs/capacity_reserve_margin/write_capacity_value.jl#L91-L93

Added lines #L91 - L93 were not covered by tests
end
capvalue .+= collect(transpose(capvalue))
capvalue = collect(transpose(capvalue))
temp_dfCapValue = DataFrame(Resource = inputs["RESOURCES"], Zone = dfGen.Zone, Reserve = fill(Symbol("CapRes_$i"), G))
temp_dfCapValue = hcat(temp_dfCapValue, DataFrame(capvalue, :auto))

Check warning on line 97 in src/write_outputs/capacity_reserve_margin/write_capacity_value.jl

View check run for this annotation

Codecov / codecov/patch

src/write_outputs/capacity_reserve_margin/write_capacity_value.jl#L95-L97

Added lines #L95 - L97 were not covered by tests
auxNew_Names = [Symbol("Resource"); Symbol("Zone"); Symbol("Reserve"); [Symbol("t$t") for t in 1:T]]
rename!(temp_dfCapValue, auxNew_Names)
append!(dfCapValue, temp_dfCapValue)
end
write_simple_csv(joinpath(path, "CapacityValue.csv"), dfCapValue)
write_simple_csv(joinpath(path, "CapacityValue.csv"), dfCapValue)

Check warning on line 102 in src/write_outputs/capacity_reserve_margin/write_capacity_value.jl

View check run for this annotation

Codecov / codecov/patch

src/write_outputs/capacity_reserve_margin/write_capacity_value.jl#L102

Added line #L102 was not covered by tests
end

@doc raw"""
Expand Down

0 comments on commit 264258a

Please sign in to comment.