Skip to content

Commit

Permalink
first success run
Browse files Browse the repository at this point in the history
  • Loading branch information
swang22 committed Dec 3, 2023
1 parent 8c038d4 commit 818b726
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 54 deletions.
Binary file not shown.
2 changes: 2 additions & 0 deletions ModelCases/MD_Excel_case/Data_PCM2035/notes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
load2035 = load2022*1.15

5 changes: 5 additions & 0 deletions ModelCases/MD_Excel_case/output/es_power_hourly.csv

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions ModelCases/MD_Excel_case/output/power_hourly.csv

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ version = "1.0.0-DEV"
[deps]
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
Cbc = "9961bab8-2fa3-5c5a-9d89-47fab24efd76"
Clustering = "aaaa29a8-35af-508c-8bc3-b662a17a0fe5"
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Expand All @@ -18,6 +19,7 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd"
SCIP = "82193955-e24f-5292-bf16-6f2c5261a85f"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
XLSX = "fdbf4ff8-1666-58a4-91e7-1b58723a45e0"
YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6"

[compat]
Expand Down
9 changes: 9 additions & 0 deletions src/HOPE.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,21 @@ module HOPE
using JuMP
using DataFrames
using CSV
using XLSX
using LinearAlgebra
using YAML
using Dates
using Clustering
using Distances
using Combinatorics
using Statistics

#using solver
#using Gurobi
#using CPLEX
using Cbc
using HiGHS
#using Clp

#include HOPE module scripts
include("read_input_data.jl"); #read input data module
Expand Down
100 changes: 50 additions & 50 deletions src/Read_input_data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function aggregate_gendata_pcm(df)
:RU => mean,
:RD => mean)
rename!(agg_df, [Symbol("Pmax (MW)_sum"), Symbol("Pmin (MW)_sum"),Symbol("Cost (\$/MWh)_mean"),:EF_mean,:CC_mean,:FOR_mean,:RM_SPIN_mean,:RU_mean,:RD_mean]
.=> [Symbol("Pmax (MW)"), Symbol("Pmin (MW)"), Symbol("Cost (\$/MWh)"),:EF,:CC,:FOR,:RM_SPIN,:RU,:RD] )
.=> [Symbol("Pmax (MW)"), Symbol("Pmin (MW)"), Symbol("Cost (\$/MWh)"),:EF,:CC,:FOR,:RM_SPIN,:RU,:RD])
return agg_df
end

Expand All @@ -32,42 +32,42 @@ function load_data(config_set::Dict,path::AbstractString)
if model_mode == "GTEP" #read data for generation and transmission expansion model
input_data = Dict()
println("Reading Input_Data Files for GTEP mode")
folderpath = path*Data_case
folderpath = joinpath(path,Data_case)
files = readdir(folderpath)
if any(endswith.(files, ".xlsx"))
println("The directory $folderpath contains .xlsx file, then try to read input data from GTEP_input_total.xlsx")
#xlsx_file = XLSX.readxlsx(path*Data_case*"GTEP_input_total.xlsx")

#network
println("Reading network")
input_data["Busdata"]=DataFrame(XLSX.readtable(folderpath*"GTEP_input_total.xlsx","busdata"))
input_data["Branchdata"]=DataFrame(XLSX.readtable(folderpath*"GTEP_input_total.xlsx","branchdata"))
input_data["Busdata"]=DataFrame(XLSX.readtable(joinpath(folderpath,"GTEP_input_total.xlsx"),"busdata"))
input_data["Branchdata"]=DataFrame(XLSX.readtable(joinpath(folderpath,"GTEP_input_total.xlsx"),"branchdata"))
#technology
println("Reading technology")
if config_set["aggregated!"]==1
input_data["Gendata"] = aggregate_gendata_gtep(DataFrame(XLSX.readtable(folderpath*"GTEP_input_total.xlsx","gendata")))
input_data["Gendata"] = aggregate_gendata_gtep(DataFrame(XLSX.readtable(joinpath(folderpath,"GTEP_input_total.xlsx"),"gendata")))
else
input_data["Gendata"]=DataFrame(XLSX.readtable(folderpath*"GTEP_input_total.xlsx","gendata"))
input_data["Gendata"]=DataFrame(XLSX.readtable(joinpath(folderpath,"GTEP_input_total.xlsx"),"gendata"))
end

