Skip to content

Commit

Permalink
Minor fixes incl. MILP, ramping & PV urban-scale tech
Browse files Browse the repository at this point in the history
  • Loading branch information
brynpickering committed Jul 3, 2017
1 parent 6f66065 commit 0a0c1c0
Show file tree
Hide file tree
Showing 10 changed files with 4,661 additions and 4,604 deletions.
2 changes: 2 additions & 0 deletions calliope/config/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ techs:
s_cap.min: 0 # Minimum storage capacity (kWh)
s_cap.max: 0 # Maximum storage capacity (kWh). If both this and s_time.max are set to non-zero values, the minimum resulting constraint of either s_time.max or s_cap.max is applied.
s_cap.equals: false # Specific storage capacity (kWh)
s_cap_per_unit: false # set the storage capacity of each integer unit of a technology perchased (kWh/unit)
c_rate: false # Charge rate (0 to 1) defining maximum charge/discharge (kW) for a given maximum storage capacity (kWh)
s_time.max: 0 # Max storage time (full load hours). If both this and s_cap.max are set to non-zero values, the minimum resulting constraint of either s_time.max or s_cap.max is applied.
s_loss: 0 # Storage loss rate (per hour)
Expand All @@ -78,6 +79,7 @@ techs:
e_cap.total_equals: false # Specific installed storage to/from carrier conversion capacity (kW), model-wide
e_cap_scale: 1.0 # Scale all ``e_cap`` min/max/equals/total_max/total_equals constraints by this value
e_cap_min_use: false # Set to a value between 0 and 1 to force minimum storage to carrier capacity use for production technologies
e_cap_per_unit: false # set the capacity of each integer unit of a technology perchased (kW/unit)
e_ramping: false # Ramping rate (fraction of installed capacity per hour), set to ``false`` to disable ramping constraints (only has an effect if the optional ramping constraints are loaded)
export_cap: false # Maximum allowed export for a technology, set to ``false`` to disable.
unit_cap.min: false # Minimum number of integer units of a technology that can be purchased.
Expand Down
4 changes: 2 additions & 2 deletions calliope/constraints/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,8 +727,8 @@ def c_prod_min_rule(m, c, y, x, t):
elif c == model.get_option(y + '.carrier', default=y + '.carrier_out'):
if y in m.y_milp and x in m.x_milp:
e_cap = model.get_option(y + '.constraints.e_cap_per_unit', x=x)
return m.c_prod[c, y, x, t] >=
(time_res.at[t] * m.operating_units[y, x, t] * e_cap * min_use)
return (m.c_prod[c, y, x, t] >= time_res.at[t] *
m.operating_units[y, x, t] * e_cap * min_use)
return (m.c_prod[c, y, x, t]
>= time_res.at[t] * m.e_cap[y, x] * min_use)
else:
Expand Down
12 changes: 8 additions & 4 deletions calliope/constraints/optional.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ def _ramping_rule(m, y, x, t, direction):
if m.t.order_dict[t] == 0:
return po.Constraint.NoConstraint
else:
carrier = model.get_option(y + '.carrier')
carrier = model.get_option(y + '.carrier', default=y + '.carrier_out')
if isinstance(carrier, dict): # conversion_plus technology
carrier = model.get_carrier(y, 'out', primary=True)
diff = ((m.c_prod[carrier, y, x, t]
+ m.c_con[carrier, y, x, t]) / time_res.at[t]
- (m.c_prod[carrier, y, x, model.prev_t(t)]
Expand Down Expand Up @@ -98,7 +100,9 @@ def equalizer(lhs, rhs, sign):
raise ValueError('Invalid sign: {}'.format(sign))

supply_techs = (model.get_group_members('supply') +
model.get_group_members('conversion'))
model.get_group_members('supply_plus') +
model.get_group_members('conversion') +
model.get_group_members('conversion_plus'))

# Sets
m.output_group = group_set('output')
Expand Down Expand Up @@ -157,7 +161,7 @@ def max_r_area_per_loc(model):
``r_area`` of all technologies requiring physical space cannot exceed the
available area of a location. Available area defined for parent locations
(in which there are locations defined as being 'within' it) will set the
available area limit for the sum of all the family (parent + all desecendants).
available area limit for the sum of all the family (parent + all descendants).
To define, assign a value to ``available_area`` for a given location, e.g.::
Expand All @@ -167,7 +171,7 @@ def max_r_area_per_loc(model):
available_area: 100000
To avoid including descendants in area limitation, ``ignore_descendants``
can be specified for the location, in the same way as ``available_area``.
can be specified as True for the location, at the same level as ``available_area``.
"""
m = model.m
Expand Down
20 changes: 18 additions & 2 deletions calliope/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ def get_carrier(self, y, direction, level=None, primary=False, all_carriers=Fals
not top level, e.g. level=3 gives `carrier_out_3`
primary: bool, optional, default = False
give `primary carrier` for a given technology, which is a carrier in
`carrier_out` given ass `primary carrier` in the technology definition
`carrier_out` given as `primary carrier` in the technology definition
all_carriers: bool, optional, default = False
give all carriers for tech y and given direction. For conversion_plus
technologies, this will give an array of carriers, if more than one
Expand Down Expand Up @@ -1644,7 +1644,7 @@ def get_c_sum(self):
return c.fillna(0)

def get_node_variables(self):
detail = ['s', 'r', 'r2', 'export']
detail = ['s', 'r', 'r2', 'export', 'operating_units']
p = xr.Dataset()
p['e'] = self.get_c_sum()
for v in detail:
Expand All @@ -1666,6 +1666,21 @@ def get_e_cap_net(self):

return self.get_var('e_cap') * p_eff

def get_purchased_units(self):
# Return either 'purchased' variable or 'units', depending on whether the
# technology is in 'y_purchased' or 'y_milp'. All other technologies
# return 1 if e_cap > 0
m = self.m
e_cap = self.get_var('e_cap')
all_units = (e_cap / e_cap).replace(np.nan, 0)
for v in ['units', 'purchased']:
try:
new_data = self.get_var(v)
all_units.ix[new_data.index, new_data.columns] = new_data
except exceptions.ModelError:
continue
return all_units

def get_node_parameters(self):
detail = ['e_cap', 's_cap', 'r_cap', 'r_area', 'r2_cap']
result = xr.Dataset()
Expand All @@ -1675,6 +1690,7 @@ def get_node_parameters(self):
except exceptions.ModelError:
continue
result['e_cap_net'] = self.get_e_cap_net()
result['purchased_units'] = self.get_purchased_units()
return result

def get_costs(self, t_subset=None):
Expand Down
Loading

0 comments on commit 0a0c1c0

Please sign in to comment.