Skip to content

Commit

Permalink
Merge pull request #320 from lodersky/new_env
Browse files Browse the repository at this point in the history
Update python packages
  • Loading branch information
JuliaGawlick authored Mar 15, 2024
2 parents 7104197 + d91c2dd commit c941c45
Show file tree
Hide file tree
Showing 13 changed files with 153 additions and 138 deletions.
68 changes: 34 additions & 34 deletions run_intertemporal.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,54 +25,54 @@
objective = 'cost' # set either 'cost' or 'CO2' as objective

# Choose Solver (cplex, glpk, gurobi, ...)
solver = 'glpk'
solver = 'gurobi'

# simulation timesteps
(offset, length) = (0, 8760) # time step selection
(offset, length) = (0, 24) # 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'),
(year+5, 'North', 'Elec'),
(year+5, 'Mid', 'Elec'),
(year+5, 'South', 'Elec'),
(year+5, ['North', 'Mid', 'South'], 'Elec'),
(year+10, 'North', 'Elec'),
(year+10, 'Mid', 'Elec'),
(year+10, 'South', 'Elec'),
(year+10, ['North', 'Mid', 'South'], 'Elec'),
(year+15, 'North', 'Elec'),
(year+15, 'Mid', 'Elec'),
(year+15, 'South', 'Elec'),
(year+15, ['North', 'Mid', 'South'], 'Elec'),
(2019, 'North', 'Elec'),
(2019, 'Mid', 'Elec'),
(2019, 'South', 'Elec'),
(2019, ['North', 'Mid', 'South'], 'Elec'),
(2024, 'North', 'Elec'),
(2024, 'Mid', 'Elec'),
(2024, 'South', 'Elec'),
(2024, ['North', 'Mid', 'South'], 'Elec'),
(2029, 'North', 'Elec'),
(2029, 'Mid', 'Elec'),
(2029, 'South', 'Elec'),
(2029, ['North', 'Mid', 'South'], 'Elec'),
(2034, 'North', 'Elec'),
(2034, 'Mid', 'Elec'),
(2034, 'South', 'Elec'),
(2034, ['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'),
(year+5, 'North', 'Elec'),
(year+5, 'Mid', 'Elec'),
(year+5, 'South', 'Elec'),
(year+5, ['North', 'Mid', 'South'], 'Elec'),
(year+10, 'North', 'Elec'),
(year+10, 'Mid', 'Elec'),
(year+10, 'South', 'Elec'),
(year+10, ['North', 'Mid', 'South'], 'Elec'),
(year+15, 'North', 'Elec'),
(year+15, 'Mid', 'Elec'),
(year+15, 'South', 'Elec'),
(year+15, ['North', 'Mid', 'South'], 'Elec'),
(2019, 'North', 'Elec'),
(2019, 'Mid', 'Elec'),
(2019, 'South', 'Elec'),
(2019, ['North', 'Mid', 'South'], 'Elec'),
(2024, 'North', 'Elec'),
(2024, 'Mid', 'Elec'),
(2024, 'South', 'Elec'),
(2024, ['North', 'Mid', 'South'], 'Elec'),
(2029, 'North', 'Elec'),
(2029, 'Mid', 'Elec'),
(2029, 'South', 'Elec'),
(2029, ['North', 'Mid', 'South'], 'Elec'),
(2034, 'North', 'Elec'),
(2034, 'Mid', 'Elec'),
(2034, 'South', 'Elec'),
(2034, ['North', 'Mid', 'South'], 'Elec'),
]

# optional: define names for sites in plot_tuples
Expand Down
2 changes: 1 addition & 1 deletion run_single_year.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
objective = 'cost' # set either 'cost' or 'CO2' as objective

# Choose Solver (cplex, glpk, gurobi, ...)
solver = 'glpk'
solver = 'gurobi'

# simulation timesteps
(offset, length) = (0, 20) # time step selection
Expand Down
3 changes: 1 addition & 2 deletions runme.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import shutil
import urbs


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)
Expand All @@ -22,7 +21,7 @@
objective = 'cost' # set either 'cost' or 'CO2' as objective

# Choose Solver (cplex, glpk, gurobi, ...)
solver = 'glpk'
solver = 'gurobi'