input_data["Estoragedata"]=DataFrame(XLSX.readtable(folderpath*"GTEP_input_total.xlsx","Estoragedata"))
input_data["Estoragedata"]=DataFrame(XLSX.readtable(joinpath(folderpath,"GTEP_input_total.xlsx"),"Estoragedata"))
input_data["Gencostdata"]=input_data["Gendata"][:,Symbol("Cost (\$/MWh)")]
#time series
println("Reading time series")
input_data["Winddata"]=DataFrame(XLSX.readtable(folderpath*"GTEP_input_total.xlsx","WT_timeseries_regional"))
input_data["Solardata"]=DataFrame(XLSX.readtable(folderpath*"GTEP_input_total.xlsx","SPV_timeseries_regional"))
input_data["Loaddata"]=DataFrame(XLSX.readtable(folderpath*"GTEP_input_total.xlsx","Load_timeseries_regional"))
input_data["Winddata"]=DataFrame(XLSX.readtable(joinpath(folderpath,"GTEP_input_total.xlsx"),"WT_timeseries_regional"))
input_data["Solardata"]=DataFrame(XLSX.readtable(joinpath(folderpath,"GTEP_input_total.xlsx"),"SPV_timeseries_regional"))
input_data["Loaddata"]=DataFrame(XLSX.readtable(joinpath(folderpath,"GTEP_input_total.xlsx"),"Load_timeseries_regional"))
input_data["NIdata"]=input_data["Loaddata"][:,"NI"]
#candidate
println("Reading resourc candidate")
input_data["Estoragedata_candidate"]=DataFrame(XLSX.readtable(folderpath*"GTEP_input_total.xlsx","Estoragedata_candidate"))
input_data["Linedata_candidate"]=DataFrame(XLSX.readtable(folderpath*"GTEP_input_total.xlsx","Linedata_candidate"))
input_data["Gendata_candidate"]=DataFrame(XLSX.readtable(folderpath*"GTEP_input_total.xlsx","Gendata_candidate"))
input_data["Estoragedata_candidate"]=DataFrame(XLSX.readtable(joinpath(folderpath,"GTEP_input_total.xlsx"),"Estoragedata_candidate"))
input_data["Linedata_candidate"]=DataFrame(XLSX.readtable(joinpath(folderpath,"GTEP_input_total.xlsx"),"Linedata_candidate"))
input_data["Gendata_candidate"]=DataFrame(XLSX.readtable(joinpath(folderpath,"GTEP_input_total.xlsx"),"Gendata_candidate"))
#policies
println("Reading polices")
input_data["CBPdata"]=DataFrame(XLSX.readtable(folderpath*"GTEP_input_total.xlsx","carbonpolices"))
input_data["CBPdata"]=DataFrame(XLSX.readtable(joinpath(folderpath,"GTEP_input_total.xlsx"),"carbonpolices"))
#rpspolicydata=
input_data["RPSdata"]=DataFrame(XLSX.readtable(folderpath*"GTEP_input_total.xlsx","rpspolices"))
input_data["RPSdata"]=DataFrame(XLSX.readtable(joinpath(folderpath,"GTEP_input_total.xlsx"),"rpspolices"))
println("xlsx Files Successfully Load From $folderpath")

