Skip to content

Commit 01fcd5a

Browse files
committed
integration of typeday and tsam
- typeday code is implemented according to the code of Daniel Zinsmeister from tum-ens#282 - the time series aggregation module from Kotzur, L., Markewitz, P., Robinius, M., & Stolten, D. (2018) is integrated into the urbs model primarily within the typeperiod module
1 parent 4fe9231 commit 01fcd5a

File tree

14 files changed

+300
-132
lines changed

14 files changed

+300
-132
lines changed

run_transdist.py

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import matplotlib.pyplot as plt
1111
from urbs.runfunctions import *
1212

13+
1314
input_files = 'Transmission_Level.xlsx' # for single year file name, for intertemporal folder name
1415
input_dir = 'Input'
1516
input_path = os.path.join(input_dir, input_files)
@@ -39,34 +40,39 @@
3940
solver = 'gurobi'
4041

4142
# simulation timesteps
42-
(offset, length) = (0,120) # time step selection
43+
(offset, length) = (0,336) # time step selection
4344
timesteps = range(offset, offset+length+1)
4445
dt = 1 # length of each time step (unit: hours)
4546

47+
# input data for tsam method
48+
noTypicalPeriods = 4
49+
hoursPerPeriod = 168
50+
4651
# detailed reporting commodity/sites
4752
report_tuples = [
4853
(2021, 'Bayern', 'Elec'),
4954
(2021, 'Hessen', 'Elec'),
50-
(2021, 'node0_A1_Bayern', 'Elec'),
51-
(2021, 'node1_A1_Bayern', 'Elec'),
52-
(2021, 'node2_A1_Bayern', 'Elec'),
53-
(2021, 'node3_A1_Bayern', 'Elec'),
54-
(2021, 'node4_A1_Bayern', 'Elec'),
55-
(2021, 'node5_A1_Bayern', 'Elec'),
56-
(2021, 'node6_A1_Bayern', 'Elec'),
57-
(2021, 'node7_A1_Bayern', 'Elec'),
58-
(2021, 'node8_A1_Bayern', 'Elec'),
59-
(2021, 'node9_A1_Bayern', 'Elec'),
60-
(2021, 'node0_A1_Bayern', 'Elec-Reactive'),
61-
(2021, 'node1_A1_Bayern', 'Elec-Reactive'),
62-
(2021, 'node2_A1_Bayern', 'Elec-Reactive'),
63-
(2021, 'node3_A1_Bayern', 'Elec-Reactive'),
64-
(2021, 'node4_A1_Bayern', 'Elec-Reactive'),
65-
(2021, 'node5_A1_Bayern', 'Elec-Reactive'),
66-
(2021, 'node6_A1_Bayern', 'Elec-Reactive'),
67-
(2021, 'node7_A1_Bayern', 'Elec-Reactive'),
68-
(2021, 'node8_A1_Bayern', 'Elec-Reactive'),
69-
(2021, 'node9_A1_Bayern', 'Elec-Reactive')
55+
# (2021, 'node0_A1_Bayern', 'Elec'),
56+
# (2021, 'node1_A1_Bayern', 'Elec'),
57+
# (2021, 'node2_A1_Bayern', 'Elec'),
58+
# (2021, 'node3_A1_Bayern', 'Elec'),
59+
# (2021, 'node4_A1_Bayern', 'Elec'),
60+
# (2021, 'node5_A1_Bayern', 'Elec'),
61+
# (2021, 'node6_A1_Bayern', 'Elec'),
62+
# (2021, 'node7_A1_Bayern', 'Elec'),
63+
# (2021, 'node8_A1_Bayern', 'Elec'),
64+
# (2021, 'node9_A1_Bayern', 'Elec'),
65+
# (2021, 'node0_A1_Bayern', 'Elec-Reactive'),
66+
# (2021, 'node1_A1_Bayern', 'Elec-Reactive'),
67+
# (2021, 'node2_A1_Bayern', 'Elec-Reactive'),
68+
# (2021, 'node3_A1_Bayern', 'Elec-Reactive'),
69+
# (2021, 'node4_A1_Bayern', 'Elec-Reactive'),
70+
# (2021, 'node5_A1_Bayern', 'Elec-Reactive'),
71+
# (2021, 'node6_A1_Bayern', 'Elec-Reactive'),
72+
# (2021, 'node7_A1_Bayern', 'Elec-Reactive'),
73+
# (2021, 'node8_A1_Bayern', 'Elec-Reactive'),
74+
# (2021, 'node9_A1_Bayern', 'Elec-Reactive')
75+
7076
# ('Baden-Württemberg', 'Elec'),
7177
# ('Bavaria', 'Elec'),
7278
# ('Berlin', 'Elec'),
@@ -92,9 +98,10 @@
9298

9399
# optional: define names for sites in report_tuples
94100
report_sites_name = {
95-
('Bayern','Hessen','node0_A1_Bayern','node1_A1_Bayern','node2_A1_Bayern',
96-
'node3_A1_Bayern','node4_A1_Bayern','node5_A1_Bayern','node6_A1_Bayern',
97-
'node7_A1_Bayern','node8_A1_Bayern','node9_A1_Bayern'):'Germany'
101+
('Bayern','Hessen'):'Germany'#
102+
#,'node0_A1_Bayern','node1_A1_Bayern','node2_A1_Bayern',
103+
#'node3_A1_Bayern','node4_A1_Bayern','node5_A1_Bayern','node6_A1_Bayern',
104+
#'node7_A1_Bayern','node8_A1_Bayern','node9_A1_Bayern'):'Germany'
98105
# ('Baden-Württemberg', 'Bavaria', 'Berlin',
99106
# 'Brandenburg', 'Bremen', 'Hamburg', 'Hesse', 'Lower Saxony',
100107
# 'Mecklenburg-Vorpommern', 'North Rhine-Westphalia',
@@ -165,5 +172,7 @@
165172
plot_sites_name=plot_sites_name,
166173
plot_periods=plot_periods,
167174
report_tuples=report_tuples,
168-
report_sites_name=report_sites_name)
175+
report_sites_name=report_sites_name,
176+
noTypicalPeriods=noTypicalPeriods,
177+
hoursPerPeriod=hoursPerPeriod)
169178

