From cde2fab342b6bb29f510dd75a06abf7ae6a9fb4d Mon Sep 17 00:00:00 2001 From: sallyrobson Date: Mon, 27 Mar 2023 09:47:20 -0400 Subject: [PATCH 1/3] build_status will update before and after sims --- src/io/data.jl | 8 ++++++-- src/results/parse.jl | 20 ++++++++++++++++++-- test/data/3bus/build_gen.csv | 4 ++-- test/testinitializedata.jl | 4 +++- 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/io/data.jl b/src/io/data.jl index 05dd1778..d4cf844c 100644 --- a/src/io/data.jl +++ b/src/io/data.jl @@ -371,6 +371,10 @@ function setup_table!(config, data, ::Val{:gen}) #removes capex_obj if loaded in from previous sim :capex_obj in propertynames(data[:gen]) && select!(data[:gen], Not(:capex_obj)) + #set build_status to 'built' for all gens marked 'new'. This marks gens built in a previous sim as 'built'. + idx_new = gen.build_status.=="new" + gen[idx_new, :build_status] .= "built" + ### Create new gens and add to the gen table if haskey(config, :build_gen_file) setup_new_gens!(config, data) @@ -577,7 +581,7 @@ function summarize_table(::Val{:gen}) push!(df, (:bus_idx, Int64, NA, true, "The index of the `bus` table that the generator corresponds to"), (:status, Bool, NA, false, "Whether or not the generator is in service"), - (:build_status, AbstractString, NA, true, "Whether the generator is 'built', 'new', or 'unbuilt'"), + (:build_status, AbstractString, NA, true, "Whether the generator is 'built', 'new', or 'unbuilt'. All generators marked 'new' when the gen file is read in will be changed to 'built'."), (:build_type, AbstractString, NA, true, "Whether the generator is 'real', 'exog' (exogenously built), or 'endog' (endogenously built)"), (:year_on, AbstractString, Year, true, "The first year of operation for the generator. (For new gens this is also the year it was built)"), (:genfuel, AbstractString, NA, true, "The fuel type that the generator uses"), @@ -660,7 +664,7 @@ function summarize_table(::Val{:build_gen}) push!(df, (:area, AbstractString, NA, true, "The area with which to filter by. I.e. \"state\". Leave blank to not filter by area."), (:subarea, AbstractString, NA, true, "The subarea to include in the filter. I.e. \"maryland\". Leave blank to not filter by area."), - (:build_status, AbstractString, NA, true, "Whether the generator is 'built', 'new', or 'unbuilt'. Should always be unbuilt for exog new gens."), + (:build_status, AbstractString, NA, true, "Whether the generator is 'built', 'new', or 'unbuilt'. Should be unbuilt for all new gens. This will be updated to 'new' for generators that were built in the sim."), (:build_type, AbstractString, NA, true, "Whether the generator is 'real', 'exog' (exogenously built), or 'endog' (endogenously built). Should either be exog or endog for buil_gen."), (:genfuel, AbstractString, NA, true, "The fuel type that the generator uses. Leave blank to not filter by genfuel."), (:gentype, AbstractString, NA, true, "The generation technology type that the generator uses. Leave blank to not filter by gentype."), diff --git a/src/results/parse.jl b/src/results/parse.jl index fbe8ceee..be74bfeb 100644 --- a/src/results/parse.jl +++ b/src/results/parse.jl @@ -22,6 +22,10 @@ function parse_results!(config, data, model) parse_lmp_results!(config, data) parse_power_results!(config, data) + + #change build_status to 'new' for generators built in the sim + set_new_gen_build_status!(config, data) + save_updated_gen_table(config, data) # Save the parsed data @@ -191,8 +195,6 @@ function save_updated_gen_table(config, data) thresh = get(config, :gen_pcap_threshold, eps()) filter!(:pcap0 => >(thresh), gen_tmp) - # Update build status - gen_tmp.build_status .= "built" CSV.write(get_out_path(config, "gen.csv"), gen_tmp) return nothing @@ -200,3 +202,17 @@ end export save_updated_gen_table +""" + set_new_gen_build_status!(config, data) -> + +Change the build_status of generators built in the simulation to 'new' +""" +function set_new_gen_build_status!(config, data) + gen = get_table(data, :gen) + + #Threshold capacity to be saved into the next run + thresh = get(config, :gen_pcap_threshold, eps()) + + new_idxs = findall(idx -> gen[idx, :build_status] == "unbuilt" && aggregate_result(total, data, :gen, :pcap, idx) >= thresh, 1:nrow(gen)) + gen[new_idxs, :build_status] .= "new" +end \ No newline at end of file diff --git a/test/data/3bus/build_gen.csv b/test/data/3bus/build_gen.csv index 8ebfe8b1..9274e20b 100644 --- a/test/data/3bus/build_gen.csv +++ b/test/data/3bus/build_gen.csv @@ -4,5 +4,5 @@ test_wind_build,none,country,archenland,1,unbuilt,endog,wind,wind,0,0,3,0,2,0,6, test_oswind_build,none,country,archenland,1,unbuilt,endog,wind,oswind,0,0,3,0,5,0,6,6,,y2035,,0 test_coal_build,none,country,narnia,1,unbuilt,endog,coal,coal,0,0,1,0.6,2,5,6,7,,,y2030,0.6 test_ngcc_build,none,buildngcc,1,1,unbuilt,endog,ng,ngcc,0,0,1,0.6,1,1,5,5,,y2015,,0.45 -test_exog_nuc_build,none,bus_idx,1,1,new,exog,nuclear,nuclear,2,0,2,0.6,10,5,5,10,y2020,,,0 -test_exog_solar_build,none,bus_idx,2,1,new,exog,solar,solar,1,0,1,0,2,0,4,5,y2060,,,0 +test_exog_nuc_build,none,bus_idx,1,1,unbuilt,exog,nuclear,nuclear,2,0,2,0.6,10,5,5,10,y2020,,,0 +test_exog_solar_build,none,bus_idx,2,1,unbuilt,exog,solar,solar,1,0,1,0,2,0,4,5,y2060,,,0 diff --git a/test/testinitializedata.jl b/test/testinitializedata.jl index 18353726..61611e84 100644 --- a/test/testinitializedata.jl +++ b/test/testinitializedata.jl @@ -117,7 +117,9 @@ end @test "endog" in gen.build_type @test "unbuilt" in gen.build_status for gen_row in eachrow(gen) - gen_row.build_status == "unbuilt" && @test gen_row.pcap0 == 0 + if gen_row.build_status == "unbuilt" && gen_row.build_type == "endog" + @test gen_row.pcap0 == 0 + end end "new" in build_gen.build_status && @test "new" in gen.build_status From 97f5c5e96063f612c9e6fa6abd07483c8f314409 Mon Sep 17 00:00:00 2001 From: sallyrobson Date: Mon, 27 Mar 2023 10:25:53 -0400 Subject: [PATCH 2/3] add a test for build_status --- test/testinitializedata.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/test/testinitializedata.jl b/test/testinitializedata.jl index 61611e84..4cf13374 100644 --- a/test/testinitializedata.jl +++ b/test/testinitializedata.jl @@ -138,6 +138,7 @@ end @test hasproperty(gen, :age) @test typeof(gen.age) == Vector{Container} @test all(age->age isa E4ST.ByYear, gen.age) + @test ~any(bs -> bs == "new", gen.build_status) end From 4ac65f80e24768f3aedd47c26656a5e477ebde11 Mon Sep 17 00:00:00 2001 From: sallyrobson Date: Thu, 30 Mar 2023 09:30:05 -0400 Subject: [PATCH 3/3] made assignment more efficient --- src/io/data.jl | 5 +++-- src/results/parse.jl | 7 +++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/io/data.jl b/src/io/data.jl index d4cf844c..e51194d3 100644 --- a/src/io/data.jl +++ b/src/io/data.jl @@ -372,8 +372,9 @@ function setup_table!(config, data, ::Val{:gen}) :capex_obj in propertynames(data[:gen]) && select!(data[:gen], Not(:capex_obj)) #set build_status to 'built' for all gens marked 'new'. This marks gens built in a previous sim as 'built'. - idx_new = gen.build_status.=="new" - gen[idx_new, :build_status] .= "built" + c = ==("new") # Comparison, one allocation + b = "built" # pre-allocate + transform!(gen, :build_status => ByRow(s->c(s) ? b : s) => :build_status) # transform in-place ### Create new gens and add to the gen table if haskey(config, :build_gen_file) diff --git a/src/results/parse.jl b/src/results/parse.jl index be74bfeb..875f0111 100644 --- a/src/results/parse.jl +++ b/src/results/parse.jl @@ -213,6 +213,9 @@ function set_new_gen_build_status!(config, data) #Threshold capacity to be saved into the next run thresh = get(config, :gen_pcap_threshold, eps()) - new_idxs = findall(idx -> gen[idx, :build_status] == "unbuilt" && aggregate_result(total, data, :gen, :pcap, idx) >= thresh, 1:nrow(gen)) - gen[new_idxs, :build_status] .= "new" + for idx in 1:nrow(gen) + gen[idx, :build_status] =="unbuilt" && aggregate_result(total, data, :gen, :pcap, idx) >= thresh ? gen[idx, :build_status] = "new" : continue + end + + end \ No newline at end of file