Passed
Pull Request — dev (#850)
by Uwe
01:35
created

emission_constraint   A

Complexity

Total Complexity 0

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 0
eloc 47
dl 0
loc 107
rs 10
c 0
b 0
f 0
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
Installation requirements
9
-------------------------
10
11
This example requires oemof.solph (v0.5.x), install by:
12
13
    pip install oemof.solph[examples]
14
15
License
16
-------
17
`MIT license <https://github.com/oemof/oemof-solph/blob/dev/LICENSE>`_
18
19
"""
20
import matplotlib.pyplot as plt
21
import pandas as pd
22
23
from oemof import solph
24
from oemof.solph import constraints
25
26
# create energy system
27
energysystem = solph.EnergySystem(
28
    timeindex=pd.date_range("1/1/2012", periods=3, freq="H")
29
)
30
31
# create gas bus
32
bgas = solph.Bus(label="gas")
33
34
# create electricity bus
35
bel = solph.Bus(label="electricity")
36
37
# adding the buses to the energy system
38
energysystem.add(bel, bgas)
39
40
# create fixed source object representing biomass plants
41
energysystem.add(
42
    solph.components.Source(
43
        label="biomass",
44
        outputs={
45
            bel: solph.Flow(
46
                nominal_value=100,
47
                variable_costs=10,
48
                emission_factor=0.01,
49
                fix=[0.1, 0.2, 0.3],
50
            )
51
        },
52
    )
53
)
54
55
# create source object representing the gas commodity
56
energysystem.add(
57
    solph.components.Source(
58
        label="gas-source",
59
        outputs={bgas: solph.Flow(variable_costs=10, emission_factor=0.2)},
60
    )
61
)
62
63
energysystem.add(
64
    solph.components.Sink(
65
        label="demand",
66
        inputs={
67
            bel: solph.Flow(
68
                nominal_value=200, variable_costs=10, fix=[0.1, 0.2, 0.3]
69
            )
70
        },
71
    )
72
)
73
74
# create simple transformer object representing a gas power plant
75
energysystem.add(
76
    solph.components.Transformer(
77
        label="pp_gas",
78
        inputs={bgas: solph.Flow()},
79
        outputs={bel: solph.Flow(nominal_value=200)},
80
        conversion_factors={bel: 0.58},
81
    )
82
)
83
84
# initialise the operational model
85
model = solph.Model(energysystem)
86
87
# add the emission constraint
88
constraints.emission_limit(model, limit=100)
89
90
# print out the emission constraint
91
model.integral_limit_emission_factor_constraint.pprint()
92
model.integral_limit_emission_factor.pprint()
93
94
# solve the model
95
model.solve()
96
97
# print out the amount of emissions from the emission constraint
98
print(model.integral_limit_emission_factor())
99
100
results = solph.processing.results(model)
101
102
data = solph.views.node(results, "electricity")["sequences"]
103
ax = data.plot(kind="line", grid=True)
104
ax.set_xlabel("Time (h)")
105
ax.set_ylabel("P (MW)")
106
plt.show()
107