urbs/features/BuySellPrice.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import math
22
import pyomo.core as pyomo
33
from .modelhelper import commodity_subset
4+
from .typeperiod import get_stf
45

56

67
def add_buy_sell_price(m):
@@ -9,10 +10,12 @@ def add_buy_sell_price(m):
910
m.com_sell = pyomo.Set(
1011
within=m.com,
1112
initialize=commodity_subset(m.com_tuples, 'Sell'),
13+
ordered=False,
1214
doc='Commodities that can be sold')
1315
m.com_buy = pyomo.Set(
1416
within=m.com,
1517
initialize=commodity_subset(m.com_tuples, 'Buy'),
18+
ordered=False,
1619
doc='Commodities that can be purchased')
1720

1821
# Variables
@@ -73,7 +76,7 @@ def res_sell_total_rule(m, stf, sit, com, com_type):
7376
total_consumption = 0
7477
for tm in m.tm:
7578
total_consumption += (
76-
m.e_co_sell[tm, stf, sit, com, com_type] * m.typeday['weight_typeday'][(stf,tm)])
79+
m.e_co_sell[tm, stf, sit, com, com_type] * m.typeperiod['weight_typeperiod'][(stf,tm)])
7780
total_consumption *= m.weight
7881
return (total_consumption <=
7982
m.commodity_dict['max'][(stf, sit, com, com_type)])
@@ -99,7 +102,7 @@ def res_buy_total_rule(m, stf, sit, com, com_type):
99102
total_consumption = 0
100103
for tm in m.tm:
101104
total_consumption += (
102-
m.e_co_buy[tm, stf, sit, com, com_type] * m.typeday['weight_typeday'][(stf,tm)])
105+
m.e_co_buy[tm, stf, sit, com, com_type] * m.typeperiod['weight_typeperiod'][(stf,tm)])
103106
total_consumption *= m.weight
104107
return (total_consumption <=
105108
m.commodity_dict['max'][(stf, sit, com, com_type)])
@@ -130,7 +133,7 @@ def search_sell_buy_tuple(m, stf, sit_in, pro_in, coin):
130133
Returns:
131134
a process
132135
"""
133-
pro_output_tuples = [x for x in list(m.pro_output_tuples.value) if x[1] == sit_in] #todo: typeday fragen
136+
pro_output_tuples = [x for x in list(m.pro_output_tuples.value) if x[1] == sit_in]
134137
pro_input_tuples = [x for x in list(m.pro_input_tuples.value) if x[1] == sit_in]
135138
# search the output commodities for the "buy" process
136139
# buy_out = (stf, site, output_commodity)
@@ -174,15 +177,15 @@ def revenue_costs(m):
174177
try:
175178
return -sum(
176179
m.e_co_sell[(tm,) + c] *
177-
m.buy_sell_price_dict[c[2]][(c[0], tm)] * m.weight * m.typeday['weight_typeday'][(m.stf[1],tm)] *
180+
m.buy_sell_price_dict[c[2]][(c[0], tm)] * m.weight * m.typeperiod['weight_typeperiod'][(get_stf(m),tm)] *
178181
m.commodity_dict['price'][c] *
179182
m.commodity_dict['cost_factor'][c]
180183
for tm in m.tm
181184
for c in sell_tuples)
182185
except KeyError:
183186
return -sum(
184187
m.e_co_sell[(tm,) + c] *
185-
m.buy_sell_price_dict[c[2], ][(c[0], tm)] * m.weight * m.typeday['weight_typeday'][(m.stf[1],tm)] *
188+
m.buy_sell_price_dict[c[2], ][(c[0], tm)] * m.weight * m.typeperiod['weight_typeperiod'][(get_stf(m),tm)] *
186189
m.commodity_dict['price'][c] *
187190
m.commodity_dict['cost_factor'][c]
188191
for tm in m.tm
@@ -194,15 +197,15 @@ def purchase_costs(m):
194197
try:
195198
return sum(
196199
m.e_co_buy[(tm,) + c] *
197-
m.buy_sell_price_dict[c[2]][(c[0], tm)] * m.weight * m.typeday['weight_typeday'][(m.stf[1],tm)] *
200+
m.buy_sell_price_dict[c[2]][(c[0], tm)] * m.weight * m.typeperiod['weight_typeperiod'][(get_stf(m),tm)] *
198201
m.commodity_dict['price'][c] *
199202
m.commodity_dict['cost_factor'][c]
200203
for tm in m.tm
201204
for c in buy_tuples)
202205
except KeyError:
203206
return sum(
204207
m.e_co_buy[(tm,) + c] *
205-
m.buy_sell_price_dict[c[2], ][(c[0], tm)] * m.weight * m.typeday['weight_typeday'][(m.stf[1],tm)] *
208+
m.buy_sell_price_dict[c[2], ][(c[0], tm)] * m.weight * m.typeperiod['weight_typeperiod'][(get_stf(m),tm)] *
206209
m.commodity_dict['price'][c] *
207210
m.commodity_dict['cost_factor'][c]
208211
for tm in m.tm

urbs/features/TypeDay.py

Lines changed: 0 additions & 31 deletions
This file was deleted.

urbs/features/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,5 @@
1313
from .BuySellPrice import add_buy_sell_price, bsp_surplus, revenue_costs, \
1414
purchase_costs
1515
from .AdvancedProcesses import add_advanced_processes
16-
from .TypeDay import add_typeday
17-
18-
#todo: muss ich hier trandisthelper auch ergänzen?
16+
from .typeperiod import *
17+
from .transdisthelper import *

urbs/features/modelhelper.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ def op_pro_tuples(pro_tuple, m):
182182
1 <= stf + m.process_dict['depreciation'][
183183
(stf, sit, pro)]):
184184
op_pro.append((sit, pro, stf, stf_later))
185-
elif ((stf_later + sorted_stf[index_helper + 1]) / 2 <= stf + m.process_dict['depreciation'][(stf, sit, pro)]
186-
and stf <= stf_later): #todo: typeday fragen
185+
elif ((stf_later + sorted_stf[index_helper+1]) / 2 <= stf + m.process_dict['depreciation'][(stf, sit, pro)]
186+
and stf <= stf_later):
187187
op_pro.append((sit, pro, stf, stf_later))
188188
else:
189189
pass
@@ -211,6 +211,6 @@ def inst_pro_tuples(m):
211211
inst_pro.append((sit, pro, stf_later))
212212
elif (stf_later + sorted_stf[index_helper + 1]) / 2 <= (min(m.stf)
213213
+ m.process_dict['lifetime'][(stf, sit, pro)]):
214-
inst_pro.append((sit, pro, stf_later)) #todo: typeday fragen
214+
inst_pro.append((sit, pro, stf_later))
215215

216216
return inst_pro

urbs/features/storage.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import math
22
import pyomo.core as pyomo
3+
from .typeperiod import get_stf
34

45

56
def add_storage(m):
@@ -10,6 +11,7 @@ def add_storage(m):
1011
indexlist.add(tuple(key)[2])
1112
m.sto = pyomo.Set(
1213
initialize=indexlist,
14+
ordered=False,
1315
doc='Set of storage technologies')
1416

1517
# storage tuples
@@ -331,11 +333,11 @@ def storage_cost(m, cost_type):
331333
m.storage_dict['cost_factor'][s]
332334
for s in m.sto_tuples)
333335
elif cost_type == 'Variable':
334-
return sum(m.e_sto_con[(tm,) + s] * m.weight * m.typeday['weight_typeday'][(m.stf[1],tm)] *
336+
return sum(m.e_sto_con[(tm,) + s] * m.weight * m.typeperiod['weight_typeperiod'][(get_stf(m),tm)] *
335337
m.storage_dict['var-cost-c'][s] *
336338
m.storage_dict['cost_factor'][s] +
337339
(m.e_sto_in[(tm,) + s] + m.e_sto_out[(tm,) + s]) *
338-
m.weight * m.typeday['weight_typeday'][(m.stf[1],tm)] * m.storage_dict['var-cost-p'][s] *
340+
m.weight * m.typeperiod['weight_typeperiod'][(get_stf(m),tm)] * m.storage_dict['var-cost-p'][s] *
339341
m.storage_dict['cost_factor'][s]
340342
for tm in m.tm
341343
for s in m.sto_tuples)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from .identify import *
1+
from urbs.identify import *
22
import copy
33
import math
44

urbs/features/transmission.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import math
2+
from .typeperiod import get_stf
23
import pyomo.core as pyomo
34

5+
46
def e_tra_domain_rule1(m, tm, stf, sin, sout, tra, com):
57
# assigning e_tra_in and e_tra_out variable domains for transport and DCPF
68
if (stf, sin, sout, tra, com) in m.tra_tuples_dc:
@@ -44,6 +46,7 @@ def add_transmission(m):
4446
indexlist.add(tuple(key)[3])
4547
m.tra = pyomo.Set(
4648
initialize=indexlist,
49+
ordered=False,
4750
doc='Set of transmission technologies')
4851

4952
# transmission tuples
@@ -144,6 +147,7 @@ def add_transmission_dc(m):
144147
indexlist.add(tuple(key)[3])
145148
m.tra = pyomo.Set(
146149
initialize=indexlist,
150+
ordered=False,
147151
doc='Set of transmission technologies')
148152

149153
# Transport and DCPF transmission tuples
@@ -301,6 +305,7 @@ def add_transmission_ac(m):
301305
indexlist.add(tuple(key)[3])
302306
m.tra = pyomo.Set(
303307
initialize=indexlist,
308+
ordered=False,
304309
doc='Set of transmission technologies')
305310

306311
# Transport and DCPF transmission tuples
@@ -621,29 +626,29 @@ def transmission_cost(m, cost_type):
621626
for t in m.tra_tuples)
622627
elif cost_type == 'Variable':
623628
if m.mode['dcpf']:
624-
return sum(m.e_tra_in[(tm,) + t] * m.weight * m.typeday['weight_typeday'][(m.stf[1],tm)] *
629+
return sum(m.e_tra_in[(tm,) + t] * m.weight * m.typeperiod['weight_typeperiod'][(get_stf(m),tm)] *
625630
m.transmission_dict['var-cost'][t] *
626631
m.transmission_dict['cost_factor'][t]
627632
for tm in m.tm
628633
for t in m.tra_tuples_tp) + \
629-
sum(m.e_tra_abs[(tm,) + t] * m.weight * m.typeday['weight_typeday'][(m.stf[1],tm)] *
634+
sum(m.e_tra_abs[(tm,) + t] * m.weight * m.typeperiod['weight_typeperiod'][(get_stf(m),tm)] *
630635
m.transmission_dict['var-cost'][t] *
631636
m.transmission_dict['cost_factor'][t]
632637
for tm in m.tm
633638
for t in m.tra_tuples_dc)
634639
if m.mode['acpf']:
635-
return sum(m.e_tra_in[(tm,) + t] * m.weight * m.typeday['weight_typeday'][(m.stf[1],tm)] *
640+
return sum(m.e_tra_in[(tm,) + t] * m.weight * m.typeperiod['weight_typeperiod'][(get_stf(m),tm)] *
636641
m.transmission_dict['var-cost'][t] *
637642
m.transmission_dict['cost_factor'][t]
638643
for tm in m.tm
639644
for t in m.tra_tuples_tp) + \
640-
sum(m.e_tra_abs[(tm,) + t] * m.weight * m.typeday['weight_typeday'][(m.stf[1],tm)] *
645+
sum(m.e_tra_abs[(tm,) + t] * m.weight * m.typeperiod['weight_typeperiod'][(get_stf(m),tm)] *
641646
m.transmission_dict['var-cost'][t] *
642647
m.transmission_dict['cost_factor'][t]
643648
for tm in m.tm
644649
for t in m.tra_tuples_ac_dc)
645650
else:
646-
return sum(m.e_tra_in[(tm,) + t] * m.weight * m.typeday['weight_typeday'][(m.stf[1],tm)] *
651+
return sum(m.e_tra_in[(tm,) + t] * m.weight * m.typeperiod['weight_typeperiod'][(get_stf(m),tm)] *
647652
m.transmission_dict['var-cost'][t] *
648653
m.transmission_dict['cost_factor'][t]
649654
for tm in m.tm

0 commit comments

Comments
 (0)