|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
|
|
3
|
|
|
""" |
|
4
|
|
|
General description |
|
5
|
|
|
------------------- |
|
6
|
|
|
Example that shows how to add an emission constraint in a model. |
|
7
|
|
|
|
|
8
|
|
|
Code |
|
9
|
|
|
---- |
|
10
|
|
|
Download source code: :download:`emission_constraint_flow.py </../examples/emission_constraint/emission_constraint_flow.py>` |
|
11
|
|
|
|
|
12
|
|
|
.. dropdown:: Click to display code |
|
13
|
|
|
|
|
14
|
|
|
.. literalinclude:: /../examples/emission_constraint/emission_constraint_flow.py |
|
15
|
|
|
:language: python |
|
16
|
|
|
:lines: 32-129 |
|
17
|
|
|
|
|
18
|
|
|
Installation requirements |
|
19
|
|
|
------------------------- |
|
20
|
|
|
|
|
21
|
|
|
This example requires oemof.solph (v0.5.x), install by: |
|
22
|
|
|
|
|
23
|
|
|
.. code:: bash |
|
24
|
|
|
|
|
25
|
|
|
pip install oemof.solph[examples] |
|
26
|
|
|
|
|
27
|
|
|
License |
|
28
|
|
|
------- |
|
29
|
|
|
`MIT license <https://github.com/oemof/oemof-solph/blob/dev/LICENSE>`_ |
|
30
|
|
|
|
|
31
|
|
|
""" |
|
32
|
|
|
import matplotlib.pyplot as plt |
|
33
|
|
|
import pandas as pd |
|
34
|
|
|
|
|
35
|
|
|
from oemof import solph |
|
36
|
|
|
from oemof.solph import constraints |
|
37
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
def main(optimize=True): |
|
40
|
|
|
# create energy system |
|
41
|
|
|
energysystem = solph.EnergySystem( |
|
42
|
|
|
timeindex=pd.date_range("1/1/2012", periods=3, freq="h") |
|
43
|
|
|
) |
|
44
|
|
|
|
|
45
|
|
|
# create gas bus |
|
46
|
|
|
bgas = solph.Bus(label="gas") |
|
47
|
|
|
|
|
48
|
|
|
# create electricity bus |
|
49
|
|
|
bel = solph.Bus(label="electricity") |
|
50
|
|
|
|
|
51
|
|
|
# adding the buses to the energy system |
|
52
|
|
|
energysystem.add(bel, bgas) |
|
53
|
|
|
|
|
54
|
|
|
# create fixed source object representing biomass plants |
|
55
|
|
|
energysystem.add( |
|
56
|
|
|
solph.components.Source( |
|
57
|
|
|
label="biomass", |
|
58
|
|
|
outputs={ |
|
59
|
|
|
bel: solph.Flow( |
|
60
|
|
|
nominal_capacity=100, |
|
61
|
|
|
variable_costs=10, |
|
62
|
|
|
fix=[0.1, 0.2, 0.3], |
|
63
|
|
|
custom_attributes={"emission_factor": 0.01}, |
|
64
|
|
|
) |
|
65
|
|
|
}, |
|
66
|
|
|
) |
|
67
|
|
|
) |
|
68
|
|
|
|
|
69
|
|
|
# create source object representing the gas commodity |
|
70
|
|
|
energysystem.add( |
|
71
|
|
|
solph.components.Source( |
|
72
|
|
|
label="gas-source", |
|
73
|
|
|
outputs={ |
|
74
|
|
|
bgas: solph.Flow( |
|
75
|
|
|
variable_costs=10, |
|
76
|
|
|
custom_attributes={"emission_factor": 0.2}, |
|
77
|
|
|
) |
|
78
|
|
|
}, |
|
79
|
|
|
) |
|
80
|
|
|
) |
|
81
|
|
|
|
|
82
|
|
|
energysystem.add( |
|
83
|
|
|
solph.components.Sink( |
|
84
|
|
|
label="demand", |
|
85
|
|
|
inputs={ |
|
86
|
|
|
bel: solph.Flow( |
|
87
|
|
|
nominal_capacity=200, |
|
88
|
|
|
variable_costs=10, |
|
89
|
|
|
fix=[0.1, 0.2, 0.3], |
|
90
|
|
|
) |
|
91
|
|
|
}, |
|
92
|
|
|
) |
|
93
|
|
|
) |
|
94
|
|
|
|
|
95
|
|
|
# create simple converter object representing a gas power plant |
|
96
|
|
|
energysystem.add( |
|
97
|
|
|
solph.components.Converter( |
|
98
|
|
|
label="pp_gas", |
|
99
|
|
|
inputs={bgas: solph.Flow()}, |
|
100
|
|
|
outputs={bel: solph.Flow(nominal_capacity=200)}, |
|
101
|
|
|
conversion_factors={bel: 0.58}, |
|
102
|
|
|
) |
|
103
|
|
|
) |
|
104
|
|
|
|
|
105
|
|
|
if optimize is False: |
|
106
|
|
|
return energysystem |
|
107
|
|
|
|
|
108
|
|
|
# initialise the operational model |
|
109
|
|
|
model = solph.Model(energysystem) |
|
110
|
|
|
|
|
111
|
|
|
# add the emission constraint |
|
112
|
|
|
constraints.emission_limit(model, limit=100) |
|
113
|
|
|
|
|
114
|
|
|
# print out the emission constraint |
|
115
|
|
|
model.integral_limit_emission_factor_upper_limit.pprint() |
|
116
|
|
|
model.integral_limit_emission_factor.pprint() |
|
117
|
|
|
|
|
118
|
|
|
# solve the model |
|
119
|
|
|
model.solve() |
|
120
|
|
|
|
|
121
|
|
|
# print out the amount of emissions from the emission constraint |
|
122
|
|
|
print(model.integral_limit_emission_factor()) |
|
123
|
|
|
|
|
124
|
|
|
results = solph.processing.results(model) |
|
125
|
|
|
|
|
126
|
|
|
data = solph.views.node(results, "electricity")["sequences"] |
|
127
|
|
|
ax = data.plot(kind="line", grid=True) |
|
128
|
|
|
ax.set_xlabel("Time (h)") |
|
129
|
|
|
ax.set_ylabel("P (MW)") |
|
130
|
|
|
plt.show() |
|
131
|
|
|
|
|
132
|
|
|
|
|
133
|
|
|
if __name__ == "__main__": |
|
134
|
|
|
main() |
|
135
|
|
|
|