else
Expand All @@ -76,107 +76,107 @@ function load_data(config_set::Dict,path::AbstractString)
#network
#Busdata=CSV.read("Data/busdata.csv",DataFrame)
println("Reading network")
input_data["Busdata"]=CSV.read(path*Data_case*"busdata.csv",DataFrame) #110% Peak
input_data["Branchdata"]=CSV.read(path*Data_case*"branchdata.csv",DataFrame)
input_data["Busdata"]=CSV.read(joinpath(folderpath,"busdata.csv"),DataFrame) #110% Peak
input_data["Branchdata"]=CSV.read(joinpath(folderpath,"branchdata.csv"),DataFrame)
#technology
println("Reading technology")
if config_set["aggregated!"]==1
input_data["Gendata"] = aggregate_gendata_gtep(CSV.read(path*Data_case*"gendata.csv",DataFrame))
input_data["Gendata"] = aggregate_gendata_gtep(CSV.read(joinpath(folderpath,"gendata.csv"),DataFrame))
else
input_data["Gendata"]=CSV.read(path*Data_case*"gendata.csv",DataFrame)
input_data["Gendata"]=CSV.read(joinpath(folderpath,"gendata.csv"),DataFrame)
end

input_data["Estoragedata"]=CSV.read(path*Data_case*"Estoragedata.csv",DataFrame)
input_data["Estoragedata"]=CSV.read(joinpath(folderpath,"Estoragedata.csv"),DataFrame)
input_data["Gencostdata"]=input_data["Gendata"][:,Symbol("Cost (\$/MWh)")]
#time series
println("Reading time series")
input_data["Winddata"]=CSV.read(path*Data_case*"WT_timeseries_regional.csv",DataFrame)
input_data["Solardata"]=CSV.read(path*Data_case*"SPV_timeseries_regional.csv",DataFrame)
input_data["Loaddata"]=CSV.read(path*Data_case*"Load_timeseries_regional.csv",DataFrame)
input_data["Winddata"]=CSV.read(joinpath(folderpath,"WT_timeseries_regional.csv"),DataFrame)
input_data["Solardata"]=CSV.read(joinpath(folderpath,"SPV_timeseries_regional.csv"),DataFrame)
input_data["Loaddata"]=CSV.read(joinpath(folderpath,"Load_timeseries_regional.csv"),DataFrame)
input_data["NIdata"]=input_data["Loaddata"][:,"NI"]
#candidate
println("Reading resourc candidate")
input_data["Estoragedata_candidate"]=CSV.read(path*Data_case*"Estoragedata_candidate.csv",DataFrame)
input_data["Linedata_candidate"]=CSV.read(path*Data_case*"Linedata_candidate.csv",DataFrame)
input_data["Gendata_candidate"]=CSV.read(path*Data_case*"Gendata_candidate.csv",DataFrame)
input_data["Estoragedata_candidate"]=CSV.read(joinpath(folderpath,"Estoragedata_candidate.csv"),DataFrame)
input_data["Linedata_candidate"]=CSV.read(joinpath(folderpath,"Linedata_candidate.csv"),DataFrame)
input_data["Gendata_candidate"]=CSV.read(joinpath(folderpath,"Gendata_candidate.csv"),DataFrame)
#policies
println("Reading polices")
input_data["CBPdata"]=CSV.read(path*Data_case*"carbonpolices.csv",DataFrame)
input_data["CBPdata"]=CSV.read(joinpath(folderpath,"carbonpolices.csv"),DataFrame)
#rpspolicydata=
input_data["RPSdata"]=CSV.read(path*Data_case*"rpspolices.csv",DataFrame)
println("CSV Files Successfully Load From $path")
input_data["RPSdata"]=CSV.read(joinpath(folderpath,"rpspolices.csv"),DataFrame)
println("CSV Files Successfully Load From $folderpath")
end



elseif model_mode == "PCM" #read data for production cost model
input_data = Dict()
println("Reading Input_Data Files for PCM mode")
folderpath = path*Data_case
folderpath = joinpath(path*"/"*Data_case)
files = readdir(folderpath)
if any(endswith.(files, ".xlsx"))
println("The directory $folderpath contains .xlsx file, then try to read input data from PCM_input_total.xlsx")
#xlsx_file = XLSX.readxlsx(path*Data_case*"PCM_input_total.xlsx")

