Skip to content

Commit d91c2dd

Browse files
committed
Update python packages
* Update all packages to the latest version * Changed code accordingly * Some warnings are remaining, have to be handled in the future
1 parent 7104197 commit d91c2dd

File tree

13 files changed

+153
-138
lines changed

13 files changed

+153
-138
lines changed

run_intertemporal.py

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -25,54 +25,54 @@
2525
objective = 'cost' # set either 'cost' or 'CO2' as objective
2626

2727
# Choose Solver (cplex, glpk, gurobi, ...)
28-
solver = 'glpk'
28+
solver = 'gurobi'
2929

3030
# simulation timesteps
31-
(offset, length) = (0, 8760) # time step selection
31+
(offset, length) = (0, 24) # time step selection
3232
timesteps = range(offset, offset+length+1)
3333
dt = 1 # length of each time step (unit: hours)
3434

3535
# detailed reporting commodity/sites
3636
report_tuples = [
37-
(year, 'North', 'Elec'),
38-
(year, 'Mid', 'Elec'),
39-
(year, 'South', 'Elec'),
40-
(year, ['North', 'Mid', 'South'], 'Elec'),
41-
(year+5, 'North', 'Elec'),
42-
(year+5, 'Mid', 'Elec'),
43-
(year+5, 'South', 'Elec'),
44-
(year+5, ['North', 'Mid', 'South'], 'Elec'),
45-
(year+10, 'North', 'Elec'),
46-
(year+10, 'Mid', 'Elec'),
47-
(year+10, 'South', 'Elec'),
48-
(year+10, ['North', 'Mid', 'South'], 'Elec'),
49-
(year+15, 'North', 'Elec'),
50-
(year+15, 'Mid', 'Elec'),
51-
(year+15, 'South', 'Elec'),
52-
(year+15, ['North', 'Mid', 'South'], 'Elec'),
37+
(2019, 'North', 'Elec'),
38+
(2019, 'Mid', 'Elec'),
39+
(2019, 'South', 'Elec'),
40+
(2019, ['North', 'Mid', 'South'], 'Elec'),
41+
(2024, 'North', 'Elec'),
42+
(2024, 'Mid', 'Elec'),
43+
(2024, 'South', 'Elec'),
44+
(2024, ['North', 'Mid', 'South'], 'Elec'),
45+
(2029, 'North', 'Elec'),
46+
(2029, 'Mid', 'Elec'),
47+
(2029, 'South', 'Elec'),
48+
(2029, ['North', 'Mid', 'South'], 'Elec'),
49+
(2034, 'North', 'Elec'),
50+
(2034, 'Mid', 'Elec'),
51+
(2034, 'South', 'Elec'),
52+
(2034, ['North', 'Mid', 'South'], 'Elec'),
5353
]
5454

5555
# optional: define names for sites in report_tuples
5656
report_sites_name = {('North', 'Mid', 'South'): 'All'}
5757

5858
# plotting commodities/sites
5959
plot_tuples = [
60-
(year, 'North', 'Elec'),
61-
(year, 'Mid', 'Elec'),
62-
(year, 'South', 'Elec'),
63-
(year, ['North', 'Mid', 'South'], 'Elec'),
64-
(year+5, 'North', 'Elec'),
65-
(year+5, 'Mid', 'Elec'),
66-
(year+5, 'South', 'Elec'),
67-
(year+5, ['North', 'Mid', 'South'], 'Elec'),
68-
(year+10, 'North', 'Elec'),
69-
(year+10, 'Mid', 'Elec'),
70-
(year+10, 'South', 'Elec'),
71-
(year+10, ['North', 'Mid', 'South'], 'Elec'),
72-
(year+15, 'North', 'Elec'),
73-
(year+15, 'Mid', 'Elec'),
74-
(year+15, 'South', 'Elec'),
75-
(year+15, ['North', 'Mid', 'South'], 'Elec'),
60+
(2019, 'North', 'Elec'),
61+
(2019, 'Mid', 'Elec'),
62+
(2019, 'South', 'Elec'),
63+
(2019, ['North', 'Mid', 'South'], 'Elec'),
64+
(2024, 'North', 'Elec'),
65+
(2024, 'Mid', 'Elec'),
66+
(2024, 'South', 'Elec'),
67+
(2024, ['North', 'Mid', 'South'], 'Elec'),
68+
(2029, 'North', 'Elec'),
69+
(2029, 'Mid', 'Elec'),
70+
(2029, 'South', 'Elec'),
71+
(2029, ['North', 'Mid', 'South'], 'Elec'),
72+
(2034, 'North', 'Elec'),
73+
(2034, 'Mid', 'Elec'),
74+
(2034, 'South', 'Elec'),
75+
(2034, ['North', 'Mid', 'South'], 'Elec'),
7676
]
7777

