From 5bb91da702cf8be555fe67e17a365e79a49d84b8 Mon Sep 17 00:00:00 2001 From: Maya Mutic Date: Mon, 22 Apr 2024 16:29:36 -0400 Subject: [PATCH 01/61] Added full time series reconstruction --- example_systems/1_three_zones/settings/genx_settings.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/example_systems/1_three_zones/settings/genx_settings.yml b/example_systems/1_three_zones/settings/genx_settings.yml index c85af312ac..278270baac 100644 --- a/example_systems/1_three_zones/settings/genx_settings.yml +++ b/example_systems/1_three_zones/settings/genx_settings.yml @@ -10,3 +10,4 @@ ParameterScale: 1 # Turn on parameter scaling wherein demand, capacity and power WriteShadowPrices: 1 # Write shadow prices of LP or relaxed MILP; 0 = not active; 1 = active UCommit: 2 # Unit committment of thermal power plants; 0 = not active; 1 = active using integer clestering; 2 = active using linearized clustering TimeDomainReduction: 1 # Time domain reduce (i.e. cluster) inputs based on Demand_data.csv, Generators_variability.csv, and Fuels_data.csv; 0 = not active (use input data as provided); 0 = active (cluster input data, or use data that has already been clustered) +OutputFullTimeSeries: 1 \ No newline at end of file From c1fd03794efcebc25c8ce1c44ebefb701eae839b Mon Sep 17 00:00:00 2001 From: Maya Mutic <62064527+mmutic@users.noreply.github.com> Date: Mon, 22 Apr 2024 16:32:08 -0400 Subject: [PATCH 02/61] Add full_time_series_reconstruction.jl --- .../full_time_series_reconstruction.jl | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/time_domain_reduction/full_time_series_reconstruction.jl diff --git a/src/time_domain_reduction/full_time_series_reconstruction.jl b/src/time_domain_reduction/full_time_series_reconstruction.jl new file mode 100644 index 0000000000..a81e7fa264 --- /dev/null +++ b/src/time_domain_reduction/full_time_series_reconstruction.jl @@ -0,0 +1,71 @@ +@doc raw"""reconstruction(case::AbstractString, + DF::DataFrame) +Create a DataFrame with all 8,760 hours of the year from the reduced output. + +case - folder for the case +DF - DataFrame to be reconstructed + +This function uses Period_map.csv to create a new DataFrame with 8,760 time steps, as well as other pre-existing rows such as "Zone". +For each 52 weeks of the year, the corresponding representative week is taken from the input DataFrame and copied into the new DataFrame. Representative periods that +represent more than one week will appear multiple times in the output. + +Note: Currently, TDR only gives the representative periods in Period_map for 52 weeks, when a (non-leap) year is 52 weeks + 24 hours. This function takes the last 24 hours of +the time series and copies them to get up to all 8,760 hours in a year. + +This function is called when output files with time series data (e.g. power.csv, emissions.csv) are created, if the setup key "OutputFullTimeSeries" is set to "1". + +""" +function reconstruction(case::AbstractString,DF::DataFrame) + settings_path = GenX.get_settings_path(case) + + # Read Period map file Period_map.csv + Period_map = CSV.read(joinpath(case,"TDR_results/Period_map.csv"),DataFrame) + + # Read time domain reduction settings file time_domain_reduction_settings.yml + myTDRsetup = YAML.load(open(joinpath(settings_path, + "time_domain_reduction_settings.yml"))) + + # Define Timesteps per Representative Period and Weight Total + TimestepsPerRepPeriod = myTDRsetup["TimestepsPerRepPeriod"] + WeightTotal = myTDRsetup["WeightTotal"] + + # Calculate the number of total periods the original time series was split into (will usually be 52) + numPeriods = floor(Int,WeightTotal/TimestepsPerRepPeriod) + + # Get the names of the input DataFrame + DFnames = names(DF) + + # Initialize an array to add the reconstructed data to + recon = ["t$t" for t in 1:TimestepsPerRepPeriod*numPeriods] + + # Find the index of the row with the first time step + t1 = findfirst(x -> x == "t1",DF[!,1]) + + # Reconstruction of all hours of the year from TDR + for j in range(2,ncol(DF)) + col = DF[t1:end,j] + col_name = DFnames[j] + recon_col = [] + for i in range(1,numPeriods) + index = Period_map[i,"Rep_Period_Index"] + recon_temp = col[(TimestepsPerRepPeriod*index-(TimestepsPerRepPeriod-1)):(TimestepsPerRepPeriod*index)] + recon_col = [recon_col; recon_temp] + end + recon = [recon recon_col] + end + reconDF = DataFrame(recon, DFnames) + + # Insert rows that were above "t1" in the original DataFrame (e.g. "Zone" and "AnnualSum") if present + for i in range(1,t1-1) + insert!(reconDF,i,DF[i,1:end]) + end + + # Repeat the last rows of the year to fill in the gap (should be 24 hours for non-leap year) + end_diff = WeightTotal - nrow(reconDF) + 1 + new_rows = reconDF[(nrow(reconDF)-end_diff):nrow(reconDF),2:end] + new_rows[!,"Resource"] = ["t$t" for t in (WeightTotal-end_diff):WeightTotal] + + reconDF = [reconDF; new_rows] + + return reconDF +end \ No newline at end of file From 9ca9e1eda021df9206454174e5b020ff0ff41c09 Mon Sep 17 00:00:00 2001 From: Maya Mutic Date: Mon, 22 Apr 2024 16:35:07 -0400 Subject: [PATCH 03/61] Added setup key --- src/configure_settings/configure_settings.jl | 2 ++ src/write_outputs/write_outputs.jl | 11 ++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/configure_settings/configure_settings.jl b/src/configure_settings/configure_settings.jl index 3130bab7cf..2054b2a50a 100644 --- a/src/configure_settings/configure_settings.jl +++ b/src/configure_settings/configure_settings.jl @@ -16,6 +16,8 @@ function default_settings() "UCommit" => 0, "TimeDomainReduction" => 0, "TimeDomainReductionFolder" => "TDR_results", + "OutputFullTimeSeries" => 0, + "OutputFullTimeSeriesFolder" => "Full_TimeSeries", "ModelingToGenerateAlternatives" => 0, "ModelingtoGenerateAlternativeSlack" => 0.1, "MGAAnnualGeneration" => 0, diff --git a/src/write_outputs/write_outputs.jl b/src/write_outputs/write_outputs.jl index d8933533e3..0e31a63e3e 100644 --- a/src/write_outputs/write_outputs.jl +++ b/src/write_outputs/write_outputs.jl @@ -496,15 +496,16 @@ function write_fulltimeseries(fullpath::AbstractString, total = DataFrame(["Total" 0 sum(dfOut[!, :AnnualSum]) fill(0.0, (1, T))], auxNew_Names) total[!, 4:(T + 3)] .= sum(dataOut, dims = 1) dfOut = vcat(dfOut, total) + + if setup["OutputFullTimeSeries"] + dfOut_full = reconstruction(case, dftranspose(dfOut, false)) + CSV.write(fullpath/FullTimeSeries, dfOut_full, writeheader = false) + end + CSV.write(fullpath, dftranspose(dfOut, false), writeheader = false) return nothing end -""" - write_settings_file(path, setup) - -Internal function for writing settings files -""" function write_settings_file(path, setup) YAML.write_file(joinpath(path, "run_settings.yml"), setup) end From 1c94efeb5a3166599a298e7b478c9aab7cf71aec Mon Sep 17 00:00:00 2001 From: Maya Mutic Date: Thu, 2 May 2024 15:02:07 -0400 Subject: [PATCH 04/61] Updates --- .../1_three_zones/settings/genx_settings.yml | 2 +- src/GenX.jl | 1 + .../full_time_series_reconstruction.jl | 38 ++++++++++--------- .../transmission/write_transmission_flows.jl | 9 +++++ .../transmission/write_transmission_losses.jl | 10 +++++ src/write_outputs/ucommit/write_commit.jl | 15 ++++++++ src/write_outputs/ucommit/write_shutdown.jl | 9 +++++ src/write_outputs/ucommit/write_start.jl | 9 +++++ src/write_outputs/write_charge.jl | 11 ++++++ src/write_outputs/write_curtailment.jl | 8 ++++ src/write_outputs/write_emissions.jl | 10 +++++ src/write_outputs/write_nse.jl | 9 +++++ src/write_outputs/write_outputs.jl | 12 +++--- src/write_outputs/write_power.jl | 8 ++++ src/write_outputs/write_power_balance.jl | 12 ++++++ src/write_outputs/write_price.jl | 9 +++++ src/write_outputs/write_reliability.jl | 10 +++++ src/write_outputs/write_storage.jl | 10 +++++ src/write_outputs/write_storagedual.jl | 10 +++++ 19 files changed, 178 insertions(+), 24 deletions(-) diff --git a/example_systems/1_three_zones/settings/genx_settings.yml b/example_systems/1_three_zones/settings/genx_settings.yml index 278270baac..191225e185 100644 --- a/example_systems/1_three_zones/settings/genx_settings.yml +++ b/example_systems/1_three_zones/settings/genx_settings.yml @@ -10,4 +10,4 @@ ParameterScale: 1 # Turn on parameter scaling wherein demand, capacity and power WriteShadowPrices: 1 # Write shadow prices of LP or relaxed MILP; 0 = not active; 1 = active UCommit: 2 # Unit committment of thermal power plants; 0 = not active; 1 = active using integer clestering; 2 = active using linearized clustering TimeDomainReduction: 1 # Time domain reduce (i.e. cluster) inputs based on Demand_data.csv, Generators_variability.csv, and Fuels_data.csv; 0 = not active (use input data as provided); 0 = active (cluster input data, or use data that has already been clustered) -OutputFullTimeSeries: 1 \ No newline at end of file +OutputFullTimeSeries: 1 diff --git a/src/GenX.jl b/src/GenX.jl index d0a53378c2..62939d3d90 100644 --- a/src/GenX.jl +++ b/src/GenX.jl @@ -71,6 +71,7 @@ include_all_in_folder("write_outputs") include("time_domain_reduction/time_domain_reduction.jl") include("time_domain_reduction/precluster.jl") +include("time_domain_reduction/full_time_series_reconstruction.jl") include_all_in_folder("multi_stage") include_all_in_folder("additional_tools") diff --git a/src/time_domain_reduction/full_time_series_reconstruction.jl b/src/time_domain_reduction/full_time_series_reconstruction.jl index a81e7fa264..a0dad433d7 100644 --- a/src/time_domain_reduction/full_time_series_reconstruction.jl +++ b/src/time_domain_reduction/full_time_series_reconstruction.jl @@ -2,7 +2,7 @@ DF::DataFrame) Create a DataFrame with all 8,760 hours of the year from the reduced output. -case - folder for the case +setup - case setup (dictionary) DF - DataFrame to be reconstructed This function uses Period_map.csv to create a new DataFrame with 8,760 time steps, as well as other pre-existing rows such as "Zone". @@ -15,15 +15,14 @@ the time series and copies them to get up to all 8,760 hours in a year. This function is called when output files with time series data (e.g. power.csv, emissions.csv) are created, if the setup key "OutputFullTimeSeries" is set to "1". """ -function reconstruction(case::AbstractString,DF::DataFrame) - settings_path = GenX.get_settings_path(case) - - # Read Period map file Period_map.csv - Period_map = CSV.read(joinpath(case,"TDR_results/Period_map.csv"),DataFrame) +function full_time_series_reconstruction(path::AbstractString,setup::Dict,DF::DataFrame,DFnames::Vector) + # Read Period map file Period_map.csv + case = path[1:findlast('/',path)] + TDRpath = joinpath(case, setup["TimeDomainReductionFolder"]) + Period_map = CSV.read(joinpath(TDRpath,"Period_map.csv"),DataFrame) # Read time domain reduction settings file time_domain_reduction_settings.yml - myTDRsetup = YAML.load(open(joinpath(settings_path, - "time_domain_reduction_settings.yml"))) + myTDRsetup = YAML.load(open(joinpath(case,"settings/time_domain_reduction_settings.yml"))) # Define Timesteps per Representative Period and Weight Total TimestepsPerRepPeriod = myTDRsetup["TimestepsPerRepPeriod"] @@ -33,38 +32,43 @@ function reconstruction(case::AbstractString,DF::DataFrame) numPeriods = floor(Int,WeightTotal/TimestepsPerRepPeriod) # Get the names of the input DataFrame - DFnames = names(DF) - + DFMatrix = Matrix(DF) + #DFnames = DFMatrix[1,:] # Initialize an array to add the reconstructed data to recon = ["t$t" for t in 1:TimestepsPerRepPeriod*numPeriods] # Find the index of the row with the first time step t1 = findfirst(x -> x == "t1",DF[!,1]) - + + reconDF = DataFrame() + #names1 = [Symbol(DFnames[1])] # Reconstruction of all hours of the year from TDR for j in range(2,ncol(DF)) col = DF[t1:end,j] - col_name = DFnames[j] + #col_name = DFnames[j] + #names1 = [names1 Symbol(col_name)] recon_col = [] for i in range(1,numPeriods) index = Period_map[i,"Rep_Period_Index"] recon_temp = col[(TimestepsPerRepPeriod*index-(TimestepsPerRepPeriod-1)):(TimestepsPerRepPeriod*index)] recon_col = [recon_col; recon_temp] end + #reconDF[!,col_name] = recon_col recon = [recon recon_col] end - reconDF = DataFrame(recon, DFnames) + reconDF = DataFrame(recon, DFnames, makeunique=true) + #auxNew_Names = [Symbol("Resource"); Symbol("Zone"); [Symbol("t$t") for t in 1:T]] + #rename!(reconDF,names1) # Insert rows that were above "t1" in the original DataFrame (e.g. "Zone" and "AnnualSum") if present for i in range(1,t1-1) - insert!(reconDF,i,DF[i,1:end]) + insert!(reconDF,i,DFMatrix[i,1:end],promote=true) end # Repeat the last rows of the year to fill in the gap (should be 24 hours for non-leap year) end_diff = WeightTotal - nrow(reconDF) + 1 - new_rows = reconDF[(nrow(reconDF)-end_diff):nrow(reconDF),2:end] - new_rows[!,"Resource"] = ["t$t" for t in (WeightTotal-end_diff):WeightTotal] - + new_rows = reconDF[(nrow(reconDF)-end_diff):nrow(reconDF),1:end] + new_rows[!,1] = ["t$t" for t in (WeightTotal-end_diff):WeightTotal] reconDF = [reconDF; new_rows] return reconDF diff --git a/src/write_outputs/transmission/write_transmission_flows.jl b/src/write_outputs/transmission/write_transmission_flows.jl index 8494a38511..e0b0d82a14 100644 --- a/src/write_outputs/transmission/write_transmission_flows.jl +++ b/src/write_outputs/transmission/write_transmission_flows.jl @@ -23,6 +23,15 @@ function write_transmission_flows(path::AbstractString, auxNew_Names = [Symbol("Line"); [Symbol("t$t") for t in 1:T]] rename!(dfFlow, auxNew_Names) CSV.write(filepath, dftranspose(dfFlow, false), writeheader = false) + + if setup["OutputFullTimeSeries"] == 1 + DFnames = ["Line","1","2"] + FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] + output_path = joinpath(path,FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfFlow, false), DFnames) + CSV.write(joinpath(output_path,"flow.csv"), dfOut_full) + println("Writing Full Time Series for Transmission Flows") + end end return nothing end diff --git a/src/write_outputs/transmission/write_transmission_losses.jl b/src/write_outputs/transmission/write_transmission_losses.jl index b82204acd0..686df8bdc6 100644 --- a/src/write_outputs/transmission/write_transmission_losses.jl +++ b/src/write_outputs/transmission/write_transmission_losses.jl @@ -30,6 +30,16 @@ function write_transmission_losses(path::AbstractString, CSV.write(joinpath(path, "tlosses.csv"), dftranspose(dfTLosses, false), writeheader = false) + + if setup["OutputFullTimeSeries"] == 1 + DFnames = ["Line", "1", "2", "Total"] + FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] + output_path = joinpath(path,FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfTLosses, false), DFnames) + CSV.write(joinpath(output_path,"tlosses.csv"), dfOut_full) + println("Writing Full Time Series for Time Losses") + end + end return nothing end diff --git a/src/write_outputs/ucommit/write_commit.jl b/src/write_outputs/ucommit/write_commit.jl index bf8e712640..b757492d70 100644 --- a/src/write_outputs/ucommit/write_commit.jl +++ b/src/write_outputs/ucommit/write_commit.jl @@ -11,4 +11,19 @@ function write_commit(path::AbstractString, inputs::Dict, setup::Dict, EP::Model auxNew_Names = [Symbol("Resource"); Symbol("Zone"); [Symbol("t$t") for t in 1:T]] rename!(dfCommit, auxNew_Names) CSV.write(joinpath(path, "commit.csv"), dftranspose(dfCommit, false), header = false) + println("-------------------------------") + println("PATH = ", path) + println("-------------------------------") + + + if setup["OutputFullTimeSeries"] == 1 + DFMatrix = Matrix(dftranspose(dfCommit, true)) + DFnames = DFMatrix[1,:] + FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] + output_path = joinpath(path,FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfCommit, true), DFnames) + CSV.write(joinpath(output_path,"commit.csv"), dfOut_full) + println("Writing Full Time Series for Commitment") + end + end diff --git a/src/write_outputs/ucommit/write_shutdown.jl b/src/write_outputs/ucommit/write_shutdown.jl index 8a726a3367..c64db9bedd 100644 --- a/src/write_outputs/ucommit/write_shutdown.jl +++ b/src/write_outputs/ucommit/write_shutdown.jl @@ -14,6 +14,15 @@ function write_shutdown(path::AbstractString, inputs::Dict, setup::Dict, EP::Mod write_annual(filepath, dfShutdown) else # setup["WriteOutputs"] == "full" write_fulltimeseries(filepath, shut, dfShutdown) + + if setup["OutputFullTimeSeries"] == 1 + df_Shutdown = CSV.read(joinpath(path,"shutdown.csv"),DataFrame) + FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] + output_path = joinpath(path,FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction(path,setup, df_Shutdown,names(df_Shutdown)) + CSV.write(joinpath(output_path,"shutdown.csv"), dfOut_full) + println("Writing Full Time Series for Shutdown") + end end return nothing end diff --git a/src/write_outputs/ucommit/write_start.jl b/src/write_outputs/ucommit/write_start.jl index be23be46bd..0362faff1d 100644 --- a/src/write_outputs/ucommit/write_start.jl +++ b/src/write_outputs/ucommit/write_start.jl @@ -13,6 +13,15 @@ function write_start(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) write_annual(filepath, dfStart) else # setup["WriteOutputs"] == "full" write_fulltimeseries(filepath, start, dfStart) + + if setup["OutputFullTimeSeries"] == 1 + df_Start = CSV.read(joinpath(path,"start.csv"),DataFrame) + FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] + output_path = joinpath(path,FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction(path,setup, df_Start,names(df_Start)) + CSV.write(joinpath(output_path,"start.csv"), dfOut_full) + println("Writing Full Time Series for Startup") + end end return nothing end diff --git a/src/write_outputs/write_charge.jl b/src/write_outputs/write_charge.jl index 1e0e835633..f43f5ec5f9 100644 --- a/src/write_outputs/write_charge.jl +++ b/src/write_outputs/write_charge.jl @@ -42,6 +42,17 @@ function write_charge(path::AbstractString, inputs::Dict, setup::Dict, EP::Model write_annual(filepath, dfCharge) else # setup["WriteOutputs"] == "full" write_fulltimeseries(filepath, charge, dfCharge) + if setup["OutputFullTimeSeries"] == 1 + df_Charge = CSV.read(joinpath(path,"charge.csv"),DataFrame) + FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] + output_path = joinpath(path,FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction(path,setup, df_Charge,names(df_Charge)) + CSV.write(joinpath(output_path,"charge.csv"), dfOut_full) + println("Writing Full Time Series for Charge") + end end + + + return nothing end diff --git a/src/write_outputs/write_curtailment.jl b/src/write_outputs/write_curtailment.jl index 8ee244f105..f7fa3bf20e 100644 --- a/src/write_outputs/write_curtailment.jl +++ b/src/write_outputs/write_curtailment.jl @@ -58,6 +58,14 @@ function write_curtailment(path::AbstractString, inputs::Dict, setup::Dict, EP:: write_annual(filename, dfCurtailment) else # setup["WriteOutputs"] == "full" write_fulltimeseries(filename, curtailment, dfCurtailment) + if setup["OutputFullTimeSeries"] == 1 + df_Curtail = CSV.read(joinpath(path,"curtail.csv"),DataFrame) + FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] + output_path = joinpath(path,FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction(path,setup, df_Curtail,names(df_Curtail)) + CSV.write(joinpath(output_path,"curtail.csv"), dfOut_full) + println("Writing Full Time Series for Curtailment") + end end return nothing end diff --git a/src/write_outputs/write_emissions.jl b/src/write_outputs/write_emissions.jl index 60758c085f..e4e2cf09b2 100644 --- a/src/write_outputs/write_emissions.jl +++ b/src/write_outputs/write_emissions.jl @@ -121,6 +121,16 @@ function write_emissions(path::AbstractString, inputs::Dict, setup::Dict, EP::Mo CSV.write(joinpath(path, "emissions.csv"), dftranspose(dfEmissions, false), writeheader = false) + + if setup["OutputFullTimeSeries"] == 1 + DFMatrix = Matrix(dftranspose(dfEmissions, true)) + DFnames = DFMatrix[1,:] + FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] + output_path = joinpath(path,FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfEmissions, false), DFnames) + CSV.write(joinpath(output_path,"emissions.csv"), dfOut_full) + println("Writing Full Time Series for Emissions") + end end end return nothing diff --git a/src/write_outputs/write_nse.jl b/src/write_outputs/write_nse.jl index 3cdc1104a7..0878a21dbd 100644 --- a/src/write_outputs/write_nse.jl +++ b/src/write_outputs/write_nse.jl @@ -37,6 +37,15 @@ function write_nse(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) dfNse = vcat(dfNse, total) CSV.write(joinpath(path, "nse.csv"), dftranspose(dfNse, false), writeheader = false) + + if setup["OutputFullTimeSeries"] == 1 + DFnames = ["Segment","1","2","3","4","1","2","3","4","1","2","3","4","Total"] + FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] + output_path = joinpath(path,FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfNse, false), DFnames) + CSV.write(joinpath(output_path,"nse.csv"), dfOut_full) + println("Writing Full Time Series for NSE") + end end return nothing end diff --git a/src/write_outputs/write_outputs.jl b/src/write_outputs/write_outputs.jl index 0e31a63e3e..65bb60d7b9 100644 --- a/src/write_outputs/write_outputs.jl +++ b/src/write_outputs/write_outputs.jl @@ -23,6 +23,10 @@ function write_outputs(EP::Model, path::AbstractString, setup::Dict, inputs::Dic mkpath(path) end + if setup["OutputFullTimeSeries"] == 1 + mkpath(joinpath(path,setup["OutputFullTimeSeriesFolder"])) + end + # https://jump.dev/MathOptInterface.jl/v0.9.10/apireference/#MathOptInterface.TerminationStatusCode status = termination_status(EP) @@ -72,6 +76,7 @@ function write_outputs(EP::Model, path::AbstractString, setup::Dict, inputs::Dic elapsed_time_power = @elapsed dfPower = write_power(path, inputs, setup, EP) println("Time elapsed for writing power is") println(elapsed_time_power) + println("Here") end if output_settings_d["WriteCharge"] @@ -174,7 +179,7 @@ function write_outputs(EP::Model, path::AbstractString, setup::Dict, inputs::Dic if setup["UCommit"] >= 1 if output_settings_d["WriteCommit"] elapsed_time_commit = @elapsed write_commit(path, inputs, setup, EP) - println("Time elapsed for writing commitment is") + println("Time elapsed for writing commitment is ") println(elapsed_time_commit) end @@ -497,11 +502,6 @@ function write_fulltimeseries(fullpath::AbstractString, total[!, 4:(T + 3)] .= sum(dataOut, dims = 1) dfOut = vcat(dfOut, total) - if setup["OutputFullTimeSeries"] - dfOut_full = reconstruction(case, dftranspose(dfOut, false)) - CSV.write(fullpath/FullTimeSeries, dfOut_full, writeheader = false) - end - CSV.write(fullpath, dftranspose(dfOut, false), writeheader = false) return nothing end diff --git a/src/write_outputs/write_power.jl b/src/write_outputs/write_power.jl index 30e14048be..aaba847382 100644 --- a/src/write_outputs/write_power.jl +++ b/src/write_outputs/write_power.jl @@ -25,6 +25,14 @@ function write_power(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) write_annual(filepath, dfPower) else # setup["WriteOutputs"] == "full" write_fulltimeseries(filepath, power, dfPower) + if setup["OutputFullTimeSeries"] == 1 + df_Power = CSV.read(joinpath(path,"power.csv"),DataFrame) + FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] + output_path = joinpath(path,FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction(path,setup, df_Power,names(df_Power)) + CSV.write(joinpath(output_path,"power.csv"), dfOut_full) + println("Writing Full Time Series for Power") + end end return dfPower #Shouldn't this be return nothing diff --git a/src/write_outputs/write_power_balance.jl b/src/write_outputs/write_power_balance.jl index 924c3b5f88..77c3f795af 100644 --- a/src/write_outputs/write_power_balance.jl +++ b/src/write_outputs/write_power_balance.jl @@ -98,6 +98,18 @@ function write_power_balance(path::AbstractString, inputs::Dict, setup::Dict, EP CSV.write(joinpath(path, "power_balance.csv"), dftranspose(dfPowerBalance, false), writeheader = false) + + if setup["OutputFullTimeSeries"] == 1 + DFnames = dfPowerBalance[:,1] + insert!(DFnames,1,"BalanceComponent") + #DFMatrix = Matrix(dftranspose(dfPowerBalance, true)) + # DFnames = DFMatrix[1,:] + FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] + output_path = joinpath(path,FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfPowerBalance, false),DFnames) + CSV.write(joinpath(output_path,"power_balance.csv"), dfOut_full) + println("Writing Full Time Series for Power Balance") + end end return nothing end diff --git a/src/write_outputs/write_price.jl b/src/write_outputs/write_price.jl index 05943c8fa8..a502fc799a 100644 --- a/src/write_outputs/write_price.jl +++ b/src/write_outputs/write_price.jl @@ -21,6 +21,15 @@ function write_price(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) CSV.write(joinpath(path, "prices.csv"), dftranspose(dfPrice, false), writeheader = false) + + if setup["OutputFullTimeSeries"] == 1 + DFnames = ["Zone", "1", "2", "3"] + FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] + output_path = joinpath(path,FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfPrice, false), DFnames) + CSV.write(joinpath(output_path,"prices.csv"), dfOut_full) + println("Writing Full Time Series for Price") + end return nothing end diff --git a/src/write_outputs/write_reliability.jl b/src/write_outputs/write_reliability.jl index 876465f8b7..588db64993 100644 --- a/src/write_outputs/write_reliability.jl +++ b/src/write_outputs/write_reliability.jl @@ -20,4 +20,14 @@ function write_reliability(path::AbstractString, inputs::Dict, setup::Dict, EP:: CSV.write(joinpath(path, "reliability.csv"), dftranspose(dfReliability, false), header = false) + + if setup["OutputFullTimeSeries"] == 1 + DFMatrix = Matrix(dftranspose(dfReliability, true)) + DFnames = ["Zone", "1", "2", "3"] + FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] + output_path = joinpath(path,FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfReliability, false), DFnames) + CSV.write(joinpath(output_path,"reliability.csv"), dfOut_full) + println("Writing Full Time Series for Reliability") + end end diff --git a/src/write_outputs/write_storage.jl b/src/write_outputs/write_storage.jl index a34c470108..b2461df762 100644 --- a/src/write_outputs/write_storage.jl +++ b/src/write_outputs/write_storage.jl @@ -39,4 +39,14 @@ function write_storage(path::AbstractString, inputs::Dict, setup::Dict, EP::Mode auxNew_Names = [Symbol("Resource"); Symbol("Zone"); [Symbol("t$t") for t in 1:T]] rename!(dfStorage, auxNew_Names) CSV.write(joinpath(path, "storage.csv"), dftranspose(dfStorage, false), header = false) + + if setup["OutputFullTimeSeries"] == 1 + DFMatrix = Matrix(dftranspose(dfStorage, true)) + DFnames = DFMatrix[1,:] + FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] + output_path = joinpath(path,FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfStorage, false), DFnames) + CSV.write(joinpath(output_path,"storage.csv"), dfOut_full) + println("Writing Full Time Series for Storage") + end end diff --git a/src/write_outputs/write_storagedual.jl b/src/write_outputs/write_storagedual.jl index a30414d4e7..e43f753c4d 100644 --- a/src/write_outputs/write_storagedual.jl +++ b/src/write_outputs/write_storagedual.jl @@ -71,4 +71,14 @@ function write_storagedual(path::AbstractString, inputs::Dict, setup::Dict, EP:: CSV.write(joinpath(path, "storagebal_duals.csv"), dftranspose(dfStorageDual, false), header = false) + + if setup["OutputFullTimeSeries"] == 1 + DFMatrix = Matrix(dftranspose(dfStorageDual, true)) + DFnames = DFMatrix[1,:] + FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] + output_path = joinpath(path,FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfStorageDual, false), DFnames) + CSV.write(joinpath(output_path,"storagebal_duals.csv"), dfOut_full) + println("Writing Full Time Series for Storage Duals") + end end From 080a4a959fa06a227b1efbbaa15168c031bbb03f Mon Sep 17 00:00:00 2001 From: Maya Mutic Date: Thu, 2 May 2024 18:09:02 -0400 Subject: [PATCH 05/61] Minor notes --- .../full_time_series_reconstruction.jl | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/time_domain_reduction/full_time_series_reconstruction.jl b/src/time_domain_reduction/full_time_series_reconstruction.jl index a0dad433d7..015ae82f2c 100644 --- a/src/time_domain_reduction/full_time_series_reconstruction.jl +++ b/src/time_domain_reduction/full_time_series_reconstruction.jl @@ -1,9 +1,13 @@ -@doc raw"""reconstruction(case::AbstractString, - DF::DataFrame) +@doc raw"""full_time_series_reconstruction(path::AbstractString, + case::AbstractString, + DF::DataFrame, + DFnames::Vector) Create a DataFrame with all 8,760 hours of the year from the reduced output. +path - setup - case setup (dictionary) DF - DataFrame to be reconstructed +DFnames - Vector of column names This function uses Period_map.csv to create a new DataFrame with 8,760 time steps, as well as other pre-existing rows such as "Zone". For each 52 weeks of the year, the corresponding representative week is taken from the input DataFrame and copied into the new DataFrame. Representative periods that @@ -15,6 +19,12 @@ the time series and copies them to get up to all 8,760 hours in a year. This function is called when output files with time series data (e.g. power.csv, emissions.csv) are created, if the setup key "OutputFullTimeSeries" is set to "1". """ +# TO DO: +# Add docstring, no example needed +# Add in a TDR check +# Try header = false in CSV.write +# Try transpose to get duplicated column names +# Look into mybinder function full_time_series_reconstruction(path::AbstractString,setup::Dict,DF::DataFrame,DFnames::Vector) # Read Period map file Period_map.csv case = path[1:findlast('/',path)] @@ -33,15 +43,14 @@ function full_time_series_reconstruction(path::AbstractString,setup::Dict,DF::Da # Get the names of the input DataFrame DFMatrix = Matrix(DF) - #DFnames = DFMatrix[1,:] + # Initialize an array to add the reconstructed data to recon = ["t$t" for t in 1:TimestepsPerRepPeriod*numPeriods] # Find the index of the row with the first time step t1 = findfirst(x -> x == "t1",DF[!,1]) - reconDF = DataFrame() - #names1 = [Symbol(DFnames[1])] + # Reconstruction of all hours of the year from TDR for j in range(2,ncol(DF)) col = DF[t1:end,j] @@ -50,14 +59,14 @@ function full_time_series_reconstruction(path::AbstractString,setup::Dict,DF::Da recon_col = [] for i in range(1,numPeriods) index = Period_map[i,"Rep_Period_Index"] - recon_temp = col[(TimestepsPerRepPeriod*index-(TimestepsPerRepPeriod-1)):(TimestepsPerRepPeriod*index)] + recon_temp = col[(TimestepsPerRepPeriod*index-(TimestepsPerRepPeriod-1)):(TimestepsPerRepPeriod*index)] # Describe how this works recon_col = [recon_col; recon_temp] end #reconDF[!,col_name] = recon_col recon = [recon recon_col] end reconDF = DataFrame(recon, DFnames, makeunique=true) - #auxNew_Names = [Symbol("Resource"); Symbol("Zone"); [Symbol("t$t") for t in 1:T]] + #rename!(reconDF,names1) # Insert rows that were above "t1" in the original DataFrame (e.g. "Zone" and "AnnualSum") if present From d506dc6d87dd4d3b2d8947ee69bcd9095b690b8e Mon Sep 17 00:00:00 2001 From: Maya Mutic Date: Wed, 8 May 2024 21:03:08 -0400 Subject: [PATCH 06/61] Updates --- .../full_time_series_reconstruction.jl | 5 +---- .../transmission/write_transmission_flows.jl | 4 ++-- .../transmission/write_transmission_losses.jl | 4 ++-- src/write_outputs/ucommit/write_commit.jl | 6 +++--- src/write_outputs/ucommit/write_shutdown.jl | 2 +- src/write_outputs/ucommit/write_start.jl | 2 +- src/write_outputs/write_charge.jl | 2 +- src/write_outputs/write_co2.jl | 9 +++++++++ src/write_outputs/write_curtailment.jl | 2 +- src/write_outputs/write_emissions.jl | 2 +- src/write_outputs/write_fuel_consumption.jl | 10 ++++++++++ src/write_outputs/write_nse.jl | 4 ++-- src/write_outputs/write_power.jl | 2 +- src/write_outputs/write_power_balance.jl | 4 ++-- src/write_outputs/write_price.jl | 4 ++-- src/write_outputs/write_reliability.jl | 5 ++--- src/write_outputs/write_storage.jl | 4 ++-- src/write_outputs/write_storagedual.jl | 4 ++-- 18 files changed, 45 insertions(+), 30 deletions(-) diff --git a/src/time_domain_reduction/full_time_series_reconstruction.jl b/src/time_domain_reduction/full_time_series_reconstruction.jl index 015ae82f2c..f483eaaa20 100644 --- a/src/time_domain_reduction/full_time_series_reconstruction.jl +++ b/src/time_domain_reduction/full_time_series_reconstruction.jl @@ -4,7 +4,7 @@ DFnames::Vector) Create a DataFrame with all 8,760 hours of the year from the reduced output. -path - +path - Path input to the results folder setup - case setup (dictionary) DF - DataFrame to be reconstructed DFnames - Vector of column names @@ -20,10 +20,7 @@ This function is called when output files with time series data (e.g. power.csv, """ # TO DO: -# Add docstring, no example needed # Add in a TDR check -# Try header = false in CSV.write -# Try transpose to get duplicated column names # Look into mybinder function full_time_series_reconstruction(path::AbstractString,setup::Dict,DF::DataFrame,DFnames::Vector) # Read Period map file Period_map.csv diff --git a/src/write_outputs/transmission/write_transmission_flows.jl b/src/write_outputs/transmission/write_transmission_flows.jl index e0b0d82a14..199f61e72f 100644 --- a/src/write_outputs/transmission/write_transmission_flows.jl +++ b/src/write_outputs/transmission/write_transmission_flows.jl @@ -24,12 +24,12 @@ function write_transmission_flows(path::AbstractString, rename!(dfFlow, auxNew_Names) CSV.write(filepath, dftranspose(dfFlow, false), writeheader = false) - if setup["OutputFullTimeSeries"] == 1 + if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 DFnames = ["Line","1","2"] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path,FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfFlow, false), DFnames) - CSV.write(joinpath(output_path,"flow.csv"), dfOut_full) + CSV.write(joinpath(output_path,"flow.csv"), dfOut_full, header = false) println("Writing Full Time Series for Transmission Flows") end end diff --git a/src/write_outputs/transmission/write_transmission_losses.jl b/src/write_outputs/transmission/write_transmission_losses.jl index 686df8bdc6..6587cac4ed 100644 --- a/src/write_outputs/transmission/write_transmission_losses.jl +++ b/src/write_outputs/transmission/write_transmission_losses.jl @@ -31,12 +31,12 @@ function write_transmission_losses(path::AbstractString, dftranspose(dfTLosses, false), writeheader = false) - if setup["OutputFullTimeSeries"] == 1 + if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 DFnames = ["Line", "1", "2", "Total"] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path,FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfTLosses, false), DFnames) - CSV.write(joinpath(output_path,"tlosses.csv"), dfOut_full) + CSV.write(joinpath(output_path,"tlosses.csv"), dfOut_full, header = false) println("Writing Full Time Series for Time Losses") end diff --git a/src/write_outputs/ucommit/write_commit.jl b/src/write_outputs/ucommit/write_commit.jl index b757492d70..1df95e1b99 100644 --- a/src/write_outputs/ucommit/write_commit.jl +++ b/src/write_outputs/ucommit/write_commit.jl @@ -16,13 +16,13 @@ function write_commit(path::AbstractString, inputs::Dict, setup::Dict, EP::Model println("-------------------------------") - if setup["OutputFullTimeSeries"] == 1 + if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 DFMatrix = Matrix(dftranspose(dfCommit, true)) DFnames = DFMatrix[1,:] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path,FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfCommit, true), DFnames) - CSV.write(joinpath(output_path,"commit.csv"), dfOut_full) + dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfCommit, false), DFnames) + CSV.write(joinpath(output_path,"commit.csv"), dfOut_full, header = false) println("Writing Full Time Series for Commitment") end diff --git a/src/write_outputs/ucommit/write_shutdown.jl b/src/write_outputs/ucommit/write_shutdown.jl index c64db9bedd..62b2e6e34f 100644 --- a/src/write_outputs/ucommit/write_shutdown.jl +++ b/src/write_outputs/ucommit/write_shutdown.jl @@ -15,7 +15,7 @@ function write_shutdown(path::AbstractString, inputs::Dict, setup::Dict, EP::Mod else # setup["WriteOutputs"] == "full" write_fulltimeseries(filepath, shut, dfShutdown) - if setup["OutputFullTimeSeries"] == 1 + if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 df_Shutdown = CSV.read(joinpath(path,"shutdown.csv"),DataFrame) FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path,FullTimeSeriesFolder) diff --git a/src/write_outputs/ucommit/write_start.jl b/src/write_outputs/ucommit/write_start.jl index 0362faff1d..c1ff25f886 100644 --- a/src/write_outputs/ucommit/write_start.jl +++ b/src/write_outputs/ucommit/write_start.jl @@ -14,7 +14,7 @@ function write_start(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) else # setup["WriteOutputs"] == "full" write_fulltimeseries(filepath, start, dfStart) - if setup["OutputFullTimeSeries"] == 1 + if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 df_Start = CSV.read(joinpath(path,"start.csv"),DataFrame) FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path,FullTimeSeriesFolder) diff --git a/src/write_outputs/write_charge.jl b/src/write_outputs/write_charge.jl index f43f5ec5f9..39827c5ff9 100644 --- a/src/write_outputs/write_charge.jl +++ b/src/write_outputs/write_charge.jl @@ -42,7 +42,7 @@ function write_charge(path::AbstractString, inputs::Dict, setup::Dict, EP::Model write_annual(filepath, dfCharge) else # setup["WriteOutputs"] == "full" write_fulltimeseries(filepath, charge, dfCharge) - if setup["OutputFullTimeSeries"] == 1 + if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 df_Charge = CSV.read(joinpath(path,"charge.csv"),DataFrame) FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path,FullTimeSeriesFolder) diff --git a/src/write_outputs/write_co2.jl b/src/write_outputs/write_co2.jl index 050cf91c04..1a6d0eab6b 100644 --- a/src/write_outputs/write_co2.jl +++ b/src/write_outputs/write_co2.jl @@ -32,6 +32,15 @@ function write_co2_emissions_plant(path::AbstractString, write_annual(filepath, dfEmissions_plant) else # setup["WriteOutputs"] == "full" write_fulltimeseries(filepath, emissions_plant, dfEmissions_plant) + if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 + DFMatrix = Matrix(dftranspose(dfEmissions_plant, true)) + DFnames = DFMatrix[1,:] + FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] + output_path = joinpath(path,FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfEmissions_plant, false), DFnames) + CSV.write(joinpath(output_path,"emissions_plant.csv"), dfOut_full, header = false) + println("Writing Full Time Series for Emissions Plant") + end end return nothing end diff --git a/src/write_outputs/write_curtailment.jl b/src/write_outputs/write_curtailment.jl index f7fa3bf20e..777740c0bc 100644 --- a/src/write_outputs/write_curtailment.jl +++ b/src/write_outputs/write_curtailment.jl @@ -58,7 +58,7 @@ function write_curtailment(path::AbstractString, inputs::Dict, setup::Dict, EP:: write_annual(filename, dfCurtailment) else # setup["WriteOutputs"] == "full" write_fulltimeseries(filename, curtailment, dfCurtailment) - if setup["OutputFullTimeSeries"] == 1 + if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 df_Curtail = CSV.read(joinpath(path,"curtail.csv"),DataFrame) FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path,FullTimeSeriesFolder) diff --git a/src/write_outputs/write_emissions.jl b/src/write_outputs/write_emissions.jl index e4e2cf09b2..e244df74c9 100644 --- a/src/write_outputs/write_emissions.jl +++ b/src/write_outputs/write_emissions.jl @@ -122,7 +122,7 @@ function write_emissions(path::AbstractString, inputs::Dict, setup::Dict, EP::Mo dftranspose(dfEmissions, false), writeheader = false) - if setup["OutputFullTimeSeries"] == 1 + if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 DFMatrix = Matrix(dftranspose(dfEmissions, true)) DFnames = DFMatrix[1,:] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] diff --git a/src/write_outputs/write_fuel_consumption.jl b/src/write_outputs/write_fuel_consumption.jl index baff1301d6..47d70301cf 100644 --- a/src/write_outputs/write_fuel_consumption.jl +++ b/src/write_outputs/write_fuel_consumption.jl @@ -90,6 +90,16 @@ function write_fuel_consumption_ts(path::AbstractString, DataFrame(tempts, [Symbol("t$t") for t in 1:T])) CSV.write(joinpath(path, "FuelConsumption_plant_MMBTU.csv"), dftranspose(dfPlantFuel_TS, false), header = false) + + if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 + DFMatrix = Matrix(dftranspose(dfPlantFuel_TS, true)) + DFnames = DFMatrix[1,:] + FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] + output_path = joinpath(path,FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfPlantFuel_TS, false), DFnames) + CSV.write(joinpath(output_path,"commit.csv"), dfOut_full, header = false) + println("Writing Full Time Series for Fuel Consumption") + end end function write_fuel_consumption_tot(path::AbstractString, diff --git a/src/write_outputs/write_nse.jl b/src/write_outputs/write_nse.jl index 0878a21dbd..03605c1dd4 100644 --- a/src/write_outputs/write_nse.jl +++ b/src/write_outputs/write_nse.jl @@ -38,12 +38,12 @@ function write_nse(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) CSV.write(joinpath(path, "nse.csv"), dftranspose(dfNse, false), writeheader = false) - if setup["OutputFullTimeSeries"] == 1 + if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 DFnames = ["Segment","1","2","3","4","1","2","3","4","1","2","3","4","Total"] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path,FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfNse, false), DFnames) - CSV.write(joinpath(output_path,"nse.csv"), dfOut_full) + CSV.write(joinpath(output_path,"nse.csv"), dfOut_full, header = false) println("Writing Full Time Series for NSE") end end diff --git a/src/write_outputs/write_power.jl b/src/write_outputs/write_power.jl index aaba847382..a729136eec 100644 --- a/src/write_outputs/write_power.jl +++ b/src/write_outputs/write_power.jl @@ -25,7 +25,7 @@ function write_power(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) write_annual(filepath, dfPower) else # setup["WriteOutputs"] == "full" write_fulltimeseries(filepath, power, dfPower) - if setup["OutputFullTimeSeries"] == 1 + if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 df_Power = CSV.read(joinpath(path,"power.csv"),DataFrame) FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path,FullTimeSeriesFolder) diff --git a/src/write_outputs/write_power_balance.jl b/src/write_outputs/write_power_balance.jl index 77c3f795af..b945755c94 100644 --- a/src/write_outputs/write_power_balance.jl +++ b/src/write_outputs/write_power_balance.jl @@ -99,7 +99,7 @@ function write_power_balance(path::AbstractString, inputs::Dict, setup::Dict, EP dftranspose(dfPowerBalance, false), writeheader = false) - if setup["OutputFullTimeSeries"] == 1 + if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 DFnames = dfPowerBalance[:,1] insert!(DFnames,1,"BalanceComponent") #DFMatrix = Matrix(dftranspose(dfPowerBalance, true)) @@ -107,7 +107,7 @@ function write_power_balance(path::AbstractString, inputs::Dict, setup::Dict, EP FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path,FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfPowerBalance, false),DFnames) - CSV.write(joinpath(output_path,"power_balance.csv"), dfOut_full) + CSV.write(joinpath(output_path,"power_balance.csv"), dfOut_full, header = false) println("Writing Full Time Series for Power Balance") end end diff --git a/src/write_outputs/write_price.jl b/src/write_outputs/write_price.jl index a502fc799a..19547f9209 100644 --- a/src/write_outputs/write_price.jl +++ b/src/write_outputs/write_price.jl @@ -22,12 +22,12 @@ function write_price(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) dftranspose(dfPrice, false), writeheader = false) - if setup["OutputFullTimeSeries"] == 1 + if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 DFnames = ["Zone", "1", "2", "3"] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path,FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfPrice, false), DFnames) - CSV.write(joinpath(output_path,"prices.csv"), dfOut_full) + CSV.write(joinpath(output_path,"prices.csv"), dfOut_full, header = false) println("Writing Full Time Series for Price") end return nothing diff --git a/src/write_outputs/write_reliability.jl b/src/write_outputs/write_reliability.jl index 588db64993..0c9ce76694 100644 --- a/src/write_outputs/write_reliability.jl +++ b/src/write_outputs/write_reliability.jl @@ -21,13 +21,12 @@ function write_reliability(path::AbstractString, inputs::Dict, setup::Dict, EP:: dftranspose(dfReliability, false), header = false) - if setup["OutputFullTimeSeries"] == 1 - DFMatrix = Matrix(dftranspose(dfReliability, true)) + if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 DFnames = ["Zone", "1", "2", "3"] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path,FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfReliability, false), DFnames) - CSV.write(joinpath(output_path,"reliability.csv"), dfOut_full) + CSV.write(joinpath(output_path,"reliability.csv"), dfOut_full, header = false) println("Writing Full Time Series for Reliability") end end diff --git a/src/write_outputs/write_storage.jl b/src/write_outputs/write_storage.jl index b2461df762..9d78dd8bba 100644 --- a/src/write_outputs/write_storage.jl +++ b/src/write_outputs/write_storage.jl @@ -40,13 +40,13 @@ function write_storage(path::AbstractString, inputs::Dict, setup::Dict, EP::Mode rename!(dfStorage, auxNew_Names) CSV.write(joinpath(path, "storage.csv"), dftranspose(dfStorage, false), header = false) - if setup["OutputFullTimeSeries"] == 1 + if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 DFMatrix = Matrix(dftranspose(dfStorage, true)) DFnames = DFMatrix[1,:] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path,FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfStorage, false), DFnames) - CSV.write(joinpath(output_path,"storage.csv"), dfOut_full) + CSV.write(joinpath(output_path,"storage.csv"), dfOut_full, header = false) println("Writing Full Time Series for Storage") end end diff --git a/src/write_outputs/write_storagedual.jl b/src/write_outputs/write_storagedual.jl index e43f753c4d..17df67d47b 100644 --- a/src/write_outputs/write_storagedual.jl +++ b/src/write_outputs/write_storagedual.jl @@ -72,13 +72,13 @@ function write_storagedual(path::AbstractString, inputs::Dict, setup::Dict, EP:: dftranspose(dfStorageDual, false), header = false) - if setup["OutputFullTimeSeries"] == 1 + if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 DFMatrix = Matrix(dftranspose(dfStorageDual, true)) DFnames = DFMatrix[1,:] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path,FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfStorageDual, false), DFnames) - CSV.write(joinpath(output_path,"storagebal_duals.csv"), dfOut_full) + CSV.write(joinpath(output_path,"storagebal_duals.csv"), dfOut_full, header = false) println("Writing Full Time Series for Storage Duals") end end From ab6685cdeb19f285097202d17f80bf8b6b4f0e8a Mon Sep 17 00:00:00 2001 From: Maya Mutic Date: Thu, 16 May 2024 14:42:42 -0400 Subject: [PATCH 07/61] Update --- src/time_domain_reduction/full_time_series_reconstruction.jl | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/time_domain_reduction/full_time_series_reconstruction.jl b/src/time_domain_reduction/full_time_series_reconstruction.jl index f483eaaa20..c3632e5f73 100644 --- a/src/time_domain_reduction/full_time_series_reconstruction.jl +++ b/src/time_domain_reduction/full_time_series_reconstruction.jl @@ -19,9 +19,7 @@ the time series and copies them to get up to all 8,760 hours in a year. This function is called when output files with time series data (e.g. power.csv, emissions.csv) are created, if the setup key "OutputFullTimeSeries" is set to "1". """ -# TO DO: -# Add in a TDR check -# Look into mybinder + function full_time_series_reconstruction(path::AbstractString,setup::Dict,DF::DataFrame,DFnames::Vector) # Read Period map file Period_map.csv case = path[1:findlast('/',path)] From 3c1c76c056800f203dc534fd010b16a0b43e1982 Mon Sep 17 00:00:00 2001 From: Maya Mutic <62064527+mmutic@users.noreply.github.com> Date: Tue, 4 Jun 2024 17:35:48 -0400 Subject: [PATCH 08/61] Update src/time_domain_reduction/full_time_series_reconstruction.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../full_time_series_reconstruction.jl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/time_domain_reduction/full_time_series_reconstruction.jl b/src/time_domain_reduction/full_time_series_reconstruction.jl index c3632e5f73..5c1df6ea9a 100644 --- a/src/time_domain_reduction/full_time_series_reconstruction.jl +++ b/src/time_domain_reduction/full_time_series_reconstruction.jl @@ -20,9 +20,10 @@ This function is called when output files with time series data (e.g. power.csv, """ -function full_time_series_reconstruction(path::AbstractString,setup::Dict,DF::DataFrame,DFnames::Vector) - # Read Period map file Period_map.csv - case = path[1:findlast('/',path)] +function full_time_series_reconstruction( + path::AbstractString, setup::Dict, DF::DataFrame, DFnames::Vector) + # Read Period map file Period_map.csv + case = path[1:findlast('/', path)] TDRpath = joinpath(case, setup["TimeDomainReductionFolder"]) Period_map = CSV.read(joinpath(TDRpath,"Period_map.csv"),DataFrame) From 0f2623e6feff634e1700e55719530156f0e90329 Mon Sep 17 00:00:00 2001 From: Maya Mutic <62064527+mmutic@users.noreply.github.com> Date: Tue, 4 Jun 2024 17:35:58 -0400 Subject: [PATCH 09/61] Update src/time_domain_reduction/full_time_series_reconstruction.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/time_domain_reduction/full_time_series_reconstruction.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/time_domain_reduction/full_time_series_reconstruction.jl b/src/time_domain_reduction/full_time_series_reconstruction.jl index 5c1df6ea9a..8f8a7009cc 100644 --- a/src/time_domain_reduction/full_time_series_reconstruction.jl +++ b/src/time_domain_reduction/full_time_series_reconstruction.jl @@ -25,8 +25,8 @@ function full_time_series_reconstruction( # Read Period map file Period_map.csv case = path[1:findlast('/', path)] TDRpath = joinpath(case, setup["TimeDomainReductionFolder"]) - Period_map = CSV.read(joinpath(TDRpath,"Period_map.csv"),DataFrame) - + Period_map = CSV.read(joinpath(TDRpath, "Period_map.csv"), DataFrame) + # Read time domain reduction settings file time_domain_reduction_settings.yml myTDRsetup = YAML.load(open(joinpath(case,"settings/time_domain_reduction_settings.yml"))) From b88e00616dc7dac1756cc85a44edd3cccba1ec1d Mon Sep 17 00:00:00 2001 From: Maya Mutic <62064527+mmutic@users.noreply.github.com> Date: Tue, 4 Jun 2024 17:36:25 -0400 Subject: [PATCH 10/61] Update src/time_domain_reduction/full_time_series_reconstruction.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/time_domain_reduction/full_time_series_reconstruction.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/time_domain_reduction/full_time_series_reconstruction.jl b/src/time_domain_reduction/full_time_series_reconstruction.jl index 8f8a7009cc..42f777df61 100644 --- a/src/time_domain_reduction/full_time_series_reconstruction.jl +++ b/src/time_domain_reduction/full_time_series_reconstruction.jl @@ -28,8 +28,9 @@ function full_time_series_reconstruction( Period_map = CSV.read(joinpath(TDRpath, "Period_map.csv"), DataFrame) # Read time domain reduction settings file time_domain_reduction_settings.yml - myTDRsetup = YAML.load(open(joinpath(case,"settings/time_domain_reduction_settings.yml"))) - + myTDRsetup = YAML.load(open(joinpath( + case, "settings/time_domain_reduction_settings.yml"))) + # Define Timesteps per Representative Period and Weight Total TimestepsPerRepPeriod = myTDRsetup["TimestepsPerRepPeriod"] WeightTotal = myTDRsetup["WeightTotal"] From 49951c2ad4d553e61cdab166ea912a8c2e74ec6c Mon Sep 17 00:00:00 2001 From: Maya Mutic <62064527+mmutic@users.noreply.github.com> Date: Tue, 4 Jun 2024 17:36:34 -0400 Subject: [PATCH 11/61] Update src/time_domain_reduction/full_time_series_reconstruction.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/time_domain_reduction/full_time_series_reconstruction.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/time_domain_reduction/full_time_series_reconstruction.jl b/src/time_domain_reduction/full_time_series_reconstruction.jl index 42f777df61..3cd0f37ec5 100644 --- a/src/time_domain_reduction/full_time_series_reconstruction.jl +++ b/src/time_domain_reduction/full_time_series_reconstruction.jl @@ -34,7 +34,6 @@ function full_time_series_reconstruction( # Define Timesteps per Representative Period and Weight Total TimestepsPerRepPeriod = myTDRsetup["TimestepsPerRepPeriod"] WeightTotal = myTDRsetup["WeightTotal"] - # Calculate the number of total periods the original time series was split into (will usually be 52) numPeriods = floor(Int,WeightTotal/TimestepsPerRepPeriod) From 35df2c0c790ed5c89303a9827c31d8ecae8b71b0 Mon Sep 17 00:00:00 2001 From: Maya Mutic <62064527+mmutic@users.noreply.github.com> Date: Tue, 4 Jun 2024 17:36:47 -0400 Subject: [PATCH 12/61] Update src/time_domain_reduction/full_time_series_reconstruction.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/time_domain_reduction/full_time_series_reconstruction.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/time_domain_reduction/full_time_series_reconstruction.jl b/src/time_domain_reduction/full_time_series_reconstruction.jl index 3cd0f37ec5..144035ace6 100644 --- a/src/time_domain_reduction/full_time_series_reconstruction.jl +++ b/src/time_domain_reduction/full_time_series_reconstruction.jl @@ -35,8 +35,8 @@ function full_time_series_reconstruction( TimestepsPerRepPeriod = myTDRsetup["TimestepsPerRepPeriod"] WeightTotal = myTDRsetup["WeightTotal"] # Calculate the number of total periods the original time series was split into (will usually be 52) - numPeriods = floor(Int,WeightTotal/TimestepsPerRepPeriod) - + numPeriods = floor(Int, WeightTotal / TimestepsPerRepPeriod) + # Get the names of the input DataFrame DFMatrix = Matrix(DF) From 8037928f1fbaeb54dca16e0daf17417d08056350 Mon Sep 17 00:00:00 2001 From: Maya Mutic <62064527+mmutic@users.noreply.github.com> Date: Tue, 4 Jun 2024 17:42:26 -0400 Subject: [PATCH 13/61] Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/time_domain_reduction/full_time_series_reconstruction.jl | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/time_domain_reduction/full_time_series_reconstruction.jl b/src/time_domain_reduction/full_time_series_reconstruction.jl index 144035ace6..026b26cb5b 100644 --- a/src/time_domain_reduction/full_time_series_reconstruction.jl +++ b/src/time_domain_reduction/full_time_series_reconstruction.jl @@ -39,10 +39,9 @@ function full_time_series_reconstruction( # Get the names of the input DataFrame DFMatrix = Matrix(DF) - # Initialize an array to add the reconstructed data to - recon = ["t$t" for t in 1:TimestepsPerRepPeriod*numPeriods] - + recon = ["t$t" for t in 1:(TimestepsPerRepPeriod * numPeriods)] + # Find the index of the row with the first time step t1 = findfirst(x -> x == "t1",DF[!,1]) From 27603f63446f4f08c3582805e2a76430ff8cdb64 Mon Sep 17 00:00:00 2001 From: Maya Mutic <62064527+mmutic@users.noreply.github.com> Date: Tue, 4 Jun 2024 17:43:37 -0400 Subject: [PATCH 14/61] Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../full_time_series_reconstruction.jl | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/time_domain_reduction/full_time_series_reconstruction.jl b/src/time_domain_reduction/full_time_series_reconstruction.jl index 026b26cb5b..13a9da046c 100644 --- a/src/time_domain_reduction/full_time_series_reconstruction.jl +++ b/src/time_domain_reduction/full_time_series_reconstruction.jl @@ -43,24 +43,23 @@ function full_time_series_reconstruction( recon = ["t$t" for t in 1:(TimestepsPerRepPeriod * numPeriods)] # Find the index of the row with the first time step - t1 = findfirst(x -> x == "t1",DF[!,1]) - + t1 = findfirst(x -> x == "t1", DF[!, 1]) # Reconstruction of all hours of the year from TDR - for j in range(2,ncol(DF)) - col = DF[t1:end,j] + for j in range(2, ncol(DF)) + col = DF[t1:end, j] #col_name = DFnames[j] #names1 = [names1 Symbol(col_name)] recon_col = [] - for i in range(1,numPeriods) - index = Period_map[i,"Rep_Period_Index"] - recon_temp = col[(TimestepsPerRepPeriod*index-(TimestepsPerRepPeriod-1)):(TimestepsPerRepPeriod*index)] # Describe how this works + for i in range(1, numPeriods) + index = Period_map[i, "Rep_Period_Index"] + recon_temp = col[(TimestepsPerRepPeriod * index - (TimestepsPerRepPeriod - 1)):(TimestepsPerRepPeriod * index)] # Describe how this works recon_col = [recon_col; recon_temp] end #reconDF[!,col_name] = recon_col recon = [recon recon_col] end - reconDF = DataFrame(recon, DFnames, makeunique=true) + reconDF = DataFrame(recon, DFnames, makeunique = true) #rename!(reconDF,names1) From 9406c399bfc09d310de400a42efde92d333790ab Mon Sep 17 00:00:00 2001 From: Maya Mutic <62064527+mmutic@users.noreply.github.com> Date: Tue, 4 Jun 2024 17:44:30 -0400 Subject: [PATCH 15/61] Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../full_time_series_reconstruction.jl | 7 ++----- .../transmission/write_transmission_flows.jl | 9 +++++---- .../transmission/write_transmission_losses.jl | 1 - src/write_outputs/ucommit/write_commit.jl | 10 +++++----- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/time_domain_reduction/full_time_series_reconstruction.jl b/src/time_domain_reduction/full_time_series_reconstruction.jl index 13a9da046c..f628ca2890 100644 --- a/src/time_domain_reduction/full_time_series_reconstruction.jl +++ b/src/time_domain_reduction/full_time_series_reconstruction.jl @@ -62,17 +62,14 @@ function full_time_series_reconstruction( reconDF = DataFrame(recon, DFnames, makeunique = true) #rename!(reconDF,names1) - # Insert rows that were above "t1" in the original DataFrame (e.g. "Zone" and "AnnualSum") if present for i in range(1,t1-1) insert!(reconDF,i,DFMatrix[i,1:end],promote=true) end - # Repeat the last rows of the year to fill in the gap (should be 24 hours for non-leap year) end_diff = WeightTotal - nrow(reconDF) + 1 - new_rows = reconDF[(nrow(reconDF)-end_diff):nrow(reconDF),1:end] - new_rows[!,1] = ["t$t" for t in (WeightTotal-end_diff):WeightTotal] + new_rows = reconDF[(nrow(reconDF) - end_diff):nrow(reconDF), 1:end] + new_rows[!, 1] = ["t$t" for t in (WeightTotal - end_diff):WeightTotal] reconDF = [reconDF; new_rows] - return reconDF end \ No newline at end of file diff --git a/src/write_outputs/transmission/write_transmission_flows.jl b/src/write_outputs/transmission/write_transmission_flows.jl index b143496b69..7decbb710a 100644 --- a/src/write_outputs/transmission/write_transmission_flows.jl +++ b/src/write_outputs/transmission/write_transmission_flows.jl @@ -25,11 +25,12 @@ function write_transmission_flows(path::AbstractString, CSV.write(filepath, dftranspose(dfFlow, false), writeheader = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - DFnames = ["Line","1","2"] + DFnames = ["Line", "1", "2"] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path,FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfFlow, false), DFnames) - CSV.write(joinpath(output_path,"flow.csv"), dfOut_full, header = false) + output_path = joinpath(path, FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction( + path, setup, dftranspose(dfFlow, false), DFnames) + CSV.write(joinpath(output_path, "flow.csv"), dfOut_full, header = false) println("Writing Full Time Series for Transmission Flows") end end diff --git a/src/write_outputs/transmission/write_transmission_losses.jl b/src/write_outputs/transmission/write_transmission_losses.jl index 8dc15f7b28..ca4ea93ca3 100644 --- a/src/write_outputs/transmission/write_transmission_losses.jl +++ b/src/write_outputs/transmission/write_transmission_losses.jl @@ -39,7 +39,6 @@ function write_transmission_losses(path::AbstractString, CSV.write(joinpath(output_path,"tlosses.csv"), dfOut_full, header = false) println("Writing Full Time Series for Time Losses") end - end return nothing end diff --git a/src/write_outputs/ucommit/write_commit.jl b/src/write_outputs/ucommit/write_commit.jl index 1df95e1b99..0f7d6cdb86 100644 --- a/src/write_outputs/ucommit/write_commit.jl +++ b/src/write_outputs/ucommit/write_commit.jl @@ -15,14 +15,14 @@ function write_commit(path::AbstractString, inputs::Dict, setup::Dict, EP::Model println("PATH = ", path) println("-------------------------------") - if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 DFMatrix = Matrix(dftranspose(dfCommit, true)) - DFnames = DFMatrix[1,:] + DFnames = DFMatrix[1, :] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path,FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfCommit, false), DFnames) - CSV.write(joinpath(output_path,"commit.csv"), dfOut_full, header = false) + output_path = joinpath(path, FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction( + path, setup, dftranspose(dfCommit, false), DFnames) + CSV.write(joinpath(output_path, "commit.csv"), dfOut_full, header = false) println("Writing Full Time Series for Commitment") end From 4cf1e85ecf126191122851d2022c9593075f5dcb Mon Sep 17 00:00:00 2001 From: Maya Mutic <62064527+mmutic@users.noreply.github.com> Date: Tue, 4 Jun 2024 17:48:50 -0400 Subject: [PATCH 16/61] Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../full_time_series_reconstruction.jl | 4 ++-- .../transmission/write_transmission_losses.jl | 7 ++++--- src/write_outputs/ucommit/write_commit.jl | 1 - src/write_outputs/ucommit/write_shutdown.jl | 2 +- src/write_outputs/ucommit/write_start.jl | 9 +++++---- src/write_outputs/write_charge.jl | 11 +++++------ src/write_outputs/write_co2.jl | 10 ++++++---- 7 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/time_domain_reduction/full_time_series_reconstruction.jl b/src/time_domain_reduction/full_time_series_reconstruction.jl index f628ca2890..9bd270b9ba 100644 --- a/src/time_domain_reduction/full_time_series_reconstruction.jl +++ b/src/time_domain_reduction/full_time_series_reconstruction.jl @@ -63,8 +63,8 @@ function full_time_series_reconstruction( #rename!(reconDF,names1) # Insert rows that were above "t1" in the original DataFrame (e.g. "Zone" and "AnnualSum") if present - for i in range(1,t1-1) - insert!(reconDF,i,DFMatrix[i,1:end],promote=true) + for i in range(1, t1 - 1) + insert!(reconDF, i, DFMatrix[i, 1:end], promote = true) end # Repeat the last rows of the year to fill in the gap (should be 24 hours for non-leap year) end_diff = WeightTotal - nrow(reconDF) + 1 diff --git a/src/write_outputs/transmission/write_transmission_losses.jl b/src/write_outputs/transmission/write_transmission_losses.jl index ca4ea93ca3..18d66a202f 100644 --- a/src/write_outputs/transmission/write_transmission_losses.jl +++ b/src/write_outputs/transmission/write_transmission_losses.jl @@ -34,9 +34,10 @@ function write_transmission_losses(path::AbstractString, if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 DFnames = ["Line", "1", "2", "Total"] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path,FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfTLosses, false), DFnames) - CSV.write(joinpath(output_path,"tlosses.csv"), dfOut_full, header = false) + output_path = joinpath(path, FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction( + path, setup, dftranspose(dfTLosses, false), DFnames) + CSV.write(joinpath(output_path, "tlosses.csv"), dfOut_full, header = false) println("Writing Full Time Series for Time Losses") end end diff --git a/src/write_outputs/ucommit/write_commit.jl b/src/write_outputs/ucommit/write_commit.jl index 0f7d6cdb86..c97994a7d0 100644 --- a/src/write_outputs/ucommit/write_commit.jl +++ b/src/write_outputs/ucommit/write_commit.jl @@ -25,5 +25,4 @@ function write_commit(path::AbstractString, inputs::Dict, setup::Dict, EP::Model CSV.write(joinpath(output_path, "commit.csv"), dfOut_full, header = false) println("Writing Full Time Series for Commitment") end - end diff --git a/src/write_outputs/ucommit/write_shutdown.jl b/src/write_outputs/ucommit/write_shutdown.jl index 62b2e6e34f..328fff1e12 100644 --- a/src/write_outputs/ucommit/write_shutdown.jl +++ b/src/write_outputs/ucommit/write_shutdown.jl @@ -16,7 +16,7 @@ function write_shutdown(path::AbstractString, inputs::Dict, setup::Dict, EP::Mod write_fulltimeseries(filepath, shut, dfShutdown) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - df_Shutdown = CSV.read(joinpath(path,"shutdown.csv"),DataFrame) + df_Shutdown = CSV.read(joinpath(path, "shutdown.csv"), DataFrame) FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path,FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction(path,setup, df_Shutdown,names(df_Shutdown)) diff --git a/src/write_outputs/ucommit/write_start.jl b/src/write_outputs/ucommit/write_start.jl index c1ff25f886..a9072b2551 100644 --- a/src/write_outputs/ucommit/write_start.jl +++ b/src/write_outputs/ucommit/write_start.jl @@ -15,11 +15,12 @@ function write_start(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) write_fulltimeseries(filepath, start, dfStart) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - df_Start = CSV.read(joinpath(path,"start.csv"),DataFrame) + df_Start = CSV.read(joinpath(path, "start.csv"), DataFrame) FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path,FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction(path,setup, df_Start,names(df_Start)) - CSV.write(joinpath(output_path,"start.csv"), dfOut_full) + output_path = joinpath(path, FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction( + path, setup, df_Start, names(df_Start)) + CSV.write(joinpath(output_path, "start.csv"), dfOut_full) println("Writing Full Time Series for Startup") end end diff --git a/src/write_outputs/write_charge.jl b/src/write_outputs/write_charge.jl index 39827c5ff9..7022293222 100644 --- a/src/write_outputs/write_charge.jl +++ b/src/write_outputs/write_charge.jl @@ -43,16 +43,15 @@ function write_charge(path::AbstractString, inputs::Dict, setup::Dict, EP::Model else # setup["WriteOutputs"] == "full" write_fulltimeseries(filepath, charge, dfCharge) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - df_Charge = CSV.read(joinpath(path,"charge.csv"),DataFrame) + df_Charge = CSV.read(joinpath(path, "charge.csv"), DataFrame) FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path,FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction(path,setup, df_Charge,names(df_Charge)) - CSV.write(joinpath(output_path,"charge.csv"), dfOut_full) + output_path = joinpath(path, FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction( + path, setup, df_Charge, names(df_Charge)) + CSV.write(joinpath(output_path, "charge.csv"), dfOut_full) println("Writing Full Time Series for Charge") end end - - return nothing end diff --git a/src/write_outputs/write_co2.jl b/src/write_outputs/write_co2.jl index 729562425e..8ea2afb81c 100644 --- a/src/write_outputs/write_co2.jl +++ b/src/write_outputs/write_co2.jl @@ -34,11 +34,13 @@ function write_co2_emissions_plant(path::AbstractString, write_fulltimeseries(filepath, emissions_plant, dfEmissions_plant) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 DFMatrix = Matrix(dftranspose(dfEmissions_plant, true)) - DFnames = DFMatrix[1,:] + DFnames = DFMatrix[1, :] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path,FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfEmissions_plant, false), DFnames) - CSV.write(joinpath(output_path,"emissions_plant.csv"), dfOut_full, header = false) + output_path = joinpath(path, FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction( + path, setup, dftranspose(dfEmissions_plant, false), DFnames) + CSV.write( + joinpath(output_path, "emissions_plant.csv"), dfOut_full, header = false) println("Writing Full Time Series for Emissions Plant") end end From 17e216271ed687f72a7bfcf905f1f3420956450c Mon Sep 17 00:00:00 2001 From: Maya Mutic <62064527+mmutic@users.noreply.github.com> Date: Tue, 4 Jun 2024 17:50:56 -0400 Subject: [PATCH 17/61] Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/write_outputs/write_curtailment.jl | 9 +++++---- src/write_outputs/write_emissions.jl | 9 +++++---- src/write_outputs/write_fuel_consumption.jl | 9 +++++---- src/write_outputs/write_nse.jl | 14 ++++++++------ src/write_outputs/write_outputs.jl | 2 +- src/write_outputs/write_power.jl | 9 +++++---- src/write_outputs/write_power_balance.jl | 6 +++--- 7 files changed, 32 insertions(+), 26 deletions(-) diff --git a/src/write_outputs/write_curtailment.jl b/src/write_outputs/write_curtailment.jl index 777740c0bc..32e8fa1cde 100644 --- a/src/write_outputs/write_curtailment.jl +++ b/src/write_outputs/write_curtailment.jl @@ -59,11 +59,12 @@ function write_curtailment(path::AbstractString, inputs::Dict, setup::Dict, EP:: else # setup["WriteOutputs"] == "full" write_fulltimeseries(filename, curtailment, dfCurtailment) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - df_Curtail = CSV.read(joinpath(path,"curtail.csv"),DataFrame) + df_Curtail = CSV.read(joinpath(path, "curtail.csv"), DataFrame) FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path,FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction(path,setup, df_Curtail,names(df_Curtail)) - CSV.write(joinpath(output_path,"curtail.csv"), dfOut_full) + output_path = joinpath(path, FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction( + path, setup, df_Curtail, names(df_Curtail)) + CSV.write(joinpath(output_path, "curtail.csv"), dfOut_full) println("Writing Full Time Series for Curtailment") end end diff --git a/src/write_outputs/write_emissions.jl b/src/write_outputs/write_emissions.jl index b53641bc6b..ed1f10eb4a 100644 --- a/src/write_outputs/write_emissions.jl +++ b/src/write_outputs/write_emissions.jl @@ -127,11 +127,12 @@ function write_emissions(path::AbstractString, inputs::Dict, setup::Dict, EP::Mo if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 DFMatrix = Matrix(dftranspose(dfEmissions, true)) - DFnames = DFMatrix[1,:] + DFnames = DFMatrix[1, :] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path,FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfEmissions, false), DFnames) - CSV.write(joinpath(output_path,"emissions.csv"), dfOut_full) + output_path = joinpath(path, FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction( + path, setup, dftranspose(dfEmissions, false), DFnames) + CSV.write(joinpath(output_path, "emissions.csv"), dfOut_full) println("Writing Full Time Series for Emissions") end end diff --git a/src/write_outputs/write_fuel_consumption.jl b/src/write_outputs/write_fuel_consumption.jl index 4ff094289d..05373bc056 100644 --- a/src/write_outputs/write_fuel_consumption.jl +++ b/src/write_outputs/write_fuel_consumption.jl @@ -88,11 +88,12 @@ function write_fuel_consumption_ts(path::AbstractString, if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 DFMatrix = Matrix(dftranspose(dfPlantFuel_TS, true)) - DFnames = DFMatrix[1,:] + DFnames = DFMatrix[1, :] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path,FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfPlantFuel_TS, false), DFnames) - CSV.write(joinpath(output_path,"commit.csv"), dfOut_full, header = false) + output_path = joinpath(path, FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction( + path, setup, dftranspose(dfPlantFuel_TS, false), DFnames) + CSV.write(joinpath(output_path, "commit.csv"), dfOut_full, header = false) println("Writing Full Time Series for Fuel Consumption") end end diff --git a/src/write_outputs/write_nse.jl b/src/write_outputs/write_nse.jl index cf34845888..67a95b5714 100644 --- a/src/write_outputs/write_nse.jl +++ b/src/write_outputs/write_nse.jl @@ -39,12 +39,14 @@ function write_nse(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) CSV.write(joinpath(path, "nse.csv"), dftranspose(dfNse, false), writeheader = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - DFnames = ["Segment","1","2","3","4","1","2","3","4","1","2","3","4","Total"] - FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path,FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfNse, false), DFnames) - CSV.write(joinpath(output_path,"nse.csv"), dfOut_full, header = false) - println("Writing Full Time Series for NSE") + DFnames = ["Segment", "1", "2", "3", "4", "1", "2", + "3", "4", "1", "2", "3", "4", "Total"] + FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] + output_path = joinpath(path, FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction( + path, setup, dftranspose(dfNse, false), DFnames) + CSV.write(joinpath(output_path, "nse.csv"), dfOut_full, header = false) + println("Writing Full Time Series for NSE") end end return nothing diff --git a/src/write_outputs/write_outputs.jl b/src/write_outputs/write_outputs.jl index f9d8c881b6..6df975bb2c 100644 --- a/src/write_outputs/write_outputs.jl +++ b/src/write_outputs/write_outputs.jl @@ -24,7 +24,7 @@ function write_outputs(EP::Model, path::AbstractString, setup::Dict, inputs::Dic end if setup["OutputFullTimeSeries"] == 1 - mkpath(joinpath(path,setup["OutputFullTimeSeriesFolder"])) + mkpath(joinpath(path, setup["OutputFullTimeSeriesFolder"])) end # https://jump.dev/MathOptInterface.jl/v0.9.10/apireference/#MathOptInterface.TerminationStatusCode diff --git a/src/write_outputs/write_power.jl b/src/write_outputs/write_power.jl index a729136eec..ff0273204a 100644 --- a/src/write_outputs/write_power.jl +++ b/src/write_outputs/write_power.jl @@ -26,11 +26,12 @@ function write_power(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) else # setup["WriteOutputs"] == "full" write_fulltimeseries(filepath, power, dfPower) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - df_Power = CSV.read(joinpath(path,"power.csv"),DataFrame) + df_Power = CSV.read(joinpath(path, "power.csv"), DataFrame) FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path,FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction(path,setup, df_Power,names(df_Power)) - CSV.write(joinpath(output_path,"power.csv"), dfOut_full) + output_path = joinpath(path, FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction( + path, setup, df_Power, names(df_Power)) + CSV.write(joinpath(output_path, "power.csv"), dfOut_full) println("Writing Full Time Series for Power") end end diff --git a/src/write_outputs/write_power_balance.jl b/src/write_outputs/write_power_balance.jl index c574ae67aa..bbcf5ee2c2 100644 --- a/src/write_outputs/write_power_balance.jl +++ b/src/write_outputs/write_power_balance.jl @@ -98,10 +98,10 @@ function write_power_balance(path::AbstractString, inputs::Dict, setup::Dict, EP writeheader = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - DFnames = dfPowerBalance[:,1] - insert!(DFnames,1,"BalanceComponent") + DFnames = dfPowerBalance[:, 1] + insert!(DFnames, 1, "BalanceComponent") #DFMatrix = Matrix(dftranspose(dfPowerBalance, true)) - # DFnames = DFMatrix[1,:] + # DFnames = DFMatrix[1,:] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path,FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfPowerBalance, false),DFnames) From 9f90b229fa65733e9079bd89a8ab2f924dcca766 Mon Sep 17 00:00:00 2001 From: Maya Mutic <62064527+mmutic@users.noreply.github.com> Date: Tue, 4 Jun 2024 17:52:10 -0400 Subject: [PATCH 18/61] Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/write_outputs/write_power_balance.jl | 8 +++++--- src/write_outputs/write_price.jl | 7 ++++--- src/write_outputs/write_reliability.jl | 7 ++++--- src/write_outputs/write_storage.jl | 9 +++++---- src/write_outputs/write_storagedual.jl | 9 +++++---- 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/write_outputs/write_power_balance.jl b/src/write_outputs/write_power_balance.jl index bbcf5ee2c2..add22c6310 100644 --- a/src/write_outputs/write_power_balance.jl +++ b/src/write_outputs/write_power_balance.jl @@ -103,9 +103,11 @@ function write_power_balance(path::AbstractString, inputs::Dict, setup::Dict, EP #DFMatrix = Matrix(dftranspose(dfPowerBalance, true)) # DFnames = DFMatrix[1,:] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path,FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfPowerBalance, false),DFnames) - CSV.write(joinpath(output_path,"power_balance.csv"), dfOut_full, header = false) + output_path = joinpath(path, FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction( + path, setup, dftranspose(dfPowerBalance, false), DFnames) + CSV.write( + joinpath(output_path, "power_balance.csv"), dfOut_full, header = false) println("Writing Full Time Series for Power Balance") end end diff --git a/src/write_outputs/write_price.jl b/src/write_outputs/write_price.jl index 19547f9209..7d5365e900 100644 --- a/src/write_outputs/write_price.jl +++ b/src/write_outputs/write_price.jl @@ -25,9 +25,10 @@ function write_price(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 DFnames = ["Zone", "1", "2", "3"] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path,FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfPrice, false), DFnames) - CSV.write(joinpath(output_path,"prices.csv"), dfOut_full, header = false) + output_path = joinpath(path, FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction( + path, setup, dftranspose(dfPrice, false), DFnames) + CSV.write(joinpath(output_path, "prices.csv"), dfOut_full, header = false) println("Writing Full Time Series for Price") end return nothing diff --git a/src/write_outputs/write_reliability.jl b/src/write_outputs/write_reliability.jl index 0c9ce76694..c19ad9b0cc 100644 --- a/src/write_outputs/write_reliability.jl +++ b/src/write_outputs/write_reliability.jl @@ -24,9 +24,10 @@ function write_reliability(path::AbstractString, inputs::Dict, setup::Dict, EP:: if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 DFnames = ["Zone", "1", "2", "3"] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path,FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfReliability, false), DFnames) - CSV.write(joinpath(output_path,"reliability.csv"), dfOut_full, header = false) + output_path = joinpath(path, FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction( + path, setup, dftranspose(dfReliability, false), DFnames) + CSV.write(joinpath(output_path, "reliability.csv"), dfOut_full, header = false) println("Writing Full Time Series for Reliability") end end diff --git a/src/write_outputs/write_storage.jl b/src/write_outputs/write_storage.jl index 9d78dd8bba..720be09821 100644 --- a/src/write_outputs/write_storage.jl +++ b/src/write_outputs/write_storage.jl @@ -42,11 +42,12 @@ function write_storage(path::AbstractString, inputs::Dict, setup::Dict, EP::Mode if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 DFMatrix = Matrix(dftranspose(dfStorage, true)) - DFnames = DFMatrix[1,:] + DFnames = DFMatrix[1, :] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path,FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfStorage, false), DFnames) - CSV.write(joinpath(output_path,"storage.csv"), dfOut_full, header = false) + output_path = joinpath(path, FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction( + path, setup, dftranspose(dfStorage, false), DFnames) + CSV.write(joinpath(output_path, "storage.csv"), dfOut_full, header = false) println("Writing Full Time Series for Storage") end end diff --git a/src/write_outputs/write_storagedual.jl b/src/write_outputs/write_storagedual.jl index 9f374b80e8..c091ec32e9 100644 --- a/src/write_outputs/write_storagedual.jl +++ b/src/write_outputs/write_storagedual.jl @@ -82,11 +82,12 @@ function write_storagedual(path::AbstractString, inputs::Dict, setup::Dict, EP:: if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 DFMatrix = Matrix(dftranspose(dfStorageDual, true)) - DFnames = DFMatrix[1,:] + DFnames = DFMatrix[1, :] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path,FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfStorageDual, false), DFnames) - CSV.write(joinpath(output_path,"storagebal_duals.csv"), dfOut_full, header = false) + output_path = joinpath(path, FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction( + path, setup, dftranspose(dfStorageDual, false), DFnames) + CSV.write(joinpath(output_path, "storagebal_duals.csv"), dfOut_full, header = false) println("Writing Full Time Series for Storage Duals") end end From a4e5cdc3d3e856c65722fbd2e71946144640bf50 Mon Sep 17 00:00:00 2001 From: Maya Mutic Date: Fri, 21 Jun 2024 18:19:27 +0200 Subject: [PATCH 19/61] Fixed emissions_plant output --- example_systems/1_three_zones/settings/genx_settings.yml | 1 + .../full_time_series_reconstruction.jl | 7 ++----- src/write_outputs/ucommit/write_commit.jl | 3 --- src/write_outputs/write_co2.jl | 8 +++----- src/write_outputs/write_outputs.jl | 1 - 5 files changed, 6 insertions(+), 14 deletions(-) diff --git a/example_systems/1_three_zones/settings/genx_settings.yml b/example_systems/1_three_zones/settings/genx_settings.yml index c85af312ac..d48032b1d1 100644 --- a/example_systems/1_three_zones/settings/genx_settings.yml +++ b/example_systems/1_three_zones/settings/genx_settings.yml @@ -10,3 +10,4 @@ ParameterScale: 1 # Turn on parameter scaling wherein demand, capacity and power WriteShadowPrices: 1 # Write shadow prices of LP or relaxed MILP; 0 = not active; 1 = active UCommit: 2 # Unit committment of thermal power plants; 0 = not active; 1 = active using integer clestering; 2 = active using linearized clustering TimeDomainReduction: 1 # Time domain reduce (i.e. cluster) inputs based on Demand_data.csv, Generators_variability.csv, and Fuels_data.csv; 0 = not active (use input data as provided); 0 = active (cluster input data, or use data that has already been clustered) +OutputFullTimeSeries: 1 \ No newline at end of file diff --git a/src/time_domain_reduction/full_time_series_reconstruction.jl b/src/time_domain_reduction/full_time_series_reconstruction.jl index 9bd270b9ba..ffa6aefb82 100644 --- a/src/time_domain_reduction/full_time_series_reconstruction.jl +++ b/src/time_domain_reduction/full_time_series_reconstruction.jl @@ -37,7 +37,7 @@ function full_time_series_reconstruction( # Calculate the number of total periods the original time series was split into (will usually be 52) numPeriods = floor(Int, WeightTotal / TimestepsPerRepPeriod) - # Get the names of the input DataFrame + # Get a matrix of the input DataFrame DFMatrix = Matrix(DF) # Initialize an array to add the reconstructed data to recon = ["t$t" for t in 1:(TimestepsPerRepPeriod * numPeriods)] @@ -48,24 +48,21 @@ function full_time_series_reconstruction( # Reconstruction of all hours of the year from TDR for j in range(2, ncol(DF)) col = DF[t1:end, j] - #col_name = DFnames[j] - #names1 = [names1 Symbol(col_name)] recon_col = [] for i in range(1, numPeriods) index = Period_map[i, "Rep_Period_Index"] recon_temp = col[(TimestepsPerRepPeriod * index - (TimestepsPerRepPeriod - 1)):(TimestepsPerRepPeriod * index)] # Describe how this works recon_col = [recon_col; recon_temp] end - #reconDF[!,col_name] = recon_col recon = [recon recon_col] end reconDF = DataFrame(recon, DFnames, makeunique = true) - #rename!(reconDF,names1) # Insert rows that were above "t1" in the original DataFrame (e.g. "Zone" and "AnnualSum") if present for i in range(1, t1 - 1) insert!(reconDF, i, DFMatrix[i, 1:end], promote = true) end + # Repeat the last rows of the year to fill in the gap (should be 24 hours for non-leap year) end_diff = WeightTotal - nrow(reconDF) + 1 new_rows = reconDF[(nrow(reconDF) - end_diff):nrow(reconDF), 1:end] diff --git a/src/write_outputs/ucommit/write_commit.jl b/src/write_outputs/ucommit/write_commit.jl index c97994a7d0..ce37cd98bc 100644 --- a/src/write_outputs/ucommit/write_commit.jl +++ b/src/write_outputs/ucommit/write_commit.jl @@ -11,9 +11,6 @@ function write_commit(path::AbstractString, inputs::Dict, setup::Dict, EP::Model auxNew_Names = [Symbol("Resource"); Symbol("Zone"); [Symbol("t$t") for t in 1:T]] rename!(dfCommit, auxNew_Names) CSV.write(joinpath(path, "commit.csv"), dftranspose(dfCommit, false), header = false) - println("-------------------------------") - println("PATH = ", path) - println("-------------------------------") if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 DFMatrix = Matrix(dftranspose(dfCommit, true)) diff --git a/src/write_outputs/write_co2.jl b/src/write_outputs/write_co2.jl index 8ea2afb81c..b4d16099b9 100644 --- a/src/write_outputs/write_co2.jl +++ b/src/write_outputs/write_co2.jl @@ -33,14 +33,12 @@ function write_co2_emissions_plant(path::AbstractString, else # setup["WriteOutputs"] == "full" write_fulltimeseries(filepath, emissions_plant, dfEmissions_plant) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - DFMatrix = Matrix(dftranspose(dfEmissions_plant, true)) - DFnames = DFMatrix[1, :] + df_Emissions_plant = CSV.read(joinpath(path, "emissions_plant.csv"), DataFrame) FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(dfEmissions_plant, false), DFnames) - CSV.write( - joinpath(output_path, "emissions_plant.csv"), dfOut_full, header = false) + path, setup, df_Emissions_plant, names(df_Emissions_plant)) + CSV.write(joinpath(output_path, "emissions_plant.csv"), dfOut_full) println("Writing Full Time Series for Emissions Plant") end end diff --git a/src/write_outputs/write_outputs.jl b/src/write_outputs/write_outputs.jl index 6df975bb2c..fb4bcbff1f 100644 --- a/src/write_outputs/write_outputs.jl +++ b/src/write_outputs/write_outputs.jl @@ -76,7 +76,6 @@ function write_outputs(EP::Model, path::AbstractString, setup::Dict, inputs::Dic elapsed_time_power = @elapsed dfPower = write_power(path, inputs, setup, EP) println("Time elapsed for writing power is") println(elapsed_time_power) - println("Here") end if output_settings_d["WriteCharge"] From d5ca33b9fdf0907bffa36ea06248ebb30e8a91b3 Mon Sep 17 00:00:00 2001 From: Maya Mutic Date: Mon, 24 Jun 2024 13:42:09 +0200 Subject: [PATCH 20/61] Change pre-processing for FTR in some files --- src/write_outputs/ucommit/write_commit.jl | 1 + src/write_outputs/ucommit/write_shutdown.jl | 18 +++++++++++++++--- src/write_outputs/ucommit/write_start.jl | 20 ++++++++++++++++---- src/write_outputs/write_charge.jl | 21 ++++++++++++++++++--- src/write_outputs/write_co2.jl | 18 +++++++++++++++--- src/write_outputs/write_curtailment.jl | 18 +++++++++++++++--- src/write_outputs/write_emissions.jl | 9 ++++----- src/write_outputs/write_power.jl | 18 +++++++++++++++--- src/write_outputs/write_power_balance.jl | 2 -- 9 files changed, 99 insertions(+), 26 deletions(-) diff --git a/src/write_outputs/ucommit/write_commit.jl b/src/write_outputs/ucommit/write_commit.jl index ce37cd98bc..75b6ec7ac3 100644 --- a/src/write_outputs/ucommit/write_commit.jl +++ b/src/write_outputs/ucommit/write_commit.jl @@ -12,6 +12,7 @@ function write_commit(path::AbstractString, inputs::Dict, setup::Dict, EP::Model rename!(dfCommit, auxNew_Names) CSV.write(joinpath(path, "commit.csv"), dftranspose(dfCommit, false), header = false) + if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 DFMatrix = Matrix(dftranspose(dfCommit, true)) DFnames = DFMatrix[1, :] diff --git a/src/write_outputs/ucommit/write_shutdown.jl b/src/write_outputs/ucommit/write_shutdown.jl index 328fff1e12..3dc54929b9 100644 --- a/src/write_outputs/ucommit/write_shutdown.jl +++ b/src/write_outputs/ucommit/write_shutdown.jl @@ -16,11 +16,23 @@ function write_shutdown(path::AbstractString, inputs::Dict, setup::Dict, EP::Mod write_fulltimeseries(filepath, shut, dfShutdown) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - df_Shutdown = CSV.read(joinpath(path, "shutdown.csv"), DataFrame) + T = size(shut, 2) + dfShutdown = hcat(dfShutdown, DataFrame(shut, :auto)) + auxNew_Names = [Symbol("Resource"); + Symbol("Zone"); + Symbol("AnnualSum"); + [Symbol("t$t") for t in 1:T]] + rename!(dfShutdown, auxNew_Names) + total = DataFrame(["Total" 0 sum(dfShutdown[!, :AnnualSum]) fill(0.0, (1, T))], auxNew_Names) + total[!, 4:(T + 3)] .= sum(shut, dims = 1) + df_Shutdown = vcat(dfShutdown, total) + DFMatrix = Matrix(dftranspose(df_Shutdown, true)) + DFnames = DFMatrix[1,:] + FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path,FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction(path,setup, df_Shutdown,names(df_Shutdown)) - CSV.write(joinpath(output_path,"shutdown.csv"), dfOut_full) + dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(df_Shutdown, false), DFnames) + CSV.write(joinpath(output_path,"shutdown.csv"), dfOut_full, writeheader = false) println("Writing Full Time Series for Shutdown") end end diff --git a/src/write_outputs/ucommit/write_start.jl b/src/write_outputs/ucommit/write_start.jl index a9072b2551..0e1c0df920 100644 --- a/src/write_outputs/ucommit/write_start.jl +++ b/src/write_outputs/ucommit/write_start.jl @@ -13,14 +13,26 @@ function write_start(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) write_annual(filepath, dfStart) else # setup["WriteOutputs"] == "full" write_fulltimeseries(filepath, start, dfStart) - + # full path, dataout, dfout if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - df_Start = CSV.read(joinpath(path, "start.csv"), DataFrame) + T = size(start, 2) + dfStart = hcat(dfStart, DataFrame(start, :auto)) + auxNew_Names = [Symbol("Resource"); + Symbol("Zone"); + Symbol("AnnualSum"); + [Symbol("t$t") for t in 1:T]] + rename!(dfStart, auxNew_Names) + total = DataFrame(["Total" 0 sum(dfStart[!, :AnnualSum]) fill(0.0, (1, T))], auxNew_Names) + total[!, 4:(T + 3)] .= sum(start, dims = 1) + df_Start = vcat(dfStart, total) + DFMatrix = Matrix(dftranspose(df_Start, true)) + DFnames = DFMatrix[1,:] + FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( - path, setup, df_Start, names(df_Start)) - CSV.write(joinpath(output_path, "start.csv"), dfOut_full) + path, setup, dftranspose(df_Start, false), DFnames) + CSV.write(joinpath(output_path, "start.csv"), dfOut_full, writeheader = false) println("Writing Full Time Series for Startup") end end diff --git a/src/write_outputs/write_charge.jl b/src/write_outputs/write_charge.jl index 7022293222..cdaef9d015 100644 --- a/src/write_outputs/write_charge.jl +++ b/src/write_outputs/write_charge.jl @@ -43,12 +43,27 @@ function write_charge(path::AbstractString, inputs::Dict, setup::Dict, EP::Model else # setup["WriteOutputs"] == "full" write_fulltimeseries(filepath, charge, dfCharge) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - df_Charge = CSV.read(joinpath(path, "charge.csv"), DataFrame) + + # full path, dataout, dfout + + T = size(charge, 2) + dfCharge = hcat(dfCharge, DataFrame(charge, :auto)) + auxNew_Names = [Symbol("Resource"); + Symbol("Zone"); + Symbol("AnnualSum"); + [Symbol("t$t") for t in 1:T]] + rename!(dfCharge, auxNew_Names) + total = DataFrame(["Total" 0 sum(dfCharge[!, :AnnualSum]) fill(0.0, (1, T))], auxNew_Names) + total[!, 4:(T + 3)] .= sum(charge, dims = 1) + df_Charge = vcat(dfCharge, total) + DFMatrix = Matrix(dftranspose(df_Charge, true)) + DFnames = DFMatrix[1,:] + FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( - path, setup, df_Charge, names(df_Charge)) - CSV.write(joinpath(output_path, "charge.csv"), dfOut_full) + path, setup, dftranspose(df_Charge, false), DFnames) + CSV.write(joinpath(output_path, "charge.csv"), dfOut_full, writeheader = false) println("Writing Full Time Series for Charge") end end diff --git a/src/write_outputs/write_co2.jl b/src/write_outputs/write_co2.jl index b4d16099b9..86112c87f2 100644 --- a/src/write_outputs/write_co2.jl +++ b/src/write_outputs/write_co2.jl @@ -33,12 +33,24 @@ function write_co2_emissions_plant(path::AbstractString, else # setup["WriteOutputs"] == "full" write_fulltimeseries(filepath, emissions_plant, dfEmissions_plant) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - df_Emissions_plant = CSV.read(joinpath(path, "emissions_plant.csv"), DataFrame) + T = size(emissions_plant, 2) + dfEmissions_plant = hcat(dfEmissions_plant, DataFrame(emissions_plant, :auto)) + auxNew_Names = [Symbol("Resource"); + Symbol("Zone"); + Symbol("AnnualSum"); + [Symbol("t$t") for t in 1:T]] + rename!(dfEmissions_plant, auxNew_Names) + total = DataFrame(["Total" 0 sum(dfEmissions_plant[!, :AnnualSum]) fill(0.0, (1, T))], auxNew_Names) + total[!, 4:(T + 3)] .= sum(emissions_plant, dims = 1) + df_Emissions_plant = vcat(dfEmissions_plant, total) + DFMatrix = Matrix(dftranspose(df_Emissions_plant, true)) + DFnames = DFMatrix[1,:] + FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( - path, setup, df_Emissions_plant, names(df_Emissions_plant)) - CSV.write(joinpath(output_path, "emissions_plant.csv"), dfOut_full) + path, setup, dftranspose(df_Emissions_plant, false), DFnames) + CSV.write(joinpath(output_path, "emissions_plant.csv"), dfOut_full, writeheader = false) println("Writing Full Time Series for Emissions Plant") end end diff --git a/src/write_outputs/write_curtailment.jl b/src/write_outputs/write_curtailment.jl index 32e8fa1cde..b0b191fca4 100644 --- a/src/write_outputs/write_curtailment.jl +++ b/src/write_outputs/write_curtailment.jl @@ -59,12 +59,24 @@ function write_curtailment(path::AbstractString, inputs::Dict, setup::Dict, EP:: else # setup["WriteOutputs"] == "full" write_fulltimeseries(filename, curtailment, dfCurtailment) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - df_Curtail = CSV.read(joinpath(path, "curtail.csv"), DataFrame) + T = size(curtailment, 2) + dfCurtailment = hcat(dfCurtailment, DataFrame(curtailment, :auto)) + auxNew_Names = [Symbol("Resource"); + Symbol("Zone"); + Symbol("AnnualSum"); + [Symbol("t$t") for t in 1:T]] + rename!(dfCurtailment, auxNew_Names) + total = DataFrame(["Total" 0 sum(dfCurtailment[!, :AnnualSum]) fill(0.0, (1, T))], auxNew_Names) + total[!, 4:(T + 3)] .= sum(curtailment, dims = 1) + df_Curtailment = vcat(dfCurtailment, total) + DFMatrix = Matrix(dftranspose(df_Curtailment, true)) + DFnames = DFMatrix[1,:] + FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( - path, setup, df_Curtail, names(df_Curtail)) - CSV.write(joinpath(output_path, "curtail.csv"), dfOut_full) + path, setup, dftranspose(df_Curtailment, false), DFnames) + CSV.write(joinpath(output_path, "curtail.csv"), dfOut_full, writeheader = false) println("Writing Full Time Series for Curtailment") end end diff --git a/src/write_outputs/write_emissions.jl b/src/write_outputs/write_emissions.jl index ed1f10eb4a..b53641bc6b 100644 --- a/src/write_outputs/write_emissions.jl +++ b/src/write_outputs/write_emissions.jl @@ -127,12 +127,11 @@ function write_emissions(path::AbstractString, inputs::Dict, setup::Dict, EP::Mo if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 DFMatrix = Matrix(dftranspose(dfEmissions, true)) - DFnames = DFMatrix[1, :] + DFnames = DFMatrix[1,:] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path, FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(dfEmissions, false), DFnames) - CSV.write(joinpath(output_path, "emissions.csv"), dfOut_full) + output_path = joinpath(path,FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfEmissions, false), DFnames) + CSV.write(joinpath(output_path,"emissions.csv"), dfOut_full) println("Writing Full Time Series for Emissions") end end diff --git a/src/write_outputs/write_power.jl b/src/write_outputs/write_power.jl index ff0273204a..8264d41d22 100644 --- a/src/write_outputs/write_power.jl +++ b/src/write_outputs/write_power.jl @@ -26,12 +26,24 @@ function write_power(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) else # setup["WriteOutputs"] == "full" write_fulltimeseries(filepath, power, dfPower) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - df_Power = CSV.read(joinpath(path, "power.csv"), DataFrame) + T = size(power, 2) + dfPower = hcat(dfPower, DataFrame(power, :auto)) + auxNew_Names = [Symbol("Resource"); + Symbol("Zone"); + Symbol("AnnualSum"); + [Symbol("t$t") for t in 1:T]] + rename!(dfPower, auxNew_Names) + total = DataFrame(["Total" 0 sum(dfPower[!, :AnnualSum]) fill(0.0, (1, T))], auxNew_Names) + total[!, 4:(T + 3)] .= sum(power, dims = 1) + df_Power = vcat(dfPower, total) + DFMatrix = Matrix(dftranspose(df_Power, true)) + DFnames = DFMatrix[1,:] + FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( - path, setup, df_Power, names(df_Power)) - CSV.write(joinpath(output_path, "power.csv"), dfOut_full) + path, setup, dftranspose(df_Power, false), DFnames) + CSV.write(joinpath(output_path, "power.csv"), dfOut_full, writeheader = false) println("Writing Full Time Series for Power") end end diff --git a/src/write_outputs/write_power_balance.jl b/src/write_outputs/write_power_balance.jl index add22c6310..79731ef495 100644 --- a/src/write_outputs/write_power_balance.jl +++ b/src/write_outputs/write_power_balance.jl @@ -100,8 +100,6 @@ function write_power_balance(path::AbstractString, inputs::Dict, setup::Dict, EP if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 DFnames = dfPowerBalance[:, 1] insert!(DFnames, 1, "BalanceComponent") - #DFMatrix = Matrix(dftranspose(dfPowerBalance, true)) - # DFnames = DFMatrix[1,:] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( From f7ce2e98429b22750a8853e68905b3b431906fb3 Mon Sep 17 00:00:00 2001 From: Maya Mutic Date: Mon, 24 Jun 2024 22:04:48 +0200 Subject: [PATCH 21/61] Changed write_fts to return dfOut, fixed recon files --- .../1_three_zones/settings/genx_settings.yml | 3 +-- src/write_outputs/ucommit/write_shutdown.jl | 14 +------------- src/write_outputs/ucommit/write_start.jl | 14 +------------- src/write_outputs/write_charge.jl | 18 ++---------------- src/write_outputs/write_co2.jl | 13 +------------ src/write_outputs/write_curtailment.jl | 13 +------------ src/write_outputs/write_outputs.jl | 2 +- src/write_outputs/write_power.jl | 13 +------------ 8 files changed, 9 insertions(+), 81 deletions(-) diff --git a/example_systems/1_three_zones/settings/genx_settings.yml b/example_systems/1_three_zones/settings/genx_settings.yml index d48032b1d1..96854d0222 100644 --- a/example_systems/1_three_zones/settings/genx_settings.yml +++ b/example_systems/1_three_zones/settings/genx_settings.yml @@ -9,5 +9,4 @@ MaxCapReq: 0 # Activate maximum technology carveout constraints; 0 = not active ParameterScale: 1 # Turn on parameter scaling wherein demand, capacity and power variables are defined in GW rather than MW. 0 = not active; 1 = active systemwide WriteShadowPrices: 1 # Write shadow prices of LP or relaxed MILP; 0 = not active; 1 = active UCommit: 2 # Unit committment of thermal power plants; 0 = not active; 1 = active using integer clestering; 2 = active using linearized clustering -TimeDomainReduction: 1 # Time domain reduce (i.e. cluster) inputs based on Demand_data.csv, Generators_variability.csv, and Fuels_data.csv; 0 = not active (use input data as provided); 0 = active (cluster input data, or use data that has already been clustered) -OutputFullTimeSeries: 1 \ No newline at end of file +TimeDomainReduction: 1 # Time domain reduce (i.e. cluster) inputs based on Demand_data.csv, Generators_variability.csv, and Fuels_data.csv; 0 = not active (use input data as provided); 0 = active (cluster input data, or use data that has already been clustered) \ No newline at end of file diff --git a/src/write_outputs/ucommit/write_shutdown.jl b/src/write_outputs/ucommit/write_shutdown.jl index 3dc54929b9..b232a0ebd6 100644 --- a/src/write_outputs/ucommit/write_shutdown.jl +++ b/src/write_outputs/ucommit/write_shutdown.jl @@ -13,22 +13,10 @@ function write_shutdown(path::AbstractString, inputs::Dict, setup::Dict, EP::Mod if setup["WriteOutputs"] == "annual" write_annual(filepath, dfShutdown) else # setup["WriteOutputs"] == "full" - write_fulltimeseries(filepath, shut, dfShutdown) - + df_Shutdown = write_fulltimeseries(filepath, shut, dfShutdown) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - T = size(shut, 2) - dfShutdown = hcat(dfShutdown, DataFrame(shut, :auto)) - auxNew_Names = [Symbol("Resource"); - Symbol("Zone"); - Symbol("AnnualSum"); - [Symbol("t$t") for t in 1:T]] - rename!(dfShutdown, auxNew_Names) - total = DataFrame(["Total" 0 sum(dfShutdown[!, :AnnualSum]) fill(0.0, (1, T))], auxNew_Names) - total[!, 4:(T + 3)] .= sum(shut, dims = 1) - df_Shutdown = vcat(dfShutdown, total) DFMatrix = Matrix(dftranspose(df_Shutdown, true)) DFnames = DFMatrix[1,:] - FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path,FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(df_Shutdown, false), DFnames) diff --git a/src/write_outputs/ucommit/write_start.jl b/src/write_outputs/ucommit/write_start.jl index 0e1c0df920..9a730c5ecb 100644 --- a/src/write_outputs/ucommit/write_start.jl +++ b/src/write_outputs/ucommit/write_start.jl @@ -12,22 +12,10 @@ function write_start(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) if setup["WriteOutputs"] == "annual" write_annual(filepath, dfStart) else # setup["WriteOutputs"] == "full" - write_fulltimeseries(filepath, start, dfStart) - # full path, dataout, dfout + df_Start = write_fulltimeseries(filepath, start, dfStart) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - T = size(start, 2) - dfStart = hcat(dfStart, DataFrame(start, :auto)) - auxNew_Names = [Symbol("Resource"); - Symbol("Zone"); - Symbol("AnnualSum"); - [Symbol("t$t") for t in 1:T]] - rename!(dfStart, auxNew_Names) - total = DataFrame(["Total" 0 sum(dfStart[!, :AnnualSum]) fill(0.0, (1, T))], auxNew_Names) - total[!, 4:(T + 3)] .= sum(start, dims = 1) - df_Start = vcat(dfStart, total) DFMatrix = Matrix(dftranspose(df_Start, true)) DFnames = DFMatrix[1,:] - FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( diff --git a/src/write_outputs/write_charge.jl b/src/write_outputs/write_charge.jl index cdaef9d015..4971f89f88 100644 --- a/src/write_outputs/write_charge.jl +++ b/src/write_outputs/write_charge.jl @@ -41,24 +41,10 @@ function write_charge(path::AbstractString, inputs::Dict, setup::Dict, EP::Model if setup["WriteOutputs"] == "annual" write_annual(filepath, dfCharge) else # setup["WriteOutputs"] == "full" - write_fulltimeseries(filepath, charge, dfCharge) - if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - - # full path, dataout, dfout - - T = size(charge, 2) - dfCharge = hcat(dfCharge, DataFrame(charge, :auto)) - auxNew_Names = [Symbol("Resource"); - Symbol("Zone"); - Symbol("AnnualSum"); - [Symbol("t$t") for t in 1:T]] - rename!(dfCharge, auxNew_Names) - total = DataFrame(["Total" 0 sum(dfCharge[!, :AnnualSum]) fill(0.0, (1, T))], auxNew_Names) - total[!, 4:(T + 3)] .= sum(charge, dims = 1) - df_Charge = vcat(dfCharge, total) + df_Charge = write_fulltimeseries(filepath, charge, dfCharge) + if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 DFMatrix = Matrix(dftranspose(df_Charge, true)) DFnames = DFMatrix[1,:] - FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( diff --git a/src/write_outputs/write_co2.jl b/src/write_outputs/write_co2.jl index 86112c87f2..256291bc69 100644 --- a/src/write_outputs/write_co2.jl +++ b/src/write_outputs/write_co2.jl @@ -31,21 +31,10 @@ function write_co2_emissions_plant(path::AbstractString, if setup["WriteOutputs"] == "annual" write_annual(filepath, dfEmissions_plant) else # setup["WriteOutputs"] == "full" - write_fulltimeseries(filepath, emissions_plant, dfEmissions_plant) + df_Emissions_plant = write_fulltimeseries(filepath, emissions_plant, dfEmissions_plant) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - T = size(emissions_plant, 2) - dfEmissions_plant = hcat(dfEmissions_plant, DataFrame(emissions_plant, :auto)) - auxNew_Names = [Symbol("Resource"); - Symbol("Zone"); - Symbol("AnnualSum"); - [Symbol("t$t") for t in 1:T]] - rename!(dfEmissions_plant, auxNew_Names) - total = DataFrame(["Total" 0 sum(dfEmissions_plant[!, :AnnualSum]) fill(0.0, (1, T))], auxNew_Names) - total[!, 4:(T + 3)] .= sum(emissions_plant, dims = 1) - df_Emissions_plant = vcat(dfEmissions_plant, total) DFMatrix = Matrix(dftranspose(df_Emissions_plant, true)) DFnames = DFMatrix[1,:] - FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( diff --git a/src/write_outputs/write_curtailment.jl b/src/write_outputs/write_curtailment.jl index b0b191fca4..091a4a3df5 100644 --- a/src/write_outputs/write_curtailment.jl +++ b/src/write_outputs/write_curtailment.jl @@ -57,21 +57,10 @@ function write_curtailment(path::AbstractString, inputs::Dict, setup::Dict, EP:: if setup["WriteOutputs"] == "annual" write_annual(filename, dfCurtailment) else # setup["WriteOutputs"] == "full" - write_fulltimeseries(filename, curtailment, dfCurtailment) + df_Curtailment = write_fulltimeseries(filename, curtailment, dfCurtailment) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - T = size(curtailment, 2) - dfCurtailment = hcat(dfCurtailment, DataFrame(curtailment, :auto)) - auxNew_Names = [Symbol("Resource"); - Symbol("Zone"); - Symbol("AnnualSum"); - [Symbol("t$t") for t in 1:T]] - rename!(dfCurtailment, auxNew_Names) - total = DataFrame(["Total" 0 sum(dfCurtailment[!, :AnnualSum]) fill(0.0, (1, T))], auxNew_Names) - total[!, 4:(T + 3)] .= sum(curtailment, dims = 1) - df_Curtailment = vcat(dfCurtailment, total) DFMatrix = Matrix(dftranspose(df_Curtailment, true)) DFnames = DFMatrix[1,:] - FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( diff --git a/src/write_outputs/write_outputs.jl b/src/write_outputs/write_outputs.jl index fb4bcbff1f..0cc5f5f9e7 100644 --- a/src/write_outputs/write_outputs.jl +++ b/src/write_outputs/write_outputs.jl @@ -508,7 +508,7 @@ function write_fulltimeseries(fullpath::AbstractString, dfOut = vcat(dfOut, total) CSV.write(fullpath, dftranspose(dfOut, false), writeheader = false) - return nothing + return dfOut end function write_settings_file(path, setup) diff --git a/src/write_outputs/write_power.jl b/src/write_outputs/write_power.jl index 8264d41d22..d0c7fd8aab 100644 --- a/src/write_outputs/write_power.jl +++ b/src/write_outputs/write_power.jl @@ -24,21 +24,10 @@ function write_power(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) if setup["WriteOutputs"] == "annual" write_annual(filepath, dfPower) else # setup["WriteOutputs"] == "full" - write_fulltimeseries(filepath, power, dfPower) + df_Power = write_fulltimeseries(filepath, power, dfPower) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - T = size(power, 2) - dfPower = hcat(dfPower, DataFrame(power, :auto)) - auxNew_Names = [Symbol("Resource"); - Symbol("Zone"); - Symbol("AnnualSum"); - [Symbol("t$t") for t in 1:T]] - rename!(dfPower, auxNew_Names) - total = DataFrame(["Total" 0 sum(dfPower[!, :AnnualSum]) fill(0.0, (1, T))], auxNew_Names) - total[!, 4:(T + 3)] .= sum(power, dims = 1) - df_Power = vcat(dfPower, total) DFMatrix = Matrix(dftranspose(df_Power, true)) DFnames = DFMatrix[1,:] - FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( From 8df2d9362996bdc00571d59d4481aa32f33b1b25 Mon Sep 17 00:00:00 2001 From: Maya Mutic Date: Wed, 26 Jun 2024 19:33:34 +0200 Subject: [PATCH 22/61] Took out DFnames as an argument in FTR --- .../full_time_series_reconstruction.jl | 5 ++--- src/write_outputs/transmission/write_transmission_flows.jl | 3 +-- src/write_outputs/transmission/write_transmission_losses.jl | 3 +-- src/write_outputs/ucommit/write_commit.jl | 5 +---- src/write_outputs/ucommit/write_shutdown.jl | 4 +--- src/write_outputs/ucommit/write_start.jl | 4 +--- src/write_outputs/write_charge.jl | 6 ++---- src/write_outputs/write_co2.jl | 4 +--- src/write_outputs/write_curtailment.jl | 4 +--- src/write_outputs/write_emissions.jl | 4 +--- src/write_outputs/write_fuel_consumption.jl | 4 +--- src/write_outputs/write_nse.jl | 4 +--- src/write_outputs/write_power.jl | 4 +--- src/write_outputs/write_power_balance.jl | 4 +--- src/write_outputs/write_price.jl | 3 +-- src/write_outputs/write_reliability.jl | 3 +-- src/write_outputs/write_storage.jl | 4 +--- src/write_outputs/write_storagedual.jl | 4 +--- 18 files changed, 20 insertions(+), 52 deletions(-) diff --git a/src/time_domain_reduction/full_time_series_reconstruction.jl b/src/time_domain_reduction/full_time_series_reconstruction.jl index ffa6aefb82..c42900d603 100644 --- a/src/time_domain_reduction/full_time_series_reconstruction.jl +++ b/src/time_domain_reduction/full_time_series_reconstruction.jl @@ -7,7 +7,6 @@ Create a DataFrame with all 8,760 hours of the year from the reduced output. path - Path input to the results folder setup - case setup (dictionary) DF - DataFrame to be reconstructed -DFnames - Vector of column names This function uses Period_map.csv to create a new DataFrame with 8,760 time steps, as well as other pre-existing rows such as "Zone". For each 52 weeks of the year, the corresponding representative week is taken from the input DataFrame and copied into the new DataFrame. Representative periods that @@ -21,7 +20,7 @@ This function is called when output files with time series data (e.g. power.csv, """ function full_time_series_reconstruction( - path::AbstractString, setup::Dict, DF::DataFrame, DFnames::Vector) + path::AbstractString, setup::Dict, DF::DataFrame) # Read Period map file Period_map.csv case = path[1:findlast('/', path)] TDRpath = joinpath(case, setup["TimeDomainReductionFolder"]) @@ -56,7 +55,7 @@ function full_time_series_reconstruction( end recon = [recon recon_col] end - reconDF = DataFrame(recon, DFnames, makeunique = true) + reconDF = DataFrame(recon, :auto) # Insert rows that were above "t1" in the original DataFrame (e.g. "Zone" and "AnnualSum") if present for i in range(1, t1 - 1) diff --git a/src/write_outputs/transmission/write_transmission_flows.jl b/src/write_outputs/transmission/write_transmission_flows.jl index 7decbb710a..ab39abf394 100644 --- a/src/write_outputs/transmission/write_transmission_flows.jl +++ b/src/write_outputs/transmission/write_transmission_flows.jl @@ -25,11 +25,10 @@ function write_transmission_flows(path::AbstractString, CSV.write(filepath, dftranspose(dfFlow, false), writeheader = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - DFnames = ["Line", "1", "2"] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(dfFlow, false), DFnames) + path, setup, dftranspose(dfFlow, false)) CSV.write(joinpath(output_path, "flow.csv"), dfOut_full, header = false) println("Writing Full Time Series for Transmission Flows") end diff --git a/src/write_outputs/transmission/write_transmission_losses.jl b/src/write_outputs/transmission/write_transmission_losses.jl index 18d66a202f..ad0c034c64 100644 --- a/src/write_outputs/transmission/write_transmission_losses.jl +++ b/src/write_outputs/transmission/write_transmission_losses.jl @@ -32,11 +32,10 @@ function write_transmission_losses(path::AbstractString, writeheader = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - DFnames = ["Line", "1", "2", "Total"] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(dfTLosses, false), DFnames) + path, setup, dftranspose(dfTLosses, false)) CSV.write(joinpath(output_path, "tlosses.csv"), dfOut_full, header = false) println("Writing Full Time Series for Time Losses") end diff --git a/src/write_outputs/ucommit/write_commit.jl b/src/write_outputs/ucommit/write_commit.jl index 75b6ec7ac3..142cc70017 100644 --- a/src/write_outputs/ucommit/write_commit.jl +++ b/src/write_outputs/ucommit/write_commit.jl @@ -12,14 +12,11 @@ function write_commit(path::AbstractString, inputs::Dict, setup::Dict, EP::Model rename!(dfCommit, auxNew_Names) CSV.write(joinpath(path, "commit.csv"), dftranspose(dfCommit, false), header = false) - if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - DFMatrix = Matrix(dftranspose(dfCommit, true)) - DFnames = DFMatrix[1, :] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(dfCommit, false), DFnames) + path, setup, dftranspose(dfCommit, false)) CSV.write(joinpath(output_path, "commit.csv"), dfOut_full, header = false) println("Writing Full Time Series for Commitment") end diff --git a/src/write_outputs/ucommit/write_shutdown.jl b/src/write_outputs/ucommit/write_shutdown.jl index b232a0ebd6..e864d0baf4 100644 --- a/src/write_outputs/ucommit/write_shutdown.jl +++ b/src/write_outputs/ucommit/write_shutdown.jl @@ -15,11 +15,9 @@ function write_shutdown(path::AbstractString, inputs::Dict, setup::Dict, EP::Mod else # setup["WriteOutputs"] == "full" df_Shutdown = write_fulltimeseries(filepath, shut, dfShutdown) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - DFMatrix = Matrix(dftranspose(df_Shutdown, true)) - DFnames = DFMatrix[1,:] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path,FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(df_Shutdown, false), DFnames) + dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(df_Shutdown, false)) CSV.write(joinpath(output_path,"shutdown.csv"), dfOut_full, writeheader = false) println("Writing Full Time Series for Shutdown") end diff --git a/src/write_outputs/ucommit/write_start.jl b/src/write_outputs/ucommit/write_start.jl index 9a730c5ecb..3bc707af54 100644 --- a/src/write_outputs/ucommit/write_start.jl +++ b/src/write_outputs/ucommit/write_start.jl @@ -14,12 +14,10 @@ function write_start(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) else # setup["WriteOutputs"] == "full" df_Start = write_fulltimeseries(filepath, start, dfStart) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - DFMatrix = Matrix(dftranspose(df_Start, true)) - DFnames = DFMatrix[1,:] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(df_Start, false), DFnames) + path, setup, dftranspose(df_Start, false)) CSV.write(joinpath(output_path, "start.csv"), dfOut_full, writeheader = false) println("Writing Full Time Series for Startup") end diff --git a/src/write_outputs/write_charge.jl b/src/write_outputs/write_charge.jl index 4971f89f88..813c9ccedc 100644 --- a/src/write_outputs/write_charge.jl +++ b/src/write_outputs/write_charge.jl @@ -42,13 +42,11 @@ function write_charge(path::AbstractString, inputs::Dict, setup::Dict, EP::Model write_annual(filepath, dfCharge) else # setup["WriteOutputs"] == "full" df_Charge = write_fulltimeseries(filepath, charge, dfCharge) - if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - DFMatrix = Matrix(dftranspose(df_Charge, true)) - DFnames = DFMatrix[1,:] + if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(df_Charge, false), DFnames) + path, setup, dftranspose(df_Charge, false)) CSV.write(joinpath(output_path, "charge.csv"), dfOut_full, writeheader = false) println("Writing Full Time Series for Charge") end diff --git a/src/write_outputs/write_co2.jl b/src/write_outputs/write_co2.jl index 256291bc69..f6097ee7cd 100644 --- a/src/write_outputs/write_co2.jl +++ b/src/write_outputs/write_co2.jl @@ -33,12 +33,10 @@ function write_co2_emissions_plant(path::AbstractString, else # setup["WriteOutputs"] == "full" df_Emissions_plant = write_fulltimeseries(filepath, emissions_plant, dfEmissions_plant) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - DFMatrix = Matrix(dftranspose(df_Emissions_plant, true)) - DFnames = DFMatrix[1,:] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(df_Emissions_plant, false), DFnames) + path, setup, dftranspose(df_Emissions_plant, false)) CSV.write(joinpath(output_path, "emissions_plant.csv"), dfOut_full, writeheader = false) println("Writing Full Time Series for Emissions Plant") end diff --git a/src/write_outputs/write_curtailment.jl b/src/write_outputs/write_curtailment.jl index 091a4a3df5..186bed9315 100644 --- a/src/write_outputs/write_curtailment.jl +++ b/src/write_outputs/write_curtailment.jl @@ -59,12 +59,10 @@ function write_curtailment(path::AbstractString, inputs::Dict, setup::Dict, EP:: else # setup["WriteOutputs"] == "full" df_Curtailment = write_fulltimeseries(filename, curtailment, dfCurtailment) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - DFMatrix = Matrix(dftranspose(df_Curtailment, true)) - DFnames = DFMatrix[1,:] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(df_Curtailment, false), DFnames) + path, setup, dftranspose(df_Curtailment, false)) CSV.write(joinpath(output_path, "curtail.csv"), dfOut_full, writeheader = false) println("Writing Full Time Series for Curtailment") end diff --git a/src/write_outputs/write_emissions.jl b/src/write_outputs/write_emissions.jl index b53641bc6b..16f92b89fa 100644 --- a/src/write_outputs/write_emissions.jl +++ b/src/write_outputs/write_emissions.jl @@ -126,11 +126,9 @@ function write_emissions(path::AbstractString, inputs::Dict, setup::Dict, EP::Mo writeheader = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - DFMatrix = Matrix(dftranspose(dfEmissions, true)) - DFnames = DFMatrix[1,:] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path,FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfEmissions, false), DFnames) + dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfEmissions, false)) CSV.write(joinpath(output_path,"emissions.csv"), dfOut_full) println("Writing Full Time Series for Emissions") end diff --git a/src/write_outputs/write_fuel_consumption.jl b/src/write_outputs/write_fuel_consumption.jl index 05373bc056..9aeb908d72 100644 --- a/src/write_outputs/write_fuel_consumption.jl +++ b/src/write_outputs/write_fuel_consumption.jl @@ -87,12 +87,10 @@ function write_fuel_consumption_ts(path::AbstractString, dftranspose(dfPlantFuel_TS, false), header = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - DFMatrix = Matrix(dftranspose(dfPlantFuel_TS, true)) - DFnames = DFMatrix[1, :] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(dfPlantFuel_TS, false), DFnames) + path, setup, dftranspose(dfPlantFuel_TS, false)) CSV.write(joinpath(output_path, "commit.csv"), dfOut_full, header = false) println("Writing Full Time Series for Fuel Consumption") end diff --git a/src/write_outputs/write_nse.jl b/src/write_outputs/write_nse.jl index 67a95b5714..786153a3c9 100644 --- a/src/write_outputs/write_nse.jl +++ b/src/write_outputs/write_nse.jl @@ -39,12 +39,10 @@ function write_nse(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) CSV.write(joinpath(path, "nse.csv"), dftranspose(dfNse, false), writeheader = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - DFnames = ["Segment", "1", "2", "3", "4", "1", "2", - "3", "4", "1", "2", "3", "4", "Total"] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(dfNse, false), DFnames) + path, setup, dftranspose(dfNse, false)) CSV.write(joinpath(output_path, "nse.csv"), dfOut_full, header = false) println("Writing Full Time Series for NSE") end diff --git a/src/write_outputs/write_power.jl b/src/write_outputs/write_power.jl index d0c7fd8aab..a2613c06e3 100644 --- a/src/write_outputs/write_power.jl +++ b/src/write_outputs/write_power.jl @@ -26,12 +26,10 @@ function write_power(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) else # setup["WriteOutputs"] == "full" df_Power = write_fulltimeseries(filepath, power, dfPower) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - DFMatrix = Matrix(dftranspose(df_Power, true)) - DFnames = DFMatrix[1,:] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(df_Power, false), DFnames) + path, setup, dftranspose(df_Power, false)) CSV.write(joinpath(output_path, "power.csv"), dfOut_full, writeheader = false) println("Writing Full Time Series for Power") end diff --git a/src/write_outputs/write_power_balance.jl b/src/write_outputs/write_power_balance.jl index 79731ef495..b1133a7837 100644 --- a/src/write_outputs/write_power_balance.jl +++ b/src/write_outputs/write_power_balance.jl @@ -98,12 +98,10 @@ function write_power_balance(path::AbstractString, inputs::Dict, setup::Dict, EP writeheader = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - DFnames = dfPowerBalance[:, 1] - insert!(DFnames, 1, "BalanceComponent") FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(dfPowerBalance, false), DFnames) + path, setup, dftranspose(dfPowerBalance, false)) CSV.write( joinpath(output_path, "power_balance.csv"), dfOut_full, header = false) println("Writing Full Time Series for Power Balance") diff --git a/src/write_outputs/write_price.jl b/src/write_outputs/write_price.jl index 7d5365e900..0cd6e2471d 100644 --- a/src/write_outputs/write_price.jl +++ b/src/write_outputs/write_price.jl @@ -23,11 +23,10 @@ function write_price(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) writeheader = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - DFnames = ["Zone", "1", "2", "3"] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(dfPrice, false), DFnames) + path, setup, dftranspose(dfPrice, false)) CSV.write(joinpath(output_path, "prices.csv"), dfOut_full, header = false) println("Writing Full Time Series for Price") end diff --git a/src/write_outputs/write_reliability.jl b/src/write_outputs/write_reliability.jl index c19ad9b0cc..95114a01b8 100644 --- a/src/write_outputs/write_reliability.jl +++ b/src/write_outputs/write_reliability.jl @@ -22,11 +22,10 @@ function write_reliability(path::AbstractString, inputs::Dict, setup::Dict, EP:: header = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - DFnames = ["Zone", "1", "2", "3"] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(dfReliability, false), DFnames) + path, setup, dftranspose(dfReliability, false)) CSV.write(joinpath(output_path, "reliability.csv"), dfOut_full, header = false) println("Writing Full Time Series for Reliability") end diff --git a/src/write_outputs/write_storage.jl b/src/write_outputs/write_storage.jl index 720be09821..fc4c099c0f 100644 --- a/src/write_outputs/write_storage.jl +++ b/src/write_outputs/write_storage.jl @@ -41,12 +41,10 @@ function write_storage(path::AbstractString, inputs::Dict, setup::Dict, EP::Mode CSV.write(joinpath(path, "storage.csv"), dftranspose(dfStorage, false), header = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - DFMatrix = Matrix(dftranspose(dfStorage, true)) - DFnames = DFMatrix[1, :] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(dfStorage, false), DFnames) + path, setup, dftranspose(dfStorage, false)) CSV.write(joinpath(output_path, "storage.csv"), dfOut_full, header = false) println("Writing Full Time Series for Storage") end diff --git a/src/write_outputs/write_storagedual.jl b/src/write_outputs/write_storagedual.jl index c091ec32e9..8b570a9131 100644 --- a/src/write_outputs/write_storagedual.jl +++ b/src/write_outputs/write_storagedual.jl @@ -81,12 +81,10 @@ function write_storagedual(path::AbstractString, inputs::Dict, setup::Dict, EP:: header = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - DFMatrix = Matrix(dftranspose(dfStorageDual, true)) - DFnames = DFMatrix[1, :] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(dfStorageDual, false), DFnames) + path, setup, dftranspose(dfStorageDual, false)) CSV.write(joinpath(output_path, "storagebal_duals.csv"), dfOut_full, header = false) println("Writing Full Time Series for Storage Duals") end From d2fc3e0b5cc9a3acb3df88ebcfaebcc9562d1a20 Mon Sep 17 00:00:00 2001 From: Maya Mutic Date: Wed, 26 Jun 2024 22:02:24 +0200 Subject: [PATCH 23/61] Added write CSV to the reconstruction, made perform_recon() function --- .../1_three_zones/settings/genx_settings.yml | 3 ++- .../full_time_series_reconstruction.jl | 25 +++++++++++++++---- .../transmission/write_transmission_flows.jl | 6 +---- .../transmission/write_transmission_losses.jl | 6 +---- src/write_outputs/ucommit/write_commit.jl | 6 +---- src/write_outputs/ucommit/write_shutdown.jl | 5 +--- src/write_outputs/ucommit/write_start.jl | 6 +---- src/write_outputs/write_charge.jl | 6 +---- src/write_outputs/write_co2.jl | 6 +---- src/write_outputs/write_curtailment.jl | 6 +---- src/write_outputs/write_emissions.jl | 5 +--- src/write_outputs/write_fuel_consumption.jl | 6 +---- src/write_outputs/write_nse.jl | 6 +---- src/write_outputs/write_power.jl | 6 +---- src/write_outputs/write_power_balance.jl | 7 +----- src/write_outputs/write_price.jl | 6 +---- src/write_outputs/write_reliability.jl | 6 +---- src/write_outputs/write_storage.jl | 6 +---- src/write_outputs/write_storagedual.jl | 6 +---- 19 files changed, 39 insertions(+), 90 deletions(-) diff --git a/example_systems/1_three_zones/settings/genx_settings.yml b/example_systems/1_three_zones/settings/genx_settings.yml index 96854d0222..d48032b1d1 100644 --- a/example_systems/1_three_zones/settings/genx_settings.yml +++ b/example_systems/1_three_zones/settings/genx_settings.yml @@ -9,4 +9,5 @@ MaxCapReq: 0 # Activate maximum technology carveout constraints; 0 = not active ParameterScale: 1 # Turn on parameter scaling wherein demand, capacity and power variables are defined in GW rather than MW. 0 = not active; 1 = active systemwide WriteShadowPrices: 1 # Write shadow prices of LP or relaxed MILP; 0 = not active; 1 = active UCommit: 2 # Unit committment of thermal power plants; 0 = not active; 1 = active using integer clestering; 2 = active using linearized clustering -TimeDomainReduction: 1 # Time domain reduce (i.e. cluster) inputs based on Demand_data.csv, Generators_variability.csv, and Fuels_data.csv; 0 = not active (use input data as provided); 0 = active (cluster input data, or use data that has already been clustered) \ No newline at end of file +TimeDomainReduction: 1 # Time domain reduce (i.e. cluster) inputs based on Demand_data.csv, Generators_variability.csv, and Fuels_data.csv; 0 = not active (use input data as provided); 0 = active (cluster input data, or use data that has already been clustered) +OutputFullTimeSeries: 1 \ No newline at end of file diff --git a/src/time_domain_reduction/full_time_series_reconstruction.jl b/src/time_domain_reduction/full_time_series_reconstruction.jl index c42900d603..8c83ef4fb7 100644 --- a/src/time_domain_reduction/full_time_series_reconstruction.jl +++ b/src/time_domain_reduction/full_time_series_reconstruction.jl @@ -1,14 +1,15 @@ @doc raw"""full_time_series_reconstruction(path::AbstractString, - case::AbstractString, + setup::Dict, DF::DataFrame, - DFnames::Vector) + name::String) Create a DataFrame with all 8,760 hours of the year from the reduced output. path - Path input to the results folder setup - case setup (dictionary) DF - DataFrame to be reconstructed +name - name desired for the .csv file -This function uses Period_map.csv to create a new DataFrame with 8,760 time steps, as well as other pre-existing rows such as "Zone". +This function calls perform_reconstruction(), which uses Period_map.csv to create a new DataFrame with 8,760 time steps, as well as other pre-existing rows such as "Zone". For each 52 weeks of the year, the corresponding representative week is taken from the input DataFrame and copied into the new DataFrame. Representative periods that represent more than one week will appear multiple times in the output. @@ -20,7 +21,21 @@ This function is called when output files with time series data (e.g. power.csv, """ function full_time_series_reconstruction( - path::AbstractString, setup::Dict, DF::DataFrame) + path::AbstractString, setup::Dict, DF::DataFrame, name::String) + FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] + output_path = joinpath(path, FullTimeSeriesFolder) + dfOut_full = perform_reconstruction(path, setup, dftranspose(DF, false)) + CSV.write(joinpath(output_path, "$name.csv"), dfOut_full, header = false) + return nothing +end + +""" + perform_reconstruction(path::AbstractString, setup::Dict, DF::DataFrame) + +Internal function for performing the reconstruction. This function returns a DataFrame with the full series reconstruction. +""" +function perform_reconstruction( + path::AbstractString, setup::Dict, DF::DataFrame) # Read Period map file Period_map.csv case = path[1:findlast('/', path)] TDRpath = joinpath(case, setup["TimeDomainReductionFolder"]) @@ -50,7 +65,7 @@ function full_time_series_reconstruction( recon_col = [] for i in range(1, numPeriods) index = Period_map[i, "Rep_Period_Index"] - recon_temp = col[(TimestepsPerRepPeriod * index - (TimestepsPerRepPeriod - 1)):(TimestepsPerRepPeriod * index)] # Describe how this works + recon_temp = col[(TimestepsPerRepPeriod * index - (TimestepsPerRepPeriod - 1)):(TimestepsPerRepPeriod * index)] recon_col = [recon_col; recon_temp] end recon = [recon recon_col] diff --git a/src/write_outputs/transmission/write_transmission_flows.jl b/src/write_outputs/transmission/write_transmission_flows.jl index ab39abf394..25c7577cc5 100644 --- a/src/write_outputs/transmission/write_transmission_flows.jl +++ b/src/write_outputs/transmission/write_transmission_flows.jl @@ -25,11 +25,7 @@ function write_transmission_flows(path::AbstractString, CSV.write(filepath, dftranspose(dfFlow, false), writeheader = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path, FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(dfFlow, false)) - CSV.write(joinpath(output_path, "flow.csv"), dfOut_full, header = false) + full_time_series_reconstruction(path, setup, dfFlow, "flow") println("Writing Full Time Series for Transmission Flows") end end diff --git a/src/write_outputs/transmission/write_transmission_losses.jl b/src/write_outputs/transmission/write_transmission_losses.jl index ad0c034c64..09b06eba71 100644 --- a/src/write_outputs/transmission/write_transmission_losses.jl +++ b/src/write_outputs/transmission/write_transmission_losses.jl @@ -32,11 +32,7 @@ function write_transmission_losses(path::AbstractString, writeheader = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path, FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(dfTLosses, false)) - CSV.write(joinpath(output_path, "tlosses.csv"), dfOut_full, header = false) + full_time_series_reconstruction(path, setup, dfTLosses, "tlosses") println("Writing Full Time Series for Time Losses") end end diff --git a/src/write_outputs/ucommit/write_commit.jl b/src/write_outputs/ucommit/write_commit.jl index 142cc70017..6aa6d48d20 100644 --- a/src/write_outputs/ucommit/write_commit.jl +++ b/src/write_outputs/ucommit/write_commit.jl @@ -13,11 +13,7 @@ function write_commit(path::AbstractString, inputs::Dict, setup::Dict, EP::Model CSV.write(joinpath(path, "commit.csv"), dftranspose(dfCommit, false), header = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path, FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(dfCommit, false)) - CSV.write(joinpath(output_path, "commit.csv"), dfOut_full, header = false) + full_time_series_reconstruction(path, setup, dfCommit, "commit") println("Writing Full Time Series for Commitment") end end diff --git a/src/write_outputs/ucommit/write_shutdown.jl b/src/write_outputs/ucommit/write_shutdown.jl index e864d0baf4..cbb9f3b6a5 100644 --- a/src/write_outputs/ucommit/write_shutdown.jl +++ b/src/write_outputs/ucommit/write_shutdown.jl @@ -15,10 +15,7 @@ function write_shutdown(path::AbstractString, inputs::Dict, setup::Dict, EP::Mod else # setup["WriteOutputs"] == "full" df_Shutdown = write_fulltimeseries(filepath, shut, dfShutdown) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path,FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(df_Shutdown, false)) - CSV.write(joinpath(output_path,"shutdown.csv"), dfOut_full, writeheader = false) + full_time_series_reconstruction(path, setup, df_Shutdown, "shutdown") println("Writing Full Time Series for Shutdown") end end diff --git a/src/write_outputs/ucommit/write_start.jl b/src/write_outputs/ucommit/write_start.jl index 3bc707af54..334b231e72 100644 --- a/src/write_outputs/ucommit/write_start.jl +++ b/src/write_outputs/ucommit/write_start.jl @@ -14,11 +14,7 @@ function write_start(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) else # setup["WriteOutputs"] == "full" df_Start = write_fulltimeseries(filepath, start, dfStart) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path, FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(df_Start, false)) - CSV.write(joinpath(output_path, "start.csv"), dfOut_full, writeheader = false) + full_time_series_reconstruction(path, setup, df_Start, "start") println("Writing Full Time Series for Startup") end end diff --git a/src/write_outputs/write_charge.jl b/src/write_outputs/write_charge.jl index 813c9ccedc..7cbf6707af 100644 --- a/src/write_outputs/write_charge.jl +++ b/src/write_outputs/write_charge.jl @@ -43,11 +43,7 @@ function write_charge(path::AbstractString, inputs::Dict, setup::Dict, EP::Model else # setup["WriteOutputs"] == "full" df_Charge = write_fulltimeseries(filepath, charge, dfCharge) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path, FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(df_Charge, false)) - CSV.write(joinpath(output_path, "charge.csv"), dfOut_full, writeheader = false) + full_time_series_reconstruction(path, setup, df_Charge, "charge") println("Writing Full Time Series for Charge") end end diff --git a/src/write_outputs/write_co2.jl b/src/write_outputs/write_co2.jl index f6097ee7cd..4774fc4435 100644 --- a/src/write_outputs/write_co2.jl +++ b/src/write_outputs/write_co2.jl @@ -33,11 +33,7 @@ function write_co2_emissions_plant(path::AbstractString, else # setup["WriteOutputs"] == "full" df_Emissions_plant = write_fulltimeseries(filepath, emissions_plant, dfEmissions_plant) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path, FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(df_Emissions_plant, false)) - CSV.write(joinpath(output_path, "emissions_plant.csv"), dfOut_full, writeheader = false) + full_time_series_reconstruction(path, setup, df_Emissions_plant, "emissions_plant") println("Writing Full Time Series for Emissions Plant") end end diff --git a/src/write_outputs/write_curtailment.jl b/src/write_outputs/write_curtailment.jl index 186bed9315..e9d3444210 100644 --- a/src/write_outputs/write_curtailment.jl +++ b/src/write_outputs/write_curtailment.jl @@ -59,11 +59,7 @@ function write_curtailment(path::AbstractString, inputs::Dict, setup::Dict, EP:: else # setup["WriteOutputs"] == "full" df_Curtailment = write_fulltimeseries(filename, curtailment, dfCurtailment) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path, FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(df_Curtailment, false)) - CSV.write(joinpath(output_path, "curtail.csv"), dfOut_full, writeheader = false) + full_time_series_reconstruction(path, setup, df_Curtailment, "curtail") println("Writing Full Time Series for Curtailment") end end diff --git a/src/write_outputs/write_emissions.jl b/src/write_outputs/write_emissions.jl index 16f92b89fa..0fb598ae81 100644 --- a/src/write_outputs/write_emissions.jl +++ b/src/write_outputs/write_emissions.jl @@ -126,10 +126,7 @@ function write_emissions(path::AbstractString, inputs::Dict, setup::Dict, EP::Mo writeheader = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path,FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfEmissions, false)) - CSV.write(joinpath(output_path,"emissions.csv"), dfOut_full) + full_time_series_reconstruction(path, setup, dfEmissions, "emissions") println("Writing Full Time Series for Emissions") end end diff --git a/src/write_outputs/write_fuel_consumption.jl b/src/write_outputs/write_fuel_consumption.jl index 9aeb908d72..53c03a480d 100644 --- a/src/write_outputs/write_fuel_consumption.jl +++ b/src/write_outputs/write_fuel_consumption.jl @@ -87,11 +87,7 @@ function write_fuel_consumption_ts(path::AbstractString, dftranspose(dfPlantFuel_TS, false), header = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path, FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(dfPlantFuel_TS, false)) - CSV.write(joinpath(output_path, "commit.csv"), dfOut_full, header = false) + full_time_series_reconstruction(path, setup, dfPlantFuel_TS, "FuelConsumption_plant_MMBTU") println("Writing Full Time Series for Fuel Consumption") end end diff --git a/src/write_outputs/write_nse.jl b/src/write_outputs/write_nse.jl index 786153a3c9..bdd8f732c3 100644 --- a/src/write_outputs/write_nse.jl +++ b/src/write_outputs/write_nse.jl @@ -39,11 +39,7 @@ function write_nse(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) CSV.write(joinpath(path, "nse.csv"), dftranspose(dfNse, false), writeheader = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path, FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(dfNse, false)) - CSV.write(joinpath(output_path, "nse.csv"), dfOut_full, header = false) + full_time_series_reconstruction(path, setup, dfNse, "nse") println("Writing Full Time Series for NSE") end end diff --git a/src/write_outputs/write_power.jl b/src/write_outputs/write_power.jl index a2613c06e3..dc8a2696af 100644 --- a/src/write_outputs/write_power.jl +++ b/src/write_outputs/write_power.jl @@ -26,11 +26,7 @@ function write_power(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) else # setup["WriteOutputs"] == "full" df_Power = write_fulltimeseries(filepath, power, dfPower) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path, FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(df_Power, false)) - CSV.write(joinpath(output_path, "power.csv"), dfOut_full, writeheader = false) + full_time_series_reconstruction(path, setup, df_Power, "power") println("Writing Full Time Series for Power") end end diff --git a/src/write_outputs/write_power_balance.jl b/src/write_outputs/write_power_balance.jl index b1133a7837..455db19224 100644 --- a/src/write_outputs/write_power_balance.jl +++ b/src/write_outputs/write_power_balance.jl @@ -98,12 +98,7 @@ function write_power_balance(path::AbstractString, inputs::Dict, setup::Dict, EP writeheader = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path, FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(dfPowerBalance, false)) - CSV.write( - joinpath(output_path, "power_balance.csv"), dfOut_full, header = false) + full_time_series_reconstruction(path, setup, dfPowerBalance, "power_balance") println("Writing Full Time Series for Power Balance") end end diff --git a/src/write_outputs/write_price.jl b/src/write_outputs/write_price.jl index 0cd6e2471d..8dace217ee 100644 --- a/src/write_outputs/write_price.jl +++ b/src/write_outputs/write_price.jl @@ -23,11 +23,7 @@ function write_price(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) writeheader = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path, FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(dfPrice, false)) - CSV.write(joinpath(output_path, "prices.csv"), dfOut_full, header = false) + full_time_series_reconstruction(path, setup, dfPrice, "prices") println("Writing Full Time Series for Price") end return nothing diff --git a/src/write_outputs/write_reliability.jl b/src/write_outputs/write_reliability.jl index 95114a01b8..7996c01de5 100644 --- a/src/write_outputs/write_reliability.jl +++ b/src/write_outputs/write_reliability.jl @@ -22,11 +22,7 @@ function write_reliability(path::AbstractString, inputs::Dict, setup::Dict, EP:: header = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path, FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(dfReliability, false)) - CSV.write(joinpath(output_path, "reliability.csv"), dfOut_full, header = false) + full_time_series_reconstruction(path, setup, dfReliability, "reliability") println("Writing Full Time Series for Reliability") end end diff --git a/src/write_outputs/write_storage.jl b/src/write_outputs/write_storage.jl index fc4c099c0f..0bc7267c00 100644 --- a/src/write_outputs/write_storage.jl +++ b/src/write_outputs/write_storage.jl @@ -41,11 +41,7 @@ function write_storage(path::AbstractString, inputs::Dict, setup::Dict, EP::Mode CSV.write(joinpath(path, "storage.csv"), dftranspose(dfStorage, false), header = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path, FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(dfStorage, false)) - CSV.write(joinpath(output_path, "storage.csv"), dfOut_full, header = false) + full_time_series_reconstruction(path, setup, dfStorage, "storage") println("Writing Full Time Series for Storage") end end diff --git a/src/write_outputs/write_storagedual.jl b/src/write_outputs/write_storagedual.jl index 8b570a9131..ad8007a165 100644 --- a/src/write_outputs/write_storagedual.jl +++ b/src/write_outputs/write_storagedual.jl @@ -81,11 +81,7 @@ function write_storagedual(path::AbstractString, inputs::Dict, setup::Dict, EP:: header = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path, FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(dfStorageDual, false)) - CSV.write(joinpath(output_path, "storagebal_duals.csv"), dfOut_full, header = false) + full_time_series_reconstruction(path, setup, dfStorageDual, "storagebal_duals") println("Writing Full Time Series for Storage Duals") end end From 60791e0fe924e20c96ab30f75972a0d421e1ad5e Mon Sep 17 00:00:00 2001 From: Maya Mutic Date: Mon, 22 Apr 2024 16:29:36 -0400 Subject: [PATCH 24/61] Added full time series reconstruction --- example_systems/1_three_zones/settings/genx_settings.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/example_systems/1_three_zones/settings/genx_settings.yml b/example_systems/1_three_zones/settings/genx_settings.yml index c85af312ac..278270baac 100644 --- a/example_systems/1_three_zones/settings/genx_settings.yml +++ b/example_systems/1_three_zones/settings/genx_settings.yml @@ -10,3 +10,4 @@ ParameterScale: 1 # Turn on parameter scaling wherein demand, capacity and power WriteShadowPrices: 1 # Write shadow prices of LP or relaxed MILP; 0 = not active; 1 = active UCommit: 2 # Unit committment of thermal power plants; 0 = not active; 1 = active using integer clestering; 2 = active using linearized clustering TimeDomainReduction: 1 # Time domain reduce (i.e. cluster) inputs based on Demand_data.csv, Generators_variability.csv, and Fuels_data.csv; 0 = not active (use input data as provided); 0 = active (cluster input data, or use data that has already been clustered) +OutputFullTimeSeries: 1 \ No newline at end of file From b93b78a6f743d1f66e7fc765d1531f2c6bc9e3c5 Mon Sep 17 00:00:00 2001 From: Maya Mutic <62064527+mmutic@users.noreply.github.com> Date: Mon, 22 Apr 2024 16:32:08 -0400 Subject: [PATCH 25/61] Add full_time_series_reconstruction.jl --- .../full_time_series_reconstruction.jl | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/time_domain_reduction/full_time_series_reconstruction.jl diff --git a/src/time_domain_reduction/full_time_series_reconstruction.jl b/src/time_domain_reduction/full_time_series_reconstruction.jl new file mode 100644 index 0000000000..a81e7fa264 --- /dev/null +++ b/src/time_domain_reduction/full_time_series_reconstruction.jl @@ -0,0 +1,71 @@ +@doc raw"""reconstruction(case::AbstractString, + DF::DataFrame) +Create a DataFrame with all 8,760 hours of the year from the reduced output. + +case - folder for the case +DF - DataFrame to be reconstructed + +This function uses Period_map.csv to create a new DataFrame with 8,760 time steps, as well as other pre-existing rows such as "Zone". +For each 52 weeks of the year, the corresponding representative week is taken from the input DataFrame and copied into the new DataFrame. Representative periods that +represent more than one week will appear multiple times in the output. + +Note: Currently, TDR only gives the representative periods in Period_map for 52 weeks, when a (non-leap) year is 52 weeks + 24 hours. This function takes the last 24 hours of +the time series and copies them to get up to all 8,760 hours in a year. + +This function is called when output files with time series data (e.g. power.csv, emissions.csv) are created, if the setup key "OutputFullTimeSeries" is set to "1". + +""" +function reconstruction(case::AbstractString,DF::DataFrame) + settings_path = GenX.get_settings_path(case) + + # Read Period map file Period_map.csv + Period_map = CSV.read(joinpath(case,"TDR_results/Period_map.csv"),DataFrame) + + # Read time domain reduction settings file time_domain_reduction_settings.yml + myTDRsetup = YAML.load(open(joinpath(settings_path, + "time_domain_reduction_settings.yml"))) + + # Define Timesteps per Representative Period and Weight Total + TimestepsPerRepPeriod = myTDRsetup["TimestepsPerRepPeriod"] + WeightTotal = myTDRsetup["WeightTotal"] + + # Calculate the number of total periods the original time series was split into (will usually be 52) + numPeriods = floor(Int,WeightTotal/TimestepsPerRepPeriod) + + # Get the names of the input DataFrame + DFnames = names(DF) + + # Initialize an array to add the reconstructed data to + recon = ["t$t" for t in 1:TimestepsPerRepPeriod*numPeriods] + + # Find the index of the row with the first time step + t1 = findfirst(x -> x == "t1",DF[!,1]) + + # Reconstruction of all hours of the year from TDR + for j in range(2,ncol(DF)) + col = DF[t1:end,j] + col_name = DFnames[j] + recon_col = [] + for i in range(1,numPeriods) + index = Period_map[i,"Rep_Period_Index"] + recon_temp = col[(TimestepsPerRepPeriod*index-(TimestepsPerRepPeriod-1)):(TimestepsPerRepPeriod*index)] + recon_col = [recon_col; recon_temp] + end + recon = [recon recon_col] + end + reconDF = DataFrame(recon, DFnames) + + # Insert rows that were above "t1" in the original DataFrame (e.g. "Zone" and "AnnualSum") if present + for i in range(1,t1-1) + insert!(reconDF,i,DF[i,1:end]) + end + + # Repeat the last rows of the year to fill in the gap (should be 24 hours for non-leap year) + end_diff = WeightTotal - nrow(reconDF) + 1 + new_rows = reconDF[(nrow(reconDF)-end_diff):nrow(reconDF),2:end] + new_rows[!,"Resource"] = ["t$t" for t in (WeightTotal-end_diff):WeightTotal] + + reconDF = [reconDF; new_rows] + + return reconDF +end \ No newline at end of file From 9b1f0ed6c3044d7374ea7acfa78953e2d0113d7e Mon Sep 17 00:00:00 2001 From: Maya Mutic Date: Mon, 22 Apr 2024 16:35:07 -0400 Subject: [PATCH 26/61] Added setup key --- src/configure_settings/configure_settings.jl | 2 ++ src/write_outputs/write_outputs.jl | 11 ++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/configure_settings/configure_settings.jl b/src/configure_settings/configure_settings.jl index 1251789702..dcfc13bd3c 100644 --- a/src/configure_settings/configure_settings.jl +++ b/src/configure_settings/configure_settings.jl @@ -16,6 +16,8 @@ function default_settings() "UCommit" => 0, "TimeDomainReduction" => 0, "TimeDomainReductionFolder" => "TDR_results", + "OutputFullTimeSeries" => 0, + "OutputFullTimeSeriesFolder" => "Full_TimeSeries", "ModelingToGenerateAlternatives" => 0, "ModelingtoGenerateAlternativeSlack" => 0.1, "MGAAnnualGeneration" => 0, diff --git a/src/write_outputs/write_outputs.jl b/src/write_outputs/write_outputs.jl index 2275174ccc..2a08172ee9 100644 --- a/src/write_outputs/write_outputs.jl +++ b/src/write_outputs/write_outputs.jl @@ -503,15 +503,16 @@ function write_fulltimeseries(fullpath::AbstractString, total = DataFrame(["Total" 0 sum(dfOut[!, :AnnualSum]) fill(0.0, (1, T))], auxNew_Names) total[!, 4:(T + 3)] .= sum(dataOut, dims = 1) dfOut = vcat(dfOut, total) + + if setup["OutputFullTimeSeries"] + dfOut_full = reconstruction(case, dftranspose(dfOut, false)) + CSV.write(fullpath/FullTimeSeries, dfOut_full, writeheader = false) + end + CSV.write(fullpath, dftranspose(dfOut, false), writeheader = false) return nothing end -""" - write_settings_file(path, setup) - -Internal function for writing settings files -""" function write_settings_file(path, setup) YAML.write_file(joinpath(path, "run_settings.yml"), setup) end From d8785e7da529430b5dee33918d82f298cf19a4f0 Mon Sep 17 00:00:00 2001 From: Maya Mutic Date: Thu, 2 May 2024 15:02:07 -0400 Subject: [PATCH 27/61] Updates --- .../1_three_zones/settings/genx_settings.yml | 2 +- src/GenX.jl | 1 + .../full_time_series_reconstruction.jl | 38 ++++++++++--------- .../transmission/write_transmission_flows.jl | 9 +++++ .../transmission/write_transmission_losses.jl | 10 +++++ src/write_outputs/ucommit/write_commit.jl | 15 ++++++++ src/write_outputs/ucommit/write_shutdown.jl | 9 +++++ src/write_outputs/ucommit/write_start.jl | 9 +++++ src/write_outputs/write_charge.jl | 11 ++++++ src/write_outputs/write_curtailment.jl | 8 ++++ src/write_outputs/write_emissions.jl | 10 +++++ src/write_outputs/write_nse.jl | 9 +++++ src/write_outputs/write_outputs.jl | 12 +++--- src/write_outputs/write_power.jl | 8 ++++ src/write_outputs/write_power_balance.jl | 12 ++++++ src/write_outputs/write_price.jl | 9 +++++ src/write_outputs/write_reliability.jl | 10 +++++ src/write_outputs/write_storage.jl | 10 +++++ src/write_outputs/write_storagedual.jl | 10 +++++ 19 files changed, 178 insertions(+), 24 deletions(-) diff --git a/example_systems/1_three_zones/settings/genx_settings.yml b/example_systems/1_three_zones/settings/genx_settings.yml index 278270baac..191225e185 100644 --- a/example_systems/1_three_zones/settings/genx_settings.yml +++ b/example_systems/1_three_zones/settings/genx_settings.yml @@ -10,4 +10,4 @@ ParameterScale: 1 # Turn on parameter scaling wherein demand, capacity and power WriteShadowPrices: 1 # Write shadow prices of LP or relaxed MILP; 0 = not active; 1 = active UCommit: 2 # Unit committment of thermal power plants; 0 = not active; 1 = active using integer clestering; 2 = active using linearized clustering TimeDomainReduction: 1 # Time domain reduce (i.e. cluster) inputs based on Demand_data.csv, Generators_variability.csv, and Fuels_data.csv; 0 = not active (use input data as provided); 0 = active (cluster input data, or use data that has already been clustered) -OutputFullTimeSeries: 1 \ No newline at end of file +OutputFullTimeSeries: 1 diff --git a/src/GenX.jl b/src/GenX.jl index 73812acc1b..07e56c95c4 100644 --- a/src/GenX.jl +++ b/src/GenX.jl @@ -72,6 +72,7 @@ include_all_in_folder("write_outputs") include("time_domain_reduction/time_domain_reduction.jl") include("time_domain_reduction/precluster.jl") +include("time_domain_reduction/full_time_series_reconstruction.jl") include_all_in_folder("multi_stage") include_all_in_folder("additional_tools") diff --git a/src/time_domain_reduction/full_time_series_reconstruction.jl b/src/time_domain_reduction/full_time_series_reconstruction.jl index a81e7fa264..a0dad433d7 100644 --- a/src/time_domain_reduction/full_time_series_reconstruction.jl +++ b/src/time_domain_reduction/full_time_series_reconstruction.jl @@ -2,7 +2,7 @@ DF::DataFrame) Create a DataFrame with all 8,760 hours of the year from the reduced output. -case - folder for the case +setup - case setup (dictionary) DF - DataFrame to be reconstructed This function uses Period_map.csv to create a new DataFrame with 8,760 time steps, as well as other pre-existing rows such as "Zone". @@ -15,15 +15,14 @@ the time series and copies them to get up to all 8,760 hours in a year. This function is called when output files with time series data (e.g. power.csv, emissions.csv) are created, if the setup key "OutputFullTimeSeries" is set to "1". """ -function reconstruction(case::AbstractString,DF::DataFrame) - settings_path = GenX.get_settings_path(case) - - # Read Period map file Period_map.csv - Period_map = CSV.read(joinpath(case,"TDR_results/Period_map.csv"),DataFrame) +function full_time_series_reconstruction(path::AbstractString,setup::Dict,DF::DataFrame,DFnames::Vector) + # Read Period map file Period_map.csv + case = path[1:findlast('/',path)] + TDRpath = joinpath(case, setup["TimeDomainReductionFolder"]) + Period_map = CSV.read(joinpath(TDRpath,"Period_map.csv"),DataFrame) # Read time domain reduction settings file time_domain_reduction_settings.yml - myTDRsetup = YAML.load(open(joinpath(settings_path, - "time_domain_reduction_settings.yml"))) + myTDRsetup = YAML.load(open(joinpath(case,"settings/time_domain_reduction_settings.yml"))) # Define Timesteps per Representative Period and Weight Total TimestepsPerRepPeriod = myTDRsetup["TimestepsPerRepPeriod"] @@ -33,38 +32,43 @@ function reconstruction(case::AbstractString,DF::DataFrame) numPeriods = floor(Int,WeightTotal/TimestepsPerRepPeriod) # Get the names of the input DataFrame - DFnames = names(DF) - + DFMatrix = Matrix(DF) + #DFnames = DFMatrix[1,:] # Initialize an array to add the reconstructed data to recon = ["t$t" for t in 1:TimestepsPerRepPeriod*numPeriods] # Find the index of the row with the first time step t1 = findfirst(x -> x == "t1",DF[!,1]) - + + reconDF = DataFrame() + #names1 = [Symbol(DFnames[1])] # Reconstruction of all hours of the year from TDR for j in range(2,ncol(DF)) col = DF[t1:end,j] - col_name = DFnames[j] + #col_name = DFnames[j] + #names1 = [names1 Symbol(col_name)] recon_col = [] for i in range(1,numPeriods) index = Period_map[i,"Rep_Period_Index"] recon_temp = col[(TimestepsPerRepPeriod*index-(TimestepsPerRepPeriod-1)):(TimestepsPerRepPeriod*index)] recon_col = [recon_col; recon_temp] end + #reconDF[!,col_name] = recon_col recon = [recon recon_col] end - reconDF = DataFrame(recon, DFnames) + reconDF = DataFrame(recon, DFnames, makeunique=true) + #auxNew_Names = [Symbol("Resource"); Symbol("Zone"); [Symbol("t$t") for t in 1:T]] + #rename!(reconDF,names1) # Insert rows that were above "t1" in the original DataFrame (e.g. "Zone" and "AnnualSum") if present for i in range(1,t1-1) - insert!(reconDF,i,DF[i,1:end]) + insert!(reconDF,i,DFMatrix[i,1:end],promote=true) end # Repeat the last rows of the year to fill in the gap (should be 24 hours for non-leap year) end_diff = WeightTotal - nrow(reconDF) + 1 - new_rows = reconDF[(nrow(reconDF)-end_diff):nrow(reconDF),2:end] - new_rows[!,"Resource"] = ["t$t" for t in (WeightTotal-end_diff):WeightTotal] - + new_rows = reconDF[(nrow(reconDF)-end_diff):nrow(reconDF),1:end] + new_rows[!,1] = ["t$t" for t in (WeightTotal-end_diff):WeightTotal] reconDF = [reconDF; new_rows] return reconDF diff --git a/src/write_outputs/transmission/write_transmission_flows.jl b/src/write_outputs/transmission/write_transmission_flows.jl index dbdaec2e4f..2519f2c087 100644 --- a/src/write_outputs/transmission/write_transmission_flows.jl +++ b/src/write_outputs/transmission/write_transmission_flows.jl @@ -23,6 +23,15 @@ function write_transmission_flows(path::AbstractString, auxNew_Names = [Symbol("Line"); [Symbol("t$t") for t in 1:T]] rename!(dfFlow, auxNew_Names) CSV.write(filepath, dftranspose(dfFlow, false), writeheader = false) + + if setup["OutputFullTimeSeries"] == 1 + DFnames = ["Line","1","2"] + FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] + output_path = joinpath(path,FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfFlow, false), DFnames) + CSV.write(joinpath(output_path,"flow.csv"), dfOut_full) + println("Writing Full Time Series for Transmission Flows") + end end return nothing end diff --git a/src/write_outputs/transmission/write_transmission_losses.jl b/src/write_outputs/transmission/write_transmission_losses.jl index 1e4bf164bf..6a59cbb792 100644 --- a/src/write_outputs/transmission/write_transmission_losses.jl +++ b/src/write_outputs/transmission/write_transmission_losses.jl @@ -30,6 +30,16 @@ function write_transmission_losses(path::AbstractString, CSV.write(joinpath(path, "tlosses.csv"), dftranspose(dfTLosses, false), writeheader = false) + + if setup["OutputFullTimeSeries"] == 1 + DFnames = ["Line", "1", "2", "Total"] + FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] + output_path = joinpath(path,FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfTLosses, false), DFnames) + CSV.write(joinpath(output_path,"tlosses.csv"), dfOut_full) + println("Writing Full Time Series for Time Losses") + end + end return nothing end diff --git a/src/write_outputs/ucommit/write_commit.jl b/src/write_outputs/ucommit/write_commit.jl index bf8e712640..b757492d70 100644 --- a/src/write_outputs/ucommit/write_commit.jl +++ b/src/write_outputs/ucommit/write_commit.jl @@ -11,4 +11,19 @@ function write_commit(path::AbstractString, inputs::Dict, setup::Dict, EP::Model auxNew_Names = [Symbol("Resource"); Symbol("Zone"); [Symbol("t$t") for t in 1:T]] rename!(dfCommit, auxNew_Names) CSV.write(joinpath(path, "commit.csv"), dftranspose(dfCommit, false), header = false) + println("-------------------------------") + println("PATH = ", path) + println("-------------------------------") + + + if setup["OutputFullTimeSeries"] == 1 + DFMatrix = Matrix(dftranspose(dfCommit, true)) + DFnames = DFMatrix[1,:] + FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] + output_path = joinpath(path,FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfCommit, true), DFnames) + CSV.write(joinpath(output_path,"commit.csv"), dfOut_full) + println("Writing Full Time Series for Commitment") + end + end diff --git a/src/write_outputs/ucommit/write_shutdown.jl b/src/write_outputs/ucommit/write_shutdown.jl index 8a726a3367..c64db9bedd 100644 --- a/src/write_outputs/ucommit/write_shutdown.jl +++ b/src/write_outputs/ucommit/write_shutdown.jl @@ -14,6 +14,15 @@ function write_shutdown(path::AbstractString, inputs::Dict, setup::Dict, EP::Mod write_annual(filepath, dfShutdown) else # setup["WriteOutputs"] == "full" write_fulltimeseries(filepath, shut, dfShutdown) + + if setup["OutputFullTimeSeries"] == 1 + df_Shutdown = CSV.read(joinpath(path,"shutdown.csv"),DataFrame) + FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] + output_path = joinpath(path,FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction(path,setup, df_Shutdown,names(df_Shutdown)) + CSV.write(joinpath(output_path,"shutdown.csv"), dfOut_full) + println("Writing Full Time Series for Shutdown") + end end return nothing end diff --git a/src/write_outputs/ucommit/write_start.jl b/src/write_outputs/ucommit/write_start.jl index be23be46bd..0362faff1d 100644 --- a/src/write_outputs/ucommit/write_start.jl +++ b/src/write_outputs/ucommit/write_start.jl @@ -13,6 +13,15 @@ function write_start(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) write_annual(filepath, dfStart) else # setup["WriteOutputs"] == "full" write_fulltimeseries(filepath, start, dfStart) + + if setup["OutputFullTimeSeries"] == 1 + df_Start = CSV.read(joinpath(path,"start.csv"),DataFrame) + FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] + output_path = joinpath(path,FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction(path,setup, df_Start,names(df_Start)) + CSV.write(joinpath(output_path,"start.csv"), dfOut_full) + println("Writing Full Time Series for Startup") + end end return nothing end diff --git a/src/write_outputs/write_charge.jl b/src/write_outputs/write_charge.jl index 1e0e835633..f43f5ec5f9 100644 --- a/src/write_outputs/write_charge.jl +++ b/src/write_outputs/write_charge.jl @@ -42,6 +42,17 @@ function write_charge(path::AbstractString, inputs::Dict, setup::Dict, EP::Model write_annual(filepath, dfCharge) else # setup["WriteOutputs"] == "full" write_fulltimeseries(filepath, charge, dfCharge) + if setup["OutputFullTimeSeries"] == 1 + df_Charge = CSV.read(joinpath(path,"charge.csv"),DataFrame) + FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] + output_path = joinpath(path,FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction(path,setup, df_Charge,names(df_Charge)) + CSV.write(joinpath(output_path,"charge.csv"), dfOut_full) + println("Writing Full Time Series for Charge") + end end + + + return nothing end diff --git a/src/write_outputs/write_curtailment.jl b/src/write_outputs/write_curtailment.jl index 8ee244f105..f7fa3bf20e 100644 --- a/src/write_outputs/write_curtailment.jl +++ b/src/write_outputs/write_curtailment.jl @@ -58,6 +58,14 @@ function write_curtailment(path::AbstractString, inputs::Dict, setup::Dict, EP:: write_annual(filename, dfCurtailment) else # setup["WriteOutputs"] == "full" write_fulltimeseries(filename, curtailment, dfCurtailment) + if setup["OutputFullTimeSeries"] == 1 + df_Curtail = CSV.read(joinpath(path,"curtail.csv"),DataFrame) + FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] + output_path = joinpath(path,FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction(path,setup, df_Curtail,names(df_Curtail)) + CSV.write(joinpath(output_path,"curtail.csv"), dfOut_full) + println("Writing Full Time Series for Curtailment") + end end return nothing end diff --git a/src/write_outputs/write_emissions.jl b/src/write_outputs/write_emissions.jl index 43c040a65e..93dae3b971 100644 --- a/src/write_outputs/write_emissions.jl +++ b/src/write_outputs/write_emissions.jl @@ -124,6 +124,16 @@ function write_emissions(path::AbstractString, inputs::Dict, setup::Dict, EP::Mo CSV.write(joinpath(path, "emissions.csv"), dftranspose(dfEmissions, false), writeheader = false) + + if setup["OutputFullTimeSeries"] == 1 + DFMatrix = Matrix(dftranspose(dfEmissions, true)) + DFnames = DFMatrix[1,:] + FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] + output_path = joinpath(path,FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfEmissions, false), DFnames) + CSV.write(joinpath(output_path,"emissions.csv"), dfOut_full) + println("Writing Full Time Series for Emissions") + end end end return nothing diff --git a/src/write_outputs/write_nse.jl b/src/write_outputs/write_nse.jl index c906624e4b..41931abbea 100644 --- a/src/write_outputs/write_nse.jl +++ b/src/write_outputs/write_nse.jl @@ -37,6 +37,15 @@ function write_nse(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) dfNse = vcat(dfNse, total) CSV.write(joinpath(path, "nse.csv"), dftranspose(dfNse, false), writeheader = false) + + if setup["OutputFullTimeSeries"] == 1 + DFnames = ["Segment","1","2","3","4","1","2","3","4","1","2","3","4","Total"] + FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] + output_path = joinpath(path,FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfNse, false), DFnames) + CSV.write(joinpath(output_path,"nse.csv"), dfOut_full) + println("Writing Full Time Series for NSE") + end end return nothing end diff --git a/src/write_outputs/write_outputs.jl b/src/write_outputs/write_outputs.jl index 2a08172ee9..e197a6a936 100644 --- a/src/write_outputs/write_outputs.jl +++ b/src/write_outputs/write_outputs.jl @@ -23,6 +23,10 @@ function write_outputs(EP::Model, path::AbstractString, setup::Dict, inputs::Dic mkpath(path) end + if setup["OutputFullTimeSeries"] == 1 + mkpath(joinpath(path,setup["OutputFullTimeSeriesFolder"])) + end + # https://jump.dev/MathOptInterface.jl/v0.9.10/apireference/#MathOptInterface.TerminationStatusCode status = termination_status(EP) @@ -73,6 +77,7 @@ function write_outputs(EP::Model, path::AbstractString, setup::Dict, inputs::Dic elapsed_time_power = @elapsed dfPower = write_power(path, inputs, setup, EP) println("Time elapsed for writing power is") println(elapsed_time_power) + println("Here") end if output_settings_d["WriteCharge"] @@ -175,7 +180,7 @@ function write_outputs(EP::Model, path::AbstractString, setup::Dict, inputs::Dic if setup["UCommit"] >= 1 if output_settings_d["WriteCommit"] elapsed_time_commit = @elapsed write_commit(path, inputs, setup, EP) - println("Time elapsed for writing commitment is") + println("Time elapsed for writing commitment is ") println(elapsed_time_commit) end @@ -504,11 +509,6 @@ function write_fulltimeseries(fullpath::AbstractString, total[!, 4:(T + 3)] .= sum(dataOut, dims = 1) dfOut = vcat(dfOut, total) - if setup["OutputFullTimeSeries"] - dfOut_full = reconstruction(case, dftranspose(dfOut, false)) - CSV.write(fullpath/FullTimeSeries, dfOut_full, writeheader = false) - end - CSV.write(fullpath, dftranspose(dfOut, false), writeheader = false) return nothing end diff --git a/src/write_outputs/write_power.jl b/src/write_outputs/write_power.jl index 30e14048be..aaba847382 100644 --- a/src/write_outputs/write_power.jl +++ b/src/write_outputs/write_power.jl @@ -25,6 +25,14 @@ function write_power(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) write_annual(filepath, dfPower) else # setup["WriteOutputs"] == "full" write_fulltimeseries(filepath, power, dfPower) + if setup["OutputFullTimeSeries"] == 1 + df_Power = CSV.read(joinpath(path,"power.csv"),DataFrame) + FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] + output_path = joinpath(path,FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction(path,setup, df_Power,names(df_Power)) + CSV.write(joinpath(output_path,"power.csv"), dfOut_full) + println("Writing Full Time Series for Power") + end end return dfPower #Shouldn't this be return nothing diff --git a/src/write_outputs/write_power_balance.jl b/src/write_outputs/write_power_balance.jl index e96a320ebb..e0d3bc49d2 100644 --- a/src/write_outputs/write_power_balance.jl +++ b/src/write_outputs/write_power_balance.jl @@ -96,6 +96,18 @@ function write_power_balance(path::AbstractString, inputs::Dict, setup::Dict, EP CSV.write(joinpath(path, "power_balance.csv"), dftranspose(dfPowerBalance, false), writeheader = false) + + if setup["OutputFullTimeSeries"] == 1 + DFnames = dfPowerBalance[:,1] + insert!(DFnames,1,"BalanceComponent") + #DFMatrix = Matrix(dftranspose(dfPowerBalance, true)) + # DFnames = DFMatrix[1,:] + FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] + output_path = joinpath(path,FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfPowerBalance, false),DFnames) + CSV.write(joinpath(output_path,"power_balance.csv"), dfOut_full) + println("Writing Full Time Series for Power Balance") + end end return nothing end diff --git a/src/write_outputs/write_price.jl b/src/write_outputs/write_price.jl index 05943c8fa8..a502fc799a 100644 --- a/src/write_outputs/write_price.jl +++ b/src/write_outputs/write_price.jl @@ -21,6 +21,15 @@ function write_price(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) CSV.write(joinpath(path, "prices.csv"), dftranspose(dfPrice, false), writeheader = false) + + if setup["OutputFullTimeSeries"] == 1 + DFnames = ["Zone", "1", "2", "3"] + FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] + output_path = joinpath(path,FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfPrice, false), DFnames) + CSV.write(joinpath(output_path,"prices.csv"), dfOut_full) + println("Writing Full Time Series for Price") + end return nothing end diff --git a/src/write_outputs/write_reliability.jl b/src/write_outputs/write_reliability.jl index 876465f8b7..588db64993 100644 --- a/src/write_outputs/write_reliability.jl +++ b/src/write_outputs/write_reliability.jl @@ -20,4 +20,14 @@ function write_reliability(path::AbstractString, inputs::Dict, setup::Dict, EP:: CSV.write(joinpath(path, "reliability.csv"), dftranspose(dfReliability, false), header = false) + + if setup["OutputFullTimeSeries"] == 1 + DFMatrix = Matrix(dftranspose(dfReliability, true)) + DFnames = ["Zone", "1", "2", "3"] + FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] + output_path = joinpath(path,FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfReliability, false), DFnames) + CSV.write(joinpath(output_path,"reliability.csv"), dfOut_full) + println("Writing Full Time Series for Reliability") + end end diff --git a/src/write_outputs/write_storage.jl b/src/write_outputs/write_storage.jl index a34c470108..b2461df762 100644 --- a/src/write_outputs/write_storage.jl +++ b/src/write_outputs/write_storage.jl @@ -39,4 +39,14 @@ function write_storage(path::AbstractString, inputs::Dict, setup::Dict, EP::Mode auxNew_Names = [Symbol("Resource"); Symbol("Zone"); [Symbol("t$t") for t in 1:T]] rename!(dfStorage, auxNew_Names) CSV.write(joinpath(path, "storage.csv"), dftranspose(dfStorage, false), header = false) + + if setup["OutputFullTimeSeries"] == 1 + DFMatrix = Matrix(dftranspose(dfStorage, true)) + DFnames = DFMatrix[1,:] + FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] + output_path = joinpath(path,FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfStorage, false), DFnames) + CSV.write(joinpath(output_path,"storage.csv"), dfOut_full) + println("Writing Full Time Series for Storage") + end end diff --git a/src/write_outputs/write_storagedual.jl b/src/write_outputs/write_storagedual.jl index 5b1eced203..24773246e7 100644 --- a/src/write_outputs/write_storagedual.jl +++ b/src/write_outputs/write_storagedual.jl @@ -79,4 +79,14 @@ function write_storagedual(path::AbstractString, inputs::Dict, setup::Dict, EP:: CSV.write(joinpath(path, "storagebal_duals.csv"), dftranspose(dfStorageDual, false), header = false) + + if setup["OutputFullTimeSeries"] == 1 + DFMatrix = Matrix(dftranspose(dfStorageDual, true)) + DFnames = DFMatrix[1,:] + FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] + output_path = joinpath(path,FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfStorageDual, false), DFnames) + CSV.write(joinpath(output_path,"storagebal_duals.csv"), dfOut_full) + println("Writing Full Time Series for Storage Duals") + end end From 5d0b5c52d43a15c12007c4435ba296aecfe1d99a Mon Sep 17 00:00:00 2001 From: Maya Mutic Date: Thu, 2 May 2024 18:09:02 -0400 Subject: [PATCH 28/61] Minor notes --- .../full_time_series_reconstruction.jl | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/time_domain_reduction/full_time_series_reconstruction.jl b/src/time_domain_reduction/full_time_series_reconstruction.jl index a0dad433d7..015ae82f2c 100644 --- a/src/time_domain_reduction/full_time_series_reconstruction.jl +++ b/src/time_domain_reduction/full_time_series_reconstruction.jl @@ -1,9 +1,13 @@ -@doc raw"""reconstruction(case::AbstractString, - DF::DataFrame) +@doc raw"""full_time_series_reconstruction(path::AbstractString, + case::AbstractString, + DF::DataFrame, + DFnames::Vector) Create a DataFrame with all 8,760 hours of the year from the reduced output. +path - setup - case setup (dictionary) DF - DataFrame to be reconstructed +DFnames - Vector of column names This function uses Period_map.csv to create a new DataFrame with 8,760 time steps, as well as other pre-existing rows such as "Zone". For each 52 weeks of the year, the corresponding representative week is taken from the input DataFrame and copied into the new DataFrame. Representative periods that @@ -15,6 +19,12 @@ the time series and copies them to get up to all 8,760 hours in a year. This function is called when output files with time series data (e.g. power.csv, emissions.csv) are created, if the setup key "OutputFullTimeSeries" is set to "1". """ +# TO DO: +# Add docstring, no example needed +# Add in a TDR check +# Try header = false in CSV.write +# Try transpose to get duplicated column names +# Look into mybinder function full_time_series_reconstruction(path::AbstractString,setup::Dict,DF::DataFrame,DFnames::Vector) # Read Period map file Period_map.csv case = path[1:findlast('/',path)] @@ -33,15 +43,14 @@ function full_time_series_reconstruction(path::AbstractString,setup::Dict,DF::Da # Get the names of the input DataFrame DFMatrix = Matrix(DF) - #DFnames = DFMatrix[1,:] + # Initialize an array to add the reconstructed data to recon = ["t$t" for t in 1:TimestepsPerRepPeriod*numPeriods] # Find the index of the row with the first time step t1 = findfirst(x -> x == "t1",DF[!,1]) - reconDF = DataFrame() - #names1 = [Symbol(DFnames[1])] + # Reconstruction of all hours of the year from TDR for j in range(2,ncol(DF)) col = DF[t1:end,j] @@ -50,14 +59,14 @@ function full_time_series_reconstruction(path::AbstractString,setup::Dict,DF::Da recon_col = [] for i in range(1,numPeriods) index = Period_map[i,"Rep_Period_Index"] - recon_temp = col[(TimestepsPerRepPeriod*index-(TimestepsPerRepPeriod-1)):(TimestepsPerRepPeriod*index)] + recon_temp = col[(TimestepsPerRepPeriod*index-(TimestepsPerRepPeriod-1)):(TimestepsPerRepPeriod*index)] # Describe how this works recon_col = [recon_col; recon_temp] end #reconDF[!,col_name] = recon_col recon = [recon recon_col] end reconDF = DataFrame(recon, DFnames, makeunique=true) - #auxNew_Names = [Symbol("Resource"); Symbol("Zone"); [Symbol("t$t") for t in 1:T]] + #rename!(reconDF,names1) # Insert rows that were above "t1" in the original DataFrame (e.g. "Zone" and "AnnualSum") if present From 9bc0bc5fc0ff6ab8b918fd3b434d77cfc82be341 Mon Sep 17 00:00:00 2001 From: Maya Mutic Date: Wed, 8 May 2024 21:03:08 -0400 Subject: [PATCH 29/61] Updates --- .../full_time_series_reconstruction.jl | 5 +---- .../transmission/write_transmission_flows.jl | 4 ++-- .../transmission/write_transmission_losses.jl | 4 ++-- src/write_outputs/ucommit/write_commit.jl | 6 +++--- src/write_outputs/ucommit/write_shutdown.jl | 2 +- src/write_outputs/ucommit/write_start.jl | 2 +- src/write_outputs/write_charge.jl | 2 +- src/write_outputs/write_co2.jl | 9 +++++++++ src/write_outputs/write_curtailment.jl | 2 +- src/write_outputs/write_emissions.jl | 2 +- src/write_outputs/write_fuel_consumption.jl | 10 ++++++++++ src/write_outputs/write_nse.jl | 4 ++-- src/write_outputs/write_power.jl | 2 +- src/write_outputs/write_power_balance.jl | 4 ++-- src/write_outputs/write_price.jl | 4 ++-- src/write_outputs/write_reliability.jl | 5 ++--- src/write_outputs/write_storage.jl | 4 ++-- src/write_outputs/write_storagedual.jl | 4 ++-- 18 files changed, 45 insertions(+), 30 deletions(-) diff --git a/src/time_domain_reduction/full_time_series_reconstruction.jl b/src/time_domain_reduction/full_time_series_reconstruction.jl index 015ae82f2c..f483eaaa20 100644 --- a/src/time_domain_reduction/full_time_series_reconstruction.jl +++ b/src/time_domain_reduction/full_time_series_reconstruction.jl @@ -4,7 +4,7 @@ DFnames::Vector) Create a DataFrame with all 8,760 hours of the year from the reduced output. -path - +path - Path input to the results folder setup - case setup (dictionary) DF - DataFrame to be reconstructed DFnames - Vector of column names @@ -20,10 +20,7 @@ This function is called when output files with time series data (e.g. power.csv, """ # TO DO: -# Add docstring, no example needed # Add in a TDR check -# Try header = false in CSV.write -# Try transpose to get duplicated column names # Look into mybinder function full_time_series_reconstruction(path::AbstractString,setup::Dict,DF::DataFrame,DFnames::Vector) # Read Period map file Period_map.csv diff --git a/src/write_outputs/transmission/write_transmission_flows.jl b/src/write_outputs/transmission/write_transmission_flows.jl index 2519f2c087..b143496b69 100644 --- a/src/write_outputs/transmission/write_transmission_flows.jl +++ b/src/write_outputs/transmission/write_transmission_flows.jl @@ -24,12 +24,12 @@ function write_transmission_flows(path::AbstractString, rename!(dfFlow, auxNew_Names) CSV.write(filepath, dftranspose(dfFlow, false), writeheader = false) - if setup["OutputFullTimeSeries"] == 1 + if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 DFnames = ["Line","1","2"] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path,FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfFlow, false), DFnames) - CSV.write(joinpath(output_path,"flow.csv"), dfOut_full) + CSV.write(joinpath(output_path,"flow.csv"), dfOut_full, header = false) println("Writing Full Time Series for Transmission Flows") end end diff --git a/src/write_outputs/transmission/write_transmission_losses.jl b/src/write_outputs/transmission/write_transmission_losses.jl index 6a59cbb792..8dc15f7b28 100644 --- a/src/write_outputs/transmission/write_transmission_losses.jl +++ b/src/write_outputs/transmission/write_transmission_losses.jl @@ -31,12 +31,12 @@ function write_transmission_losses(path::AbstractString, dftranspose(dfTLosses, false), writeheader = false) - if setup["OutputFullTimeSeries"] == 1 + if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 DFnames = ["Line", "1", "2", "Total"] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path,FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfTLosses, false), DFnames) - CSV.write(joinpath(output_path,"tlosses.csv"), dfOut_full) + CSV.write(joinpath(output_path,"tlosses.csv"), dfOut_full, header = false) println("Writing Full Time Series for Time Losses") end diff --git a/src/write_outputs/ucommit/write_commit.jl b/src/write_outputs/ucommit/write_commit.jl index b757492d70..1df95e1b99 100644 --- a/src/write_outputs/ucommit/write_commit.jl +++ b/src/write_outputs/ucommit/write_commit.jl @@ -16,13 +16,13 @@ function write_commit(path::AbstractString, inputs::Dict, setup::Dict, EP::Model println("-------------------------------") - if setup["OutputFullTimeSeries"] == 1 + if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 DFMatrix = Matrix(dftranspose(dfCommit, true)) DFnames = DFMatrix[1,:] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path,FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfCommit, true), DFnames) - CSV.write(joinpath(output_path,"commit.csv"), dfOut_full) + dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfCommit, false), DFnames) + CSV.write(joinpath(output_path,"commit.csv"), dfOut_full, header = false) println("Writing Full Time Series for Commitment") end diff --git a/src/write_outputs/ucommit/write_shutdown.jl b/src/write_outputs/ucommit/write_shutdown.jl index c64db9bedd..62b2e6e34f 100644 --- a/src/write_outputs/ucommit/write_shutdown.jl +++ b/src/write_outputs/ucommit/write_shutdown.jl @@ -15,7 +15,7 @@ function write_shutdown(path::AbstractString, inputs::Dict, setup::Dict, EP::Mod else # setup["WriteOutputs"] == "full" write_fulltimeseries(filepath, shut, dfShutdown) - if setup["OutputFullTimeSeries"] == 1 + if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 df_Shutdown = CSV.read(joinpath(path,"shutdown.csv"),DataFrame) FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path,FullTimeSeriesFolder) diff --git a/src/write_outputs/ucommit/write_start.jl b/src/write_outputs/ucommit/write_start.jl index 0362faff1d..c1ff25f886 100644 --- a/src/write_outputs/ucommit/write_start.jl +++ b/src/write_outputs/ucommit/write_start.jl @@ -14,7 +14,7 @@ function write_start(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) else # setup["WriteOutputs"] == "full" write_fulltimeseries(filepath, start, dfStart) - if setup["OutputFullTimeSeries"] == 1 + if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 df_Start = CSV.read(joinpath(path,"start.csv"),DataFrame) FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path,FullTimeSeriesFolder) diff --git a/src/write_outputs/write_charge.jl b/src/write_outputs/write_charge.jl index f43f5ec5f9..39827c5ff9 100644 --- a/src/write_outputs/write_charge.jl +++ b/src/write_outputs/write_charge.jl @@ -42,7 +42,7 @@ function write_charge(path::AbstractString, inputs::Dict, setup::Dict, EP::Model write_annual(filepath, dfCharge) else # setup["WriteOutputs"] == "full" write_fulltimeseries(filepath, charge, dfCharge) - if setup["OutputFullTimeSeries"] == 1 + if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 df_Charge = CSV.read(joinpath(path,"charge.csv"),DataFrame) FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path,FullTimeSeriesFolder) diff --git a/src/write_outputs/write_co2.jl b/src/write_outputs/write_co2.jl index a096dc55ab..729562425e 100644 --- a/src/write_outputs/write_co2.jl +++ b/src/write_outputs/write_co2.jl @@ -32,6 +32,15 @@ function write_co2_emissions_plant(path::AbstractString, write_annual(filepath, dfEmissions_plant) else # setup["WriteOutputs"] == "full" write_fulltimeseries(filepath, emissions_plant, dfEmissions_plant) + if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 + DFMatrix = Matrix(dftranspose(dfEmissions_plant, true)) + DFnames = DFMatrix[1,:] + FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] + output_path = joinpath(path,FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfEmissions_plant, false), DFnames) + CSV.write(joinpath(output_path,"emissions_plant.csv"), dfOut_full, header = false) + println("Writing Full Time Series for Emissions Plant") + end end return nothing end diff --git a/src/write_outputs/write_curtailment.jl b/src/write_outputs/write_curtailment.jl index f7fa3bf20e..777740c0bc 100644 --- a/src/write_outputs/write_curtailment.jl +++ b/src/write_outputs/write_curtailment.jl @@ -58,7 +58,7 @@ function write_curtailment(path::AbstractString, inputs::Dict, setup::Dict, EP:: write_annual(filename, dfCurtailment) else # setup["WriteOutputs"] == "full" write_fulltimeseries(filename, curtailment, dfCurtailment) - if setup["OutputFullTimeSeries"] == 1 + if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 df_Curtail = CSV.read(joinpath(path,"curtail.csv"),DataFrame) FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path,FullTimeSeriesFolder) diff --git a/src/write_outputs/write_emissions.jl b/src/write_outputs/write_emissions.jl index 93dae3b971..b53641bc6b 100644 --- a/src/write_outputs/write_emissions.jl +++ b/src/write_outputs/write_emissions.jl @@ -125,7 +125,7 @@ function write_emissions(path::AbstractString, inputs::Dict, setup::Dict, EP::Mo dftranspose(dfEmissions, false), writeheader = false) - if setup["OutputFullTimeSeries"] == 1 + if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 DFMatrix = Matrix(dftranspose(dfEmissions, true)) DFnames = DFMatrix[1,:] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] diff --git a/src/write_outputs/write_fuel_consumption.jl b/src/write_outputs/write_fuel_consumption.jl index a5f05f839a..4ff094289d 100644 --- a/src/write_outputs/write_fuel_consumption.jl +++ b/src/write_outputs/write_fuel_consumption.jl @@ -85,6 +85,16 @@ function write_fuel_consumption_ts(path::AbstractString, DataFrame(tempts, [Symbol("t$t") for t in 1:T])) CSV.write(joinpath(path, "FuelConsumption_plant_MMBTU.csv"), dftranspose(dfPlantFuel_TS, false), header = false) + + if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 + DFMatrix = Matrix(dftranspose(dfPlantFuel_TS, true)) + DFnames = DFMatrix[1,:] + FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] + output_path = joinpath(path,FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfPlantFuel_TS, false), DFnames) + CSV.write(joinpath(output_path,"commit.csv"), dfOut_full, header = false) + println("Writing Full Time Series for Fuel Consumption") + end end function write_fuel_consumption_tot(path::AbstractString, diff --git a/src/write_outputs/write_nse.jl b/src/write_outputs/write_nse.jl index 41931abbea..cf34845888 100644 --- a/src/write_outputs/write_nse.jl +++ b/src/write_outputs/write_nse.jl @@ -38,12 +38,12 @@ function write_nse(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) CSV.write(joinpath(path, "nse.csv"), dftranspose(dfNse, false), writeheader = false) - if setup["OutputFullTimeSeries"] == 1 + if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 DFnames = ["Segment","1","2","3","4","1","2","3","4","1","2","3","4","Total"] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path,FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfNse, false), DFnames) - CSV.write(joinpath(output_path,"nse.csv"), dfOut_full) + CSV.write(joinpath(output_path,"nse.csv"), dfOut_full, header = false) println("Writing Full Time Series for NSE") end end diff --git a/src/write_outputs/write_power.jl b/src/write_outputs/write_power.jl index aaba847382..a729136eec 100644 --- a/src/write_outputs/write_power.jl +++ b/src/write_outputs/write_power.jl @@ -25,7 +25,7 @@ function write_power(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) write_annual(filepath, dfPower) else # setup["WriteOutputs"] == "full" write_fulltimeseries(filepath, power, dfPower) - if setup["OutputFullTimeSeries"] == 1 + if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 df_Power = CSV.read(joinpath(path,"power.csv"),DataFrame) FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path,FullTimeSeriesFolder) diff --git a/src/write_outputs/write_power_balance.jl b/src/write_outputs/write_power_balance.jl index e0d3bc49d2..c574ae67aa 100644 --- a/src/write_outputs/write_power_balance.jl +++ b/src/write_outputs/write_power_balance.jl @@ -97,7 +97,7 @@ function write_power_balance(path::AbstractString, inputs::Dict, setup::Dict, EP dftranspose(dfPowerBalance, false), writeheader = false) - if setup["OutputFullTimeSeries"] == 1 + if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 DFnames = dfPowerBalance[:,1] insert!(DFnames,1,"BalanceComponent") #DFMatrix = Matrix(dftranspose(dfPowerBalance, true)) @@ -105,7 +105,7 @@ function write_power_balance(path::AbstractString, inputs::Dict, setup::Dict, EP FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path,FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfPowerBalance, false),DFnames) - CSV.write(joinpath(output_path,"power_balance.csv"), dfOut_full) + CSV.write(joinpath(output_path,"power_balance.csv"), dfOut_full, header = false) println("Writing Full Time Series for Power Balance") end end diff --git a/src/write_outputs/write_price.jl b/src/write_outputs/write_price.jl index a502fc799a..19547f9209 100644 --- a/src/write_outputs/write_price.jl +++ b/src/write_outputs/write_price.jl @@ -22,12 +22,12 @@ function write_price(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) dftranspose(dfPrice, false), writeheader = false) - if setup["OutputFullTimeSeries"] == 1 + if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 DFnames = ["Zone", "1", "2", "3"] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path,FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfPrice, false), DFnames) - CSV.write(joinpath(output_path,"prices.csv"), dfOut_full) + CSV.write(joinpath(output_path,"prices.csv"), dfOut_full, header = false) println("Writing Full Time Series for Price") end return nothing diff --git a/src/write_outputs/write_reliability.jl b/src/write_outputs/write_reliability.jl index 588db64993..0c9ce76694 100644 --- a/src/write_outputs/write_reliability.jl +++ b/src/write_outputs/write_reliability.jl @@ -21,13 +21,12 @@ function write_reliability(path::AbstractString, inputs::Dict, setup::Dict, EP:: dftranspose(dfReliability, false), header = false) - if setup["OutputFullTimeSeries"] == 1 - DFMatrix = Matrix(dftranspose(dfReliability, true)) + if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 DFnames = ["Zone", "1", "2", "3"] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path,FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfReliability, false), DFnames) - CSV.write(joinpath(output_path,"reliability.csv"), dfOut_full) + CSV.write(joinpath(output_path,"reliability.csv"), dfOut_full, header = false) println("Writing Full Time Series for Reliability") end end diff --git a/src/write_outputs/write_storage.jl b/src/write_outputs/write_storage.jl index b2461df762..9d78dd8bba 100644 --- a/src/write_outputs/write_storage.jl +++ b/src/write_outputs/write_storage.jl @@ -40,13 +40,13 @@ function write_storage(path::AbstractString, inputs::Dict, setup::Dict, EP::Mode rename!(dfStorage, auxNew_Names) CSV.write(joinpath(path, "storage.csv"), dftranspose(dfStorage, false), header = false) - if setup["OutputFullTimeSeries"] == 1 + if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 DFMatrix = Matrix(dftranspose(dfStorage, true)) DFnames = DFMatrix[1,:] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path,FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfStorage, false), DFnames) - CSV.write(joinpath(output_path,"storage.csv"), dfOut_full) + CSV.write(joinpath(output_path,"storage.csv"), dfOut_full, header = false) println("Writing Full Time Series for Storage") end end diff --git a/src/write_outputs/write_storagedual.jl b/src/write_outputs/write_storagedual.jl index 24773246e7..9f374b80e8 100644 --- a/src/write_outputs/write_storagedual.jl +++ b/src/write_outputs/write_storagedual.jl @@ -80,13 +80,13 @@ function write_storagedual(path::AbstractString, inputs::Dict, setup::Dict, EP:: dftranspose(dfStorageDual, false), header = false) - if setup["OutputFullTimeSeries"] == 1 + if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 DFMatrix = Matrix(dftranspose(dfStorageDual, true)) DFnames = DFMatrix[1,:] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path,FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfStorageDual, false), DFnames) - CSV.write(joinpath(output_path,"storagebal_duals.csv"), dfOut_full) + CSV.write(joinpath(output_path,"storagebal_duals.csv"), dfOut_full, header = false) println("Writing Full Time Series for Storage Duals") end end From a3374724e03ff4b8f41ca3948ace4acee1e9e4cf Mon Sep 17 00:00:00 2001 From: Maya Mutic Date: Thu, 16 May 2024 14:42:42 -0400 Subject: [PATCH 30/61] Update --- src/time_domain_reduction/full_time_series_reconstruction.jl | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/time_domain_reduction/full_time_series_reconstruction.jl b/src/time_domain_reduction/full_time_series_reconstruction.jl index f483eaaa20..c3632e5f73 100644 --- a/src/time_domain_reduction/full_time_series_reconstruction.jl +++ b/src/time_domain_reduction/full_time_series_reconstruction.jl @@ -19,9 +19,7 @@ the time series and copies them to get up to all 8,760 hours in a year. This function is called when output files with time series data (e.g. power.csv, emissions.csv) are created, if the setup key "OutputFullTimeSeries" is set to "1". """ -# TO DO: -# Add in a TDR check -# Look into mybinder + function full_time_series_reconstruction(path::AbstractString,setup::Dict,DF::DataFrame,DFnames::Vector) # Read Period map file Period_map.csv case = path[1:findlast('/',path)] From 259c0269037e29b4bff576ccc7e8d9614475dfbd Mon Sep 17 00:00:00 2001 From: Maya Mutic <62064527+mmutic@users.noreply.github.com> Date: Tue, 4 Jun 2024 17:35:48 -0400 Subject: [PATCH 31/61] Update src/time_domain_reduction/full_time_series_reconstruction.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../full_time_series_reconstruction.jl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/time_domain_reduction/full_time_series_reconstruction.jl b/src/time_domain_reduction/full_time_series_reconstruction.jl index c3632e5f73..5c1df6ea9a 100644 --- a/src/time_domain_reduction/full_time_series_reconstruction.jl +++ b/src/time_domain_reduction/full_time_series_reconstruction.jl @@ -20,9 +20,10 @@ This function is called when output files with time series data (e.g. power.csv, """ -function full_time_series_reconstruction(path::AbstractString,setup::Dict,DF::DataFrame,DFnames::Vector) - # Read Period map file Period_map.csv - case = path[1:findlast('/',path)] +function full_time_series_reconstruction( + path::AbstractString, setup::Dict, DF::DataFrame, DFnames::Vector) + # Read Period map file Period_map.csv + case = path[1:findlast('/', path)] TDRpath = joinpath(case, setup["TimeDomainReductionFolder"]) Period_map = CSV.read(joinpath(TDRpath,"Period_map.csv"),DataFrame) From c0b3aaa6706131322237dc30813e5675aed2221d Mon Sep 17 00:00:00 2001 From: Maya Mutic <62064527+mmutic@users.noreply.github.com> Date: Tue, 4 Jun 2024 17:35:58 -0400 Subject: [PATCH 32/61] Update src/time_domain_reduction/full_time_series_reconstruction.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/time_domain_reduction/full_time_series_reconstruction.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/time_domain_reduction/full_time_series_reconstruction.jl b/src/time_domain_reduction/full_time_series_reconstruction.jl index 5c1df6ea9a..8f8a7009cc 100644 --- a/src/time_domain_reduction/full_time_series_reconstruction.jl +++ b/src/time_domain_reduction/full_time_series_reconstruction.jl @@ -25,8 +25,8 @@ function full_time_series_reconstruction( # Read Period map file Period_map.csv case = path[1:findlast('/', path)] TDRpath = joinpath(case, setup["TimeDomainReductionFolder"]) - Period_map = CSV.read(joinpath(TDRpath,"Period_map.csv"),DataFrame) - + Period_map = CSV.read(joinpath(TDRpath, "Period_map.csv"), DataFrame) + # Read time domain reduction settings file time_domain_reduction_settings.yml myTDRsetup = YAML.load(open(joinpath(case,"settings/time_domain_reduction_settings.yml"))) From adc0978a571ac6078c8560d4f46d056c7b3da291 Mon Sep 17 00:00:00 2001 From: Maya Mutic <62064527+mmutic@users.noreply.github.com> Date: Tue, 4 Jun 2024 17:36:25 -0400 Subject: [PATCH 33/61] Update src/time_domain_reduction/full_time_series_reconstruction.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/time_domain_reduction/full_time_series_reconstruction.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/time_domain_reduction/full_time_series_reconstruction.jl b/src/time_domain_reduction/full_time_series_reconstruction.jl index 8f8a7009cc..42f777df61 100644 --- a/src/time_domain_reduction/full_time_series_reconstruction.jl +++ b/src/time_domain_reduction/full_time_series_reconstruction.jl @@ -28,8 +28,9 @@ function full_time_series_reconstruction( Period_map = CSV.read(joinpath(TDRpath, "Period_map.csv"), DataFrame) # Read time domain reduction settings file time_domain_reduction_settings.yml - myTDRsetup = YAML.load(open(joinpath(case,"settings/time_domain_reduction_settings.yml"))) - + myTDRsetup = YAML.load(open(joinpath( + case, "settings/time_domain_reduction_settings.yml"))) + # Define Timesteps per Representative Period and Weight Total TimestepsPerRepPeriod = myTDRsetup["TimestepsPerRepPeriod"] WeightTotal = myTDRsetup["WeightTotal"] From c42c4dc33be3639c23a7dba637d704550590805e Mon Sep 17 00:00:00 2001 From: Maya Mutic <62064527+mmutic@users.noreply.github.com> Date: Tue, 4 Jun 2024 17:36:34 -0400 Subject: [PATCH 34/61] Update src/time_domain_reduction/full_time_series_reconstruction.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/time_domain_reduction/full_time_series_reconstruction.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/time_domain_reduction/full_time_series_reconstruction.jl b/src/time_domain_reduction/full_time_series_reconstruction.jl index 42f777df61..3cd0f37ec5 100644 --- a/src/time_domain_reduction/full_time_series_reconstruction.jl +++ b/src/time_domain_reduction/full_time_series_reconstruction.jl @@ -34,7 +34,6 @@ function full_time_series_reconstruction( # Define Timesteps per Representative Period and Weight Total TimestepsPerRepPeriod = myTDRsetup["TimestepsPerRepPeriod"] WeightTotal = myTDRsetup["WeightTotal"] - # Calculate the number of total periods the original time series was split into (will usually be 52) numPeriods = floor(Int,WeightTotal/TimestepsPerRepPeriod) From 4a1dee0f555539c8a1755e6b26cdb1b12b172105 Mon Sep 17 00:00:00 2001 From: Maya Mutic <62064527+mmutic@users.noreply.github.com> Date: Tue, 4 Jun 2024 17:36:47 -0400 Subject: [PATCH 35/61] Update src/time_domain_reduction/full_time_series_reconstruction.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/time_domain_reduction/full_time_series_reconstruction.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/time_domain_reduction/full_time_series_reconstruction.jl b/src/time_domain_reduction/full_time_series_reconstruction.jl index 3cd0f37ec5..144035ace6 100644 --- a/src/time_domain_reduction/full_time_series_reconstruction.jl +++ b/src/time_domain_reduction/full_time_series_reconstruction.jl @@ -35,8 +35,8 @@ function full_time_series_reconstruction( TimestepsPerRepPeriod = myTDRsetup["TimestepsPerRepPeriod"] WeightTotal = myTDRsetup["WeightTotal"] # Calculate the number of total periods the original time series was split into (will usually be 52) - numPeriods = floor(Int,WeightTotal/TimestepsPerRepPeriod) - + numPeriods = floor(Int, WeightTotal / TimestepsPerRepPeriod) + # Get the names of the input DataFrame DFMatrix = Matrix(DF) From 9cf6a355227f6cbb243f7b3a93d66aad42657425 Mon Sep 17 00:00:00 2001 From: Maya Mutic <62064527+mmutic@users.noreply.github.com> Date: Tue, 4 Jun 2024 17:42:26 -0400 Subject: [PATCH 36/61] Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/time_domain_reduction/full_time_series_reconstruction.jl | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/time_domain_reduction/full_time_series_reconstruction.jl b/src/time_domain_reduction/full_time_series_reconstruction.jl index 144035ace6..026b26cb5b 100644 --- a/src/time_domain_reduction/full_time_series_reconstruction.jl +++ b/src/time_domain_reduction/full_time_series_reconstruction.jl @@ -39,10 +39,9 @@ function full_time_series_reconstruction( # Get the names of the input DataFrame DFMatrix = Matrix(DF) - # Initialize an array to add the reconstructed data to - recon = ["t$t" for t in 1:TimestepsPerRepPeriod*numPeriods] - + recon = ["t$t" for t in 1:(TimestepsPerRepPeriod * numPeriods)] + # Find the index of the row with the first time step t1 = findfirst(x -> x == "t1",DF[!,1]) From 27c3062242134e2924e2a311bcd26361d9f085d8 Mon Sep 17 00:00:00 2001 From: Maya Mutic <62064527+mmutic@users.noreply.github.com> Date: Tue, 4 Jun 2024 17:43:37 -0400 Subject: [PATCH 37/61] Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../full_time_series_reconstruction.jl | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/time_domain_reduction/full_time_series_reconstruction.jl b/src/time_domain_reduction/full_time_series_reconstruction.jl index 026b26cb5b..13a9da046c 100644 --- a/src/time_domain_reduction/full_time_series_reconstruction.jl +++ b/src/time_domain_reduction/full_time_series_reconstruction.jl @@ -43,24 +43,23 @@ function full_time_series_reconstruction( recon = ["t$t" for t in 1:(TimestepsPerRepPeriod * numPeriods)] # Find the index of the row with the first time step - t1 = findfirst(x -> x == "t1",DF[!,1]) - + t1 = findfirst(x -> x == "t1", DF[!, 1]) # Reconstruction of all hours of the year from TDR - for j in range(2,ncol(DF)) - col = DF[t1:end,j] + for j in range(2, ncol(DF)) + col = DF[t1:end, j] #col_name = DFnames[j] #names1 = [names1 Symbol(col_name)] recon_col = [] - for i in range(1,numPeriods) - index = Period_map[i,"Rep_Period_Index"] - recon_temp = col[(TimestepsPerRepPeriod*index-(TimestepsPerRepPeriod-1)):(TimestepsPerRepPeriod*index)] # Describe how this works + for i in range(1, numPeriods) + index = Period_map[i, "Rep_Period_Index"] + recon_temp = col[(TimestepsPerRepPeriod * index - (TimestepsPerRepPeriod - 1)):(TimestepsPerRepPeriod * index)] # Describe how this works recon_col = [recon_col; recon_temp] end #reconDF[!,col_name] = recon_col recon = [recon recon_col] end - reconDF = DataFrame(recon, DFnames, makeunique=true) + reconDF = DataFrame(recon, DFnames, makeunique = true) #rename!(reconDF,names1) From e7c35fd76b369626621c373e1307afc89e1e135f Mon Sep 17 00:00:00 2001 From: Maya Mutic <62064527+mmutic@users.noreply.github.com> Date: Tue, 4 Jun 2024 17:44:30 -0400 Subject: [PATCH 38/61] Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../full_time_series_reconstruction.jl | 7 ++----- .../transmission/write_transmission_flows.jl | 9 +++++---- .../transmission/write_transmission_losses.jl | 1 - src/write_outputs/ucommit/write_commit.jl | 10 +++++----- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/time_domain_reduction/full_time_series_reconstruction.jl b/src/time_domain_reduction/full_time_series_reconstruction.jl index 13a9da046c..f628ca2890 100644 --- a/src/time_domain_reduction/full_time_series_reconstruction.jl +++ b/src/time_domain_reduction/full_time_series_reconstruction.jl @@ -62,17 +62,14 @@ function full_time_series_reconstruction( reconDF = DataFrame(recon, DFnames, makeunique = true) #rename!(reconDF,names1) - # Insert rows that were above "t1" in the original DataFrame (e.g. "Zone" and "AnnualSum") if present for i in range(1,t1-1) insert!(reconDF,i,DFMatrix[i,1:end],promote=true) end - # Repeat the last rows of the year to fill in the gap (should be 24 hours for non-leap year) end_diff = WeightTotal - nrow(reconDF) + 1 - new_rows = reconDF[(nrow(reconDF)-end_diff):nrow(reconDF),1:end] - new_rows[!,1] = ["t$t" for t in (WeightTotal-end_diff):WeightTotal] + new_rows = reconDF[(nrow(reconDF) - end_diff):nrow(reconDF), 1:end] + new_rows[!, 1] = ["t$t" for t in (WeightTotal - end_diff):WeightTotal] reconDF = [reconDF; new_rows] - return reconDF end \ No newline at end of file diff --git a/src/write_outputs/transmission/write_transmission_flows.jl b/src/write_outputs/transmission/write_transmission_flows.jl index b143496b69..7decbb710a 100644 --- a/src/write_outputs/transmission/write_transmission_flows.jl +++ b/src/write_outputs/transmission/write_transmission_flows.jl @@ -25,11 +25,12 @@ function write_transmission_flows(path::AbstractString, CSV.write(filepath, dftranspose(dfFlow, false), writeheader = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - DFnames = ["Line","1","2"] + DFnames = ["Line", "1", "2"] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path,FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfFlow, false), DFnames) - CSV.write(joinpath(output_path,"flow.csv"), dfOut_full, header = false) + output_path = joinpath(path, FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction( + path, setup, dftranspose(dfFlow, false), DFnames) + CSV.write(joinpath(output_path, "flow.csv"), dfOut_full, header = false) println("Writing Full Time Series for Transmission Flows") end end diff --git a/src/write_outputs/transmission/write_transmission_losses.jl b/src/write_outputs/transmission/write_transmission_losses.jl index 8dc15f7b28..ca4ea93ca3 100644 --- a/src/write_outputs/transmission/write_transmission_losses.jl +++ b/src/write_outputs/transmission/write_transmission_losses.jl @@ -39,7 +39,6 @@ function write_transmission_losses(path::AbstractString, CSV.write(joinpath(output_path,"tlosses.csv"), dfOut_full, header = false) println("Writing Full Time Series for Time Losses") end - end return nothing end diff --git a/src/write_outputs/ucommit/write_commit.jl b/src/write_outputs/ucommit/write_commit.jl index 1df95e1b99..0f7d6cdb86 100644 --- a/src/write_outputs/ucommit/write_commit.jl +++ b/src/write_outputs/ucommit/write_commit.jl @@ -15,14 +15,14 @@ function write_commit(path::AbstractString, inputs::Dict, setup::Dict, EP::Model println("PATH = ", path) println("-------------------------------") - if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 DFMatrix = Matrix(dftranspose(dfCommit, true)) - DFnames = DFMatrix[1,:] + DFnames = DFMatrix[1, :] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path,FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfCommit, false), DFnames) - CSV.write(joinpath(output_path,"commit.csv"), dfOut_full, header = false) + output_path = joinpath(path, FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction( + path, setup, dftranspose(dfCommit, false), DFnames) + CSV.write(joinpath(output_path, "commit.csv"), dfOut_full, header = false) println("Writing Full Time Series for Commitment") end From c91909cf23c2895ef522ee9148077ef63ee9f0f7 Mon Sep 17 00:00:00 2001 From: Maya Mutic <62064527+mmutic@users.noreply.github.com> Date: Tue, 4 Jun 2024 17:48:50 -0400 Subject: [PATCH 39/61] Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../full_time_series_reconstruction.jl | 4 ++-- .../transmission/write_transmission_losses.jl | 7 ++++--- src/write_outputs/ucommit/write_commit.jl | 1 - src/write_outputs/ucommit/write_shutdown.jl | 2 +- src/write_outputs/ucommit/write_start.jl | 9 +++++---- src/write_outputs/write_charge.jl | 11 +++++------ src/write_outputs/write_co2.jl | 10 ++++++---- 7 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/time_domain_reduction/full_time_series_reconstruction.jl b/src/time_domain_reduction/full_time_series_reconstruction.jl index f628ca2890..9bd270b9ba 100644 --- a/src/time_domain_reduction/full_time_series_reconstruction.jl +++ b/src/time_domain_reduction/full_time_series_reconstruction.jl @@ -63,8 +63,8 @@ function full_time_series_reconstruction( #rename!(reconDF,names1) # Insert rows that were above "t1" in the original DataFrame (e.g. "Zone" and "AnnualSum") if present - for i in range(1,t1-1) - insert!(reconDF,i,DFMatrix[i,1:end],promote=true) + for i in range(1, t1 - 1) + insert!(reconDF, i, DFMatrix[i, 1:end], promote = true) end # Repeat the last rows of the year to fill in the gap (should be 24 hours for non-leap year) end_diff = WeightTotal - nrow(reconDF) + 1 diff --git a/src/write_outputs/transmission/write_transmission_losses.jl b/src/write_outputs/transmission/write_transmission_losses.jl index ca4ea93ca3..18d66a202f 100644 --- a/src/write_outputs/transmission/write_transmission_losses.jl +++ b/src/write_outputs/transmission/write_transmission_losses.jl @@ -34,9 +34,10 @@ function write_transmission_losses(path::AbstractString, if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 DFnames = ["Line", "1", "2", "Total"] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path,FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfTLosses, false), DFnames) - CSV.write(joinpath(output_path,"tlosses.csv"), dfOut_full, header = false) + output_path = joinpath(path, FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction( + path, setup, dftranspose(dfTLosses, false), DFnames) + CSV.write(joinpath(output_path, "tlosses.csv"), dfOut_full, header = false) println("Writing Full Time Series for Time Losses") end end diff --git a/src/write_outputs/ucommit/write_commit.jl b/src/write_outputs/ucommit/write_commit.jl index 0f7d6cdb86..c97994a7d0 100644 --- a/src/write_outputs/ucommit/write_commit.jl +++ b/src/write_outputs/ucommit/write_commit.jl @@ -25,5 +25,4 @@ function write_commit(path::AbstractString, inputs::Dict, setup::Dict, EP::Model CSV.write(joinpath(output_path, "commit.csv"), dfOut_full, header = false) println("Writing Full Time Series for Commitment") end - end diff --git a/src/write_outputs/ucommit/write_shutdown.jl b/src/write_outputs/ucommit/write_shutdown.jl index 62b2e6e34f..328fff1e12 100644 --- a/src/write_outputs/ucommit/write_shutdown.jl +++ b/src/write_outputs/ucommit/write_shutdown.jl @@ -16,7 +16,7 @@ function write_shutdown(path::AbstractString, inputs::Dict, setup::Dict, EP::Mod write_fulltimeseries(filepath, shut, dfShutdown) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - df_Shutdown = CSV.read(joinpath(path,"shutdown.csv"),DataFrame) + df_Shutdown = CSV.read(joinpath(path, "shutdown.csv"), DataFrame) FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path,FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction(path,setup, df_Shutdown,names(df_Shutdown)) diff --git a/src/write_outputs/ucommit/write_start.jl b/src/write_outputs/ucommit/write_start.jl index c1ff25f886..a9072b2551 100644 --- a/src/write_outputs/ucommit/write_start.jl +++ b/src/write_outputs/ucommit/write_start.jl @@ -15,11 +15,12 @@ function write_start(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) write_fulltimeseries(filepath, start, dfStart) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - df_Start = CSV.read(joinpath(path,"start.csv"),DataFrame) + df_Start = CSV.read(joinpath(path, "start.csv"), DataFrame) FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path,FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction(path,setup, df_Start,names(df_Start)) - CSV.write(joinpath(output_path,"start.csv"), dfOut_full) + output_path = joinpath(path, FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction( + path, setup, df_Start, names(df_Start)) + CSV.write(joinpath(output_path, "start.csv"), dfOut_full) println("Writing Full Time Series for Startup") end end diff --git a/src/write_outputs/write_charge.jl b/src/write_outputs/write_charge.jl index 39827c5ff9..7022293222 100644 --- a/src/write_outputs/write_charge.jl +++ b/src/write_outputs/write_charge.jl @@ -43,16 +43,15 @@ function write_charge(path::AbstractString, inputs::Dict, setup::Dict, EP::Model else # setup["WriteOutputs"] == "full" write_fulltimeseries(filepath, charge, dfCharge) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - df_Charge = CSV.read(joinpath(path,"charge.csv"),DataFrame) + df_Charge = CSV.read(joinpath(path, "charge.csv"), DataFrame) FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path,FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction(path,setup, df_Charge,names(df_Charge)) - CSV.write(joinpath(output_path,"charge.csv"), dfOut_full) + output_path = joinpath(path, FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction( + path, setup, df_Charge, names(df_Charge)) + CSV.write(joinpath(output_path, "charge.csv"), dfOut_full) println("Writing Full Time Series for Charge") end end - - return nothing end diff --git a/src/write_outputs/write_co2.jl b/src/write_outputs/write_co2.jl index 729562425e..8ea2afb81c 100644 --- a/src/write_outputs/write_co2.jl +++ b/src/write_outputs/write_co2.jl @@ -34,11 +34,13 @@ function write_co2_emissions_plant(path::AbstractString, write_fulltimeseries(filepath, emissions_plant, dfEmissions_plant) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 DFMatrix = Matrix(dftranspose(dfEmissions_plant, true)) - DFnames = DFMatrix[1,:] + DFnames = DFMatrix[1, :] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path,FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfEmissions_plant, false), DFnames) - CSV.write(joinpath(output_path,"emissions_plant.csv"), dfOut_full, header = false) + output_path = joinpath(path, FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction( + path, setup, dftranspose(dfEmissions_plant, false), DFnames) + CSV.write( + joinpath(output_path, "emissions_plant.csv"), dfOut_full, header = false) println("Writing Full Time Series for Emissions Plant") end end From d043739930a46fce172a2fe716d21eafa2456299 Mon Sep 17 00:00:00 2001 From: Maya Mutic <62064527+mmutic@users.noreply.github.com> Date: Tue, 4 Jun 2024 17:50:56 -0400 Subject: [PATCH 40/61] Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/write_outputs/write_curtailment.jl | 9 +++++---- src/write_outputs/write_emissions.jl | 9 +++++---- src/write_outputs/write_fuel_consumption.jl | 9 +++++---- src/write_outputs/write_nse.jl | 14 ++++++++------ src/write_outputs/write_outputs.jl | 2 +- src/write_outputs/write_power.jl | 9 +++++---- src/write_outputs/write_power_balance.jl | 6 +++--- 7 files changed, 32 insertions(+), 26 deletions(-) diff --git a/src/write_outputs/write_curtailment.jl b/src/write_outputs/write_curtailment.jl index 777740c0bc..32e8fa1cde 100644 --- a/src/write_outputs/write_curtailment.jl +++ b/src/write_outputs/write_curtailment.jl @@ -59,11 +59,12 @@ function write_curtailment(path::AbstractString, inputs::Dict, setup::Dict, EP:: else # setup["WriteOutputs"] == "full" write_fulltimeseries(filename, curtailment, dfCurtailment) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - df_Curtail = CSV.read(joinpath(path,"curtail.csv"),DataFrame) + df_Curtail = CSV.read(joinpath(path, "curtail.csv"), DataFrame) FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path,FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction(path,setup, df_Curtail,names(df_Curtail)) - CSV.write(joinpath(output_path,"curtail.csv"), dfOut_full) + output_path = joinpath(path, FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction( + path, setup, df_Curtail, names(df_Curtail)) + CSV.write(joinpath(output_path, "curtail.csv"), dfOut_full) println("Writing Full Time Series for Curtailment") end end diff --git a/src/write_outputs/write_emissions.jl b/src/write_outputs/write_emissions.jl index b53641bc6b..ed1f10eb4a 100644 --- a/src/write_outputs/write_emissions.jl +++ b/src/write_outputs/write_emissions.jl @@ -127,11 +127,12 @@ function write_emissions(path::AbstractString, inputs::Dict, setup::Dict, EP::Mo if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 DFMatrix = Matrix(dftranspose(dfEmissions, true)) - DFnames = DFMatrix[1,:] + DFnames = DFMatrix[1, :] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path,FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfEmissions, false), DFnames) - CSV.write(joinpath(output_path,"emissions.csv"), dfOut_full) + output_path = joinpath(path, FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction( + path, setup, dftranspose(dfEmissions, false), DFnames) + CSV.write(joinpath(output_path, "emissions.csv"), dfOut_full) println("Writing Full Time Series for Emissions") end end diff --git a/src/write_outputs/write_fuel_consumption.jl b/src/write_outputs/write_fuel_consumption.jl index 4ff094289d..05373bc056 100644 --- a/src/write_outputs/write_fuel_consumption.jl +++ b/src/write_outputs/write_fuel_consumption.jl @@ -88,11 +88,12 @@ function write_fuel_consumption_ts(path::AbstractString, if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 DFMatrix = Matrix(dftranspose(dfPlantFuel_TS, true)) - DFnames = DFMatrix[1,:] + DFnames = DFMatrix[1, :] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path,FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfPlantFuel_TS, false), DFnames) - CSV.write(joinpath(output_path,"commit.csv"), dfOut_full, header = false) + output_path = joinpath(path, FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction( + path, setup, dftranspose(dfPlantFuel_TS, false), DFnames) + CSV.write(joinpath(output_path, "commit.csv"), dfOut_full, header = false) println("Writing Full Time Series for Fuel Consumption") end end diff --git a/src/write_outputs/write_nse.jl b/src/write_outputs/write_nse.jl index cf34845888..67a95b5714 100644 --- a/src/write_outputs/write_nse.jl +++ b/src/write_outputs/write_nse.jl @@ -39,12 +39,14 @@ function write_nse(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) CSV.write(joinpath(path, "nse.csv"), dftranspose(dfNse, false), writeheader = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - DFnames = ["Segment","1","2","3","4","1","2","3","4","1","2","3","4","Total"] - FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path,FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfNse, false), DFnames) - CSV.write(joinpath(output_path,"nse.csv"), dfOut_full, header = false) - println("Writing Full Time Series for NSE") + DFnames = ["Segment", "1", "2", "3", "4", "1", "2", + "3", "4", "1", "2", "3", "4", "Total"] + FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] + output_path = joinpath(path, FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction( + path, setup, dftranspose(dfNse, false), DFnames) + CSV.write(joinpath(output_path, "nse.csv"), dfOut_full, header = false) + println("Writing Full Time Series for NSE") end end return nothing diff --git a/src/write_outputs/write_outputs.jl b/src/write_outputs/write_outputs.jl index e197a6a936..af36c56def 100644 --- a/src/write_outputs/write_outputs.jl +++ b/src/write_outputs/write_outputs.jl @@ -24,7 +24,7 @@ function write_outputs(EP::Model, path::AbstractString, setup::Dict, inputs::Dic end if setup["OutputFullTimeSeries"] == 1 - mkpath(joinpath(path,setup["OutputFullTimeSeriesFolder"])) + mkpath(joinpath(path, setup["OutputFullTimeSeriesFolder"])) end # https://jump.dev/MathOptInterface.jl/v0.9.10/apireference/#MathOptInterface.TerminationStatusCode diff --git a/src/write_outputs/write_power.jl b/src/write_outputs/write_power.jl index a729136eec..ff0273204a 100644 --- a/src/write_outputs/write_power.jl +++ b/src/write_outputs/write_power.jl @@ -26,11 +26,12 @@ function write_power(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) else # setup["WriteOutputs"] == "full" write_fulltimeseries(filepath, power, dfPower) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - df_Power = CSV.read(joinpath(path,"power.csv"),DataFrame) + df_Power = CSV.read(joinpath(path, "power.csv"), DataFrame) FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path,FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction(path,setup, df_Power,names(df_Power)) - CSV.write(joinpath(output_path,"power.csv"), dfOut_full) + output_path = joinpath(path, FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction( + path, setup, df_Power, names(df_Power)) + CSV.write(joinpath(output_path, "power.csv"), dfOut_full) println("Writing Full Time Series for Power") end end diff --git a/src/write_outputs/write_power_balance.jl b/src/write_outputs/write_power_balance.jl index c574ae67aa..bbcf5ee2c2 100644 --- a/src/write_outputs/write_power_balance.jl +++ b/src/write_outputs/write_power_balance.jl @@ -98,10 +98,10 @@ function write_power_balance(path::AbstractString, inputs::Dict, setup::Dict, EP writeheader = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - DFnames = dfPowerBalance[:,1] - insert!(DFnames,1,"BalanceComponent") + DFnames = dfPowerBalance[:, 1] + insert!(DFnames, 1, "BalanceComponent") #DFMatrix = Matrix(dftranspose(dfPowerBalance, true)) - # DFnames = DFMatrix[1,:] + # DFnames = DFMatrix[1,:] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path,FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfPowerBalance, false),DFnames) From 04b661e7da4b5d5723c30a26f25b8fc2e682ae35 Mon Sep 17 00:00:00 2001 From: Maya Mutic <62064527+mmutic@users.noreply.github.com> Date: Tue, 4 Jun 2024 17:52:10 -0400 Subject: [PATCH 41/61] Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/write_outputs/write_power_balance.jl | 8 +++++--- src/write_outputs/write_price.jl | 7 ++++--- src/write_outputs/write_reliability.jl | 7 ++++--- src/write_outputs/write_storage.jl | 9 +++++---- src/write_outputs/write_storagedual.jl | 9 +++++---- 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/write_outputs/write_power_balance.jl b/src/write_outputs/write_power_balance.jl index bbcf5ee2c2..add22c6310 100644 --- a/src/write_outputs/write_power_balance.jl +++ b/src/write_outputs/write_power_balance.jl @@ -103,9 +103,11 @@ function write_power_balance(path::AbstractString, inputs::Dict, setup::Dict, EP #DFMatrix = Matrix(dftranspose(dfPowerBalance, true)) # DFnames = DFMatrix[1,:] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path,FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfPowerBalance, false),DFnames) - CSV.write(joinpath(output_path,"power_balance.csv"), dfOut_full, header = false) + output_path = joinpath(path, FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction( + path, setup, dftranspose(dfPowerBalance, false), DFnames) + CSV.write( + joinpath(output_path, "power_balance.csv"), dfOut_full, header = false) println("Writing Full Time Series for Power Balance") end end diff --git a/src/write_outputs/write_price.jl b/src/write_outputs/write_price.jl index 19547f9209..7d5365e900 100644 --- a/src/write_outputs/write_price.jl +++ b/src/write_outputs/write_price.jl @@ -25,9 +25,10 @@ function write_price(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 DFnames = ["Zone", "1", "2", "3"] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path,FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfPrice, false), DFnames) - CSV.write(joinpath(output_path,"prices.csv"), dfOut_full, header = false) + output_path = joinpath(path, FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction( + path, setup, dftranspose(dfPrice, false), DFnames) + CSV.write(joinpath(output_path, "prices.csv"), dfOut_full, header = false) println("Writing Full Time Series for Price") end return nothing diff --git a/src/write_outputs/write_reliability.jl b/src/write_outputs/write_reliability.jl index 0c9ce76694..c19ad9b0cc 100644 --- a/src/write_outputs/write_reliability.jl +++ b/src/write_outputs/write_reliability.jl @@ -24,9 +24,10 @@ function write_reliability(path::AbstractString, inputs::Dict, setup::Dict, EP:: if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 DFnames = ["Zone", "1", "2", "3"] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path,FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfReliability, false), DFnames) - CSV.write(joinpath(output_path,"reliability.csv"), dfOut_full, header = false) + output_path = joinpath(path, FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction( + path, setup, dftranspose(dfReliability, false), DFnames) + CSV.write(joinpath(output_path, "reliability.csv"), dfOut_full, header = false) println("Writing Full Time Series for Reliability") end end diff --git a/src/write_outputs/write_storage.jl b/src/write_outputs/write_storage.jl index 9d78dd8bba..720be09821 100644 --- a/src/write_outputs/write_storage.jl +++ b/src/write_outputs/write_storage.jl @@ -42,11 +42,12 @@ function write_storage(path::AbstractString, inputs::Dict, setup::Dict, EP::Mode if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 DFMatrix = Matrix(dftranspose(dfStorage, true)) - DFnames = DFMatrix[1,:] + DFnames = DFMatrix[1, :] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path,FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfStorage, false), DFnames) - CSV.write(joinpath(output_path,"storage.csv"), dfOut_full, header = false) + output_path = joinpath(path, FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction( + path, setup, dftranspose(dfStorage, false), DFnames) + CSV.write(joinpath(output_path, "storage.csv"), dfOut_full, header = false) println("Writing Full Time Series for Storage") end end diff --git a/src/write_outputs/write_storagedual.jl b/src/write_outputs/write_storagedual.jl index 9f374b80e8..c091ec32e9 100644 --- a/src/write_outputs/write_storagedual.jl +++ b/src/write_outputs/write_storagedual.jl @@ -82,11 +82,12 @@ function write_storagedual(path::AbstractString, inputs::Dict, setup::Dict, EP:: if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 DFMatrix = Matrix(dftranspose(dfStorageDual, true)) - DFnames = DFMatrix[1,:] + DFnames = DFMatrix[1, :] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path,FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfStorageDual, false), DFnames) - CSV.write(joinpath(output_path,"storagebal_duals.csv"), dfOut_full, header = false) + output_path = joinpath(path, FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction( + path, setup, dftranspose(dfStorageDual, false), DFnames) + CSV.write(joinpath(output_path, "storagebal_duals.csv"), dfOut_full, header = false) println("Writing Full Time Series for Storage Duals") end end From 3bb7dc759ac3be24beb0ccf42f277bb152a8672c Mon Sep 17 00:00:00 2001 From: Maya Mutic Date: Fri, 21 Jun 2024 18:19:27 +0200 Subject: [PATCH 42/61] Fixed emissions_plant output --- example_systems/1_three_zones/settings/genx_settings.yml | 2 +- .../full_time_series_reconstruction.jl | 7 ++----- src/write_outputs/ucommit/write_commit.jl | 3 --- src/write_outputs/write_co2.jl | 8 +++----- src/write_outputs/write_outputs.jl | 1 - 5 files changed, 6 insertions(+), 15 deletions(-) diff --git a/example_systems/1_three_zones/settings/genx_settings.yml b/example_systems/1_three_zones/settings/genx_settings.yml index 191225e185..5c529c44cd 100644 --- a/example_systems/1_three_zones/settings/genx_settings.yml +++ b/example_systems/1_three_zones/settings/genx_settings.yml @@ -10,4 +10,4 @@ ParameterScale: 1 # Turn on parameter scaling wherein demand, capacity and power WriteShadowPrices: 1 # Write shadow prices of LP or relaxed MILP; 0 = not active; 1 = active UCommit: 2 # Unit committment of thermal power plants; 0 = not active; 1 = active using integer clestering; 2 = active using linearized clustering TimeDomainReduction: 1 # Time domain reduce (i.e. cluster) inputs based on Demand_data.csv, Generators_variability.csv, and Fuels_data.csv; 0 = not active (use input data as provided); 0 = active (cluster input data, or use data that has already been clustered) -OutputFullTimeSeries: 1 +OutputFullTimeSeries: 1 diff --git a/src/time_domain_reduction/full_time_series_reconstruction.jl b/src/time_domain_reduction/full_time_series_reconstruction.jl index 9bd270b9ba..ffa6aefb82 100644 --- a/src/time_domain_reduction/full_time_series_reconstruction.jl +++ b/src/time_domain_reduction/full_time_series_reconstruction.jl @@ -37,7 +37,7 @@ function full_time_series_reconstruction( # Calculate the number of total periods the original time series was split into (will usually be 52) numPeriods = floor(Int, WeightTotal / TimestepsPerRepPeriod) - # Get the names of the input DataFrame + # Get a matrix of the input DataFrame DFMatrix = Matrix(DF) # Initialize an array to add the reconstructed data to recon = ["t$t" for t in 1:(TimestepsPerRepPeriod * numPeriods)] @@ -48,24 +48,21 @@ function full_time_series_reconstruction( # Reconstruction of all hours of the year from TDR for j in range(2, ncol(DF)) col = DF[t1:end, j] - #col_name = DFnames[j] - #names1 = [names1 Symbol(col_name)] recon_col = [] for i in range(1, numPeriods) index = Period_map[i, "Rep_Period_Index"] recon_temp = col[(TimestepsPerRepPeriod * index - (TimestepsPerRepPeriod - 1)):(TimestepsPerRepPeriod * index)] # Describe how this works recon_col = [recon_col; recon_temp] end - #reconDF[!,col_name] = recon_col recon = [recon recon_col] end reconDF = DataFrame(recon, DFnames, makeunique = true) - #rename!(reconDF,names1) # Insert rows that were above "t1" in the original DataFrame (e.g. "Zone" and "AnnualSum") if present for i in range(1, t1 - 1) insert!(reconDF, i, DFMatrix[i, 1:end], promote = true) end + # Repeat the last rows of the year to fill in the gap (should be 24 hours for non-leap year) end_diff = WeightTotal - nrow(reconDF) + 1 new_rows = reconDF[(nrow(reconDF) - end_diff):nrow(reconDF), 1:end] diff --git a/src/write_outputs/ucommit/write_commit.jl b/src/write_outputs/ucommit/write_commit.jl index c97994a7d0..ce37cd98bc 100644 --- a/src/write_outputs/ucommit/write_commit.jl +++ b/src/write_outputs/ucommit/write_commit.jl @@ -11,9 +11,6 @@ function write_commit(path::AbstractString, inputs::Dict, setup::Dict, EP::Model auxNew_Names = [Symbol("Resource"); Symbol("Zone"); [Symbol("t$t") for t in 1:T]] rename!(dfCommit, auxNew_Names) CSV.write(joinpath(path, "commit.csv"), dftranspose(dfCommit, false), header = false) - println("-------------------------------") - println("PATH = ", path) - println("-------------------------------") if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 DFMatrix = Matrix(dftranspose(dfCommit, true)) diff --git a/src/write_outputs/write_co2.jl b/src/write_outputs/write_co2.jl index 8ea2afb81c..b4d16099b9 100644 --- a/src/write_outputs/write_co2.jl +++ b/src/write_outputs/write_co2.jl @@ -33,14 +33,12 @@ function write_co2_emissions_plant(path::AbstractString, else # setup["WriteOutputs"] == "full" write_fulltimeseries(filepath, emissions_plant, dfEmissions_plant) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - DFMatrix = Matrix(dftranspose(dfEmissions_plant, true)) - DFnames = DFMatrix[1, :] + df_Emissions_plant = CSV.read(joinpath(path, "emissions_plant.csv"), DataFrame) FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(dfEmissions_plant, false), DFnames) - CSV.write( - joinpath(output_path, "emissions_plant.csv"), dfOut_full, header = false) + path, setup, df_Emissions_plant, names(df_Emissions_plant)) + CSV.write(joinpath(output_path, "emissions_plant.csv"), dfOut_full) println("Writing Full Time Series for Emissions Plant") end end diff --git a/src/write_outputs/write_outputs.jl b/src/write_outputs/write_outputs.jl index af36c56def..8a42ea8d75 100644 --- a/src/write_outputs/write_outputs.jl +++ b/src/write_outputs/write_outputs.jl @@ -77,7 +77,6 @@ function write_outputs(EP::Model, path::AbstractString, setup::Dict, inputs::Dic elapsed_time_power = @elapsed dfPower = write_power(path, inputs, setup, EP) println("Time elapsed for writing power is") println(elapsed_time_power) - println("Here") end if output_settings_d["WriteCharge"] From 47b5bb657423c405f53801efac7d90c25fb2a877 Mon Sep 17 00:00:00 2001 From: Maya Mutic Date: Mon, 24 Jun 2024 13:42:09 +0200 Subject: [PATCH 43/61] Change pre-processing for FTR in some files --- src/write_outputs/ucommit/write_commit.jl | 1 + src/write_outputs/ucommit/write_shutdown.jl | 18 +++++++++++++++--- src/write_outputs/ucommit/write_start.jl | 20 ++++++++++++++++---- src/write_outputs/write_charge.jl | 21 ++++++++++++++++++--- src/write_outputs/write_co2.jl | 18 +++++++++++++++--- src/write_outputs/write_curtailment.jl | 18 +++++++++++++++--- src/write_outputs/write_emissions.jl | 9 ++++----- src/write_outputs/write_power.jl | 18 +++++++++++++++--- src/write_outputs/write_power_balance.jl | 2 -- 9 files changed, 99 insertions(+), 26 deletions(-) diff --git a/src/write_outputs/ucommit/write_commit.jl b/src/write_outputs/ucommit/write_commit.jl index ce37cd98bc..75b6ec7ac3 100644 --- a/src/write_outputs/ucommit/write_commit.jl +++ b/src/write_outputs/ucommit/write_commit.jl @@ -12,6 +12,7 @@ function write_commit(path::AbstractString, inputs::Dict, setup::Dict, EP::Model rename!(dfCommit, auxNew_Names) CSV.write(joinpath(path, "commit.csv"), dftranspose(dfCommit, false), header = false) + if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 DFMatrix = Matrix(dftranspose(dfCommit, true)) DFnames = DFMatrix[1, :] diff --git a/src/write_outputs/ucommit/write_shutdown.jl b/src/write_outputs/ucommit/write_shutdown.jl index 328fff1e12..3dc54929b9 100644 --- a/src/write_outputs/ucommit/write_shutdown.jl +++ b/src/write_outputs/ucommit/write_shutdown.jl @@ -16,11 +16,23 @@ function write_shutdown(path::AbstractString, inputs::Dict, setup::Dict, EP::Mod write_fulltimeseries(filepath, shut, dfShutdown) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - df_Shutdown = CSV.read(joinpath(path, "shutdown.csv"), DataFrame) + T = size(shut, 2) + dfShutdown = hcat(dfShutdown, DataFrame(shut, :auto)) + auxNew_Names = [Symbol("Resource"); + Symbol("Zone"); + Symbol("AnnualSum"); + [Symbol("t$t") for t in 1:T]] + rename!(dfShutdown, auxNew_Names) + total = DataFrame(["Total" 0 sum(dfShutdown[!, :AnnualSum]) fill(0.0, (1, T))], auxNew_Names) + total[!, 4:(T + 3)] .= sum(shut, dims = 1) + df_Shutdown = vcat(dfShutdown, total) + DFMatrix = Matrix(dftranspose(df_Shutdown, true)) + DFnames = DFMatrix[1,:] + FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path,FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction(path,setup, df_Shutdown,names(df_Shutdown)) - CSV.write(joinpath(output_path,"shutdown.csv"), dfOut_full) + dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(df_Shutdown, false), DFnames) + CSV.write(joinpath(output_path,"shutdown.csv"), dfOut_full, writeheader = false) println("Writing Full Time Series for Shutdown") end end diff --git a/src/write_outputs/ucommit/write_start.jl b/src/write_outputs/ucommit/write_start.jl index a9072b2551..0e1c0df920 100644 --- a/src/write_outputs/ucommit/write_start.jl +++ b/src/write_outputs/ucommit/write_start.jl @@ -13,14 +13,26 @@ function write_start(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) write_annual(filepath, dfStart) else # setup["WriteOutputs"] == "full" write_fulltimeseries(filepath, start, dfStart) - + # full path, dataout, dfout if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - df_Start = CSV.read(joinpath(path, "start.csv"), DataFrame) + T = size(start, 2) + dfStart = hcat(dfStart, DataFrame(start, :auto)) + auxNew_Names = [Symbol("Resource"); + Symbol("Zone"); + Symbol("AnnualSum"); + [Symbol("t$t") for t in 1:T]] + rename!(dfStart, auxNew_Names) + total = DataFrame(["Total" 0 sum(dfStart[!, :AnnualSum]) fill(0.0, (1, T))], auxNew_Names) + total[!, 4:(T + 3)] .= sum(start, dims = 1) + df_Start = vcat(dfStart, total) + DFMatrix = Matrix(dftranspose(df_Start, true)) + DFnames = DFMatrix[1,:] + FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( - path, setup, df_Start, names(df_Start)) - CSV.write(joinpath(output_path, "start.csv"), dfOut_full) + path, setup, dftranspose(df_Start, false), DFnames) + CSV.write(joinpath(output_path, "start.csv"), dfOut_full, writeheader = false) println("Writing Full Time Series for Startup") end end diff --git a/src/write_outputs/write_charge.jl b/src/write_outputs/write_charge.jl index 7022293222..cdaef9d015 100644 --- a/src/write_outputs/write_charge.jl +++ b/src/write_outputs/write_charge.jl @@ -43,12 +43,27 @@ function write_charge(path::AbstractString, inputs::Dict, setup::Dict, EP::Model else # setup["WriteOutputs"] == "full" write_fulltimeseries(filepath, charge, dfCharge) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - df_Charge = CSV.read(joinpath(path, "charge.csv"), DataFrame) + + # full path, dataout, dfout + + T = size(charge, 2) + dfCharge = hcat(dfCharge, DataFrame(charge, :auto)) + auxNew_Names = [Symbol("Resource"); + Symbol("Zone"); + Symbol("AnnualSum"); + [Symbol("t$t") for t in 1:T]] + rename!(dfCharge, auxNew_Names) + total = DataFrame(["Total" 0 sum(dfCharge[!, :AnnualSum]) fill(0.0, (1, T))], auxNew_Names) + total[!, 4:(T + 3)] .= sum(charge, dims = 1) + df_Charge = vcat(dfCharge, total) + DFMatrix = Matrix(dftranspose(df_Charge, true)) + DFnames = DFMatrix[1,:] + FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( - path, setup, df_Charge, names(df_Charge)) - CSV.write(joinpath(output_path, "charge.csv"), dfOut_full) + path, setup, dftranspose(df_Charge, false), DFnames) + CSV.write(joinpath(output_path, "charge.csv"), dfOut_full, writeheader = false) println("Writing Full Time Series for Charge") end end diff --git a/src/write_outputs/write_co2.jl b/src/write_outputs/write_co2.jl index b4d16099b9..86112c87f2 100644 --- a/src/write_outputs/write_co2.jl +++ b/src/write_outputs/write_co2.jl @@ -33,12 +33,24 @@ function write_co2_emissions_plant(path::AbstractString, else # setup["WriteOutputs"] == "full" write_fulltimeseries(filepath, emissions_plant, dfEmissions_plant) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - df_Emissions_plant = CSV.read(joinpath(path, "emissions_plant.csv"), DataFrame) + T = size(emissions_plant, 2) + dfEmissions_plant = hcat(dfEmissions_plant, DataFrame(emissions_plant, :auto)) + auxNew_Names = [Symbol("Resource"); + Symbol("Zone"); + Symbol("AnnualSum"); + [Symbol("t$t") for t in 1:T]] + rename!(dfEmissions_plant, auxNew_Names) + total = DataFrame(["Total" 0 sum(dfEmissions_plant[!, :AnnualSum]) fill(0.0, (1, T))], auxNew_Names) + total[!, 4:(T + 3)] .= sum(emissions_plant, dims = 1) + df_Emissions_plant = vcat(dfEmissions_plant, total) + DFMatrix = Matrix(dftranspose(df_Emissions_plant, true)) + DFnames = DFMatrix[1,:] + FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( - path, setup, df_Emissions_plant, names(df_Emissions_plant)) - CSV.write(joinpath(output_path, "emissions_plant.csv"), dfOut_full) + path, setup, dftranspose(df_Emissions_plant, false), DFnames) + CSV.write(joinpath(output_path, "emissions_plant.csv"), dfOut_full, writeheader = false) println("Writing Full Time Series for Emissions Plant") end end diff --git a/src/write_outputs/write_curtailment.jl b/src/write_outputs/write_curtailment.jl index 32e8fa1cde..b0b191fca4 100644 --- a/src/write_outputs/write_curtailment.jl +++ b/src/write_outputs/write_curtailment.jl @@ -59,12 +59,24 @@ function write_curtailment(path::AbstractString, inputs::Dict, setup::Dict, EP:: else # setup["WriteOutputs"] == "full" write_fulltimeseries(filename, curtailment, dfCurtailment) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - df_Curtail = CSV.read(joinpath(path, "curtail.csv"), DataFrame) + T = size(curtailment, 2) + dfCurtailment = hcat(dfCurtailment, DataFrame(curtailment, :auto)) + auxNew_Names = [Symbol("Resource"); + Symbol("Zone"); + Symbol("AnnualSum"); + [Symbol("t$t") for t in 1:T]] + rename!(dfCurtailment, auxNew_Names) + total = DataFrame(["Total" 0 sum(dfCurtailment[!, :AnnualSum]) fill(0.0, (1, T))], auxNew_Names) + total[!, 4:(T + 3)] .= sum(curtailment, dims = 1) + df_Curtailment = vcat(dfCurtailment, total) + DFMatrix = Matrix(dftranspose(df_Curtailment, true)) + DFnames = DFMatrix[1,:] + FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( - path, setup, df_Curtail, names(df_Curtail)) - CSV.write(joinpath(output_path, "curtail.csv"), dfOut_full) + path, setup, dftranspose(df_Curtailment, false), DFnames) + CSV.write(joinpath(output_path, "curtail.csv"), dfOut_full, writeheader = false) println("Writing Full Time Series for Curtailment") end end diff --git a/src/write_outputs/write_emissions.jl b/src/write_outputs/write_emissions.jl index ed1f10eb4a..b53641bc6b 100644 --- a/src/write_outputs/write_emissions.jl +++ b/src/write_outputs/write_emissions.jl @@ -127,12 +127,11 @@ function write_emissions(path::AbstractString, inputs::Dict, setup::Dict, EP::Mo if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 DFMatrix = Matrix(dftranspose(dfEmissions, true)) - DFnames = DFMatrix[1, :] + DFnames = DFMatrix[1,:] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path, FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(dfEmissions, false), DFnames) - CSV.write(joinpath(output_path, "emissions.csv"), dfOut_full) + output_path = joinpath(path,FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfEmissions, false), DFnames) + CSV.write(joinpath(output_path,"emissions.csv"), dfOut_full) println("Writing Full Time Series for Emissions") end end diff --git a/src/write_outputs/write_power.jl b/src/write_outputs/write_power.jl index ff0273204a..8264d41d22 100644 --- a/src/write_outputs/write_power.jl +++ b/src/write_outputs/write_power.jl @@ -26,12 +26,24 @@ function write_power(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) else # setup["WriteOutputs"] == "full" write_fulltimeseries(filepath, power, dfPower) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - df_Power = CSV.read(joinpath(path, "power.csv"), DataFrame) + T = size(power, 2) + dfPower = hcat(dfPower, DataFrame(power, :auto)) + auxNew_Names = [Symbol("Resource"); + Symbol("Zone"); + Symbol("AnnualSum"); + [Symbol("t$t") for t in 1:T]] + rename!(dfPower, auxNew_Names) + total = DataFrame(["Total" 0 sum(dfPower[!, :AnnualSum]) fill(0.0, (1, T))], auxNew_Names) + total[!, 4:(T + 3)] .= sum(power, dims = 1) + df_Power = vcat(dfPower, total) + DFMatrix = Matrix(dftranspose(df_Power, true)) + DFnames = DFMatrix[1,:] + FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( - path, setup, df_Power, names(df_Power)) - CSV.write(joinpath(output_path, "power.csv"), dfOut_full) + path, setup, dftranspose(df_Power, false), DFnames) + CSV.write(joinpath(output_path, "power.csv"), dfOut_full, writeheader = false) println("Writing Full Time Series for Power") end end diff --git a/src/write_outputs/write_power_balance.jl b/src/write_outputs/write_power_balance.jl index add22c6310..79731ef495 100644 --- a/src/write_outputs/write_power_balance.jl +++ b/src/write_outputs/write_power_balance.jl @@ -100,8 +100,6 @@ function write_power_balance(path::AbstractString, inputs::Dict, setup::Dict, EP if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 DFnames = dfPowerBalance[:, 1] insert!(DFnames, 1, "BalanceComponent") - #DFMatrix = Matrix(dftranspose(dfPowerBalance, true)) - # DFnames = DFMatrix[1,:] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( From 75160a0bc1ecf5b552addddb5d65b942f563e780 Mon Sep 17 00:00:00 2001 From: Maya Mutic Date: Mon, 24 Jun 2024 22:04:48 +0200 Subject: [PATCH 44/61] Changed write_fts to return dfOut, fixed recon files --- src/write_outputs/ucommit/write_shutdown.jl | 14 +------------- src/write_outputs/ucommit/write_start.jl | 14 +------------- src/write_outputs/write_charge.jl | 18 ++---------------- src/write_outputs/write_co2.jl | 13 +------------ src/write_outputs/write_curtailment.jl | 13 +------------ src/write_outputs/write_outputs.jl | 2 +- src/write_outputs/write_power.jl | 13 +------------ 7 files changed, 8 insertions(+), 79 deletions(-) diff --git a/src/write_outputs/ucommit/write_shutdown.jl b/src/write_outputs/ucommit/write_shutdown.jl index 3dc54929b9..b232a0ebd6 100644 --- a/src/write_outputs/ucommit/write_shutdown.jl +++ b/src/write_outputs/ucommit/write_shutdown.jl @@ -13,22 +13,10 @@ function write_shutdown(path::AbstractString, inputs::Dict, setup::Dict, EP::Mod if setup["WriteOutputs"] == "annual" write_annual(filepath, dfShutdown) else # setup["WriteOutputs"] == "full" - write_fulltimeseries(filepath, shut, dfShutdown) - + df_Shutdown = write_fulltimeseries(filepath, shut, dfShutdown) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - T = size(shut, 2) - dfShutdown = hcat(dfShutdown, DataFrame(shut, :auto)) - auxNew_Names = [Symbol("Resource"); - Symbol("Zone"); - Symbol("AnnualSum"); - [Symbol("t$t") for t in 1:T]] - rename!(dfShutdown, auxNew_Names) - total = DataFrame(["Total" 0 sum(dfShutdown[!, :AnnualSum]) fill(0.0, (1, T))], auxNew_Names) - total[!, 4:(T + 3)] .= sum(shut, dims = 1) - df_Shutdown = vcat(dfShutdown, total) DFMatrix = Matrix(dftranspose(df_Shutdown, true)) DFnames = DFMatrix[1,:] - FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path,FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(df_Shutdown, false), DFnames) diff --git a/src/write_outputs/ucommit/write_start.jl b/src/write_outputs/ucommit/write_start.jl index 0e1c0df920..9a730c5ecb 100644 --- a/src/write_outputs/ucommit/write_start.jl +++ b/src/write_outputs/ucommit/write_start.jl @@ -12,22 +12,10 @@ function write_start(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) if setup["WriteOutputs"] == "annual" write_annual(filepath, dfStart) else # setup["WriteOutputs"] == "full" - write_fulltimeseries(filepath, start, dfStart) - # full path, dataout, dfout + df_Start = write_fulltimeseries(filepath, start, dfStart) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - T = size(start, 2) - dfStart = hcat(dfStart, DataFrame(start, :auto)) - auxNew_Names = [Symbol("Resource"); - Symbol("Zone"); - Symbol("AnnualSum"); - [Symbol("t$t") for t in 1:T]] - rename!(dfStart, auxNew_Names) - total = DataFrame(["Total" 0 sum(dfStart[!, :AnnualSum]) fill(0.0, (1, T))], auxNew_Names) - total[!, 4:(T + 3)] .= sum(start, dims = 1) - df_Start = vcat(dfStart, total) DFMatrix = Matrix(dftranspose(df_Start, true)) DFnames = DFMatrix[1,:] - FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( diff --git a/src/write_outputs/write_charge.jl b/src/write_outputs/write_charge.jl index cdaef9d015..4971f89f88 100644 --- a/src/write_outputs/write_charge.jl +++ b/src/write_outputs/write_charge.jl @@ -41,24 +41,10 @@ function write_charge(path::AbstractString, inputs::Dict, setup::Dict, EP::Model if setup["WriteOutputs"] == "annual" write_annual(filepath, dfCharge) else # setup["WriteOutputs"] == "full" - write_fulltimeseries(filepath, charge, dfCharge) - if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - - # full path, dataout, dfout - - T = size(charge, 2) - dfCharge = hcat(dfCharge, DataFrame(charge, :auto)) - auxNew_Names = [Symbol("Resource"); - Symbol("Zone"); - Symbol("AnnualSum"); - [Symbol("t$t") for t in 1:T]] - rename!(dfCharge, auxNew_Names) - total = DataFrame(["Total" 0 sum(dfCharge[!, :AnnualSum]) fill(0.0, (1, T))], auxNew_Names) - total[!, 4:(T + 3)] .= sum(charge, dims = 1) - df_Charge = vcat(dfCharge, total) + df_Charge = write_fulltimeseries(filepath, charge, dfCharge) + if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 DFMatrix = Matrix(dftranspose(df_Charge, true)) DFnames = DFMatrix[1,:] - FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( diff --git a/src/write_outputs/write_co2.jl b/src/write_outputs/write_co2.jl index 86112c87f2..256291bc69 100644 --- a/src/write_outputs/write_co2.jl +++ b/src/write_outputs/write_co2.jl @@ -31,21 +31,10 @@ function write_co2_emissions_plant(path::AbstractString, if setup["WriteOutputs"] == "annual" write_annual(filepath, dfEmissions_plant) else # setup["WriteOutputs"] == "full" - write_fulltimeseries(filepath, emissions_plant, dfEmissions_plant) + df_Emissions_plant = write_fulltimeseries(filepath, emissions_plant, dfEmissions_plant) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - T = size(emissions_plant, 2) - dfEmissions_plant = hcat(dfEmissions_plant, DataFrame(emissions_plant, :auto)) - auxNew_Names = [Symbol("Resource"); - Symbol("Zone"); - Symbol("AnnualSum"); - [Symbol("t$t") for t in 1:T]] - rename!(dfEmissions_plant, auxNew_Names) - total = DataFrame(["Total" 0 sum(dfEmissions_plant[!, :AnnualSum]) fill(0.0, (1, T))], auxNew_Names) - total[!, 4:(T + 3)] .= sum(emissions_plant, dims = 1) - df_Emissions_plant = vcat(dfEmissions_plant, total) DFMatrix = Matrix(dftranspose(df_Emissions_plant, true)) DFnames = DFMatrix[1,:] - FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( diff --git a/src/write_outputs/write_curtailment.jl b/src/write_outputs/write_curtailment.jl index b0b191fca4..091a4a3df5 100644 --- a/src/write_outputs/write_curtailment.jl +++ b/src/write_outputs/write_curtailment.jl @@ -57,21 +57,10 @@ function write_curtailment(path::AbstractString, inputs::Dict, setup::Dict, EP:: if setup["WriteOutputs"] == "annual" write_annual(filename, dfCurtailment) else # setup["WriteOutputs"] == "full" - write_fulltimeseries(filename, curtailment, dfCurtailment) + df_Curtailment = write_fulltimeseries(filename, curtailment, dfCurtailment) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - T = size(curtailment, 2) - dfCurtailment = hcat(dfCurtailment, DataFrame(curtailment, :auto)) - auxNew_Names = [Symbol("Resource"); - Symbol("Zone"); - Symbol("AnnualSum"); - [Symbol("t$t") for t in 1:T]] - rename!(dfCurtailment, auxNew_Names) - total = DataFrame(["Total" 0 sum(dfCurtailment[!, :AnnualSum]) fill(0.0, (1, T))], auxNew_Names) - total[!, 4:(T + 3)] .= sum(curtailment, dims = 1) - df_Curtailment = vcat(dfCurtailment, total) DFMatrix = Matrix(dftranspose(df_Curtailment, true)) DFnames = DFMatrix[1,:] - FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( diff --git a/src/write_outputs/write_outputs.jl b/src/write_outputs/write_outputs.jl index 8a42ea8d75..c39c384af0 100644 --- a/src/write_outputs/write_outputs.jl +++ b/src/write_outputs/write_outputs.jl @@ -509,7 +509,7 @@ function write_fulltimeseries(fullpath::AbstractString, dfOut = vcat(dfOut, total) CSV.write(fullpath, dftranspose(dfOut, false), writeheader = false) - return nothing + return dfOut end function write_settings_file(path, setup) diff --git a/src/write_outputs/write_power.jl b/src/write_outputs/write_power.jl index 8264d41d22..d0c7fd8aab 100644 --- a/src/write_outputs/write_power.jl +++ b/src/write_outputs/write_power.jl @@ -24,21 +24,10 @@ function write_power(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) if setup["WriteOutputs"] == "annual" write_annual(filepath, dfPower) else # setup["WriteOutputs"] == "full" - write_fulltimeseries(filepath, power, dfPower) + df_Power = write_fulltimeseries(filepath, power, dfPower) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - T = size(power, 2) - dfPower = hcat(dfPower, DataFrame(power, :auto)) - auxNew_Names = [Symbol("Resource"); - Symbol("Zone"); - Symbol("AnnualSum"); - [Symbol("t$t") for t in 1:T]] - rename!(dfPower, auxNew_Names) - total = DataFrame(["Total" 0 sum(dfPower[!, :AnnualSum]) fill(0.0, (1, T))], auxNew_Names) - total[!, 4:(T + 3)] .= sum(power, dims = 1) - df_Power = vcat(dfPower, total) DFMatrix = Matrix(dftranspose(df_Power, true)) DFnames = DFMatrix[1,:] - FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( From 83941906457b182043df1077a473d0a2c71d1e03 Mon Sep 17 00:00:00 2001 From: Maya Mutic Date: Wed, 26 Jun 2024 19:33:34 +0200 Subject: [PATCH 45/61] Took out DFnames as an argument in FTR --- .../full_time_series_reconstruction.jl | 5 ++--- src/write_outputs/transmission/write_transmission_flows.jl | 3 +-- src/write_outputs/transmission/write_transmission_losses.jl | 3 +-- src/write_outputs/ucommit/write_commit.jl | 5 +---- src/write_outputs/ucommit/write_shutdown.jl | 4 +--- src/write_outputs/ucommit/write_start.jl | 4 +--- src/write_outputs/write_charge.jl | 6 ++---- src/write_outputs/write_co2.jl | 4 +--- src/write_outputs/write_curtailment.jl | 4 +--- src/write_outputs/write_emissions.jl | 4 +--- src/write_outputs/write_fuel_consumption.jl | 4 +--- src/write_outputs/write_nse.jl | 4 +--- src/write_outputs/write_power.jl | 4 +--- src/write_outputs/write_power_balance.jl | 4 +--- src/write_outputs/write_price.jl | 3 +-- src/write_outputs/write_reliability.jl | 3 +-- src/write_outputs/write_storage.jl | 4 +--- src/write_outputs/write_storagedual.jl | 4 +--- 18 files changed, 20 insertions(+), 52 deletions(-) diff --git a/src/time_domain_reduction/full_time_series_reconstruction.jl b/src/time_domain_reduction/full_time_series_reconstruction.jl index ffa6aefb82..c42900d603 100644 --- a/src/time_domain_reduction/full_time_series_reconstruction.jl +++ b/src/time_domain_reduction/full_time_series_reconstruction.jl @@ -7,7 +7,6 @@ Create a DataFrame with all 8,760 hours of the year from the reduced output. path - Path input to the results folder setup - case setup (dictionary) DF - DataFrame to be reconstructed -DFnames - Vector of column names This function uses Period_map.csv to create a new DataFrame with 8,760 time steps, as well as other pre-existing rows such as "Zone". For each 52 weeks of the year, the corresponding representative week is taken from the input DataFrame and copied into the new DataFrame. Representative periods that @@ -21,7 +20,7 @@ This function is called when output files with time series data (e.g. power.csv, """ function full_time_series_reconstruction( - path::AbstractString, setup::Dict, DF::DataFrame, DFnames::Vector) + path::AbstractString, setup::Dict, DF::DataFrame) # Read Period map file Period_map.csv case = path[1:findlast('/', path)] TDRpath = joinpath(case, setup["TimeDomainReductionFolder"]) @@ -56,7 +55,7 @@ function full_time_series_reconstruction( end recon = [recon recon_col] end - reconDF = DataFrame(recon, DFnames, makeunique = true) + reconDF = DataFrame(recon, :auto) # Insert rows that were above "t1" in the original DataFrame (e.g. "Zone" and "AnnualSum") if present for i in range(1, t1 - 1) diff --git a/src/write_outputs/transmission/write_transmission_flows.jl b/src/write_outputs/transmission/write_transmission_flows.jl index 7decbb710a..ab39abf394 100644 --- a/src/write_outputs/transmission/write_transmission_flows.jl +++ b/src/write_outputs/transmission/write_transmission_flows.jl @@ -25,11 +25,10 @@ function write_transmission_flows(path::AbstractString, CSV.write(filepath, dftranspose(dfFlow, false), writeheader = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - DFnames = ["Line", "1", "2"] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(dfFlow, false), DFnames) + path, setup, dftranspose(dfFlow, false)) CSV.write(joinpath(output_path, "flow.csv"), dfOut_full, header = false) println("Writing Full Time Series for Transmission Flows") end diff --git a/src/write_outputs/transmission/write_transmission_losses.jl b/src/write_outputs/transmission/write_transmission_losses.jl index 18d66a202f..ad0c034c64 100644 --- a/src/write_outputs/transmission/write_transmission_losses.jl +++ b/src/write_outputs/transmission/write_transmission_losses.jl @@ -32,11 +32,10 @@ function write_transmission_losses(path::AbstractString, writeheader = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - DFnames = ["Line", "1", "2", "Total"] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(dfTLosses, false), DFnames) + path, setup, dftranspose(dfTLosses, false)) CSV.write(joinpath(output_path, "tlosses.csv"), dfOut_full, header = false) println("Writing Full Time Series for Time Losses") end diff --git a/src/write_outputs/ucommit/write_commit.jl b/src/write_outputs/ucommit/write_commit.jl index 75b6ec7ac3..142cc70017 100644 --- a/src/write_outputs/ucommit/write_commit.jl +++ b/src/write_outputs/ucommit/write_commit.jl @@ -12,14 +12,11 @@ function write_commit(path::AbstractString, inputs::Dict, setup::Dict, EP::Model rename!(dfCommit, auxNew_Names) CSV.write(joinpath(path, "commit.csv"), dftranspose(dfCommit, false), header = false) - if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - DFMatrix = Matrix(dftranspose(dfCommit, true)) - DFnames = DFMatrix[1, :] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(dfCommit, false), DFnames) + path, setup, dftranspose(dfCommit, false)) CSV.write(joinpath(output_path, "commit.csv"), dfOut_full, header = false) println("Writing Full Time Series for Commitment") end diff --git a/src/write_outputs/ucommit/write_shutdown.jl b/src/write_outputs/ucommit/write_shutdown.jl index b232a0ebd6..e864d0baf4 100644 --- a/src/write_outputs/ucommit/write_shutdown.jl +++ b/src/write_outputs/ucommit/write_shutdown.jl @@ -15,11 +15,9 @@ function write_shutdown(path::AbstractString, inputs::Dict, setup::Dict, EP::Mod else # setup["WriteOutputs"] == "full" df_Shutdown = write_fulltimeseries(filepath, shut, dfShutdown) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - DFMatrix = Matrix(dftranspose(df_Shutdown, true)) - DFnames = DFMatrix[1,:] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path,FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(df_Shutdown, false), DFnames) + dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(df_Shutdown, false)) CSV.write(joinpath(output_path,"shutdown.csv"), dfOut_full, writeheader = false) println("Writing Full Time Series for Shutdown") end diff --git a/src/write_outputs/ucommit/write_start.jl b/src/write_outputs/ucommit/write_start.jl index 9a730c5ecb..3bc707af54 100644 --- a/src/write_outputs/ucommit/write_start.jl +++ b/src/write_outputs/ucommit/write_start.jl @@ -14,12 +14,10 @@ function write_start(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) else # setup["WriteOutputs"] == "full" df_Start = write_fulltimeseries(filepath, start, dfStart) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - DFMatrix = Matrix(dftranspose(df_Start, true)) - DFnames = DFMatrix[1,:] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(df_Start, false), DFnames) + path, setup, dftranspose(df_Start, false)) CSV.write(joinpath(output_path, "start.csv"), dfOut_full, writeheader = false) println("Writing Full Time Series for Startup") end diff --git a/src/write_outputs/write_charge.jl b/src/write_outputs/write_charge.jl index 4971f89f88..813c9ccedc 100644 --- a/src/write_outputs/write_charge.jl +++ b/src/write_outputs/write_charge.jl @@ -42,13 +42,11 @@ function write_charge(path::AbstractString, inputs::Dict, setup::Dict, EP::Model write_annual(filepath, dfCharge) else # setup["WriteOutputs"] == "full" df_Charge = write_fulltimeseries(filepath, charge, dfCharge) - if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - DFMatrix = Matrix(dftranspose(df_Charge, true)) - DFnames = DFMatrix[1,:] + if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(df_Charge, false), DFnames) + path, setup, dftranspose(df_Charge, false)) CSV.write(joinpath(output_path, "charge.csv"), dfOut_full, writeheader = false) println("Writing Full Time Series for Charge") end diff --git a/src/write_outputs/write_co2.jl b/src/write_outputs/write_co2.jl index 256291bc69..f6097ee7cd 100644 --- a/src/write_outputs/write_co2.jl +++ b/src/write_outputs/write_co2.jl @@ -33,12 +33,10 @@ function write_co2_emissions_plant(path::AbstractString, else # setup["WriteOutputs"] == "full" df_Emissions_plant = write_fulltimeseries(filepath, emissions_plant, dfEmissions_plant) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - DFMatrix = Matrix(dftranspose(df_Emissions_plant, true)) - DFnames = DFMatrix[1,:] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(df_Emissions_plant, false), DFnames) + path, setup, dftranspose(df_Emissions_plant, false)) CSV.write(joinpath(output_path, "emissions_plant.csv"), dfOut_full, writeheader = false) println("Writing Full Time Series for Emissions Plant") end diff --git a/src/write_outputs/write_curtailment.jl b/src/write_outputs/write_curtailment.jl index 091a4a3df5..186bed9315 100644 --- a/src/write_outputs/write_curtailment.jl +++ b/src/write_outputs/write_curtailment.jl @@ -59,12 +59,10 @@ function write_curtailment(path::AbstractString, inputs::Dict, setup::Dict, EP:: else # setup["WriteOutputs"] == "full" df_Curtailment = write_fulltimeseries(filename, curtailment, dfCurtailment) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - DFMatrix = Matrix(dftranspose(df_Curtailment, true)) - DFnames = DFMatrix[1,:] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(df_Curtailment, false), DFnames) + path, setup, dftranspose(df_Curtailment, false)) CSV.write(joinpath(output_path, "curtail.csv"), dfOut_full, writeheader = false) println("Writing Full Time Series for Curtailment") end diff --git a/src/write_outputs/write_emissions.jl b/src/write_outputs/write_emissions.jl index b53641bc6b..16f92b89fa 100644 --- a/src/write_outputs/write_emissions.jl +++ b/src/write_outputs/write_emissions.jl @@ -126,11 +126,9 @@ function write_emissions(path::AbstractString, inputs::Dict, setup::Dict, EP::Mo writeheader = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - DFMatrix = Matrix(dftranspose(dfEmissions, true)) - DFnames = DFMatrix[1,:] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path,FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfEmissions, false), DFnames) + dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfEmissions, false)) CSV.write(joinpath(output_path,"emissions.csv"), dfOut_full) println("Writing Full Time Series for Emissions") end diff --git a/src/write_outputs/write_fuel_consumption.jl b/src/write_outputs/write_fuel_consumption.jl index 05373bc056..9aeb908d72 100644 --- a/src/write_outputs/write_fuel_consumption.jl +++ b/src/write_outputs/write_fuel_consumption.jl @@ -87,12 +87,10 @@ function write_fuel_consumption_ts(path::AbstractString, dftranspose(dfPlantFuel_TS, false), header = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - DFMatrix = Matrix(dftranspose(dfPlantFuel_TS, true)) - DFnames = DFMatrix[1, :] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(dfPlantFuel_TS, false), DFnames) + path, setup, dftranspose(dfPlantFuel_TS, false)) CSV.write(joinpath(output_path, "commit.csv"), dfOut_full, header = false) println("Writing Full Time Series for Fuel Consumption") end diff --git a/src/write_outputs/write_nse.jl b/src/write_outputs/write_nse.jl index 67a95b5714..786153a3c9 100644 --- a/src/write_outputs/write_nse.jl +++ b/src/write_outputs/write_nse.jl @@ -39,12 +39,10 @@ function write_nse(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) CSV.write(joinpath(path, "nse.csv"), dftranspose(dfNse, false), writeheader = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - DFnames = ["Segment", "1", "2", "3", "4", "1", "2", - "3", "4", "1", "2", "3", "4", "Total"] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(dfNse, false), DFnames) + path, setup, dftranspose(dfNse, false)) CSV.write(joinpath(output_path, "nse.csv"), dfOut_full, header = false) println("Writing Full Time Series for NSE") end diff --git a/src/write_outputs/write_power.jl b/src/write_outputs/write_power.jl index d0c7fd8aab..a2613c06e3 100644 --- a/src/write_outputs/write_power.jl +++ b/src/write_outputs/write_power.jl @@ -26,12 +26,10 @@ function write_power(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) else # setup["WriteOutputs"] == "full" df_Power = write_fulltimeseries(filepath, power, dfPower) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - DFMatrix = Matrix(dftranspose(df_Power, true)) - DFnames = DFMatrix[1,:] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(df_Power, false), DFnames) + path, setup, dftranspose(df_Power, false)) CSV.write(joinpath(output_path, "power.csv"), dfOut_full, writeheader = false) println("Writing Full Time Series for Power") end diff --git a/src/write_outputs/write_power_balance.jl b/src/write_outputs/write_power_balance.jl index 79731ef495..b1133a7837 100644 --- a/src/write_outputs/write_power_balance.jl +++ b/src/write_outputs/write_power_balance.jl @@ -98,12 +98,10 @@ function write_power_balance(path::AbstractString, inputs::Dict, setup::Dict, EP writeheader = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - DFnames = dfPowerBalance[:, 1] - insert!(DFnames, 1, "BalanceComponent") FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(dfPowerBalance, false), DFnames) + path, setup, dftranspose(dfPowerBalance, false)) CSV.write( joinpath(output_path, "power_balance.csv"), dfOut_full, header = false) println("Writing Full Time Series for Power Balance") diff --git a/src/write_outputs/write_price.jl b/src/write_outputs/write_price.jl index 7d5365e900..0cd6e2471d 100644 --- a/src/write_outputs/write_price.jl +++ b/src/write_outputs/write_price.jl @@ -23,11 +23,10 @@ function write_price(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) writeheader = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - DFnames = ["Zone", "1", "2", "3"] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(dfPrice, false), DFnames) + path, setup, dftranspose(dfPrice, false)) CSV.write(joinpath(output_path, "prices.csv"), dfOut_full, header = false) println("Writing Full Time Series for Price") end diff --git a/src/write_outputs/write_reliability.jl b/src/write_outputs/write_reliability.jl index c19ad9b0cc..95114a01b8 100644 --- a/src/write_outputs/write_reliability.jl +++ b/src/write_outputs/write_reliability.jl @@ -22,11 +22,10 @@ function write_reliability(path::AbstractString, inputs::Dict, setup::Dict, EP:: header = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - DFnames = ["Zone", "1", "2", "3"] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(dfReliability, false), DFnames) + path, setup, dftranspose(dfReliability, false)) CSV.write(joinpath(output_path, "reliability.csv"), dfOut_full, header = false) println("Writing Full Time Series for Reliability") end diff --git a/src/write_outputs/write_storage.jl b/src/write_outputs/write_storage.jl index 720be09821..fc4c099c0f 100644 --- a/src/write_outputs/write_storage.jl +++ b/src/write_outputs/write_storage.jl @@ -41,12 +41,10 @@ function write_storage(path::AbstractString, inputs::Dict, setup::Dict, EP::Mode CSV.write(joinpath(path, "storage.csv"), dftranspose(dfStorage, false), header = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - DFMatrix = Matrix(dftranspose(dfStorage, true)) - DFnames = DFMatrix[1, :] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(dfStorage, false), DFnames) + path, setup, dftranspose(dfStorage, false)) CSV.write(joinpath(output_path, "storage.csv"), dfOut_full, header = false) println("Writing Full Time Series for Storage") end diff --git a/src/write_outputs/write_storagedual.jl b/src/write_outputs/write_storagedual.jl index c091ec32e9..8b570a9131 100644 --- a/src/write_outputs/write_storagedual.jl +++ b/src/write_outputs/write_storagedual.jl @@ -81,12 +81,10 @@ function write_storagedual(path::AbstractString, inputs::Dict, setup::Dict, EP:: header = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - DFMatrix = Matrix(dftranspose(dfStorageDual, true)) - DFnames = DFMatrix[1, :] FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(dfStorageDual, false), DFnames) + path, setup, dftranspose(dfStorageDual, false)) CSV.write(joinpath(output_path, "storagebal_duals.csv"), dfOut_full, header = false) println("Writing Full Time Series for Storage Duals") end From b3f603c5e5b371be8fd324f9387fcc0389f10437 Mon Sep 17 00:00:00 2001 From: Maya Mutic Date: Wed, 26 Jun 2024 22:02:24 +0200 Subject: [PATCH 46/61] Added write CSV to the reconstruction, made perform_recon() function --- .../full_time_series_reconstruction.jl | 25 +++++++++++++++---- .../transmission/write_transmission_flows.jl | 6 +---- .../transmission/write_transmission_losses.jl | 6 +---- src/write_outputs/ucommit/write_commit.jl | 6 +---- src/write_outputs/ucommit/write_shutdown.jl | 5 +--- src/write_outputs/ucommit/write_start.jl | 6 +---- src/write_outputs/write_charge.jl | 6 +---- src/write_outputs/write_co2.jl | 6 +---- src/write_outputs/write_curtailment.jl | 6 +---- src/write_outputs/write_emissions.jl | 5 +--- src/write_outputs/write_fuel_consumption.jl | 6 +---- src/write_outputs/write_nse.jl | 6 +---- src/write_outputs/write_power.jl | 6 +---- src/write_outputs/write_power_balance.jl | 7 +----- src/write_outputs/write_price.jl | 6 +---- src/write_outputs/write_reliability.jl | 6 +---- src/write_outputs/write_storage.jl | 6 +---- src/write_outputs/write_storagedual.jl | 6 +---- 18 files changed, 37 insertions(+), 89 deletions(-) diff --git a/src/time_domain_reduction/full_time_series_reconstruction.jl b/src/time_domain_reduction/full_time_series_reconstruction.jl index c42900d603..8c83ef4fb7 100644 --- a/src/time_domain_reduction/full_time_series_reconstruction.jl +++ b/src/time_domain_reduction/full_time_series_reconstruction.jl @@ -1,14 +1,15 @@ @doc raw"""full_time_series_reconstruction(path::AbstractString, - case::AbstractString, + setup::Dict, DF::DataFrame, - DFnames::Vector) + name::String) Create a DataFrame with all 8,760 hours of the year from the reduced output. path - Path input to the results folder setup - case setup (dictionary) DF - DataFrame to be reconstructed +name - name desired for the .csv file -This function uses Period_map.csv to create a new DataFrame with 8,760 time steps, as well as other pre-existing rows such as "Zone". +This function calls perform_reconstruction(), which uses Period_map.csv to create a new DataFrame with 8,760 time steps, as well as other pre-existing rows such as "Zone". For each 52 weeks of the year, the corresponding representative week is taken from the input DataFrame and copied into the new DataFrame. Representative periods that represent more than one week will appear multiple times in the output. @@ -20,7 +21,21 @@ This function is called when output files with time series data (e.g. power.csv, """ function full_time_series_reconstruction( - path::AbstractString, setup::Dict, DF::DataFrame) + path::AbstractString, setup::Dict, DF::DataFrame, name::String) + FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] + output_path = joinpath(path, FullTimeSeriesFolder) + dfOut_full = perform_reconstruction(path, setup, dftranspose(DF, false)) + CSV.write(joinpath(output_path, "$name.csv"), dfOut_full, header = false) + return nothing +end + +""" + perform_reconstruction(path::AbstractString, setup::Dict, DF::DataFrame) + +Internal function for performing the reconstruction. This function returns a DataFrame with the full series reconstruction. +""" +function perform_reconstruction( + path::AbstractString, setup::Dict, DF::DataFrame) # Read Period map file Period_map.csv case = path[1:findlast('/', path)] TDRpath = joinpath(case, setup["TimeDomainReductionFolder"]) @@ -50,7 +65,7 @@ function full_time_series_reconstruction( recon_col = [] for i in range(1, numPeriods) index = Period_map[i, "Rep_Period_Index"] - recon_temp = col[(TimestepsPerRepPeriod * index - (TimestepsPerRepPeriod - 1)):(TimestepsPerRepPeriod * index)] # Describe how this works + recon_temp = col[(TimestepsPerRepPeriod * index - (TimestepsPerRepPeriod - 1)):(TimestepsPerRepPeriod * index)] recon_col = [recon_col; recon_temp] end recon = [recon recon_col] diff --git a/src/write_outputs/transmission/write_transmission_flows.jl b/src/write_outputs/transmission/write_transmission_flows.jl index ab39abf394..25c7577cc5 100644 --- a/src/write_outputs/transmission/write_transmission_flows.jl +++ b/src/write_outputs/transmission/write_transmission_flows.jl @@ -25,11 +25,7 @@ function write_transmission_flows(path::AbstractString, CSV.write(filepath, dftranspose(dfFlow, false), writeheader = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path, FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(dfFlow, false)) - CSV.write(joinpath(output_path, "flow.csv"), dfOut_full, header = false) + full_time_series_reconstruction(path, setup, dfFlow, "flow") println("Writing Full Time Series for Transmission Flows") end end diff --git a/src/write_outputs/transmission/write_transmission_losses.jl b/src/write_outputs/transmission/write_transmission_losses.jl index ad0c034c64..09b06eba71 100644 --- a/src/write_outputs/transmission/write_transmission_losses.jl +++ b/src/write_outputs/transmission/write_transmission_losses.jl @@ -32,11 +32,7 @@ function write_transmission_losses(path::AbstractString, writeheader = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path, FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(dfTLosses, false)) - CSV.write(joinpath(output_path, "tlosses.csv"), dfOut_full, header = false) + full_time_series_reconstruction(path, setup, dfTLosses, "tlosses") println("Writing Full Time Series for Time Losses") end end diff --git a/src/write_outputs/ucommit/write_commit.jl b/src/write_outputs/ucommit/write_commit.jl index 142cc70017..6aa6d48d20 100644 --- a/src/write_outputs/ucommit/write_commit.jl +++ b/src/write_outputs/ucommit/write_commit.jl @@ -13,11 +13,7 @@ function write_commit(path::AbstractString, inputs::Dict, setup::Dict, EP::Model CSV.write(joinpath(path, "commit.csv"), dftranspose(dfCommit, false), header = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path, FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(dfCommit, false)) - CSV.write(joinpath(output_path, "commit.csv"), dfOut_full, header = false) + full_time_series_reconstruction(path, setup, dfCommit, "commit") println("Writing Full Time Series for Commitment") end end diff --git a/src/write_outputs/ucommit/write_shutdown.jl b/src/write_outputs/ucommit/write_shutdown.jl index e864d0baf4..cbb9f3b6a5 100644 --- a/src/write_outputs/ucommit/write_shutdown.jl +++ b/src/write_outputs/ucommit/write_shutdown.jl @@ -15,10 +15,7 @@ function write_shutdown(path::AbstractString, inputs::Dict, setup::Dict, EP::Mod else # setup["WriteOutputs"] == "full" df_Shutdown = write_fulltimeseries(filepath, shut, dfShutdown) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path,FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(df_Shutdown, false)) - CSV.write(joinpath(output_path,"shutdown.csv"), dfOut_full, writeheader = false) + full_time_series_reconstruction(path, setup, df_Shutdown, "shutdown") println("Writing Full Time Series for Shutdown") end end diff --git a/src/write_outputs/ucommit/write_start.jl b/src/write_outputs/ucommit/write_start.jl index 3bc707af54..334b231e72 100644 --- a/src/write_outputs/ucommit/write_start.jl +++ b/src/write_outputs/ucommit/write_start.jl @@ -14,11 +14,7 @@ function write_start(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) else # setup["WriteOutputs"] == "full" df_Start = write_fulltimeseries(filepath, start, dfStart) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path, FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(df_Start, false)) - CSV.write(joinpath(output_path, "start.csv"), dfOut_full, writeheader = false) + full_time_series_reconstruction(path, setup, df_Start, "start") println("Writing Full Time Series for Startup") end end diff --git a/src/write_outputs/write_charge.jl b/src/write_outputs/write_charge.jl index 813c9ccedc..7cbf6707af 100644 --- a/src/write_outputs/write_charge.jl +++ b/src/write_outputs/write_charge.jl @@ -43,11 +43,7 @@ function write_charge(path::AbstractString, inputs::Dict, setup::Dict, EP::Model else # setup["WriteOutputs"] == "full" df_Charge = write_fulltimeseries(filepath, charge, dfCharge) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path, FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(df_Charge, false)) - CSV.write(joinpath(output_path, "charge.csv"), dfOut_full, writeheader = false) + full_time_series_reconstruction(path, setup, df_Charge, "charge") println("Writing Full Time Series for Charge") end end diff --git a/src/write_outputs/write_co2.jl b/src/write_outputs/write_co2.jl index f6097ee7cd..4774fc4435 100644 --- a/src/write_outputs/write_co2.jl +++ b/src/write_outputs/write_co2.jl @@ -33,11 +33,7 @@ function write_co2_emissions_plant(path::AbstractString, else # setup["WriteOutputs"] == "full" df_Emissions_plant = write_fulltimeseries(filepath, emissions_plant, dfEmissions_plant) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path, FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(df_Emissions_plant, false)) - CSV.write(joinpath(output_path, "emissions_plant.csv"), dfOut_full, writeheader = false) + full_time_series_reconstruction(path, setup, df_Emissions_plant, "emissions_plant") println("Writing Full Time Series for Emissions Plant") end end diff --git a/src/write_outputs/write_curtailment.jl b/src/write_outputs/write_curtailment.jl index 186bed9315..e9d3444210 100644 --- a/src/write_outputs/write_curtailment.jl +++ b/src/write_outputs/write_curtailment.jl @@ -59,11 +59,7 @@ function write_curtailment(path::AbstractString, inputs::Dict, setup::Dict, EP:: else # setup["WriteOutputs"] == "full" df_Curtailment = write_fulltimeseries(filename, curtailment, dfCurtailment) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path, FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(df_Curtailment, false)) - CSV.write(joinpath(output_path, "curtail.csv"), dfOut_full, writeheader = false) + full_time_series_reconstruction(path, setup, df_Curtailment, "curtail") println("Writing Full Time Series for Curtailment") end end diff --git a/src/write_outputs/write_emissions.jl b/src/write_outputs/write_emissions.jl index 16f92b89fa..0fb598ae81 100644 --- a/src/write_outputs/write_emissions.jl +++ b/src/write_outputs/write_emissions.jl @@ -126,10 +126,7 @@ function write_emissions(path::AbstractString, inputs::Dict, setup::Dict, EP::Mo writeheader = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path,FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction(path,setup, dftranspose(dfEmissions, false)) - CSV.write(joinpath(output_path,"emissions.csv"), dfOut_full) + full_time_series_reconstruction(path, setup, dfEmissions, "emissions") println("Writing Full Time Series for Emissions") end end diff --git a/src/write_outputs/write_fuel_consumption.jl b/src/write_outputs/write_fuel_consumption.jl index 9aeb908d72..53c03a480d 100644 --- a/src/write_outputs/write_fuel_consumption.jl +++ b/src/write_outputs/write_fuel_consumption.jl @@ -87,11 +87,7 @@ function write_fuel_consumption_ts(path::AbstractString, dftranspose(dfPlantFuel_TS, false), header = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path, FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(dfPlantFuel_TS, false)) - CSV.write(joinpath(output_path, "commit.csv"), dfOut_full, header = false) + full_time_series_reconstruction(path, setup, dfPlantFuel_TS, "FuelConsumption_plant_MMBTU") println("Writing Full Time Series for Fuel Consumption") end end diff --git a/src/write_outputs/write_nse.jl b/src/write_outputs/write_nse.jl index 786153a3c9..bdd8f732c3 100644 --- a/src/write_outputs/write_nse.jl +++ b/src/write_outputs/write_nse.jl @@ -39,11 +39,7 @@ function write_nse(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) CSV.write(joinpath(path, "nse.csv"), dftranspose(dfNse, false), writeheader = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path, FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(dfNse, false)) - CSV.write(joinpath(output_path, "nse.csv"), dfOut_full, header = false) + full_time_series_reconstruction(path, setup, dfNse, "nse") println("Writing Full Time Series for NSE") end end diff --git a/src/write_outputs/write_power.jl b/src/write_outputs/write_power.jl index a2613c06e3..dc8a2696af 100644 --- a/src/write_outputs/write_power.jl +++ b/src/write_outputs/write_power.jl @@ -26,11 +26,7 @@ function write_power(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) else # setup["WriteOutputs"] == "full" df_Power = write_fulltimeseries(filepath, power, dfPower) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path, FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(df_Power, false)) - CSV.write(joinpath(output_path, "power.csv"), dfOut_full, writeheader = false) + full_time_series_reconstruction(path, setup, df_Power, "power") println("Writing Full Time Series for Power") end end diff --git a/src/write_outputs/write_power_balance.jl b/src/write_outputs/write_power_balance.jl index b1133a7837..455db19224 100644 --- a/src/write_outputs/write_power_balance.jl +++ b/src/write_outputs/write_power_balance.jl @@ -98,12 +98,7 @@ function write_power_balance(path::AbstractString, inputs::Dict, setup::Dict, EP writeheader = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path, FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(dfPowerBalance, false)) - CSV.write( - joinpath(output_path, "power_balance.csv"), dfOut_full, header = false) + full_time_series_reconstruction(path, setup, dfPowerBalance, "power_balance") println("Writing Full Time Series for Power Balance") end end diff --git a/src/write_outputs/write_price.jl b/src/write_outputs/write_price.jl index 0cd6e2471d..8dace217ee 100644 --- a/src/write_outputs/write_price.jl +++ b/src/write_outputs/write_price.jl @@ -23,11 +23,7 @@ function write_price(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) writeheader = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path, FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(dfPrice, false)) - CSV.write(joinpath(output_path, "prices.csv"), dfOut_full, header = false) + full_time_series_reconstruction(path, setup, dfPrice, "prices") println("Writing Full Time Series for Price") end return nothing diff --git a/src/write_outputs/write_reliability.jl b/src/write_outputs/write_reliability.jl index 95114a01b8..7996c01de5 100644 --- a/src/write_outputs/write_reliability.jl +++ b/src/write_outputs/write_reliability.jl @@ -22,11 +22,7 @@ function write_reliability(path::AbstractString, inputs::Dict, setup::Dict, EP:: header = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path, FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(dfReliability, false)) - CSV.write(joinpath(output_path, "reliability.csv"), dfOut_full, header = false) + full_time_series_reconstruction(path, setup, dfReliability, "reliability") println("Writing Full Time Series for Reliability") end end diff --git a/src/write_outputs/write_storage.jl b/src/write_outputs/write_storage.jl index fc4c099c0f..0bc7267c00 100644 --- a/src/write_outputs/write_storage.jl +++ b/src/write_outputs/write_storage.jl @@ -41,11 +41,7 @@ function write_storage(path::AbstractString, inputs::Dict, setup::Dict, EP::Mode CSV.write(joinpath(path, "storage.csv"), dftranspose(dfStorage, false), header = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path, FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(dfStorage, false)) - CSV.write(joinpath(output_path, "storage.csv"), dfOut_full, header = false) + full_time_series_reconstruction(path, setup, dfStorage, "storage") println("Writing Full Time Series for Storage") end end diff --git a/src/write_outputs/write_storagedual.jl b/src/write_outputs/write_storagedual.jl index 8b570a9131..ad8007a165 100644 --- a/src/write_outputs/write_storagedual.jl +++ b/src/write_outputs/write_storagedual.jl @@ -81,11 +81,7 @@ function write_storagedual(path::AbstractString, inputs::Dict, setup::Dict, EP:: header = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path, FullTimeSeriesFolder) - dfOut_full = full_time_series_reconstruction( - path, setup, dftranspose(dfStorageDual, false)) - CSV.write(joinpath(output_path, "storagebal_duals.csv"), dfOut_full, header = false) + full_time_series_reconstruction(path, setup, dfStorageDual, "storagebal_duals") println("Writing Full Time Series for Storage Duals") end end From abe982f3ad8c0c9b14a6d244ca7e11636e51374d Mon Sep 17 00:00:00 2001 From: lbonaldo Date: Wed, 26 Jun 2024 19:09:37 -0400 Subject: [PATCH 47/61] Change function name to follow convention --- docs/src/Model_Reference/TDR.md | 7 +++- .../full_time_series_reconstruction.jl | 41 ++++-------------- .../transmission/write_transmission_flows.jl | 2 +- .../transmission/write_transmission_losses.jl | 2 +- src/write_outputs/ucommit/write_commit.jl | 2 +- src/write_outputs/ucommit/write_shutdown.jl | 2 +- src/write_outputs/ucommit/write_start.jl | 2 +- src/write_outputs/write_charge.jl | 3 +- src/write_outputs/write_co2.jl | 2 +- src/write_outputs/write_curtailment.jl | 2 +- src/write_outputs/write_emissions.jl | 2 +- src/write_outputs/write_fuel_consumption.jl | 2 +- src/write_outputs/write_nse.jl | 2 +- src/write_outputs/write_outputs.jl | 42 +++++++++++++++++-- src/write_outputs/write_power.jl | 2 +- src/write_outputs/write_power_balance.jl | 2 +- src/write_outputs/write_price.jl | 2 +- src/write_outputs/write_reliability.jl | 2 +- src/write_outputs/write_storage.jl | 2 +- src/write_outputs/write_storagedual.jl | 2 +- 20 files changed, 71 insertions(+), 54 deletions(-) diff --git a/docs/src/Model_Reference/TDR.md b/docs/src/Model_Reference/TDR.md index 64c0021aba..c9edbe3204 100644 --- a/docs/src/Model_Reference/TDR.md +++ b/docs/src/Model_Reference/TDR.md @@ -8,4 +8,9 @@ Order = [:type, :function] ```@docs GenX.run_timedomainreduction! -``` \ No newline at end of file +``` + +```@docs +GenX.full_time_series_reconstruction +``` + diff --git a/src/time_domain_reduction/full_time_series_reconstruction.jl b/src/time_domain_reduction/full_time_series_reconstruction.jl index 8c83ef4fb7..92fd66e507 100644 --- a/src/time_domain_reduction/full_time_series_reconstruction.jl +++ b/src/time_domain_reduction/full_time_series_reconstruction.jl @@ -1,40 +1,17 @@ -@doc raw"""full_time_series_reconstruction(path::AbstractString, - setup::Dict, - DF::DataFrame, - name::String) -Create a DataFrame with all 8,760 hours of the year from the reduced output. - -path - Path input to the results folder -setup - case setup (dictionary) -DF - DataFrame to be reconstructed -name - name desired for the .csv file - -This function calls perform_reconstruction(), which uses Period_map.csv to create a new DataFrame with 8,760 time steps, as well as other pre-existing rows such as "Zone". -For each 52 weeks of the year, the corresponding representative week is taken from the input DataFrame and copied into the new DataFrame. Representative periods that -represent more than one week will appear multiple times in the output. - -Note: Currently, TDR only gives the representative periods in Period_map for 52 weeks, when a (non-leap) year is 52 weeks + 24 hours. This function takes the last 24 hours of -the time series and copies them to get up to all 8,760 hours in a year. - -This function is called when output files with time series data (e.g. power.csv, emissions.csv) are created, if the setup key "OutputFullTimeSeries" is set to "1". - """ + full_time_series_reconstruction(path::AbstractString, setup::Dict, DF::DataFrame) -function full_time_series_reconstruction( - path::AbstractString, setup::Dict, DF::DataFrame, name::String) - FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] - output_path = joinpath(path, FullTimeSeriesFolder) - dfOut_full = perform_reconstruction(path, setup, dftranspose(DF, false)) - CSV.write(joinpath(output_path, "$name.csv"), dfOut_full, header = false) - return nothing -end +Internal function for performing the reconstruction. This function returns a DataFrame with the full series reconstruction. -""" - perform_reconstruction(path::AbstractString, setup::Dict, DF::DataFrame) +# Arguments +- `path` (AbstractString): Path input to the results folder +- `setup` (Dict): Case setup +- `DF` (DataFrame): DataFrame to be reconstructed -Internal function for performing the reconstruction. This function returns a DataFrame with the full series reconstruction. +# Returns +- `reconDF` (DataFrame): DataFrame with the full series reconstruction """ -function perform_reconstruction( +function full_time_series_reconstruction( path::AbstractString, setup::Dict, DF::DataFrame) # Read Period map file Period_map.csv case = path[1:findlast('/', path)] diff --git a/src/write_outputs/transmission/write_transmission_flows.jl b/src/write_outputs/transmission/write_transmission_flows.jl index 25c7577cc5..3dd341ba7a 100644 --- a/src/write_outputs/transmission/write_transmission_flows.jl +++ b/src/write_outputs/transmission/write_transmission_flows.jl @@ -25,7 +25,7 @@ function write_transmission_flows(path::AbstractString, CSV.write(filepath, dftranspose(dfFlow, false), writeheader = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - full_time_series_reconstruction(path, setup, dfFlow, "flow") + write_full_time_series_reconstruction(path, setup, dfFlow, "flow") println("Writing Full Time Series for Transmission Flows") end end diff --git a/src/write_outputs/transmission/write_transmission_losses.jl b/src/write_outputs/transmission/write_transmission_losses.jl index 09b06eba71..781988d454 100644 --- a/src/write_outputs/transmission/write_transmission_losses.jl +++ b/src/write_outputs/transmission/write_transmission_losses.jl @@ -32,7 +32,7 @@ function write_transmission_losses(path::AbstractString, writeheader = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - full_time_series_reconstruction(path, setup, dfTLosses, "tlosses") + write_full_time_series_reconstruction(path, setup, dfTLosses, "tlosses") println("Writing Full Time Series for Time Losses") end end diff --git a/src/write_outputs/ucommit/write_commit.jl b/src/write_outputs/ucommit/write_commit.jl index 6aa6d48d20..eefa73074b 100644 --- a/src/write_outputs/ucommit/write_commit.jl +++ b/src/write_outputs/ucommit/write_commit.jl @@ -13,7 +13,7 @@ function write_commit(path::AbstractString, inputs::Dict, setup::Dict, EP::Model CSV.write(joinpath(path, "commit.csv"), dftranspose(dfCommit, false), header = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - full_time_series_reconstruction(path, setup, dfCommit, "commit") + write_full_time_series_reconstruction(path, setup, dfCommit, "commit") println("Writing Full Time Series for Commitment") end end diff --git a/src/write_outputs/ucommit/write_shutdown.jl b/src/write_outputs/ucommit/write_shutdown.jl index cbb9f3b6a5..33a636af74 100644 --- a/src/write_outputs/ucommit/write_shutdown.jl +++ b/src/write_outputs/ucommit/write_shutdown.jl @@ -15,7 +15,7 @@ function write_shutdown(path::AbstractString, inputs::Dict, setup::Dict, EP::Mod else # setup["WriteOutputs"] == "full" df_Shutdown = write_fulltimeseries(filepath, shut, dfShutdown) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - full_time_series_reconstruction(path, setup, df_Shutdown, "shutdown") + write_full_time_series_reconstruction(path, setup, df_Shutdown, "shutdown") println("Writing Full Time Series for Shutdown") end end diff --git a/src/write_outputs/ucommit/write_start.jl b/src/write_outputs/ucommit/write_start.jl index 334b231e72..b2b9009c81 100644 --- a/src/write_outputs/ucommit/write_start.jl +++ b/src/write_outputs/ucommit/write_start.jl @@ -14,7 +14,7 @@ function write_start(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) else # setup["WriteOutputs"] == "full" df_Start = write_fulltimeseries(filepath, start, dfStart) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - full_time_series_reconstruction(path, setup, df_Start, "start") + write_full_time_series_reconstruction(path, setup, df_Start, "start") println("Writing Full Time Series for Startup") end end diff --git a/src/write_outputs/write_charge.jl b/src/write_outputs/write_charge.jl index 7cbf6707af..943d423600 100644 --- a/src/write_outputs/write_charge.jl +++ b/src/write_outputs/write_charge.jl @@ -43,10 +43,9 @@ function write_charge(path::AbstractString, inputs::Dict, setup::Dict, EP::Model else # setup["WriteOutputs"] == "full" df_Charge = write_fulltimeseries(filepath, charge, dfCharge) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - full_time_series_reconstruction(path, setup, df_Charge, "charge") + write_full_time_series_reconstruction(path, setup, df_Charge, "charge") println("Writing Full Time Series for Charge") end end - return nothing end diff --git a/src/write_outputs/write_co2.jl b/src/write_outputs/write_co2.jl index 4774fc4435..079b76f1f4 100644 --- a/src/write_outputs/write_co2.jl +++ b/src/write_outputs/write_co2.jl @@ -33,7 +33,7 @@ function write_co2_emissions_plant(path::AbstractString, else # setup["WriteOutputs"] == "full" df_Emissions_plant = write_fulltimeseries(filepath, emissions_plant, dfEmissions_plant) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - full_time_series_reconstruction(path, setup, df_Emissions_plant, "emissions_plant") + write_full_time_series_reconstruction(path, setup, df_Emissions_plant, "emissions_plant") println("Writing Full Time Series for Emissions Plant") end end diff --git a/src/write_outputs/write_curtailment.jl b/src/write_outputs/write_curtailment.jl index e9d3444210..836d3ba168 100644 --- a/src/write_outputs/write_curtailment.jl +++ b/src/write_outputs/write_curtailment.jl @@ -59,7 +59,7 @@ function write_curtailment(path::AbstractString, inputs::Dict, setup::Dict, EP:: else # setup["WriteOutputs"] == "full" df_Curtailment = write_fulltimeseries(filename, curtailment, dfCurtailment) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - full_time_series_reconstruction(path, setup, df_Curtailment, "curtail") + write_full_time_series_reconstruction(path, setup, df_Curtailment, "curtail") println("Writing Full Time Series for Curtailment") end end diff --git a/src/write_outputs/write_emissions.jl b/src/write_outputs/write_emissions.jl index 0fb598ae81..3e211cf37a 100644 --- a/src/write_outputs/write_emissions.jl +++ b/src/write_outputs/write_emissions.jl @@ -126,7 +126,7 @@ function write_emissions(path::AbstractString, inputs::Dict, setup::Dict, EP::Mo writeheader = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - full_time_series_reconstruction(path, setup, dfEmissions, "emissions") + write_full_time_series_reconstruction(path, setup, dfEmissions, "emissions") println("Writing Full Time Series for Emissions") end end diff --git a/src/write_outputs/write_fuel_consumption.jl b/src/write_outputs/write_fuel_consumption.jl index 53c03a480d..47a9b0533a 100644 --- a/src/write_outputs/write_fuel_consumption.jl +++ b/src/write_outputs/write_fuel_consumption.jl @@ -87,7 +87,7 @@ function write_fuel_consumption_ts(path::AbstractString, dftranspose(dfPlantFuel_TS, false), header = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - full_time_series_reconstruction(path, setup, dfPlantFuel_TS, "FuelConsumption_plant_MMBTU") + write_full_time_series_reconstruction(path, setup, dfPlantFuel_TS, "FuelConsumption_plant_MMBTU") println("Writing Full Time Series for Fuel Consumption") end end diff --git a/src/write_outputs/write_nse.jl b/src/write_outputs/write_nse.jl index bdd8f732c3..4eaaf4fcb6 100644 --- a/src/write_outputs/write_nse.jl +++ b/src/write_outputs/write_nse.jl @@ -39,7 +39,7 @@ function write_nse(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) CSV.write(joinpath(path, "nse.csv"), dftranspose(dfNse, false), writeheader = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - full_time_series_reconstruction(path, setup, dfNse, "nse") + write_full_time_series_reconstruction(path, setup, dfNse, "nse") println("Writing Full Time Series for NSE") end end diff --git a/src/write_outputs/write_outputs.jl b/src/write_outputs/write_outputs.jl index c39c384af0..d0c2013472 100644 --- a/src/write_outputs/write_outputs.jl +++ b/src/write_outputs/write_outputs.jl @@ -179,7 +179,7 @@ function write_outputs(EP::Model, path::AbstractString, setup::Dict, inputs::Dic if setup["UCommit"] >= 1 if output_settings_d["WriteCommit"] elapsed_time_commit = @elapsed write_commit(path, inputs, setup, EP) - println("Time elapsed for writing commitment is ") + println("Time elapsed for writing commitment is") println(elapsed_time_commit) end @@ -507,11 +507,15 @@ function write_fulltimeseries(fullpath::AbstractString, total = DataFrame(["Total" 0 sum(dfOut[!, :AnnualSum]) fill(0.0, (1, T))], auxNew_Names) total[!, 4:(T + 3)] .= sum(dataOut, dims = 1) dfOut = vcat(dfOut, total) - CSV.write(fullpath, dftranspose(dfOut, false), writeheader = false) return dfOut end +""" + write_settings_file(path, setup) + +Internal function for writing settings files +""" function write_settings_file(path, setup) YAML.write_file(joinpath(path, "run_settings.yml"), setup) end @@ -546,4 +550,36 @@ function write_system_env_summary(path::AbstractString) ) YAML.write_file(joinpath(path, "system_summary.yml"), env_summary) -end \ No newline at end of file +end + +@doc raw"""write_full_time_series_reconstruction(path::AbstractString, + setup::Dict, + DF::DataFrame, + name::String) +Create a DataFrame with all 8,760 hours of the year from the reduced output. + +This function calls `full_time_series_reconstruction()``, which uses Period_map.csv to create a new DataFrame with 8,760 time steps, as well as other pre-existing rows such as "Zone". +For each 52 weeks of the year, the corresponding representative week is taken from the input DataFrame and copied into the new DataFrame. Representative periods that +represent more than one week will appear multiple times in the output. + +Note: Currently, TDR only gives the representative periods in Period_map for 52 weeks, when a (non-leap) year is 52 weeks + 24 hours. This function takes the last 24 hours of +the time series and copies them to get up to all 8,760 hours in a year. + +This function is called when output files with time series data (e.g. power.csv, emissions.csv) are created, if the setup key "OutputFullTimeSeries" is set to "1". + +# Arguments +- `path` (AbstractString): Path input to the results folder +- `setup` (Dict): Case setup +- `DF` (DataFrame): DataFrame to be reconstructed +- `name` (String): Name desired for the .csv file + +""" +function write_full_time_series_reconstruction( + path::AbstractString, setup::Dict, DF::DataFrame, name::String) + FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] + output_path = joinpath(path, FullTimeSeriesFolder) + dfOut_full = full_time_series_reconstruction(path, setup, dftranspose(DF, false)) + CSV.write(joinpath(output_path, "$name.csv"), dfOut_full, header = false) + return nothing +end + diff --git a/src/write_outputs/write_power.jl b/src/write_outputs/write_power.jl index dc8a2696af..2bd0bc024a 100644 --- a/src/write_outputs/write_power.jl +++ b/src/write_outputs/write_power.jl @@ -26,7 +26,7 @@ function write_power(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) else # setup["WriteOutputs"] == "full" df_Power = write_fulltimeseries(filepath, power, dfPower) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - full_time_series_reconstruction(path, setup, df_Power, "power") + write_full_time_series_reconstruction(path, setup, df_Power, "power") println("Writing Full Time Series for Power") end end diff --git a/src/write_outputs/write_power_balance.jl b/src/write_outputs/write_power_balance.jl index 455db19224..6851e1b84a 100644 --- a/src/write_outputs/write_power_balance.jl +++ b/src/write_outputs/write_power_balance.jl @@ -98,7 +98,7 @@ function write_power_balance(path::AbstractString, inputs::Dict, setup::Dict, EP writeheader = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - full_time_series_reconstruction(path, setup, dfPowerBalance, "power_balance") + write_full_time_series_reconstruction(path, setup, dfPowerBalance, "power_balance") println("Writing Full Time Series for Power Balance") end end diff --git a/src/write_outputs/write_price.jl b/src/write_outputs/write_price.jl index 8dace217ee..5b4440c152 100644 --- a/src/write_outputs/write_price.jl +++ b/src/write_outputs/write_price.jl @@ -23,7 +23,7 @@ function write_price(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) writeheader = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - full_time_series_reconstruction(path, setup, dfPrice, "prices") + write_full_time_series_reconstruction(path, setup, dfPrice, "prices") println("Writing Full Time Series for Price") end return nothing diff --git a/src/write_outputs/write_reliability.jl b/src/write_outputs/write_reliability.jl index 7996c01de5..8219c77b1d 100644 --- a/src/write_outputs/write_reliability.jl +++ b/src/write_outputs/write_reliability.jl @@ -22,7 +22,7 @@ function write_reliability(path::AbstractString, inputs::Dict, setup::Dict, EP:: header = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - full_time_series_reconstruction(path, setup, dfReliability, "reliability") + write_full_time_series_reconstruction(path, setup, dfReliability, "reliability") println("Writing Full Time Series for Reliability") end end diff --git a/src/write_outputs/write_storage.jl b/src/write_outputs/write_storage.jl index 0bc7267c00..67a38d5229 100644 --- a/src/write_outputs/write_storage.jl +++ b/src/write_outputs/write_storage.jl @@ -41,7 +41,7 @@ function write_storage(path::AbstractString, inputs::Dict, setup::Dict, EP::Mode CSV.write(joinpath(path, "storage.csv"), dftranspose(dfStorage, false), header = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - full_time_series_reconstruction(path, setup, dfStorage, "storage") + write_full_time_series_reconstruction(path, setup, dfStorage, "storage") println("Writing Full Time Series for Storage") end end diff --git a/src/write_outputs/write_storagedual.jl b/src/write_outputs/write_storagedual.jl index ad8007a165..ba5fccc8b8 100644 --- a/src/write_outputs/write_storagedual.jl +++ b/src/write_outputs/write_storagedual.jl @@ -81,7 +81,7 @@ function write_storagedual(path::AbstractString, inputs::Dict, setup::Dict, EP:: header = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - full_time_series_reconstruction(path, setup, dfStorageDual, "storagebal_duals") + write_full_time_series_reconstruction(path, setup, dfStorageDual, "storagebal_duals") println("Writing Full Time Series for Storage Duals") end end From 26244276fffce654f33fe6dfb1467436b338dbf6 Mon Sep 17 00:00:00 2001 From: Maya Mutic Date: Thu, 27 Jun 2024 22:13:20 +0100 Subject: [PATCH 48/61] Changed name to write_full_time_series_reconstruction --- src/GenX.jl | 2 +- ...nstruction.jl => write_full_time_series_reconstruction.jl} | 4 ++-- src/write_outputs/transmission/write_transmission_flows.jl | 2 +- src/write_outputs/transmission/write_transmission_losses.jl | 2 +- src/write_outputs/ucommit/write_commit.jl | 2 +- src/write_outputs/ucommit/write_shutdown.jl | 2 +- src/write_outputs/ucommit/write_start.jl | 2 +- src/write_outputs/write_charge.jl | 2 +- src/write_outputs/write_co2.jl | 2 +- src/write_outputs/write_curtailment.jl | 2 +- src/write_outputs/write_emissions.jl | 2 +- src/write_outputs/write_fuel_consumption.jl | 2 +- src/write_outputs/write_nse.jl | 2 +- src/write_outputs/write_power.jl | 2 +- src/write_outputs/write_power_balance.jl | 2 +- src/write_outputs/write_price.jl | 2 +- src/write_outputs/write_reliability.jl | 2 +- src/write_outputs/write_storage.jl | 2 +- src/write_outputs/write_storagedual.jl | 2 +- 19 files changed, 20 insertions(+), 20 deletions(-) rename src/time_domain_reduction/{full_time_series_reconstruction.jl => write_full_time_series_reconstruction.jl} (97%) diff --git a/src/GenX.jl b/src/GenX.jl index 62939d3d90..9e3878d6ec 100644 --- a/src/GenX.jl +++ b/src/GenX.jl @@ -71,7 +71,7 @@ include_all_in_folder("write_outputs") include("time_domain_reduction/time_domain_reduction.jl") include("time_domain_reduction/precluster.jl") -include("time_domain_reduction/full_time_series_reconstruction.jl") +include("time_domain_reduction/ write_full_time_series_reconstruction.jl") include_all_in_folder("multi_stage") include_all_in_folder("additional_tools") diff --git a/src/time_domain_reduction/full_time_series_reconstruction.jl b/src/time_domain_reduction/write_full_time_series_reconstruction.jl similarity index 97% rename from src/time_domain_reduction/full_time_series_reconstruction.jl rename to src/time_domain_reduction/write_full_time_series_reconstruction.jl index 8c83ef4fb7..694ef30ae1 100644 --- a/src/time_domain_reduction/full_time_series_reconstruction.jl +++ b/src/time_domain_reduction/write_full_time_series_reconstruction.jl @@ -1,4 +1,4 @@ -@doc raw"""full_time_series_reconstruction(path::AbstractString, +@doc raw"""write_full_time_series_reconstruction(path::AbstractString, setup::Dict, DF::DataFrame, name::String) @@ -20,7 +20,7 @@ This function is called when output files with time series data (e.g. power.csv, """ -function full_time_series_reconstruction( +function write_full_time_series_reconstruction( path::AbstractString, setup::Dict, DF::DataFrame, name::String) FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] output_path = joinpath(path, FullTimeSeriesFolder) diff --git a/src/write_outputs/transmission/write_transmission_flows.jl b/src/write_outputs/transmission/write_transmission_flows.jl index 25c7577cc5..3dd341ba7a 100644 --- a/src/write_outputs/transmission/write_transmission_flows.jl +++ b/src/write_outputs/transmission/write_transmission_flows.jl @@ -25,7 +25,7 @@ function write_transmission_flows(path::AbstractString, CSV.write(filepath, dftranspose(dfFlow, false), writeheader = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - full_time_series_reconstruction(path, setup, dfFlow, "flow") + write_full_time_series_reconstruction(path, setup, dfFlow, "flow") println("Writing Full Time Series for Transmission Flows") end end diff --git a/src/write_outputs/transmission/write_transmission_losses.jl b/src/write_outputs/transmission/write_transmission_losses.jl index 09b06eba71..781988d454 100644 --- a/src/write_outputs/transmission/write_transmission_losses.jl +++ b/src/write_outputs/transmission/write_transmission_losses.jl @@ -32,7 +32,7 @@ function write_transmission_losses(path::AbstractString, writeheader = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - full_time_series_reconstruction(path, setup, dfTLosses, "tlosses") + write_full_time_series_reconstruction(path, setup, dfTLosses, "tlosses") println("Writing Full Time Series for Time Losses") end end diff --git a/src/write_outputs/ucommit/write_commit.jl b/src/write_outputs/ucommit/write_commit.jl index 6aa6d48d20..eefa73074b 100644 --- a/src/write_outputs/ucommit/write_commit.jl +++ b/src/write_outputs/ucommit/write_commit.jl @@ -13,7 +13,7 @@ function write_commit(path::AbstractString, inputs::Dict, setup::Dict, EP::Model CSV.write(joinpath(path, "commit.csv"), dftranspose(dfCommit, false), header = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - full_time_series_reconstruction(path, setup, dfCommit, "commit") + write_full_time_series_reconstruction(path, setup, dfCommit, "commit") println("Writing Full Time Series for Commitment") end end diff --git a/src/write_outputs/ucommit/write_shutdown.jl b/src/write_outputs/ucommit/write_shutdown.jl index cbb9f3b6a5..33a636af74 100644 --- a/src/write_outputs/ucommit/write_shutdown.jl +++ b/src/write_outputs/ucommit/write_shutdown.jl @@ -15,7 +15,7 @@ function write_shutdown(path::AbstractString, inputs::Dict, setup::Dict, EP::Mod else # setup["WriteOutputs"] == "full" df_Shutdown = write_fulltimeseries(filepath, shut, dfShutdown) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - full_time_series_reconstruction(path, setup, df_Shutdown, "shutdown") + write_full_time_series_reconstruction(path, setup, df_Shutdown, "shutdown") println("Writing Full Time Series for Shutdown") end end diff --git a/src/write_outputs/ucommit/write_start.jl b/src/write_outputs/ucommit/write_start.jl index 334b231e72..b2b9009c81 100644 --- a/src/write_outputs/ucommit/write_start.jl +++ b/src/write_outputs/ucommit/write_start.jl @@ -14,7 +14,7 @@ function write_start(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) else # setup["WriteOutputs"] == "full" df_Start = write_fulltimeseries(filepath, start, dfStart) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - full_time_series_reconstruction(path, setup, df_Start, "start") + write_full_time_series_reconstruction(path, setup, df_Start, "start") println("Writing Full Time Series for Startup") end end diff --git a/src/write_outputs/write_charge.jl b/src/write_outputs/write_charge.jl index 7cbf6707af..9380536da0 100644 --- a/src/write_outputs/write_charge.jl +++ b/src/write_outputs/write_charge.jl @@ -43,7 +43,7 @@ function write_charge(path::AbstractString, inputs::Dict, setup::Dict, EP::Model else # setup["WriteOutputs"] == "full" df_Charge = write_fulltimeseries(filepath, charge, dfCharge) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - full_time_series_reconstruction(path, setup, df_Charge, "charge") + write_full_time_series_reconstruction_reconstruction(path, setup, df_Charge, "charge") println("Writing Full Time Series for Charge") end end diff --git a/src/write_outputs/write_co2.jl b/src/write_outputs/write_co2.jl index 4774fc4435..079b76f1f4 100644 --- a/src/write_outputs/write_co2.jl +++ b/src/write_outputs/write_co2.jl @@ -33,7 +33,7 @@ function write_co2_emissions_plant(path::AbstractString, else # setup["WriteOutputs"] == "full" df_Emissions_plant = write_fulltimeseries(filepath, emissions_plant, dfEmissions_plant) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - full_time_series_reconstruction(path, setup, df_Emissions_plant, "emissions_plant") + write_full_time_series_reconstruction(path, setup, df_Emissions_plant, "emissions_plant") println("Writing Full Time Series for Emissions Plant") end end diff --git a/src/write_outputs/write_curtailment.jl b/src/write_outputs/write_curtailment.jl index e9d3444210..836d3ba168 100644 --- a/src/write_outputs/write_curtailment.jl +++ b/src/write_outputs/write_curtailment.jl @@ -59,7 +59,7 @@ function write_curtailment(path::AbstractString, inputs::Dict, setup::Dict, EP:: else # setup["WriteOutputs"] == "full" df_Curtailment = write_fulltimeseries(filename, curtailment, dfCurtailment) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - full_time_series_reconstruction(path, setup, df_Curtailment, "curtail") + write_full_time_series_reconstruction(path, setup, df_Curtailment, "curtail") println("Writing Full Time Series for Curtailment") end end diff --git a/src/write_outputs/write_emissions.jl b/src/write_outputs/write_emissions.jl index 0fb598ae81..3e211cf37a 100644 --- a/src/write_outputs/write_emissions.jl +++ b/src/write_outputs/write_emissions.jl @@ -126,7 +126,7 @@ function write_emissions(path::AbstractString, inputs::Dict, setup::Dict, EP::Mo writeheader = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - full_time_series_reconstruction(path, setup, dfEmissions, "emissions") + write_full_time_series_reconstruction(path, setup, dfEmissions, "emissions") println("Writing Full Time Series for Emissions") end end diff --git a/src/write_outputs/write_fuel_consumption.jl b/src/write_outputs/write_fuel_consumption.jl index 53c03a480d..47a9b0533a 100644 --- a/src/write_outputs/write_fuel_consumption.jl +++ b/src/write_outputs/write_fuel_consumption.jl @@ -87,7 +87,7 @@ function write_fuel_consumption_ts(path::AbstractString, dftranspose(dfPlantFuel_TS, false), header = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - full_time_series_reconstruction(path, setup, dfPlantFuel_TS, "FuelConsumption_plant_MMBTU") + write_full_time_series_reconstruction(path, setup, dfPlantFuel_TS, "FuelConsumption_plant_MMBTU") println("Writing Full Time Series for Fuel Consumption") end end diff --git a/src/write_outputs/write_nse.jl b/src/write_outputs/write_nse.jl index bdd8f732c3..4eaaf4fcb6 100644 --- a/src/write_outputs/write_nse.jl +++ b/src/write_outputs/write_nse.jl @@ -39,7 +39,7 @@ function write_nse(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) CSV.write(joinpath(path, "nse.csv"), dftranspose(dfNse, false), writeheader = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - full_time_series_reconstruction(path, setup, dfNse, "nse") + write_full_time_series_reconstruction(path, setup, dfNse, "nse") println("Writing Full Time Series for NSE") end end diff --git a/src/write_outputs/write_power.jl b/src/write_outputs/write_power.jl index dc8a2696af..2bd0bc024a 100644 --- a/src/write_outputs/write_power.jl +++ b/src/write_outputs/write_power.jl @@ -26,7 +26,7 @@ function write_power(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) else # setup["WriteOutputs"] == "full" df_Power = write_fulltimeseries(filepath, power, dfPower) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - full_time_series_reconstruction(path, setup, df_Power, "power") + write_full_time_series_reconstruction(path, setup, df_Power, "power") println("Writing Full Time Series for Power") end end diff --git a/src/write_outputs/write_power_balance.jl b/src/write_outputs/write_power_balance.jl index 455db19224..6851e1b84a 100644 --- a/src/write_outputs/write_power_balance.jl +++ b/src/write_outputs/write_power_balance.jl @@ -98,7 +98,7 @@ function write_power_balance(path::AbstractString, inputs::Dict, setup::Dict, EP writeheader = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - full_time_series_reconstruction(path, setup, dfPowerBalance, "power_balance") + write_full_time_series_reconstruction(path, setup, dfPowerBalance, "power_balance") println("Writing Full Time Series for Power Balance") end end diff --git a/src/write_outputs/write_price.jl b/src/write_outputs/write_price.jl index 8dace217ee..5b4440c152 100644 --- a/src/write_outputs/write_price.jl +++ b/src/write_outputs/write_price.jl @@ -23,7 +23,7 @@ function write_price(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) writeheader = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - full_time_series_reconstruction(path, setup, dfPrice, "prices") + write_full_time_series_reconstruction(path, setup, dfPrice, "prices") println("Writing Full Time Series for Price") end return nothing diff --git a/src/write_outputs/write_reliability.jl b/src/write_outputs/write_reliability.jl index 7996c01de5..8219c77b1d 100644 --- a/src/write_outputs/write_reliability.jl +++ b/src/write_outputs/write_reliability.jl @@ -22,7 +22,7 @@ function write_reliability(path::AbstractString, inputs::Dict, setup::Dict, EP:: header = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - full_time_series_reconstruction(path, setup, dfReliability, "reliability") + write_full_time_series_reconstruction(path, setup, dfReliability, "reliability") println("Writing Full Time Series for Reliability") end end diff --git a/src/write_outputs/write_storage.jl b/src/write_outputs/write_storage.jl index 0bc7267c00..67a38d5229 100644 --- a/src/write_outputs/write_storage.jl +++ b/src/write_outputs/write_storage.jl @@ -41,7 +41,7 @@ function write_storage(path::AbstractString, inputs::Dict, setup::Dict, EP::Mode CSV.write(joinpath(path, "storage.csv"), dftranspose(dfStorage, false), header = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - full_time_series_reconstruction(path, setup, dfStorage, "storage") + write_full_time_series_reconstruction(path, setup, dfStorage, "storage") println("Writing Full Time Series for Storage") end end diff --git a/src/write_outputs/write_storagedual.jl b/src/write_outputs/write_storagedual.jl index ad8007a165..ba5fccc8b8 100644 --- a/src/write_outputs/write_storagedual.jl +++ b/src/write_outputs/write_storagedual.jl @@ -81,7 +81,7 @@ function write_storagedual(path::AbstractString, inputs::Dict, setup::Dict, EP:: header = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - full_time_series_reconstruction(path, setup, dfStorageDual, "storagebal_duals") + write_full_time_series_reconstruction(path, setup, dfStorageDual, "storagebal_duals") println("Writing Full Time Series for Storage Duals") end end From ab901b706c5d70b5bb6951e17bf6397d70814417 Mon Sep 17 00:00:00 2001 From: Maya Mutic Date: Thu, 27 Jun 2024 22:17:55 +0100 Subject: [PATCH 49/61] Connect doc string to function body --- .../write_full_time_series_reconstruction.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/time_domain_reduction/write_full_time_series_reconstruction.jl b/src/time_domain_reduction/write_full_time_series_reconstruction.jl index 694ef30ae1..1b852b190a 100644 --- a/src/time_domain_reduction/write_full_time_series_reconstruction.jl +++ b/src/time_domain_reduction/write_full_time_series_reconstruction.jl @@ -19,7 +19,6 @@ the time series and copies them to get up to all 8,760 hours in a year. This function is called when output files with time series data (e.g. power.csv, emissions.csv) are created, if the setup key "OutputFullTimeSeries" is set to "1". """ - function write_full_time_series_reconstruction( path::AbstractString, setup::Dict, DF::DataFrame, name::String) FullTimeSeriesFolder = setup["OutputFullTimeSeriesFolder"] From b30fc223c175f74fb51baf7da04526c2dcd9d22e Mon Sep 17 00:00:00 2001 From: lbonaldo Date: Fri, 28 Jun 2024 11:26:57 -0400 Subject: [PATCH 50/61] Remove blank lines --- docs/src/Model_Reference/TDR.md | 3 +-- example_systems/1_three_zones/settings/genx_settings.yml | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/src/Model_Reference/TDR.md b/docs/src/Model_Reference/TDR.md index c9edbe3204..eb228523a1 100644 --- a/docs/src/Model_Reference/TDR.md +++ b/docs/src/Model_Reference/TDR.md @@ -12,5 +12,4 @@ GenX.run_timedomainreduction! ```@docs GenX.full_time_series_reconstruction -``` - +``` \ No newline at end of file diff --git a/example_systems/1_three_zones/settings/genx_settings.yml b/example_systems/1_three_zones/settings/genx_settings.yml index 5c529c44cd..d48032b1d1 100644 --- a/example_systems/1_three_zones/settings/genx_settings.yml +++ b/example_systems/1_three_zones/settings/genx_settings.yml @@ -10,4 +10,4 @@ ParameterScale: 1 # Turn on parameter scaling wherein demand, capacity and power WriteShadowPrices: 1 # Write shadow prices of LP or relaxed MILP; 0 = not active; 1 = active UCommit: 2 # Unit committment of thermal power plants; 0 = not active; 1 = active using integer clestering; 2 = active using linearized clustering TimeDomainReduction: 1 # Time domain reduce (i.e. cluster) inputs based on Demand_data.csv, Generators_variability.csv, and Fuels_data.csv; 0 = not active (use input data as provided); 0 = active (cluster input data, or use data that has already been clustered) -OutputFullTimeSeries: 1 +OutputFullTimeSeries: 1 \ No newline at end of file From 512d57745fdaa2cabc885107805b0eb4f17d7cdb Mon Sep 17 00:00:00 2001 From: lbonaldo Date: Fri, 28 Jun 2024 15:57:16 -0400 Subject: [PATCH 51/61] Update log --- src/write_outputs/transmission/write_transmission_flows.jl | 2 +- src/write_outputs/transmission/write_transmission_losses.jl | 2 +- src/write_outputs/ucommit/write_commit.jl | 2 +- src/write_outputs/ucommit/write_shutdown.jl | 2 +- src/write_outputs/ucommit/write_start.jl | 2 +- src/write_outputs/write_charge.jl | 5 +++-- src/write_outputs/write_co2.jl | 5 +++-- src/write_outputs/write_curtailment.jl | 2 +- src/write_outputs/write_emissions.jl | 2 +- src/write_outputs/write_fuel_consumption.jl | 5 +++-- src/write_outputs/write_nse.jl | 2 +- src/write_outputs/write_power.jl | 2 +- src/write_outputs/write_power_balance.jl | 5 +++-- src/write_outputs/write_price.jl | 2 +- src/write_outputs/write_reliability.jl | 2 +- src/write_outputs/write_storage.jl | 2 +- src/write_outputs/write_storagedual.jl | 2 +- 17 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/write_outputs/transmission/write_transmission_flows.jl b/src/write_outputs/transmission/write_transmission_flows.jl index 3dd341ba7a..2180c6624c 100644 --- a/src/write_outputs/transmission/write_transmission_flows.jl +++ b/src/write_outputs/transmission/write_transmission_flows.jl @@ -26,7 +26,7 @@ function write_transmission_flows(path::AbstractString, if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 write_full_time_series_reconstruction(path, setup, dfFlow, "flow") - println("Writing Full Time Series for Transmission Flows") + @info("Writing Full Time Series for Transmission Flows") end end return nothing diff --git a/src/write_outputs/transmission/write_transmission_losses.jl b/src/write_outputs/transmission/write_transmission_losses.jl index 781988d454..ca72371606 100644 --- a/src/write_outputs/transmission/write_transmission_losses.jl +++ b/src/write_outputs/transmission/write_transmission_losses.jl @@ -33,7 +33,7 @@ function write_transmission_losses(path::AbstractString, if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 write_full_time_series_reconstruction(path, setup, dfTLosses, "tlosses") - println("Writing Full Time Series for Time Losses") + @info("Writing Full Time Series for Time Losses") end end return nothing diff --git a/src/write_outputs/ucommit/write_commit.jl b/src/write_outputs/ucommit/write_commit.jl index eefa73074b..9689f9b9e9 100644 --- a/src/write_outputs/ucommit/write_commit.jl +++ b/src/write_outputs/ucommit/write_commit.jl @@ -14,6 +14,6 @@ function write_commit(path::AbstractString, inputs::Dict, setup::Dict, EP::Model if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 write_full_time_series_reconstruction(path, setup, dfCommit, "commit") - println("Writing Full Time Series for Commitment") + @info("Writing Full Time Series for Commitment") end end diff --git a/src/write_outputs/ucommit/write_shutdown.jl b/src/write_outputs/ucommit/write_shutdown.jl index 33a636af74..80997ee290 100644 --- a/src/write_outputs/ucommit/write_shutdown.jl +++ b/src/write_outputs/ucommit/write_shutdown.jl @@ -16,7 +16,7 @@ function write_shutdown(path::AbstractString, inputs::Dict, setup::Dict, EP::Mod df_Shutdown = write_fulltimeseries(filepath, shut, dfShutdown) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 write_full_time_series_reconstruction(path, setup, df_Shutdown, "shutdown") - println("Writing Full Time Series for Shutdown") + @info("Writing Full Time Series for Shutdown") end end return nothing diff --git a/src/write_outputs/ucommit/write_start.jl b/src/write_outputs/ucommit/write_start.jl index b2b9009c81..c674ad380a 100644 --- a/src/write_outputs/ucommit/write_start.jl +++ b/src/write_outputs/ucommit/write_start.jl @@ -15,7 +15,7 @@ function write_start(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) df_Start = write_fulltimeseries(filepath, start, dfStart) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 write_full_time_series_reconstruction(path, setup, df_Start, "start") - println("Writing Full Time Series for Startup") + @info("Writing Full Time Series for Startup") end end return nothing diff --git a/src/write_outputs/write_charge.jl b/src/write_outputs/write_charge.jl index 943d423600..7f87e198ae 100644 --- a/src/write_outputs/write_charge.jl +++ b/src/write_outputs/write_charge.jl @@ -43,8 +43,9 @@ function write_charge(path::AbstractString, inputs::Dict, setup::Dict, EP::Model else # setup["WriteOutputs"] == "full" df_Charge = write_fulltimeseries(filepath, charge, dfCharge) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - write_full_time_series_reconstruction(path, setup, df_Charge, "charge") - println("Writing Full Time Series for Charge") + write_full_time_series_reconstruction( + path, setup, df_Charge, "charge") + @info("Writing Full Time Series for Charge") end end return nothing diff --git a/src/write_outputs/write_co2.jl b/src/write_outputs/write_co2.jl index 079b76f1f4..14712271c1 100644 --- a/src/write_outputs/write_co2.jl +++ b/src/write_outputs/write_co2.jl @@ -31,10 +31,11 @@ function write_co2_emissions_plant(path::AbstractString, if setup["WriteOutputs"] == "annual" write_annual(filepath, dfEmissions_plant) else # setup["WriteOutputs"] == "full" - df_Emissions_plant = write_fulltimeseries(filepath, emissions_plant, dfEmissions_plant) + df_Emissions_plant = write_fulltimeseries( + filepath, emissions_plant, dfEmissions_plant) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 write_full_time_series_reconstruction(path, setup, df_Emissions_plant, "emissions_plant") - println("Writing Full Time Series for Emissions Plant") + @info("Writing Full Time Series for Emissions Plant") end end return nothing diff --git a/src/write_outputs/write_curtailment.jl b/src/write_outputs/write_curtailment.jl index 836d3ba168..b9ca172571 100644 --- a/src/write_outputs/write_curtailment.jl +++ b/src/write_outputs/write_curtailment.jl @@ -60,7 +60,7 @@ function write_curtailment(path::AbstractString, inputs::Dict, setup::Dict, EP:: df_Curtailment = write_fulltimeseries(filename, curtailment, dfCurtailment) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 write_full_time_series_reconstruction(path, setup, df_Curtailment, "curtail") - println("Writing Full Time Series for Curtailment") + @info("Writing Full Time Series for Curtailment") end end return nothing diff --git a/src/write_outputs/write_emissions.jl b/src/write_outputs/write_emissions.jl index 3e211cf37a..369b7af69b 100644 --- a/src/write_outputs/write_emissions.jl +++ b/src/write_outputs/write_emissions.jl @@ -127,7 +127,7 @@ function write_emissions(path::AbstractString, inputs::Dict, setup::Dict, EP::Mo if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 write_full_time_series_reconstruction(path, setup, dfEmissions, "emissions") - println("Writing Full Time Series for Emissions") + @info("Writing Full Time Series for Emissions") end end end diff --git a/src/write_outputs/write_fuel_consumption.jl b/src/write_outputs/write_fuel_consumption.jl index 47a9b0533a..bf36f51f40 100644 --- a/src/write_outputs/write_fuel_consumption.jl +++ b/src/write_outputs/write_fuel_consumption.jl @@ -87,8 +87,9 @@ function write_fuel_consumption_ts(path::AbstractString, dftranspose(dfPlantFuel_TS, false), header = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - write_full_time_series_reconstruction(path, setup, dfPlantFuel_TS, "FuelConsumption_plant_MMBTU") - println("Writing Full Time Series for Fuel Consumption") + write_full_time_series_reconstruction( + path, setup, dfPlantFuel_TS, "FuelConsumption_plant_MMBTU") + @info("Writing Full Time Series for Fuel Consumption") end end diff --git a/src/write_outputs/write_nse.jl b/src/write_outputs/write_nse.jl index 4eaaf4fcb6..5f319244ea 100644 --- a/src/write_outputs/write_nse.jl +++ b/src/write_outputs/write_nse.jl @@ -40,7 +40,7 @@ function write_nse(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 write_full_time_series_reconstruction(path, setup, dfNse, "nse") - println("Writing Full Time Series for NSE") + @info("Writing Full Time Series for NSE") end end return nothing diff --git a/src/write_outputs/write_power.jl b/src/write_outputs/write_power.jl index 2bd0bc024a..f71f29d6a3 100644 --- a/src/write_outputs/write_power.jl +++ b/src/write_outputs/write_power.jl @@ -27,7 +27,7 @@ function write_power(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) df_Power = write_fulltimeseries(filepath, power, dfPower) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 write_full_time_series_reconstruction(path, setup, df_Power, "power") - println("Writing Full Time Series for Power") + @info("Writing Full Time Series for Power") end end diff --git a/src/write_outputs/write_power_balance.jl b/src/write_outputs/write_power_balance.jl index 6851e1b84a..425b6fa6d5 100644 --- a/src/write_outputs/write_power_balance.jl +++ b/src/write_outputs/write_power_balance.jl @@ -98,8 +98,9 @@ function write_power_balance(path::AbstractString, inputs::Dict, setup::Dict, EP writeheader = false) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - write_full_time_series_reconstruction(path, setup, dfPowerBalance, "power_balance") - println("Writing Full Time Series for Power Balance") + write_full_time_series_reconstruction( + path, setup, dfPowerBalance, "power_balance") + @info("Writing Full Time Series for Power Balance") end end return nothing diff --git a/src/write_outputs/write_price.jl b/src/write_outputs/write_price.jl index 5b4440c152..1abcf7fef2 100644 --- a/src/write_outputs/write_price.jl +++ b/src/write_outputs/write_price.jl @@ -24,7 +24,7 @@ function write_price(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 write_full_time_series_reconstruction(path, setup, dfPrice, "prices") - println("Writing Full Time Series for Price") + @info("Writing Full Time Series for Price") end return nothing end diff --git a/src/write_outputs/write_reliability.jl b/src/write_outputs/write_reliability.jl index 8219c77b1d..65a49a28bf 100644 --- a/src/write_outputs/write_reliability.jl +++ b/src/write_outputs/write_reliability.jl @@ -23,6 +23,6 @@ function write_reliability(path::AbstractString, inputs::Dict, setup::Dict, EP:: if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 write_full_time_series_reconstruction(path, setup, dfReliability, "reliability") - println("Writing Full Time Series for Reliability") + @info("Writing Full Time Series for Reliability") end end diff --git a/src/write_outputs/write_storage.jl b/src/write_outputs/write_storage.jl index 67a38d5229..e1ee16e58b 100644 --- a/src/write_outputs/write_storage.jl +++ b/src/write_outputs/write_storage.jl @@ -42,6 +42,6 @@ function write_storage(path::AbstractString, inputs::Dict, setup::Dict, EP::Mode if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 write_full_time_series_reconstruction(path, setup, dfStorage, "storage") - println("Writing Full Time Series for Storage") + @info("Writing Full Time Series for Storage") end end diff --git a/src/write_outputs/write_storagedual.jl b/src/write_outputs/write_storagedual.jl index ba5fccc8b8..2714fe0025 100644 --- a/src/write_outputs/write_storagedual.jl +++ b/src/write_outputs/write_storagedual.jl @@ -82,6 +82,6 @@ function write_storagedual(path::AbstractString, inputs::Dict, setup::Dict, EP:: if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 write_full_time_series_reconstruction(path, setup, dfStorageDual, "storagebal_duals") - println("Writing Full Time Series for Storage Duals") + @info("Writing Full Time Series for Storage Duals") end end From 5cfdb75ee2bef2ea8b26eacb108681f9da14ee91 Mon Sep 17 00:00:00 2001 From: lbonaldo Date: Fri, 28 Jun 2024 15:57:43 -0400 Subject: [PATCH 52/61] Update CHANGELOG.md --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4bf3c79409..a76936d3d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Add objective scaler for addressing problem ill-conditioning (#667) - Add workflow that ensures that CHANGELOG.md and the version number are updated (#711) -- Print GenX version at startup and export it to disk (#712) +- Print GenX version at startup and export it to disk (#712) +- Added the option to output results with time series reconstructed for the entire year (#700) ## [0.4.0] - 2024-03-18 From 9d0162ec27546f7e223ca3a85553c7a9c4b81c40 Mon Sep 17 00:00:00 2001 From: lbonaldo Date: Fri, 28 Jun 2024 16:02:52 -0400 Subject: [PATCH 53/61] Fix formatting --- src/time_domain_reduction/full_time_series_reconstruction.jl | 4 ++-- src/write_outputs/write_co2.jl | 3 ++- src/write_outputs/write_outputs.jl | 1 - 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/time_domain_reduction/full_time_series_reconstruction.jl b/src/time_domain_reduction/full_time_series_reconstruction.jl index 92fd66e507..e65419f2c1 100644 --- a/src/time_domain_reduction/full_time_series_reconstruction.jl +++ b/src/time_domain_reduction/full_time_series_reconstruction.jl @@ -12,7 +12,7 @@ Internal function for performing the reconstruction. This function returns a Dat - `reconDF` (DataFrame): DataFrame with the full series reconstruction """ function full_time_series_reconstruction( - path::AbstractString, setup::Dict, DF::DataFrame) + path::AbstractString, setup::Dict, DF::DataFrame) # Read Period map file Period_map.csv case = path[1:findlast('/', path)] TDRpath = joinpath(case, setup["TimeDomainReductionFolder"]) @@ -60,4 +60,4 @@ function full_time_series_reconstruction( new_rows[!, 1] = ["t$t" for t in (WeightTotal - end_diff):WeightTotal] reconDF = [reconDF; new_rows] return reconDF -end \ No newline at end of file +end diff --git a/src/write_outputs/write_co2.jl b/src/write_outputs/write_co2.jl index 14712271c1..ce923877c0 100644 --- a/src/write_outputs/write_co2.jl +++ b/src/write_outputs/write_co2.jl @@ -34,7 +34,8 @@ function write_co2_emissions_plant(path::AbstractString, df_Emissions_plant = write_fulltimeseries( filepath, emissions_plant, dfEmissions_plant) if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 - write_full_time_series_reconstruction(path, setup, df_Emissions_plant, "emissions_plant") + write_full_time_series_reconstruction( + path, setup, df_Emissions_plant, "emissions_plant") @info("Writing Full Time Series for Emissions Plant") end end diff --git a/src/write_outputs/write_outputs.jl b/src/write_outputs/write_outputs.jl index 4dd6b68b52..fcff73e84b 100644 --- a/src/write_outputs/write_outputs.jl +++ b/src/write_outputs/write_outputs.jl @@ -583,4 +583,3 @@ function write_full_time_series_reconstruction( CSV.write(joinpath(output_path, "$name.csv"), dfOut_full, header = false) return nothing end - From a969e670451f1839c3d94a00100f8b218a284222 Mon Sep 17 00:00:00 2001 From: lbonaldo Date: Fri, 28 Jun 2024 16:04:47 -0400 Subject: [PATCH 54/61] Update GenX dev branch version to 0.4.0-dev.7 --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 73f68d1531..4c90dc1973 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "GenX" uuid = "5d317b1e-30ec-4ed6-a8ce-8d2d88d7cfac" authors = ["Bonaldo, Luca", "Chakrabarti, Sambuddha", "Cheng, Fangwei", "Ding, Yifu", "Jenkins, Jesse D.", "Luo, Qian", "Macdonald, Ruaridh", "Mallapragada, Dharik", "Manocha, Aneesha", "Mantegna, Gabe ", "Morris, Jack", "Patankar, Neha", "Pecci, Filippo", "Schwartz, Aaron", "Schwartz, Jacob", "Schivley, Greg", "Sepulveda, Nestor", "Xu, Qingyu", "Zhou, Justin"] -version = "0.4.0-dev.6" +version = "0.4.0-dev.7" [deps] CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b" From 7ff4da671983b4db87f2994c4d322f3ac69e1d70 Mon Sep 17 00:00:00 2001 From: lbonaldo Date: Fri, 28 Jun 2024 17:41:07 -0400 Subject: [PATCH 55/61] Update and operator in logical operations --- src/write_outputs/transmission/write_transmission_flows.jl | 2 +- src/write_outputs/transmission/write_transmission_losses.jl | 2 +- src/write_outputs/ucommit/write_commit.jl | 2 +- src/write_outputs/ucommit/write_shutdown.jl | 2 +- src/write_outputs/ucommit/write_start.jl | 2 +- src/write_outputs/write_charge.jl | 2 +- src/write_outputs/write_co2.jl | 2 +- src/write_outputs/write_curtailment.jl | 2 +- src/write_outputs/write_emissions.jl | 2 +- src/write_outputs/write_fuel_consumption.jl | 2 +- src/write_outputs/write_nse.jl | 2 +- src/write_outputs/write_power.jl | 2 +- src/write_outputs/write_power_balance.jl | 2 +- src/write_outputs/write_price.jl | 2 +- src/write_outputs/write_reliability.jl | 2 +- src/write_outputs/write_storage.jl | 2 +- src/write_outputs/write_storagedual.jl | 2 +- 17 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/write_outputs/transmission/write_transmission_flows.jl b/src/write_outputs/transmission/write_transmission_flows.jl index 2180c6624c..5290d71afe 100644 --- a/src/write_outputs/transmission/write_transmission_flows.jl +++ b/src/write_outputs/transmission/write_transmission_flows.jl @@ -24,7 +24,7 @@ function write_transmission_flows(path::AbstractString, rename!(dfFlow, auxNew_Names) CSV.write(filepath, dftranspose(dfFlow, false), writeheader = false) - if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 + if setup["OutputFullTimeSeries"] == 1 && setup["TimeDomainReduction"] == 1 write_full_time_series_reconstruction(path, setup, dfFlow, "flow") @info("Writing Full Time Series for Transmission Flows") end diff --git a/src/write_outputs/transmission/write_transmission_losses.jl b/src/write_outputs/transmission/write_transmission_losses.jl index ca72371606..a76bca1180 100644 --- a/src/write_outputs/transmission/write_transmission_losses.jl +++ b/src/write_outputs/transmission/write_transmission_losses.jl @@ -31,7 +31,7 @@ function write_transmission_losses(path::AbstractString, dftranspose(dfTLosses, false), writeheader = false) - if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 + if setup["OutputFullTimeSeries"] == 1 && setup["TimeDomainReduction"] == 1 write_full_time_series_reconstruction(path, setup, dfTLosses, "tlosses") @info("Writing Full Time Series for Time Losses") end diff --git a/src/write_outputs/ucommit/write_commit.jl b/src/write_outputs/ucommit/write_commit.jl index 9689f9b9e9..8aa24de6f8 100644 --- a/src/write_outputs/ucommit/write_commit.jl +++ b/src/write_outputs/ucommit/write_commit.jl @@ -12,7 +12,7 @@ function write_commit(path::AbstractString, inputs::Dict, setup::Dict, EP::Model rename!(dfCommit, auxNew_Names) CSV.write(joinpath(path, "commit.csv"), dftranspose(dfCommit, false), header = false) - if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 + if setup["OutputFullTimeSeries"] == 1 && setup["TimeDomainReduction"] == 1 write_full_time_series_reconstruction(path, setup, dfCommit, "commit") @info("Writing Full Time Series for Commitment") end diff --git a/src/write_outputs/ucommit/write_shutdown.jl b/src/write_outputs/ucommit/write_shutdown.jl index 80997ee290..d949102174 100644 --- a/src/write_outputs/ucommit/write_shutdown.jl +++ b/src/write_outputs/ucommit/write_shutdown.jl @@ -14,7 +14,7 @@ function write_shutdown(path::AbstractString, inputs::Dict, setup::Dict, EP::Mod write_annual(filepath, dfShutdown) else # setup["WriteOutputs"] == "full" df_Shutdown = write_fulltimeseries(filepath, shut, dfShutdown) - if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 + if setup["OutputFullTimeSeries"] == 1 && setup["TimeDomainReduction"] == 1 write_full_time_series_reconstruction(path, setup, df_Shutdown, "shutdown") @info("Writing Full Time Series for Shutdown") end diff --git a/src/write_outputs/ucommit/write_start.jl b/src/write_outputs/ucommit/write_start.jl index c674ad380a..c98ed7564b 100644 --- a/src/write_outputs/ucommit/write_start.jl +++ b/src/write_outputs/ucommit/write_start.jl @@ -13,7 +13,7 @@ function write_start(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) write_annual(filepath, dfStart) else # setup["WriteOutputs"] == "full" df_Start = write_fulltimeseries(filepath, start, dfStart) - if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 + if setup["OutputFullTimeSeries"] == 1 && setup["TimeDomainReduction"] == 1 write_full_time_series_reconstruction(path, setup, df_Start, "start") @info("Writing Full Time Series for Startup") end diff --git a/src/write_outputs/write_charge.jl b/src/write_outputs/write_charge.jl index 7f87e198ae..08856fc866 100644 --- a/src/write_outputs/write_charge.jl +++ b/src/write_outputs/write_charge.jl @@ -42,7 +42,7 @@ function write_charge(path::AbstractString, inputs::Dict, setup::Dict, EP::Model write_annual(filepath, dfCharge) else # setup["WriteOutputs"] == "full" df_Charge = write_fulltimeseries(filepath, charge, dfCharge) - if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 + if setup["OutputFullTimeSeries"] == 1 && setup["TimeDomainReduction"] == 1 write_full_time_series_reconstruction( path, setup, df_Charge, "charge") @info("Writing Full Time Series for Charge") diff --git a/src/write_outputs/write_co2.jl b/src/write_outputs/write_co2.jl index ce923877c0..223b960541 100644 --- a/src/write_outputs/write_co2.jl +++ b/src/write_outputs/write_co2.jl @@ -33,7 +33,7 @@ function write_co2_emissions_plant(path::AbstractString, else # setup["WriteOutputs"] == "full" df_Emissions_plant = write_fulltimeseries( filepath, emissions_plant, dfEmissions_plant) - if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 + if setup["OutputFullTimeSeries"] == 1 && setup["TimeDomainReduction"] == 1 write_full_time_series_reconstruction( path, setup, df_Emissions_plant, "emissions_plant") @info("Writing Full Time Series for Emissions Plant") diff --git a/src/write_outputs/write_curtailment.jl b/src/write_outputs/write_curtailment.jl index b9ca172571..6f9a57dfe8 100644 --- a/src/write_outputs/write_curtailment.jl +++ b/src/write_outputs/write_curtailment.jl @@ -58,7 +58,7 @@ function write_curtailment(path::AbstractString, inputs::Dict, setup::Dict, EP:: write_annual(filename, dfCurtailment) else # setup["WriteOutputs"] == "full" df_Curtailment = write_fulltimeseries(filename, curtailment, dfCurtailment) - if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 + if setup["OutputFullTimeSeries"] == 1 && setup["TimeDomainReduction"] == 1 write_full_time_series_reconstruction(path, setup, df_Curtailment, "curtail") @info("Writing Full Time Series for Curtailment") end diff --git a/src/write_outputs/write_emissions.jl b/src/write_outputs/write_emissions.jl index 369b7af69b..2e0c011f68 100644 --- a/src/write_outputs/write_emissions.jl +++ b/src/write_outputs/write_emissions.jl @@ -125,7 +125,7 @@ function write_emissions(path::AbstractString, inputs::Dict, setup::Dict, EP::Mo dftranspose(dfEmissions, false), writeheader = false) - if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 + if setup["OutputFullTimeSeries"] == 1 && setup["TimeDomainReduction"] == 1 write_full_time_series_reconstruction(path, setup, dfEmissions, "emissions") @info("Writing Full Time Series for Emissions") end diff --git a/src/write_outputs/write_fuel_consumption.jl b/src/write_outputs/write_fuel_consumption.jl index bf36f51f40..8385e3e5ce 100644 --- a/src/write_outputs/write_fuel_consumption.jl +++ b/src/write_outputs/write_fuel_consumption.jl @@ -86,7 +86,7 @@ function write_fuel_consumption_ts(path::AbstractString, CSV.write(joinpath(path, "FuelConsumption_plant_MMBTU.csv"), dftranspose(dfPlantFuel_TS, false), header = false) - if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 + if setup["OutputFullTimeSeries"] == 1 && setup["TimeDomainReduction"] == 1 write_full_time_series_reconstruction( path, setup, dfPlantFuel_TS, "FuelConsumption_plant_MMBTU") @info("Writing Full Time Series for Fuel Consumption") diff --git a/src/write_outputs/write_nse.jl b/src/write_outputs/write_nse.jl index 5f319244ea..9d1c73e835 100644 --- a/src/write_outputs/write_nse.jl +++ b/src/write_outputs/write_nse.jl @@ -38,7 +38,7 @@ function write_nse(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) CSV.write(joinpath(path, "nse.csv"), dftranspose(dfNse, false), writeheader = false) - if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 + if setup["OutputFullTimeSeries"] == 1 && setup["TimeDomainReduction"] == 1 write_full_time_series_reconstruction(path, setup, dfNse, "nse") @info("Writing Full Time Series for NSE") end diff --git a/src/write_outputs/write_power.jl b/src/write_outputs/write_power.jl index f71f29d6a3..756f027330 100644 --- a/src/write_outputs/write_power.jl +++ b/src/write_outputs/write_power.jl @@ -25,7 +25,7 @@ function write_power(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) write_annual(filepath, dfPower) else # setup["WriteOutputs"] == "full" df_Power = write_fulltimeseries(filepath, power, dfPower) - if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 + if setup["OutputFullTimeSeries"] == 1 && setup["TimeDomainReduction"] == 1 write_full_time_series_reconstruction(path, setup, df_Power, "power") @info("Writing Full Time Series for Power") end diff --git a/src/write_outputs/write_power_balance.jl b/src/write_outputs/write_power_balance.jl index 425b6fa6d5..8f9c5eb73a 100644 --- a/src/write_outputs/write_power_balance.jl +++ b/src/write_outputs/write_power_balance.jl @@ -97,7 +97,7 @@ function write_power_balance(path::AbstractString, inputs::Dict, setup::Dict, EP dftranspose(dfPowerBalance, false), writeheader = false) - if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 + if setup["OutputFullTimeSeries"] == 1 && setup["TimeDomainReduction"] == 1 write_full_time_series_reconstruction( path, setup, dfPowerBalance, "power_balance") @info("Writing Full Time Series for Power Balance") diff --git a/src/write_outputs/write_price.jl b/src/write_outputs/write_price.jl index 1abcf7fef2..79afb5b428 100644 --- a/src/write_outputs/write_price.jl +++ b/src/write_outputs/write_price.jl @@ -22,7 +22,7 @@ function write_price(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) dftranspose(dfPrice, false), writeheader = false) - if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 + if setup["OutputFullTimeSeries"] == 1 && setup["TimeDomainReduction"] == 1 write_full_time_series_reconstruction(path, setup, dfPrice, "prices") @info("Writing Full Time Series for Price") end diff --git a/src/write_outputs/write_reliability.jl b/src/write_outputs/write_reliability.jl index 65a49a28bf..afb3a3284c 100644 --- a/src/write_outputs/write_reliability.jl +++ b/src/write_outputs/write_reliability.jl @@ -21,7 +21,7 @@ function write_reliability(path::AbstractString, inputs::Dict, setup::Dict, EP:: dftranspose(dfReliability, false), header = false) - if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 + if setup["OutputFullTimeSeries"] == 1 && setup["TimeDomainReduction"] == 1 write_full_time_series_reconstruction(path, setup, dfReliability, "reliability") @info("Writing Full Time Series for Reliability") end diff --git a/src/write_outputs/write_storage.jl b/src/write_outputs/write_storage.jl index e1ee16e58b..96c0a61c9d 100644 --- a/src/write_outputs/write_storage.jl +++ b/src/write_outputs/write_storage.jl @@ -40,7 +40,7 @@ function write_storage(path::AbstractString, inputs::Dict, setup::Dict, EP::Mode rename!(dfStorage, auxNew_Names) CSV.write(joinpath(path, "storage.csv"), dftranspose(dfStorage, false), header = false) - if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 + if setup["OutputFullTimeSeries"] == 1 && setup["TimeDomainReduction"] == 1 write_full_time_series_reconstruction(path, setup, dfStorage, "storage") @info("Writing Full Time Series for Storage") end diff --git a/src/write_outputs/write_storagedual.jl b/src/write_outputs/write_storagedual.jl index 2714fe0025..ed8f71b758 100644 --- a/src/write_outputs/write_storagedual.jl +++ b/src/write_outputs/write_storagedual.jl @@ -80,7 +80,7 @@ function write_storagedual(path::AbstractString, inputs::Dict, setup::Dict, EP:: dftranspose(dfStorageDual, false), header = false) - if setup["OutputFullTimeSeries"] == 1 & setup["TimeDomainReduction"] == 1 + if setup["OutputFullTimeSeries"] == 1 && setup["TimeDomainReduction"] == 1 write_full_time_series_reconstruction(path, setup, dfStorageDual, "storagebal_duals") @info("Writing Full Time Series for Storage Duals") end From 20f5fe1fdd3c0290ba3b3bd531c2d3140abe2713 Mon Sep 17 00:00:00 2001 From: lbonaldo Date: Fri, 28 Jun 2024 17:43:23 -0400 Subject: [PATCH 56/61] Enable full ts reconstruction with multistage --- src/case_runners/case_runner.jl | 1 + .../full_time_series_reconstruction.jl | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/case_runners/case_runner.jl b/src/case_runners/case_runner.jl index 9cbcb076c3..7d828d59f6 100644 --- a/src/case_runners/case_runner.jl +++ b/src/case_runners/case_runner.jl @@ -187,6 +187,7 @@ function run_genx_case_multistage!(case::AbstractString, mysetup::Dict, optimize # Step 4) Write final outputs from each stage for p in 1:mysetup["MultiStageSettingsDict"]["NumStages"] + mysetup["MultiStageSettingsDict"]["CurStage"] = p outpath_cur = joinpath(outpath, "results_p$p") write_outputs(model_dict[p], outpath_cur, mysetup, inputs_dict[p]) end diff --git a/src/time_domain_reduction/full_time_series_reconstruction.jl b/src/time_domain_reduction/full_time_series_reconstruction.jl index e65419f2c1..098b919239 100644 --- a/src/time_domain_reduction/full_time_series_reconstruction.jl +++ b/src/time_domain_reduction/full_time_series_reconstruction.jl @@ -13,9 +13,17 @@ Internal function for performing the reconstruction. This function returns a Dat """ function full_time_series_reconstruction( path::AbstractString, setup::Dict, DF::DataFrame) + + if setup["MultiStage"] == 1 + dirs = splitpath(path) + case = joinpath(dirs[.!occursin.("result", dirs)]) # Get the case folder without the "results" folder(s) + cur_stage = setup["MultiStageSettingsDict"]["CurStage"] + TDRpath = joinpath(case, "inputs", string("inputs_p", cur_stage), setup["TimeDomainReductionFolder"]) + else + case = path[1:findlast('/', path)] + TDRpath = joinpath(case, setup["TimeDomainReductionFolder"]) + end # Read Period map file Period_map.csv - case = path[1:findlast('/', path)] - TDRpath = joinpath(case, setup["TimeDomainReductionFolder"]) Period_map = CSV.read(joinpath(TDRpath, "Period_map.csv"), DataFrame) # Read time domain reduction settings file time_domain_reduction_settings.yml From 1ab9836457800d941362509bbdb4cd8e0a5594ac Mon Sep 17 00:00:00 2001 From: lbonaldo Date: Fri, 28 Jun 2024 17:47:23 -0400 Subject: [PATCH 57/61] Update model_configuration.md in the docs --- docs/src/User_Guide/model_configuration.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/src/User_Guide/model_configuration.md b/docs/src/User_Guide/model_configuration.md index bcf30137e9..6267e4a500 100644 --- a/docs/src/User_Guide/model_configuration.md +++ b/docs/src/User_Guide/model_configuration.md @@ -92,5 +92,9 @@ The following tables summarize the model settings parameters and their default/p | WriteOutputs | Flag for writing the model outputs with hourly resolution or just the annual sum.| || "full" = write the model outputs with hourly resolution.| || "annual" = write only the annual sum of the model outputs.| +| OutputFullTimeSeries | Flag for writing the full time series of the model outputs.| +||1 = write the full time series of the model outputs.| +||0 = write only the reduced time series of the model outputs.| +| OutputFullTimeSeriesFolder | Name of the folder where the full time series of the model outputs will be stored inside the results directory (default: Full_TimeSeries).| The next step in configuring a GenX model is to specify the solver settings parameters using a `[solver_name]_settings.yml` file inside the `settings` folder. The solver settings parameters are solver specific and are described in the following section. From 5437e0d61a0c6eccb714ef89411930728ea76a4d Mon Sep 17 00:00:00 2001 From: Luca Bonaldo <39280783+lbonaldo@users.noreply.github.com> Date: Fri, 28 Jun 2024 17:53:47 -0400 Subject: [PATCH 58/61] Update src/time_domain_reduction/full_time_series_reconstruction.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/time_domain_reduction/full_time_series_reconstruction.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/time_domain_reduction/full_time_series_reconstruction.jl b/src/time_domain_reduction/full_time_series_reconstruction.jl index 098b919239..1eb2c20585 100644 --- a/src/time_domain_reduction/full_time_series_reconstruction.jl +++ b/src/time_domain_reduction/full_time_series_reconstruction.jl @@ -13,7 +13,6 @@ Internal function for performing the reconstruction. This function returns a Dat """ function full_time_series_reconstruction( path::AbstractString, setup::Dict, DF::DataFrame) - if setup["MultiStage"] == 1 dirs = splitpath(path) case = joinpath(dirs[.!occursin.("result", dirs)]) # Get the case folder without the "results" folder(s) From 85a603733fb7b78be9c99584645468610b91491e Mon Sep 17 00:00:00 2001 From: Luca Bonaldo <39280783+lbonaldo@users.noreply.github.com> Date: Fri, 28 Jun 2024 17:53:59 -0400 Subject: [PATCH 59/61] Update src/time_domain_reduction/full_time_series_reconstruction.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/time_domain_reduction/full_time_series_reconstruction.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/time_domain_reduction/full_time_series_reconstruction.jl b/src/time_domain_reduction/full_time_series_reconstruction.jl index 1eb2c20585..7421efa656 100644 --- a/src/time_domain_reduction/full_time_series_reconstruction.jl +++ b/src/time_domain_reduction/full_time_series_reconstruction.jl @@ -21,7 +21,7 @@ function full_time_series_reconstruction( else case = path[1:findlast('/', path)] TDRpath = joinpath(case, setup["TimeDomainReductionFolder"]) - end + end # Read Period map file Period_map.csv Period_map = CSV.read(joinpath(TDRpath, "Period_map.csv"), DataFrame) From 314fa1e02561c5156cafbc17308da6edf3988ac1 Mon Sep 17 00:00:00 2001 From: Luca Bonaldo <39280783+lbonaldo@users.noreply.github.com> Date: Fri, 28 Jun 2024 17:54:13 -0400 Subject: [PATCH 60/61] Update src/time_domain_reduction/full_time_series_reconstruction.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/time_domain_reduction/full_time_series_reconstruction.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/time_domain_reduction/full_time_series_reconstruction.jl b/src/time_domain_reduction/full_time_series_reconstruction.jl index 7421efa656..768f3ba0b1 100644 --- a/src/time_domain_reduction/full_time_series_reconstruction.jl +++ b/src/time_domain_reduction/full_time_series_reconstruction.jl @@ -17,7 +17,8 @@ function full_time_series_reconstruction( dirs = splitpath(path) case = joinpath(dirs[.!occursin.("result", dirs)]) # Get the case folder without the "results" folder(s) cur_stage = setup["MultiStageSettingsDict"]["CurStage"] - TDRpath = joinpath(case, "inputs", string("inputs_p", cur_stage), setup["TimeDomainReductionFolder"]) + TDRpath = joinpath(case, "inputs", string("inputs_p", cur_stage), + setup["TimeDomainReductionFolder"]) else case = path[1:findlast('/', path)] TDRpath = joinpath(case, setup["TimeDomainReductionFolder"]) From 2d33ae6d049a07e77030235c8eec4beefb5c65a1 Mon Sep 17 00:00:00 2001 From: Luca Bonaldo <39280783+lbonaldo@users.noreply.github.com> Date: Fri, 28 Jun 2024 18:03:22 -0400 Subject: [PATCH 61/61] Update src/write_outputs/write_storagedual.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/write_outputs/write_storagedual.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/write_outputs/write_storagedual.jl b/src/write_outputs/write_storagedual.jl index ed8f71b758..90eae94ff2 100644 --- a/src/write_outputs/write_storagedual.jl +++ b/src/write_outputs/write_storagedual.jl @@ -81,7 +81,8 @@ function write_storagedual(path::AbstractString, inputs::Dict, setup::Dict, EP:: header = false) if setup["OutputFullTimeSeries"] == 1 && setup["TimeDomainReduction"] == 1 - write_full_time_series_reconstruction(path, setup, dfStorageDual, "storagebal_duals") + write_full_time_series_reconstruction( + path, setup, dfStorageDual, "storagebal_duals") @info("Writing Full Time Series for Storage Duals") end end