#network
println("Reading network")
input_data["Busdata"]=DataFrame(XLSX.readtable(folderpath*"PCM_input_total.xlsx","busdata"))
input_data["Branchdata"]=DataFrame(XLSX.readtable(folderpath*"PCM_input_total.xlsx","branchdata"))
input_data["Busdata"]=DataFrame(XLSX.readtable(joinpath(folderpath,"PCM_input_total.xlsx"),"busdata"))
input_data["Branchdata"]=DataFrame(XLSX.readtable(joinpath(folderpath,"PCM_input_total.xlsx"),"branchdata"))
#technology
println("Reading technology")
if config_set["aggregated!"]==1
input_data["Gendata"] = aggregate_gendata_pcm(DataFrame(XLSX.readtable(folderpath*"PCM_input_total.xlsx","gendata")))
input_data["Gendata"] = aggregate_gendata_pcm(DataFrame(XLSX.readtable(joinpath(folderpath,"PCM_input_total.xlsx"),"gendata")))
else
input_data["Gendata"]=DataFrame(XLSX.readtable(folderpath*"PCM_input_total.xlsx","gendata"))
input_data["Gendata"]=DataFrame(XLSX.readtable(joinpath(folderpath,"PCM_input_total.xlsx"),"gendata"))
end

input_data["Estoragedata"]=DataFrame(XLSX.readtable(folderpath*"PCM_input_total.xlsx","Estoragedata"))
input_data["Estoragedata"]=DataFrame(XLSX.readtable(joinpath(folderpath,"PCM_input_total.xlsx"),"Estoragedata"))
input_data["Gencostdata"]=input_data["Gendata"][:,Symbol("Cost (\$/MWh)")]


#time series
println("Reading time series")
input_data["Winddata"]=DataFrame(XLSX.readtable(folderpath*"PCM_input_total.xlsx","WT_timeseries_regional"))
input_data["Solardata"]=DataFrame(XLSX.readtable(folderpath*"PCM_input_total.xlsx","SPV_timeseries_regional"))
input_data["Loaddata"]=DataFrame(XLSX.readtable(folderpath*"PCM_input_total.xlsx","Load_timeseries_regional"))
input_data["Winddata"]=DataFrame(XLSX.readtable(joinpath(folderpath,"PCM_input_total.xlsx"),"WT_timeseries_regional"))
input_data["Solardata"]=DataFrame(XLSX.readtable(joinpath(folderpath,"PCM_input_total.xlsx"),"SPV_timeseries_regional"))
input_data["Loaddata"]=DataFrame(XLSX.readtable(joinpath(folderpath*"PCM_input_total.xlsx"),"Load_timeseries_regional"))
input_data["NIdata"]=input_data["Loaddata"][:,"NI"]

#policies
println("Reading polices")
input_data["CBPdata"]=DataFrame(XLSX.readtable(folderpath*"PCM_input_total.xlsx","carbonpolices"))
input_data["CBPdata"]=DataFrame(XLSX.readtable(joinpath(folderpath,"PCM_input_total.xlsx"),"carbonpolices"))
#rpspolicydata=
input_data["RPSdata"]=DataFrame(XLSX.readtable(folderpath*"PCM_input_total.xlsx","rpspolices"))
input_data["RPSdata"]=DataFrame(XLSX.readtable(joinpath(folderpath,"PCM_input_total.xlsx"),"rpspolices"))
println("xlsx Files Successfully Load From $folderpath")
else
println("No xlsx file found in the directory $folderpath, try to read data from .csv files")