7878
# optional: define names for sites in plot_tuples

run_single_year.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
objective = 'cost' # set either 'cost' or 'CO2' as objective
2626

2727
# Choose Solver (cplex, glpk, gurobi, ...)
28-
solver = 'glpk'
28+
solver = 'gurobi'
2929

3030
# simulation timesteps
3131
(offset, length) = (0, 20) # time step selection

runme.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import shutil
33
import urbs
44

5-
65
input_files = 'single_year_example.xlsx' # for single year file name, for intertemporal folder name
76
input_dir = 'Input'
87
input_path = os.path.join(input_dir, input_files)
@@ -22,7 +21,7 @@
2221
objective = 'cost' # set either 'cost' or 'CO2' as objective
2322

2423
# Choose Solver (cplex, glpk, gurobi, ...)
25-
solver = 'glpk'
24+
solver = 'gurobi'
2625

2726
# simulation timesteps
2827
(offset, length) = (3500, 24) # time step selection

urbs-env.yml

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
name: urbs
1+
name: urbs-env
22
channels:
3-
- defaults
43
- conda-forge
54
dependencies:
6-
- python=3.6
7-
- numpy=1.17.3
8-
- matplotlib=3.1.1
9-
- pandas=0.24.2
10-
- pandas-datareader=0.8.1
11-
- pytables=3.6.1
12-
- openpyxl=3.0.1
13-
- xlrd=1.2.0
14-
- pyomo=5.6.7
5+
- python=3.12.2
6+
- numpy=1.26.4
7+
- matplotlib=3.8.3
8+
- pandas=2.2.1
9+
- pandas-datareader=0.10.0
10+
- pytables=3.9.2
11+
- openpyxl=3.1.2
12+
- xlrd=2.0.1
13+
- pyomo=6.7.1
1514
- glpk
16-
- psutil=5.6.5
17-
- pyutilib=5.8.0
15+
- psutil=5.9.8
16+
- pyutilib=6.0.0

