Skip to content

Commit

Permalink
Clean resources.jl and load_resources_data.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
lbonaldo committed Dec 12, 2023
1 parent 561f8ce commit 60aabd2
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 155 deletions.
2 changes: 0 additions & 2 deletions src/GenX.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ const ModelScalingFactor = 1e+3

# abstract type for all resources
abstract type AbstractResource end
# Name of the type of resources available in the model
const resources_type = (:ELECTROLYZER, :FLEX, :HYDRO, :STOR, :THERM, :VRE, :MUST_RUN)

# thanks, ChatGPT
function include_all_in_folder(folder)
Expand Down
80 changes: 43 additions & 37 deletions src/load_inputs/load_resources_data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,21 @@ function _get_resource_df(path::AbstractString, scale_factor::Float64=1.0)
return resource_in
end

function _get_resource_indices(resources_in::DataFrame, offset::Int64)
# return array of indices of resources
range = (1,nrow(resources_in)) .+ offset
return UnitRange{Int64}(range...)
end

function _add_indices_to_resource_df!(df::DataFrame, indices::AbstractVector)
df[!, :id] = indices
return nothing
end

function dataframerow_to_tuple(dfr::DataFrameRow)
return NamedTuple(pairs(dfr))
end

function _get_resource_array(resource_in::DataFrame, Resource)
# convert dataframe to array of resources of correct type
resources::Vector{Resource} = Resource.(dataframerow_to_tuple.(eachrow(resource_in)))
Expand Down Expand Up @@ -117,43 +132,6 @@ function _get_all_resources(resources_folder::AbstractString, resources_info::Na
return reduce(vcat, resources)
end

function _add_indices_to_resource_df!(df::DataFrame, indices::AbstractVector)
df[!, :id] = indices
return nothing
end

function _get_resource_indices(resources_in::DataFrame, offset::Int64)
# return array of indices of resources
range = (1,nrow(resources_in)) .+ offset
return UnitRange{Int64}(range...)
end

function load_resources_data!(setup::Dict, case_path::AbstractString, input_data::Dict)
if isfile(joinpath(case_path, "Generators_data.csv"))
Base.depwarn(
"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.",
:load_resources_data!, force=true)
@info "Exiting GenX..."
exit(-1)
# load_generators_data!(setup, case_path, input_data)
# translate_generators_data!(setup, input_data)
else
# Scale factor for energy and currency units
scale_factor = setup["ParameterScale"] == 1 ? ModelScalingFactor : 1

# get path to resources data
resources_folder = setup["ResourcesPath"]
resources_folder = joinpath(case_path,resources_folder)

resources = load_scaled_resources_data(resources_folder, scale_factor)

add_resources_to_input_data!(setup, input_data, resources)

return nothing
end
end

function load_scaled_resources_data(resources_folder::AbstractString, scale_factor::Float64=1.0)
# get type, filename and resource-key for each type of resources
resources_info = _get_resource_info()
Expand Down Expand Up @@ -301,6 +279,34 @@ function add_resources_to_input_data!(setup::Dict, input_data::Dict, resources::
return nothing
end

function load_resources_data!(setup::Dict, case_path::AbstractString, input_data::Dict)
if isfile(joinpath(case_path, "Generators_data.csv"))
Base.depwarn(
"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.",
:load_resources_data!, force=true)
@info "Exiting GenX..."
exit(-1)
# load_generators_data!(setup, case_path, input_data)
# translate_generators_data!(setup, input_data)
else
# Scale factor for energy and currency units
scale_factor = setup["ParameterScale"] == 1 ? ModelScalingFactor : 1

# get path to resources data
resources_folder = setup["ResourcesPath"]
resources_folder = joinpath(case_path,resources_folder)

# load resources data and scale it if necessary
resources = load_scaled_resources_data(resources_folder, scale_factor)

# add resources to input_data dict
add_resources_to_input_data!(setup, input_data, resources)

return nothing
end
end

function translate_generators_data!(setup::Dict, inputs_gen::Dict)
end

Expand Down
Loading

0 comments on commit 60aabd2

Please sign in to comment.