println("Reading network")
input_data["Busdata"]=CSV.read(path*Data_case*"busdata.csv",DataFrame) #110% Peak
input_data["Branchdata"]=CSV.read(path*Data_case*"branchdata.csv",DataFrame)
input_data["Busdata"]=CSV.read(joinpath(folderpath,"busdata.csv"),DataFrame)
input_data["Branchdata"]=CSV.read(joinpath(folderpath,"branchdata.csv"),DataFrame)
#technology
println("Reading technology")
if config_set["aggregated!"]==1
input_data["Gendata"] = aggregate_gendata_pcm(CSV.read(path*Data_case*"gendata.csv",DataFrame))
input_data["Gendata"] = aggregate_gendata_pcm(CSV.read(joinpath(folderpath,"gendata.csv"),DataFrame))
else
input_data["Gendata"]=CSV.read(path*Data_case*"gendata.csv",DataFrame)
input_data["Gendata"]=CSV.read(joinpath(folderpath,"gendata.csv"),DataFrame)
end

input_data["Estoragedata"]=CSV.read(path*Data_case*"Estoragedata.csv",DataFrame)
input_data["Estoragedata"]=CSV.read(joinpath(folderpath,"Estoragedata.csv"),DataFrame)
input_data["Gencostdata"]=input_data["Gendata"][:,Symbol("Cost (\$/MWh)")]


#time series
println("Reading time series")
input_data["Winddata"]=CSV.read(path*Data_case*"WT_timeseries_regional.csv",DataFrame)
input_data["Solardata"]=CSV.read(path*Data_case*"SPV_timeseries_regional.csv",DataFrame)
input_data["Loaddata"]=CSV.read(path*Data_case*"Load_timeseries_regional.csv",DataFrame)
input_data["Winddata"]=CSV.read(joinpath(folderpath,"WT_timeseries_regional.csv"),DataFrame)
input_data["Solardata"]=CSV.read(joinpath(folderpath,"SPV_timeseries_regional.csv"),DataFrame)
input_data["Loaddata"]=CSV.read(joinpath(folderpath,"Load_timeseries_regional.csv"),DataFrame)
input_data["NIdata"]=input_data["Loaddata"][:,"NI"]

#policies
println("Reading polices")
input_data["CBPdata"]=CSV.read(path*Data_case*"carbonpolices.csv",DataFrame)
input_data["CBPdata"]=CSV.read(joinpath(folderpath,"carbonpolices.csv"),DataFrame)
#rpspolicydata=
input_data["RPSdata"]=CSV.read(path*Data_case*"rpspolices.csv",DataFrame)
input_data["RPSdata"]=CSV.read(joinpath(folderpath,"rpspolices.csv"),DataFrame)
println("CSV Files Successfully Load From $folderpath")
end
end
Expand Down
6 changes: 4 additions & 2 deletions src/run.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
function run_hope(case::AbstractString)
#wk_dir = @__DIR__
#path = joinpath(wk_dir,case)
path = case
outpath = case*"/output/"
outpath = path*"/output/"
#Set model configuration
config_set = YAML.load(open("Settings/HOPE_model_settings.yml"))
config_set = YAML.load(open(case*"/Settings/HOPE_model_settings.yml"))

#Set solver configuration
optimizer = initiate_solver(config_set["solver"])
Expand Down
13 changes: 11 additions & 2 deletions src/write_output.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
function mkdir_overwrite(path::AbstractString)
if isdir(path)
rm(path; force=true, recursive=true)
println("'output' folder exists, will be overwrite now!")
end
mkdir(path)
end

function write_output(outpath::AbstractString,config_set::Dict, input_data::Dict, model::Model)
mkdir(outpath, exist_ok=true)
mkdir_overwrite(outpath)
model_mode = config_set["model_mode"]
println("HOPE model ("*model_mode*" mode) is successfully solved!")
if model_mode == "GTEP"
##read input for print
Gendata = input_data["Gendata"]
Expand Down Expand Up @@ -187,5 +196,5 @@ function write_output(outpath::AbstractString,config_set::Dict, input_data::Dict
CSV.write(joinpath(outpath, "es_power_hourly.csv"), P_es_df, writeheader=true)

end
return
println("Write solved results in the folder 'output' DONE!")
end

0 comments on commit 818b726

Please sign in to comment.