# simulation timesteps
(offset, length) = (3500, 24) # time step selection
Expand Down
25 changes: 12 additions & 13 deletions urbs-env.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
name: urbs
name: urbs-env
channels:
- defaults
- conda-forge
dependencies:
- python=3.6
- numpy=1.17.3
- matplotlib=3.1.1
- pandas=0.24.2
- pandas-datareader=0.8.1
- pytables=3.6.1
- openpyxl=3.0.1
- xlrd=1.2.0
- pyomo=5.6.7
- python=3.12.2
- numpy=1.26.4
- matplotlib=3.8.3
- pandas=2.2.1
- pandas-datareader=0.10.0
- pytables=3.9.2
- openpyxl=3.1.2
- xlrd=2.0.1
- pyomo=6.7.1
- glpk
- psutil=5.6.5
- pyutilib=5.8.0
- psutil=5.9.8
- pyutilib=6.0.0
4 changes: 2 additions & 2 deletions urbs/features/BuySellPrice.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ def search_sell_buy_tuple(m, stf, sit_in, pro_in, coin):
Returns:
a process
"""
pro_output_tuples = [x for x in list(m.pro_output_tuples.value) if x[1] == sit_in]
pro_input_tuples = [x for x in list(m.pro_input_tuples.value) if x[1] == sit_in]
pro_output_tuples = [x for x in list(m.pro_output_tuples.data()) if x[1] == sit_in]
pro_input_tuples = [x for x in list(m.pro_input_tuples.data()) if x[1] == sit_in]
# search the output commodities for the "buy" process
# buy_out = (stf, site, output_commodity)
buy_out = set([(x[0], x[1], x[3])
Expand Down
11 changes: 6 additions & 5 deletions urbs/features/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
def add_storage(m):

# storage (e.g. hydrogen, pump storage)
indexlist = set()
indexlist = list()
for key in m.storage_dict["eff-in"]:
indexlist.add(tuple(key)[2])
if key[2] not in indexlist:
indexlist.append(key[2])
m.sto = pyomo.Set(
initialize=indexlist,
doc='Set of storage technologies')
Expand Down Expand Up @@ -245,14 +246,14 @@ def res_storage_capacity_rule(m, stf, sit, sto, com):
# forced minimun storage content in final timestep t[len(m.t)]
# content[t=1] == storage capacity * fraction <= content[t=final]
def def_initial_storage_state_rule(m, stf, sit, sto, com):
return (m.e_sto_con[m.t[1], stf, sit, sto, com] ==
return (m.e_sto_con[m.t.at(1), stf, sit, sto, com] ==
m.cap_sto_c[stf, sit, sto, com] *
m.storage_dict['init'][(stf, sit, sto, com)])


def res_storage_state_cyclicity_rule(m, stf, sit, sto, com):
return (m.e_sto_con[m.t[1], stf, sit, sto, com] <=
m.e_sto_con[m.t[len(m.t)], stf, sit, sto, com])
return (m.e_sto_con[m.t.at(1), stf, sit, sto, com] <=
m.e_sto_con[m.t.at(len(m.t)), stf, sit, sto, com])


def def_storage_energy_power_ratio_rule(m, stf, sit, sto, com):
Expand Down
20 changes: 11 additions & 9 deletions urbs/features/transmission.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@ def remove_duplicate_transmission(transmission_keys):
i -= 1
break
i += 1
return set(tra_tuple_list)
return list(tra_tuple_list)


def add_transmission(m):

# tranmission (e.g. hvac, hvdc, pipeline...)
indexlist = set()
indexlist = list()
for key in m.transmission_dict["eff"]:
indexlist.add(tuple(key)[3])
if key[3] not in indexlist:
indexlist.append(key[3])
m.tra = pyomo.Set(
initialize=indexlist,
doc='Set of transmission technologies')
Expand Down Expand Up @@ -117,20 +118,21 @@ def add_transmission(m):
# adds the transmission features to model with DCPF model features
def add_transmission_dc(m):
# defining transmission tuple sets for transport and DCPF model separately
tra_tuples = set()
tra_tuples_dc = set()
tra_tuples = list()
tra_tuples_dc = list()
for key in m.transmission_dict['reactance']:
tra_tuples.add(tuple(key))
tra_tuples.append(key)
for key in m.transmission_dc_dict['reactance']:
tra_tuples_dc.add(tuple(key))
tra_tuples_dc.append(key)
tra_tuples_tp = tra_tuples - tra_tuples_dc
tra_tuples_dc = remove_duplicate_transmission(tra_tuples_dc)
tra_tuples = tra_tuples_dc | tra_tuples_tp

# tranmission (e.g. hvac, hvdc, pipeline...)
indexlist = set()
indexlist = list()
for key in m.transmission_dict["eff"]:
indexlist.add(tuple(key)[3])
if key[3] not in indexlist:
indexlist.append(key[3])
m.tra = pyomo.Set(
initialize=indexlist,
doc='Set of transmission technologies')
Expand Down
4 changes: 2 additions & 2 deletions urbs/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def read_input(input_files, year):
global_prop = xls.parse('Global').set_index(['Property'])
# create support timeframe index
if ('Support timeframe' in
xls.parse('Global').set_index('Property').value):
global_prop.value):
support_timeframe = (
global_prop.loc['Support timeframe']['value'])
global_prop = (
Expand Down Expand Up @@ -174,7 +174,7 @@ def read_input(input_files, year):

# sort nested indexes to make direct assignments work
for key in data:
if isinstance(data[key].index, pd.core.index.MultiIndex):
if isinstance(data[key].index, pd.MultiIndex):
data[key].sort_index(inplace=True)
return data

Expand Down
30 changes: 20 additions & 10 deletions urbs/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,21 @@ def create_model(data, dt=1, timesteps=None, objective='cost',
# costs are annual by default, variable costs are scaled by weight) and
# among different simulation durations meaningful.
m.weight = pyomo.Param(
within=pyomo.Reals,
initialize=float(8760) / ((len(m.timesteps) - 1) * dt),
doc='Pre-factor for variable costs and emissions for an annual result')

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

# import objective function information
m.obj = pyomo.Param(
within=pyomo.Any,
initialize=objective,
doc='Specification of minimized quantity, default: "cost"')

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

# generate ordered time step sets
m.t = pyomo.Set(
within=pyomo.Reals,
initialize=m.timesteps,
ordered=True,
doc='Set of timesteps')
Expand All @@ -74,41 +78,47 @@ def create_model(data, dt=1, timesteps=None, objective='cost',
doc='Set of modelled timesteps')

# support timeframes (e.g. 2020, 2030...)
indexlist = set()
indexlist = list()
for key in m.commodity_dict["price"]:
indexlist.add(tuple(key)[0])
if key[0] not in indexlist:
indexlist.append(key[0])
m.stf = pyomo.Set(
within=pyomo.Reals,
initialize=indexlist,
doc='Set of modeled support timeframes (e.g. years)')

# site (e.g. north, middle, south...)
indexlist = set()
indexlist = list()
for key in m.commodity_dict["price"]:
indexlist.add(tuple(key)[1])
if key[1] not in indexlist:
indexlist.append(key[1])
m.sit = pyomo.Set(
initialize=indexlist,
doc='Set of sites')

# commodity (e.g. solar, wind, coal...)
indexlist = set()
indexlist = list()
for key in m.commodity_dict["price"]:
indexlist.add(tuple(key)[2])
if key[2] not in indexlist:
indexlist.append(key[2])
m.com = pyomo.Set(
initialize=indexlist,
doc='Set of commodities')

# commodity type (i.e. SupIm, Demand, Stock, Env)
indexlist = set()
indexlist = list()
for key in m.commodity_dict["price"]:
indexlist.add(tuple(key)[3])
if key[3] not in indexlist:
indexlist.append(key[3])
m.com_type = pyomo.Set(
initialize=indexlist,
doc='Set of commodity types')

# process (e.g. Wind turbine, Gas plant, Photovoltaics...)
indexlist = set()
indexlist = list()
for key in m.process_dict["inv-cost"]:
indexlist.add(tuple(key)[2])
if key[2] not in indexlist:
indexlist.append(key[2])
m.pro = pyomo.Set(
initialize=indexlist,
doc='Set of conversion processes')
Expand Down
Loading

0 comments on commit c941c45

Please sign in to comment.