Skip to content

Commit

Permalink
Update paths in source code
Browse files Browse the repository at this point in the history
  • Loading branch information
lbonaldo committed Feb 16, 2024
1 parent e666aea commit cac1316
Show file tree
Hide file tree
Showing 12 changed files with 131 additions and 85 deletions.
20 changes: 11 additions & 9 deletions src/case_runners/case_runner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ function run_genx_case_simple!(case::AbstractString, mysetup::Dict, optimizer::A
settings_path = get_settings_path(case)

### Cluster time series inputs if necessary and if specified by the user
TDRpath = joinpath(case, mysetup["TimeDomainReductionFolder"])


if mysetup["TimeDomainReduction"] == 1
prevent_doubled_timedomainreduction(case)
TDRpath = joinpath(case, mysetup["TimeDomainReductionFolder"])
system_path = joinpath(case, mysetup["SystemFolder"])
prevent_doubled_timedomainreduction(system_path)
if !time_domain_reduced_files_exist(TDRpath)
println("Clustering Time Series Data (Grouped)...")
cluster_inputs(case, settings_path, mysetup)
Expand Down Expand Up @@ -92,13 +93,14 @@ function run_genx_case_multistage!(case::AbstractString, mysetup::Dict, optimize
mysetup["MultiStageSettingsDict"] = YAML.load(open(multistage_settings))

### Cluster time series inputs if necessary and if specified by the user
tdr_settings = get_settings_path(case, "time_domain_reduction_settings.yml") # Multi stage settings YAML file path
TDRSettingsDict = YAML.load(open(tdr_settings))

first_stage_path = joinpath(case, "Inputs", "Inputs_p1")
TDRpath = joinpath(first_stage_path, mysetup["TimeDomainReductionFolder"])
if mysetup["TimeDomainReduction"] == 1
prevent_doubled_timedomainreduction(first_stage_path)
tdr_settings = get_settings_path(case, "time_domain_reduction_settings.yml") # Multi stage settings YAML file path
TDRSettingsDict = YAML.load(open(tdr_settings))

first_stage_path = joinpath(case, "Inputs", "Inputs_p1")
TDRpath = joinpath(first_stage_path, mysetup["TimeDomainReductionFolder"])
system_path = joinpath(first_stage_path, mysetup["SystemFolder"])
prevent_doubled_timedomainreduction(system_path)
if !time_domain_reduced_files_exist(TDRpath)
if (mysetup["MultiStage"] == 1) && (TDRSettingsDict["MultiStageConcatenate"] == 0)
println("Clustering Time Series Data (Individually)...")
Expand Down
5 changes: 4 additions & 1 deletion src/configure_settings/configure_settings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ function default_settings()
"HydrogenHourlyMatching" => 0,
"EnableJuMPStringNames" => false,
"ComputeConflicts" => 0,
"ResourcePath" => "Resources",
"ResourcesFolder" => "Resources",
"ResourcePoliciesFolder" => "Policy_assignments",
"SystemFolder" => "System",
"PoliciesFolder" => "Policies",
)
end

Expand Down
3 changes: 2 additions & 1 deletion src/load_inputs/load_demand_data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ function load_demand_data!(setup::Dict, path::AbstractString, inputs::Dict)
if setup["TimeDomainReduction"] == 1 && time_domain_reduced_files_exist(data_directory)
my_dir = data_directory
else
my_dir = path
# If TDR is not used, then use the directory specified in the default setup
my_dir = joinpath(path, setup["SystemFolder"])
end
demand_in = get_demand_dataframe(my_dir)

Expand Down
3 changes: 2 additions & 1 deletion src/load_inputs/load_fuels_data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ function load_fuels_data!(setup::Dict, path::AbstractString, inputs::Dict)
if setup["TimeDomainReduction"] == 1 && time_domain_reduced_files_exist(data_directory)
my_dir = data_directory
else
my_dir = path
# If TDR is not used, then use the directory specified in the default setup
my_dir = joinpath(path, setup["SystemFolder"])
end
filename = "Fuels_data.csv"
fuels_in = load_dataframe(joinpath(my_dir, filename))
Expand Down
2 changes: 1 addition & 1 deletion src/load_inputs/load_generators_variability.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function load_generators_variability!(setup::Dict, path::AbstractString, inputs:
if setup["TimeDomainReduction"] == 1 && time_domain_reduced_files_exist(data_directory)
my_dir = data_directory
else
my_dir = path
my_dir = joinpath(path, setup["SystemFolder"])
end
filename = "Generators_variability.csv"
gen_var = load_dataframe(joinpath(my_dir, filename))
Expand Down
28 changes: 16 additions & 12 deletions src/load_inputs/load_inputs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ function load_inputs(setup::Dict,path::AbstractString)

## Read input files
println("Reading Input CSV Files")
## input paths
system_path = joinpath(path, setup["SystemFolder"])
resources_path = joinpath(path, setup["ResourcesFolder"])
policy_path = joinpath(path, setup["PoliciesFolder"])
## Declare Dict (dictionary) object used to store parameters
inputs = Dict()
# Read input data about power network topology, operating and expansion attributes
if isfile(joinpath(path,"Network.csv"))
network_var = load_network_data!(setup, path, inputs)
if isfile(joinpath(system_path,"Network.csv"))
network_var = load_network_data!(setup, system_path, inputs)
else
inputs["Z"] = 1
inputs["L"] = 0
Expand All @@ -28,47 +32,47 @@ function load_inputs(setup::Dict,path::AbstractString)
# Read fuel cost data, including time-varying fuel costs
load_fuels_data!(setup, path, inputs)
# Read in generator/resource related inputs
load_resources_data!(inputs, setup, path)
load_resources_data!(inputs, setup, path, resources_path)
# Read in generator/resource availability profiles
load_generators_variability!(setup, path, inputs)

validatetimebasis(inputs)

if setup["CapacityReserveMargin"]==1
load_cap_reserve_margin!(setup, path, inputs)
load_cap_reserve_margin!(setup, policy_path, inputs)
if inputs["Z"] >1
load_cap_reserve_margin_trans!(setup, inputs, network_var)
end
end

# Read in general configuration parameters for reserves (resource-specific reserve parameters are read in generators_data())
if setup["Reserves"]==1
load_reserves!(setup, path, inputs)
load_reserves!(setup, system_path, inputs)
end

if setup["MinCapReq"] == 1
load_minimum_capacity_requirement!(path, inputs, setup)
load_minimum_capacity_requirement!(policy_path, inputs, setup)
end

if setup["MaxCapReq"] == 1
load_maximum_capacity_requirement!(path, inputs, setup)
load_maximum_capacity_requirement!(policy_path, inputs, setup)
end

if setup["EnergyShareRequirement"]==1
load_energy_share_requirement!(setup, path, inputs)
load_energy_share_requirement!(setup, policy_path, inputs)
end

if setup["CO2Cap"] >= 1
load_co2_cap!(setup, path, inputs)
load_co2_cap!(setup, policy_path, inputs)
end

if !isempty(inputs["VRE_STOR"])
load_vre_stor_variability!(setup, path, inputs)
load_vre_stor_variability!(setup, system_path, inputs)
end

# Read in mapping of modeled periods to representative periods
if is_period_map_necessary(inputs) && is_period_map_exist(setup, path, inputs)
load_period_map!(setup, path, inputs)
if is_period_map_necessary(inputs) && is_period_map_exist(setup, system_path, inputs)
load_period_map!(setup, system_path, inputs)
end

# Virtual charge discharge cost
Expand Down
94 changes: 56 additions & 38 deletions src/load_inputs/load_resources_data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ Internal function to get policy file information.
"""
function _get_policyfile_info()
policyfile_info = (
esr = (filename="Resource_energy_share_requirement.csv"),
cap_res = (filename="Resource_capacity_reserve_margin.csv"),
min_cap = (filename="Resource_minimum_capacity_requirement.csv"),
max_cap = (filename="Resource_maximum_capacity_requirement.csv"),
esr = (filename="Resource_energy_share_requirement.csv", setupflag="EnergyShareRequirement"),
cap_res = (filename="Resource_capacity_reserve_margin.csv", setupflag="CapacityReserveMargin"),
min_cap = (filename="Resource_minimum_capacity_requirement.csv", setupflag="MinCapReq"),
max_cap = (filename="Resource_maximum_capacity_requirement.csv", setupflag="MaxCapReq"),
)
return policyfile_info
end
Expand Down Expand Up @@ -444,34 +444,56 @@ function validate_resources(resources::T) where T <: Vector{AbstractResource}
end

"""
create_resources(setup::Dict, case_path::AbstractString)
create_resources(setup::Dict, resources_path::AbstractString)
Function that loads and scales resources data from folder specified in `setup["ResourcePath"] and returns an array of GenX resources.
Function that loads and scales resources data from folder specified in resources_path and returns an array of GenX resources.
# Arguments
- `setup (Dict)`: Dictionary containing GenX settings.
- `case_path (AbstractString)`: The path to the case.
- `resources_path (AbstractString)`: The path to the resources folder.
# Returns
- `resources (Vector{AbstractResource})`: An array of scaled resources.
"""
function create_resource_array(setup::Dict, case_path::AbstractString)
function create_resource_array(setup::Dict, resources_path::AbstractString)
scale_factor = setup["ParameterScale"] == 1 ? ModelScalingFactor : 1.0

resources_folder = setup["ResourcePath"]
resources_folder = joinpath(case_path,resources_folder)

# get filename and GenX type for each type of resources available in GenX
resources_info = _get_resource_info()

# load each resource type, scale data and return array of resources
resources = create_resource_array(resources_folder, resources_info, scale_factor)
resources = create_resource_array(resources_path, resources_info, scale_factor)
# validate input before returning resources
validate_resources(resources)
return resources
end


"""
validate_policy_files(resource_policies_path::AbstractString, setup::Dict)
Validate the policy files by checking if they exist in the specified folder and if the setup flags are consistent with the files found.
# Arguments
- `resource_policies_path::AbstractString`: The path to the policy files.
- `setup::Dict`: Dictionary containing GenX settings.
# Returns
- warning messages if the polcies are set to 1 in settings but the files are not found in the resource_policies_path.
"""
function validate_policy_files(resource_policies_path::AbstractString, setup::Dict)
policyfile_info = _get_policyfile_info()
for (filename, setup_flag) in values(policyfile_info)
if setup[setup_flag] == 1 && !isfile(joinpath(resource_policies_path, filename))
msg = string(setup_flag, " is set to 1 in settings but the file ", filename, " was not found in ", resource_policies_path)
@warn(msg)
end
end
return nothing
end

"""
validate_policy_dataframe!(filename::AbstractString, policy_in::DataFrame)
Expand Down Expand Up @@ -578,23 +600,20 @@ function add_policy_to_resources!(resources::Vector{<:AbstractResource}, path::A
end

"""
add_policies_to_resources!(resources::Vector{<:AbstractResource}, setup::Dict, case_path::AbstractString)
add_policies_to_resources!(resources::Vector{<:AbstractResource}, resources_path::AbstractString)
Reads policy files and adds policies-related attributes to resources in the model.
# Arguments
- `resources::Vector{<:AbstractResource}`: Vector of resources in the model.
- `setup (Dict)`: Dictionary containing GenX settings.
- `case_path::AbstractString`: The path to the case.
- `resources_path::AbstractString`: The path to the resources folder.
"""
function add_policies_to_resources!(resources::Vector{<:AbstractResource}, setup::Dict, case_path::AbstractString)
policy_folder = setup["ResourcePath"]
policy_folder = joinpath(case_path, policy_folder)
function add_policies_to_resources!(resources::Vector{<:AbstractResource}, resource_policy_path::AbstractString)
# get filename for each type of policy available in GenX
policies_info = _get_policyfile_info()
# loop over policy files
for filename in values(policies_info)
path = joinpath(policy_folder, filename)
for (filename,_) in values(policies_info)
path = joinpath(resource_policy_path, filename)
# if file exists, add policy to resources
if isfile(path)
add_policy_to_resources!(resources, path, filename)
Expand All @@ -620,25 +639,22 @@ function add_module_to_resources!(resources::Vector{<:AbstractResource}, module_
end

"""
add_modules_to_resources!(resources::Vector{<:AbstractResource}, setup::Dict, case_path::AbstractString)
add_modules_to_resources!(resources::Vector{<:AbstractResource}, setup::Dict, resources_path::AbstractString)
Reads module dataframes, loops over files and adds columns as new attributes to the resources in the model.
# Arguments
- `resources::Vector{<:AbstractResource}`: A vector of resources.
- `setup (Dict)`: A dictionary containing GenX settings.
- `case_path::AbstractString`: The path to the case.
- `resources_path::AbstractString`: The path to the resources folder.
"""
function add_modules_to_resources!(resources::Vector{<:AbstractResource}, setup::Dict, case_path::AbstractString)
function add_modules_to_resources!(resources::Vector{<:AbstractResource}, setup::Dict, resources_path::AbstractString)
modules = Vector{DataFrame}()

module_folder = setup["ResourcePath"]
module_folder = joinpath(case_path, module_folder)

## Load all modules and add them to the list of modules to be added to resources
# Add multistage if multistage is activated
if setup["MultiStage"] == 1
filename = joinpath(module_folder, "Resource_multistage_data.csv")
filename = joinpath(resources_path, "Resource_multistage_data.csv")
multistage_in = load_multistage_dataframe(filename)
push!(modules, multistage_in)
@info "Multistage data successfully read."
Expand Down Expand Up @@ -847,18 +863,17 @@ function split_storage_resources!(inputs::Dict, gen::Vector{<:AbstractResource})
end

"""
add_resources_to_input_data!(inputs::Dict, setup::Dict, case_path::AbstractString, gen::Vector{<:AbstractResource})
add_resources_to_input_data!(inputs::Dict, setup::Dict, gen::Vector{<:AbstractResource})
Adds resources to the `inputs` `Dict` with the key "RESOURCES" together with sevaral sets of resource indices that are used inside GenX to construct the optimization problem. The `inputs` `Dict` is modified in-place.
# Arguments
- `inputs (Dict)`: Dictionary to store the GenX input data.
- `setup (Dict)`: Dictionary containing GenX settings.
- `case_path (AbstractString)`: Path to the case.
- `gen (Vector{<:AbstractResource})`: Array of GenX resources.
"""
function add_resources_to_input_data!(inputs::Dict, setup::Dict, case_path::AbstractString, gen::Vector{<:AbstractResource})
function add_resources_to_input_data!(inputs::Dict, setup::Dict, gen::Vector{<:AbstractResource})

# Number of resources
G = length(gen)
Expand Down Expand Up @@ -1094,36 +1109,39 @@ function summary(rs::Vector{<:AbstractResource})
end

"""
load_resources_data!(inputs::Dict, setup::Dict, case_path::AbstractString)
load_resources_data!(inputs::Dict, setup::Dict, case_path::AbstractString, resources_path::AbstractString)
This function loads resources data from the `setup["ResourcePath"]` folder and create the GenX data structures and add them to the `inputs` `Dict`.
This function loads resources data from the resources_path folder and create the GenX data structures and add them to the `inputs` `Dict`.
# Arguments
- `inputs (Dict)`: A dictionary to store the input data.
- `setup (Dict)`: A dictionary containing GenX settings.
- `case_path (AbstractString)`: The path to the case.
- `case_path (AbstractString)`: The path to the case folder.
- `resources_path (AbstractString)`: The path to the case resources folder.
Raises:
DeprecationWarning: If the `Generators_data.csv` file is found, a deprecation warning is issued, together with an error message.
"""
function load_resources_data!(inputs::Dict, setup::Dict, case_path::AbstractString)
function load_resources_data!(inputs::Dict, setup::Dict, case_path::AbstractString, resources_path::AbstractString)
if isfile(joinpath(case_path, "Generators_data.csv"))
msg = "The `Generators_data.csv` file was deprecated in release v0.4. " *
"Please use the new interface for generators creation, and see the documentation for additional details."
Base.depwarn(msg, :load_resources_data!, force=true)
error("Exiting GenX...")
else
# create vector of resources from dataframes
resources = create_resource_array(setup, case_path)
resources = create_resource_array(setup, resources_path)

# read policy files and add policies-related attributes to resource dataframe
add_policies_to_resources!(resources, setup, case_path)
resource_policies_path = joinpath(resources_path, setup["ResourcePoliciesFolder"])
validate_policy_files(resource_policies_path, setup)
add_policies_to_resources!(resources, resource_policies_path)

# read module files add module-related attributes to resource dataframe
add_modules_to_resources!(resources, setup, case_path)
add_modules_to_resources!(resources, setup, resources_path)

# add resources information to inputs dict
add_resources_to_input_data!(inputs, setup, case_path, resources)
add_resources_to_input_data!(inputs, setup, resources)

# print summary of resources
summary(resources)
Expand Down
2 changes: 1 addition & 1 deletion src/multi_stage/dual_dynamic_programming.jl
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ function write_multi_stage_outputs(stats_d::Dict, outpath::String, settings_d::D
write_multi_stage_network_expansion(outpath, multi_stage_settings_d)
end
write_multi_stage_costs(outpath, multi_stage_settings_d, inputs_dict)
write_multi_stage_stats(outpath, stats_d)
multi_stage_settings_d["Myopic"] == 0 && write_multi_stage_stats(outpath, stats_d)
write_multi_stage_settings(outpath, settings_d)

end
Expand Down
Loading

0 comments on commit cac1316

Please sign in to comment.