-
Notifications
You must be signed in to change notification settings - Fork 132
/
run_single_year.py
88 lines (73 loc) · 2.55 KB
/
run_single_year.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import os
import shutil
import urbs
from datetime import date
input_files = 'single_year_example.xlsx' # for single year file name, for intertemporal folder name
input_dir = 'Input'
input_path = os.path.join(input_dir, input_files)
result_name = 'single-year'
result_dir = urbs.prepare_result_directory(result_name) # name + time stamp
#get year
year = date.today().year
# copy input file to result directory
try:
shutil.copytree(input_path, os.path.join(result_dir, input_dir))
except NotADirectoryError:
shutil.copyfile(input_path, os.path.join(result_dir, input_files))
# copy run file to result directory
shutil.copy(__file__, result_dir)
# objective function
objective = 'cost' # set either 'cost' or 'CO2' as objective
# Choose Solver (cplex, glpk, gurobi, ...)
solver = 'gurobi'
# simulation timesteps
(offset, length) = (0, 20) # time step selection
timesteps = range(offset, offset+length+1)
dt = 1 # length of each time step (unit: hours)
# detailed reporting commodity/sites
report_tuples = [
(year, 'North', 'Elec'),
(year, 'Mid', 'Elec'),
(year, 'South', 'Elec'),
(year, ['North', 'Mid', 'South'], 'Elec')
]
# optional: define names for sites in report_tuples
report_sites_name = {('North', 'Mid', 'South'): 'All'}
# plotting commodities/sites
plot_tuples = [
(year, 'North', 'Elec'),
(year, 'Mid', 'Elec'),
(year, 'South', 'Elec'),
(year, ['North', 'Mid', 'South'], 'Elec')
]
# optional: define names for sites in plot_tuples
plot_sites_name = {('North', 'Mid', 'South'): 'All'}
# plotting timesteps
plot_periods = {
'all': timesteps[1:]
}
# add or change plot colors
my_colors = {
'South': (230, 200, 200),
'Mid': (200, 230, 200),
'North': (200, 200, 230)}
for country, color in my_colors.items():
urbs.COLORS[country] = color
# select scenarios to be run
scenarios = [
urbs.scenario_base,
urbs.scenario_stock_prices,
urbs.scenario_co2_limit,
urbs.scenario_co2_tax_mid,
urbs.scenario_no_dsm,
urbs.scenario_north_process_caps,
urbs.scenario_all_together
]
for scenario in scenarios:
prob = urbs.run_scenario(input_path, solver, timesteps, scenario,
result_dir, dt, objective,
plot_tuples=plot_tuples,
plot_sites_name=plot_sites_name,
plot_periods=plot_periods,
report_tuples=report_tuples,
report_sites_name=report_sites_name)