From 08b5d4de2bdbdc8a994c05eaba3d7e3197338766 Mon Sep 17 00:00:00 2001 From: Jacob Schwartz Date: Wed, 22 Nov 2023 14:19:21 -0500 Subject: [PATCH] Polishing --- .../write_capacity_value.jl | 50 ++++++++++--------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/src/write_outputs/capacity_reserve_margin/write_capacity_value.jl b/src/write_outputs/capacity_reserve_margin/write_capacity_value.jl index e00162e016..4d374fa702 100644 --- a/src/write_outputs/capacity_reserve_margin/write_capacity_value.jl +++ b/src/write_outputs/capacity_reserve_margin/write_capacity_value.jl @@ -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]) + + minimum_plant_size = 1 # MW large_plants = findall(>=(minimum_plant_size), eTotalCap * scale_factor) THERM_ALL_EX = intersect(THERM_ALL, large_plants) @@ -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) + + minimum_crm_price = 1 # $/MW + riskyhour = findall(>=(minimum_crm_price), capacity_reserve_margin_price(EP, inputs, setup, i)) power(y) = value.(EP[:vP][y, riskyhour])' - capvalue[riskyhour, THERM_ALL_EX] .= crm_derate(i, THERM_ALL_EX) + capvalue[riskyhour, THERM_ALL_EX] = crm_derate(i, THERM_ALL_EX) - 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) - 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) - 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) 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)' - 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) 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) 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 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 - 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) - 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) - 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) - 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) 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)) 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) end @doc raw"""