Output functions
collect_results
MacroEnergy.collect_results
— Functioncollect_results(system::System, model::Model, settings::NamedTuple, period_index::Int64=1, scaling::Float64=1.0)
Returns a DataFrame
with all the results after the optimization is performed.
Arguments
system::System
: The system object containing the case inputs.model::Model
: The model being optimized.settings::NamedTuple
: The settings for the system, including output configurations.period_index::Int64
: The index of the period to collect results for (default is 1).scaling::Float64
: The scaling factor for the results.
Returns
DataFrame
: A `DataFrame containing all the outputs from a system.
Example
collect_results(system, model)
198534×12 DataFrame
Row │ case_name commodity commodity_subtype zone resource_id component_id type variable segment time value
│ Missing Symbol Symbol Symbol Symbol Symbol Symbol Symbol Int64 Int64 Float64
────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
1 │ missing Biomass flow bioherb_SE SE_BECCS_Electricity_Herb SE_BECCS_Electricity_Herb_biomas… BECCSElectricity flow 1 1 0.0
2 │ missing Biomass flow bioherb_SE SE_BECCS_Electricity_Herb SE_BECCS_Electricity_Herb_biomas… BECCSElectricity flow 1 2 0.0
3 │ missing Biomass flow bioherb_SE SE_BECCS_Electricity_Herb SE_BECCS_Electricity_Herb_biomas… BECCSElectricity flow 1 3 0.0
...
get_optimal_capacity
MacroEnergy.get_optimal_capacity
— Functionget_optimal_capacity(system::System; scaling::Float64=1.0)
Get the optimal capacity values for all assets/edges in a system.
Arguments
system::System
: The system containing the assets/edges to analyzescaling::Float64
: The scaling factor for the results.
Returns
DataFrame
: A dataframe containing the optimal capacity values for all assets/edges, with missing columns removed
Example
get_optimal_capacity(system)
153×8 DataFrame
Row │ commodity commodity_subtype zone resource_id component_id type variable value
│ Symbol Symbol Symbol Symbol Symbol Symbol Symbol Float64
─────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
1 │ Electricity capacity elec_SE existing_solar_SE existing_solar_SE_edge VRE capacity 8.5022
2 │ Electricity capacity elec_NE existing_solar_NE existing_solar_NE_edge VRE capacity 0.0
3 │ Electricity capacity elec_NE existing_wind_NE existing_wind_NE_edge VRE capacity 3.6545
get_optimal_discounted_costs
MacroEnergy.get_optimal_discounted_costs
— FunctionHelper function to extract discounted costs from the optimization results and return them as a DataFrame.
get_optimal_flow
MacroEnergy.get_optimal_flow
— Functionget_optimal_flow(
system::System;
scaling::Float64=1.0,
commodity::Union{AbstractString,Vector{<:AbstractString},Nothing}=nothing,
asset_type::Union{AbstractString,Vector{<:AbstractString},Nothing}=nothing
)
Get the optimal flow values for all edges in a system.
Filtering
Results can be filtered by:
commodity
: Specific commodity type(s)asset_type
: Specific asset type(s)
Pattern Matching
Two types of pattern matching are supported:
Parameter-free matching:
"ThermalPower"
matches anyThermalPower{...}
type (i.e. no need to specify parameters inside{}
)
Wildcards using "*":
"ThermalPower*"
matchesThermalPower{Fuel}
,ThermalPowerCCS{Fuel}
, etc."CO2*"
matchesCO2
,CO2Captured
, etc.
Arguments
system::System
: The system containing the all edges to outputscaling::Float64
: The scaling factor for the results.commodity::Union{AbstractString,Vector{<:AbstractString},Nothing}
: The commodity to filter byasset_type::Union{AbstractString,Vector{<:AbstractString},Nothing}
: The asset type to filter by
Returns
DataFrame
: A dataframe containing the optimal flow values for all edges, with missing columns removed
Example
get_optimal_flow(system)
186984×11 DataFrame
Row │ commodity commodity_subtype zone resource_id component_id type variable segment time value
│ Symbol Symbol Symbol Symbol Symbol Symbol Symbol Int64 Int64 Float64
────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
1 │ Biomass flow bioherb_SE SE_BECCS_Electricity_Herb SE_BECCS_Electricity_Herb_biomas… BECCSElectricity flow 1 1 0.0
2 │ Biomass flow bioherb_SE SE_BECCS_Electricity_Herb SE_BECCS_Electricity_Herb_biomas… BECCSElectricity flow 1 2 0.0
3 │ Biomass flow bioherb_SE SE_BECCS_Electricity_Herb SE_BECCS_Electricity_Herb_biomas… BECCSElectricity flow 1 3 0.0
...
# Filter by commodity
get_optimal_flow(system, commodity="Electricity")
# Filter by commodity and asset type using parameter-free matching
get_optimal_flow(system, commodity="Electricity", asset_type="ThermalPower") # only ThermalPower{Fuel} will be returned
# Filter by commodity and asset type using wildcard matching
get_optimal_flow(system, commodity="Electricity", asset_type="ThermalPower*") # all types starting with ThermalPower (e.g., ThermalPower{Fuel}, ThermalPowerCCS{Fuel}) will be returned)
get_optimal_flow(asset::AbstractAsset, scaling::Float64=1.0)
Get the optimal flow values for all edges in an asset.
Arguments
asset::AbstractAsset
: The asset containing the edges to analyzescaling::Float64
: The scaling factor for the results.
Returns
DataFrame
: A dataframe containing the optimal flow values for all edges, with missing columns removed
Example
asset = get_asset_by_id(system, :elec_SE)
get_optimal_flow(asset)
get_optimal_flow(edge::AbstractEdge, scaling::Float64=1.0)
Get the optimal flow values for an edge.
Arguments
edge::AbstractEdge
: The edge to analyzescaling::Float64
: The scaling factor for the results.
Returns
DataFrame
: A dataframe containing the optimal flow values for the edge, with missing columns removed
Example
asset = get_asset_by_id(system, :elec_SE)
elec_edge = asset.elec_edge
get_optimal_flow(elec_edge)
get_optimal_new_capacity
MacroEnergy.get_optimal_new_capacity
— Functionget_optimal_new_capacity(system::System; scaling::Float64=1.0)
Get the optimal new capacity values for all assets/edges in a system.
Arguments
system::System
: The system containing the assets/edges to analyzescaling::Float64
: The scaling factor for the results.
Returns
DataFrame
: A dataframe containing the optimal new capacity values for all assets/edges, with missing columns removed
Example
get_optimal_new_capacity(system)
153×8 DataFrame
Row │ commodity commodity_subtype zone resource_id component_id type variable value
│ Symbol Symbol Symbol Symbol Symbol Symbol Symbol Float64
─────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
1 │ Biomass capacity bioherb_SE SE_BECCS_Electricity_Herb SE_BECCS_Electricity_Herb_biomas… BECCSElectricity new_capacity 0.0
2 │ Biomass capacity bioherb_MIDAT MIDAT_BECCS_Electricity_Herb MIDAT_BECCS_Electricity_Herb_bio… BECCSElectricity new_capacity 0.0
3 │ Biomass capacity bioherb_NE NE_BECCS_Electricity_Herb NE_BECCS_Electricity_Herb_biomas… BECCSElectricity new_capacity 0.0
get_optimal_retired_capacity
MacroEnergy.get_optimal_retired_capacity
— Functionget_optimal_retired_capacity(system::System; scaling::Float64=1.0)
Get the optimal retired capacity values for all assets/edges in a system.
Arguments
system::System
: The system containing the assets/edges to analyzescaling::Float64
: The scaling factor for the results.
Returns
DataFrame
: A dataframe containing the optimal retired capacity values for all assets/edges, with missing columns removed
Example
get_optimal_retired_capacity(system)
153×8 DataFrame
Row │ commodity commodity_subtype zone resource_id component_id type variable value
│ Symbol Symbol Symbol Symbol Symbol Symbol Symbol Float64
─────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
1 │ Biomass capacity bioherb_SE SE_BECCS_Electricity_Herb SE_BECCS_Electricity_Herb_biomas… BECCSElectricity retired_capacity 0.0
2 │ Biomass capacity bioherb_MIDAT MIDAT_BECCS_Electricity_Herb MIDAT_BECCS_Electricity_Herb_bio… BECCSElectricity retired_capacity 0.0
3 │ Biomass capacity bioherb_NE NE_BECCS_Electricity_Herb NE_BECCS_Electricity_Herb_biomas… BECCSElectricity retired_capacity 0.0
write_capacity
MacroEnergy.write_capacity
— Functionwrite_capacity(
file_path::AbstractString,
system::System;
scaling::Float64=1.0,
drop_cols::Vector{AbstractString}=String[],
commodity::Union{AbstractString,Vector{AbstractString},Nothing}=nothing,
asset_type::Union{AbstractString,Vector{AbstractString},Nothing}=nothing
)
Write the optimal capacity results for all assets/edges in a system to a file. The extension of the file determines the format of the file. Capacity
, NewCapacity
, and RetiredCapacity
are first concatenated and then written to the file.
Filtering
Results can be filtered by:
commodity
: Specific commodity type(s)asset_type
: Specific asset type(s)
Pattern Matching
Two types of pattern matching are supported:
Parameter-free matching:
"ThermalPower"
matches anyThermalPower{...}
type (i.e. no need to specify parameters inside{}
)
Wildcards using "*":
"ThermalPower*"
matchesThermalPower{Fuel}
,ThermalPowerCCS{Fuel}
, etc."CO2*"
matchesCO2
,CO2Captured
, etc.
Arguments
file_path::AbstractString
: The path to the file where the results will be writtensystem::System
: The system containing the assets/edges to analyze as well as the settings for the outputscaling::Float64
: The scaling factor for the resultsdrop_cols::Vector{AbstractString}
: Columns to drop from the DataFramecommodity::Union{AbstractString,Vector{AbstractString},Nothing}
: The commodity to filter byasset_type::Union{AbstractString,Vector{AbstractString},Nothing}
: The asset type to filter by
Returns
nothing
: The function returns nothing, but writes the results to the file
Example
write_capacity("capacity.csv", system)
# Filter by commodity
write_capacity("capacity.csv", system, commodity="Electricity")
# Filter by commodity and asset type using parameter-free matching
write_capacity("capacity.csv", system, asset_type="ThermalPower")
# Filter by asset type using wildcard matching
write_capacity("capacity.csv", system, asset_type="ThermalPower*")
# Filter by commodity and asset type
write_capacity("capacity.csv", system, commodity="Electricity", asset_type=["ThermalPower", "Battery"])
write_costs
MacroEnergy.write_costs
— Functionwrite_costs(
file_path::AbstractString,
system::System,
model::Union{Model,NamedTuple};
scaling::Float64=1.0,
drop_cols::Vector{<:AbstractString}=String[]
)
Write the optimal costs for the system to a file. The extension of the file determines the format of the file.
Arguments
file_path::AbstractString
: The path to the file where the results will be writtensystem::System
: The system containing the assets/edges to analyze as well as the settings for the outputmodel::Union{Model,NamedTuple}
: The optimal model after the optimizationscaling::Float64
: The scaling factor for the resultsdrop_cols::Vector{<:AbstractString}
: Columns to drop from the DataFrame
Returns
nothing
: The function returns nothing, but writes the results to the file
write_flow
MacroEnergy.write_flow
— Functionwrite_flow(
file_path::AbstractString,
system::System;
scaling::Float64=1.0,
drop_cols::Vector{<:AbstractString}=String[],
commodity::Union{AbstractString,Vector{<:AbstractString},Nothing}=nothing,
asset_type::Union{AbstractString,Vector{<:AbstractString},Nothing}=nothing
)
Write the optimal flow results for the system to a file. The extension of the file determines the format of the file.
Filtering
Results can be filtered by:
commodity
: Specific commodity type(s)asset_type
: Specific asset type(s)
Pattern Matching
Two types of pattern matching are supported:
Parameter-free matching:
"ThermalPower"
matches anyThermalPower{...}
type (i.e. no need to specify parameters inside{}
)
Wildcards using "*":
"ThermalPower*"
matchesThermalPower{Fuel}
,ThermalPowerCCS{Fuel}
, etc."CO2*"
matchesCO2
,CO2Captured
, etc.
Arguments
file_path::AbstractString
: The path to the file where the results will be writtensystem::System
: The system containing the edges to analyze as well as the settings for the outputscaling::Float64
: The scaling factor for the resultsdrop_cols::Vector{<:AbstractString}
: Columns to drop from the DataFramecommodity::Union{AbstractString,Vector{<:AbstractString},Nothing}
: The commodity to filter byasset_type::Union{AbstractString,Vector{<:AbstractString},Nothing}
: The asset type to filter by
Returns
nothing
: The function returns nothing, but writes the results to the file
Example
write_flow("flow.csv", system)
# Filter by commodity
write_flow("flow.csv", system, commodity="Electricity")
# Filter by commodity and asset type using parameter-free matching
write_flow("flow.csv", system, commodity="Electricity", asset_type="ThermalPower")
# Filter by commodity and asset type using wildcard matching
write_flow("flow.csv", system, commodity="Electricity", asset_type="ThermalPower*")
write_dataframe
MacroEnergy.write_dataframe
— Functionwrite_dataframe(
file_path::AbstractString,
df::AbstractDataFrame,
drop_cols::Vector{<:AbstractString}=String[]
)
Write a DataFrame to a file in the appropriate format based on file extension. Supported formats: .csv, .csv.gz, .parquet
Arguments
file_path::AbstractString
: Path where to save the filedf::AbstractDataFrame
: DataFrame to writedrop_cols::Vector{<:AbstractString}
: Columns to drop from the DataFrame
write_results
MacroEnergy.write_results
— Functionwrite_results(file_path::AbstractString, system::System, model::Model, settings::NamedTuple, period_index::Int64=1)
Collects all the results as a DataFrame
and then writes them to disk after the optimization is performed.
Arguments
file_path::AbstractString
: full path of the file to export.system::System
: The system object containing the case inputs.model::Model
: The model being optimized.period_index::Int64
: The index of the period to collect results for (default is 1).settings::NamedTuple
: The settings for the system, including output configurations.
Returns
Example
write_results(case_path * "results.csv", system, model) # CSV
write_results(case_path * "results.csv.gz", system, model) # GZIP
write_results(case_path * "results.parquet", system, model) # PARQUET
MacroEnergy.write_outputs
MacroEnergy.write_outputs
— FunctionWrite results when using Monolithic as solution algorithm.
Write results when using Myopic as solution algorithm.
Write results when using Benders as solution algorithm.