Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build_status will update before and after sim is run #94

Merged
merged 3 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/io/data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"
sallyrobson marked this conversation as resolved.
Show resolved Hide resolved

### Create new gens and add to the gen table
if haskey(config, :build_gen_file)
setup_new_gens!(config, data)
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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."),
Expand Down
20 changes: 18 additions & 2 deletions src/results/parse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -191,12 +195,24 @@ 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
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))
sallyrobson marked this conversation as resolved.
Show resolved Hide resolved
gen[new_idxs, :build_status] .= "new"
end
4 changes: 2 additions & 2 deletions test/data/3bus/build_gen.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 4 additions & 1 deletion test/testinitializedata.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -136,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