urbs/features/BuySellPrice.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ def search_sell_buy_tuple(m, stf, sit_in, pro_in, coin):
130130
Returns:
131131
a process
132132
"""
133-
pro_output_tuples = [x for x in list(m.pro_output_tuples.value) if x[1] == sit_in]
134-
pro_input_tuples = [x for x in list(m.pro_input_tuples.value) if x[1] == sit_in]
133+
pro_output_tuples = [x for x in list(m.pro_output_tuples.data()) if x[1] == sit_in]
134+
pro_input_tuples = [x for x in list(m.pro_input_tuples.data()) if x[1] == sit_in]
135135
# search the output commodities for the "buy" process
136136
# buy_out = (stf, site, output_commodity)
137137
buy_out = set([(x[0], x[1], x[3])

urbs/features/storage.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
def add_storage(m):
66

77
# storage (e.g. hydrogen, pump storage)
8-
indexlist = set()
8+
indexlist = list()
99
for key in m.storage_dict["eff-in"]:
10-
indexlist.add(tuple(key)[2])
10+
if key[2] not in indexlist:
11+
indexlist.append(key[2])
1112
m.sto = pyomo.Set(
1213
initialize=indexlist,
1314
doc='Set of storage technologies')
@@ -245,14 +246,14 @@ def res_storage_capacity_rule(m, stf, sit, sto, com):
245246
# forced minimun storage content in final timestep t[len(m.t)]
246247
# content[t=1] == storage capacity * fraction <= content[t=final]
247248
def def_initial_storage_state_rule(m, stf, sit, sto, com):
248-
return (m.e_sto_con[m.t[1], stf, sit, sto, com] ==
249+
return (m.e_sto_con[m.t.at(1), stf, sit, sto, com] ==
249250
m.cap_sto_c[stf, sit, sto, com] *
250251
m.storage_dict['init'][(stf, sit, sto, com)])
251252

252253

253254
def res_storage_state_cyclicity_rule(m, stf, sit, sto, com):
254-
return (m.e_sto_con[m.t[1], stf, sit, sto, com] <=
255-
m.e_sto_con[m.t[len(m.t)], stf, sit, sto, com])
255+
return (m.e_sto_con[m.t.at(1), stf, sit, sto, com] <=
256+
m.e_sto_con[m.t.at(len(m.t)), stf, sit, sto, com])
256257

257258

258259
def def_storage_energy_power_ratio_rule(m, stf, sit, sto, com):

urbs/features/transmission.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,16 @@ def remove_duplicate_transmission(transmission_keys):
2323
i -= 1
2424
break
2525
i += 1
26-
return set(tra_tuple_list)
26+
return list(tra_tuple_list)
2727

2828

2929
def add_transmission(m):
3030

3131
# tranmission (e.g. hvac, hvdc, pipeline...)
32-
indexlist = set()
32+
indexlist = list()
3333
for key in m.transmission_dict["eff"]:
34-
indexlist.add(tuple(key)[3])
34+
if key[3] not in indexlist:
35+
indexlist.append(key[3])
3536
m.tra = pyomo.Set(
3637
initialize=indexlist,
3738
doc='Set of transmission technologies')
@@ -117,20 +118,21 @@ def add_transmission(m):
117118
# adds the transmission features to model with DCPF model features
118119
def add_transmission_dc(m):
119120
# defining transmission tuple sets for transport and DCPF model separately
120-
tra_tuples = set()
121-
tra_tuples_dc = set()
121+
tra_tuples = list()
122+
tra_tuples_dc = list()
122123
for key in m.transmission_dict['reactance']:
123-
tra_tuples.add(tuple(key))
124+
tra_tuples.append(key)
124125
for key in m.transmission_dc_dict['reactance']:
125-
tra_tuples_dc.add(tuple(key))
126+
tra_tuples_dc.append(key)
126127
tra_tuples_tp = tra_tuples - tra_tuples_dc
127128
tra_tuples_dc = remove_duplicate_transmission(tra_tuples_dc)
128129
tra_tuples = tra_tuples_dc | tra_tuples_tp
129130

130131
# tranmission (e.g. hvac, hvdc, pipeline...)
131-
indexlist = set()
132+
indexlist = list()
132133
for key in m.transmission_dict["eff"]:
133-
indexlist.add(tuple(key)[3])
134+
if key[3] not in indexlist:
135+
indexlist.append(key[3])
134136
m.tra = pyomo.Set(
135137
initialize=indexlist,
136138
doc='Set of transmission technologies')

urbs/input.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def read_input(input_files, year):
4747
global_prop = xls.parse('Global').set_index(['Property'])
4848
# create support timeframe index
4949
if ('Support timeframe' in
50-
xls.parse('Global').set_index('Property').value):
50+
global_prop.value):
5151
support_timeframe = (
5252
global_prop.loc['Support timeframe']['value'])
5353
global_prop = (
@@ -174,7 +174,7 @@ def read_input(input_files, year):
174174

175175
# sort nested indexes to make direct assignments work
176176
for key in data:
177-
if isinstance(data[key].index, pd.core.index.MultiIndex):
177+
if isinstance(data[key].index, pd.MultiIndex):
178178
data[key].sort_index(inplace=True)
179179
return data
180180

urbs/model.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,21 @@ def create_model(data, dt=1, timesteps=None, objective='cost',
3838
# costs are annual by default, variable costs are scaled by weight) and
3939
# among different simulation durations meaningful.
4040
m.weight = pyomo.Param(
41+
within=pyomo.Reals,
4142
initialize=float(8760) / ((len(m.timesteps) - 1) * dt),
4243
doc='Pre-factor for variable costs and emissions for an annual result')
4344

4445
# dt = spacing between timesteps. Required for storage equation that
4546
# converts between energy (storage content, e_sto_con) and power (all other
4647
# quantities that start with "e_")
4748
m.dt = pyomo.Param(
49+
within=pyomo.Reals,
4850
initialize=dt,
4951
doc='Time step duration (in hours), default: 1')
5052

5153
# import objective function information
5254
m.obj = pyomo.Param(
55+
within=pyomo.Any,
5356
initialize=objective,
5457
doc='Specification of minimized quantity, default: "cost"')
5558

@@ -62,6 +65,7 @@ def create_model(data, dt=1, timesteps=None, objective='cost',
6265

6366
# generate ordered time step sets
6467
m.t = pyomo.Set(
68+
within=pyomo.Reals,
6569
initialize=m.timesteps,
6670
ordered=True,
6771
doc='Set of timesteps')
@@ -74,41 +78,47 @@ def create_model(data, dt=1, timesteps=None, objective='cost',
7478
doc='Set of modelled timesteps')
7579

7680
# support timeframes (e.g. 2020, 2030...)
77-
indexlist = set()
81+
indexlist = list()
7882
for key in m.commodity_dict["price"]:
79-
indexlist.add(tuple(key)[0])
83+
if key[0] not in indexlist:
84+
indexlist.append(key[0])
8085
m.stf = pyomo.Set(
86+
within=pyomo.Reals,
8187
initialize=indexlist,
8288
doc='Set of modeled support timeframes (e.g. years)')
8389

8490
# site (e.g. north, middle, south...)
85-
indexlist = set()
91+
indexlist = list()
8692
for key in m.commodity_dict["price"]:
87-
indexlist.add(tuple(key)[1])
93+
if key[1] not in indexlist:
94+
indexlist.append(key[1])
8895
m.sit = pyomo.Set(
8996
initialize=indexlist,
9097
doc='Set of sites')
9198

9299
# commodity (e.g. solar, wind, coal...)
93-
indexlist = set()
100+
indexlist = list()
94101
for key in m.commodity_dict["price"]:
95-
indexlist.add(tuple(key)[2])
102+
if key[2] not in indexlist:
103+
indexlist.append(key[2])
96104
m.com = pyomo.Set(
97105
initialize=indexlist,
98106
doc='Set of commodities')
99107

100108
# commodity type (i.e. SupIm, Demand, Stock, Env)
101-
indexlist = set()
109+
indexlist = list()
102110
for key in m.commodity_dict["price"]:
103-
indexlist.add(tuple(key)[3])
111+
if key[3] not in indexlist:
112+
indexlist.append(key[3])
104113
m.com_type = pyomo.Set(
105114
initialize=indexlist,
106115
doc='Set of commodity types')
107116

108117
# process (e.g. Wind turbine, Gas plant, Photovoltaics...)
109-
indexlist = set()
118+
indexlist = list()
110119
for key in m.process_dict["inv-cost"]:
111-
indexlist.add(tuple(key)[2])
120+
if key[2] not in indexlist:
121+
indexlist.append(key[2])
112122
m.pro = pyomo.Set(
113123
initialize=indexlist,
114124
doc='Set of conversion processes')

0 commit comments

Comments
 (0)