Planning mode¶
Tutorial 2: Planning Single-Node Example¶
This example analyzes the planning mode of the energy system in a hypothetical region named Utopia.
In this example, the Reference Energy System starts from an Oil Extraction technology which supplies raw oil to the refineries (Oil Refinery technology) where the oil fuel is processed to be sent to the Oil Power Plants or Diesel Pipelines. The Oil Power Plants alongside the Hydro Power Plants produce electricity which later is sent to the Electricity Transmission and Distribution technology to be delivered to the final demand sector. The Diesel Pipelines also take the processed oil fuel and transport it to the final demand sector.
There are four technologies which are the representatives of the demand side of the energy system including Electric Vehicles, Internal Combustion Engine Vehicles, Household Electricity Demand and Other Electicity Demand.
The time horizon of the model is set from 2020 to 2030 with weekdays/weekends and days/nights temporal resolution.
1. Building the excel-based structural input (set) files:¶
Following the single-node approach of the Hypatia model, two set files including “global.xlsx” and “reg1.xlsx” must be provided. The global technologies and carriers in this case are identical to the regional ones as Utopia is modeled only as one region and no spatial resolution is considered. However, in a multi-node model application, the global technologies and carriers are the the aggregated list of the technologies and carriers involved in the Reference Energy System of all the locations.
Therefore, in single node approach, the "Technologies" and "Carriers" tables are completely identical in "reg1.xlsx" and "global.xlsx" files.
Note: The name of the excel files must be determined as above. It is not possible to include arbitrary file names
1.1“global” excel file:¶
As it is described in the building model documentation, the structural input excels consist of several tables for different sets of the model. The first table in the global file is “Regions” including the locations of the study and the name of each location. In this case only one location as whole utopia must be considered.
The second table is “Technologies_glob” which includes all the technologies within Utopia, their names, categories, capacity and activity units. Please note that the technology categories must be chosen from Supply, Conversion, Conversion_plus, Transmission, and Storage categories and can not be anything different from the mentioned names.
After global technologies, global carriers must be indicated in the table “Carriers_glob”. In this table, all the carriers with their types and names must be included as below. The allowed carrier type are Resource, Intermediate, and Demand.
The next table to be specified is the “Emissions” table. In this table, the user must indicate all the emissions represented in the model with their names and units of measure. Currently, Hypatia allows to conisder only one type of emission in terms of CO2 or CO2-equivalent.
Ultimately, the time horizon and temporal resolution of the model must be determined by the “Years” and “Timesteps” tables respectively.In this case, 11 modelling years have been considered starting from 2020 to 2030 without considering any past years for the callibration of the model and fixing the total installed capacities or production of the technologies.
In this case, the temporal resolution considered within each year is a hierarchy of weekend and weekdays with a day/night time bracket for each day type. Therefore, there are four time slices within each year including Weekdays-days, Weekdays-nights, Weekends-days and Weekends-nights. The lengths of the time slices as a fraction of the length of the whole year are different from each other. It is assumed that from 365 days within each year, 261 days are weekdays and 104 days are weekend days, therefore, as an example the Timeslice_fraction of weekdays-days is 261/365 * 0.5 = 0.35534247.
1.2 “reg1” excel file:¶
As it is mentioed above, the “reg1.xlsx” file consists of regional technologies, carriers (which are similar to global ones in this specific case), and the interconnections among them based on the Reference Energy System. The first table of regional files is named “Technologies” where the user must indicate the technologies within the specific location (Utopia) as shown below:
The second table is named “Carriers” which is dedicated to determining the carriers within the specific location (Utopia).
The connections among the technologies and carriers within the Reference Energy System are determined by “Carrier-input” and “Carrier-output” tables. In the former, the input carriers of the technologies, and in the latter, the output carriers of technologies are represented. Please note that the “Supply” technologies and “Demand” technologies should not be included in the “Carrier-input" and “Carrier-output” tables respectively because the “Supply” category of technology just provide energy carrier to the system without any conversion process and the “Demand” category just sinks and removes the demand energy carriers from the system.
Carrier Input
Carrier Output
There are a few important things to note about the structural input files:
Formulas tab of the ribbon > Name Manager > Edit > Name
2. Initializing the Hypatia model by reading the excel-based set files¶
After specifying all the sets of the model, it is time to initialize the Hypatia model and read the structural input files.
Importing the hypatia model¶
from hypatia import Model
Intializing the hypatia model by passing the optimization mode and the path of the structural input files (sets of the model)¶
utopia = Model(
path = 'sets',
mode = 'Planning'
)
3. Creating the excel-based parameter files¶
Now the user can create the parameter files with their default values through running the following commands
After running this command line, we are going to open the created parameter files and fill them with the model data.
#utopia.create_data_excels(
# path = r'parameters'
#)
In this case, as we have a single-node approach, it is expected to see only one file named as “parameters_reg1.xlsx” in the given path.
4. Filling the parameter files with the input data¶
Now it is time to insert the input data in the parameter file.
In this case study, we are focusing on the planning mode of the energy system. Therefore, the following sheets can be found in the excel files:
5. Reading the input data¶
After filling out the parameter files, it is time to ask the model to read the input data following the below command line.
utopia.read_input_data(
path = r'parameters'
)
6. Running the model¶
Now we can run the model by giving the preferred solver, verbosity and the force_rewrite parameter which avoids overwriting the output results when it is equal to False and allows to overwrite them by taking a backup from the previous results when it is equal to True.
utopia.run(
solver = 'scipy',
verbosity = True,
force_rewrite = False
)
=============================================================================== CVXPY v1.1.17 =============================================================================== (CVXPY) Jan 30 03:01:44 PM: Your problem has 506 variables, 90 constraints, and 0 parameters. (CVXPY) Jan 30 03:01:44 PM: It is compliant with the following grammars: DCP, DQCP (CVXPY) Jan 30 03:01:44 PM: (If you need to solve this problem multiple times, but with different data, consider using parameters.) (CVXPY) Jan 30 03:01:44 PM: CVXPY will first compile your problem; then, it will invoke a numerical solver to obtain a solution. ------------------------------------------------------------------------------- Compilation ------------------------------------------------------------------------------- (CVXPY) Jan 30 03:01:44 PM: Compiling problem (target solver=SCIPY). (CVXPY) Jan 30 03:01:44 PM: Reduction chain: Dcp2Cone -> CvxAttr2Constr -> ConeMatrixStuffing -> SCIPY (CVXPY) Jan 30 03:01:44 PM: Applying reduction Dcp2Cone (CVXPY) Jan 30 03:01:44 PM: Applying reduction CvxAttr2Constr (CVXPY) Jan 30 03:01:44 PM: Applying reduction ConeMatrixStuffing (CVXPY) Jan 30 03:01:44 PM: Applying reduction SCIPY (CVXPY) Jan 30 03:01:44 PM: Finished problem compilation (took 2.337e-01 seconds). ------------------------------------------------------------------------------- Numerical solver ------------------------------------------------------------------------------- (CVXPY) Jan 30 03:01:44 PM: Invoking solver SCIPY to obtain a solution. Solver terminated with message: Optimization terminated successfully. ------------------------------------------------------------------------------- Summary ------------------------------------------------------------------------------- (CVXPY) Jan 30 03:01:44 PM: Problem status: optimal (CVXPY) Jan 30 03:01:44 PM: Optimal value: 4.432e+07 (CVXPY) Jan 30 03:01:44 PM: Compilation took 2.337e-01 seconds (CVXPY) Jan 30 03:01:44 PM: Solver (including time spent in interface) took 4.778e-03 seconds
/opt/anaconda3/envs/hypatia/lib/python3.8/site-packages/cvxpy/reductions/solvers/conic_solvers/scipy_conif.py:154: UserWarning: It is best to specify the 'method' parameter within scipy_options. The main advantage of this solver, is its ability to use the HiGHS LP solvers via scipy.optimize.linprog() which require a SciPy version >= 1.6.1 . The default method 'highs' will be used in this case.
7. Exporting the raw results to csv files¶
There is the possibility to export the raw results into the csv files by passing the arbitary folder path and force_rewrite parameter which avoids to overwrite the results when it is equal to False.
utopia.to_csv(path='results')
8. Visualizing the results¶
After solving the model, we can visualize the raw results by importing the plotting tool of the Hypatia model but before that, we need to ask the model to create the configuration excel file for indicating the desired information on technologies, fuels and regions.
#utopia.create_config_file(path=r'config.xlsx')
from hypatia import Plotter
Now, it is the time to initiallize the plotter class by passing the model's name, the created config file for the plots and the hourly resolution boolean parameter. The latter is True when the model has a hourly stepwise resolution and False when the timesteps are not in a hourly basis.
results = Plotter(utopia,config=r'config.xlsx',hourly_resolution=False)
# Sketching the new installed capacity of different technologies for given tech group
results.plot_new_capacity(
path = r'plots/newcapacity.html',
tech_group = 'Power Generation',
regions = ['reg1'],
cummulative=False,
)
# Sketching the total installed capacity of different technologies for given tech group (considering the decommissioned capacities)
results.plot_total_capacity(
path = r'plots/totalcapacity.html',
tech_group = 'Power Generation',
regions = ['reg1'],
kind="bar",
decom_cap=True,
)
# Sketching the annual production of each technology
results.plot_prod_by_tech(
tech_group ='Power Generation',
regions = ['reg1'],
path = r'plots/productionbytech.html',
)
# Sketching the annual production of each technology
results.plot_prod_by_tech(
tech_group ='Refinery',
regions = ['reg1'],
path = r'plots/productionbytech_oil.html',
)
# Skething the prduction and consumption share of each technology including the imports and exports
results.plot_fuel_prod_cons(
path = r'plots/prod_con_share.html',
years = [2030],
fuel_group = 'Electricity',
regions = ['reg1'],
trade=False,
)
# Skething the prduction and consumption share of each technology including the imports and exports
results.plot_fuel_prod_cons(
path = r'plots/prod_con_share_oil.html',
years = [2030],
fuel_group = 'Fuel',
regions = ['reg1'],
trade=False,
)
# Sketching the annual CO2-equivalent emissions
results.plot_emissions(
path = r'plots/emissions.html',
regions = ['reg1'],
tech_group = 'Resource Extraction',
)