district_heating_supply_1   A
last analyzed

Complexity

Total Complexity 0

Size/Duplication

Total Lines 113
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 0
eloc 58
dl 0
loc 113
rs 10
c 0
b 0
f 0
1
from helpers import LCOH
2
3
# %%[sec_1_start]
4
import pandas as pd
5
6
data = pd.read_csv("input_data.csv", sep=";", index_col=0, parse_dates=True)
7
# %%[sec_1_end]
8
9
# %%[sec_2_start]
10
import oemof.solph as solph
11
12
district_heating_system = solph.EnergySystem(
13
    timeindex=data.index, infer_last_interval=False
14
)
15
# %%[sec_2_end]
16
17
# %%[sec_3_start]
18
heat_bus = solph.Bus(label="heat network")
19
gas_bus = solph.Bus(label="gas network")
20
21
district_heating_system.add(heat_bus, gas_bus)
22
# %%[sec_3_end]
23
24
# %%[sec_4_start]
25
gas_source = solph.components.Source(
26
    label="gas source",
27
    outputs={gas_bus: solph.flows.Flow(variable_costs=data["gas price"])},
28
)
29
30
# nominal_value -> nominal_capacity
31
heat_sink = solph.components.Sink(
32
    label="heat sink",
33
    inputs={
34
        heat_bus: solph.flows.Flow(
35
            nominal_value=data["heat demand"].max(),
36
            fix=data["heat demand"] / data["heat demand"].max(),
37
        )
38
    },
39
)
40
41
district_heating_system.add(heat_sink, gas_source)
42
# %%[sec_4_end]
43
44
# %%[sec_5_start]
45
gas_boiler = solph.components.Converter(
46
    label="gas boiler",
47
    inputs={gas_bus: solph.flows.Flow()},
48
    outputs={
49
        heat_bus: solph.flows.Flow(
50
            nominal_value=data["heat demand"].max(), variable_costs=1.10
51
        )
52
    },
53
    conversion_factors={gas_bus: 0.95},
54
)
55
56
district_heating_system.add(gas_boiler)
57
# %%[sec_5_end]
58
59
# %%[sec_6_start]
60
model = solph.Model(district_heating_system)
61
model.solve(solver="cbc", solve_kwargs={"tee": True})
62
# %%[sec_6_end]
63
64
# %%[sec_7_start]
65
results = solph.processing.results(model)
66
67
data_gas_bus = solph.views.node(results, "gas network")["sequences"]
68
data_heat_bus = solph.views.node(results, "heat network")["sequences"]
69
# %%[sec_7_end]
70
71
72
# %%[sec_8_start]
73
import matplotlib.pyplot as plt
74
75
# plt.style.use('dark_background')
76
77
fig, ax = plt.subplots(figsize=[10, 6])
78
79
ax.bar(
80
    data_heat_bus.index,
81
    data_heat_bus[(("gas boiler", "heat network"), "flow")],
82
    label="gas boiler",
83
    color="#EC6707",
84
)
85
86
ax.legend(loc="upper right")
87
ax.grid(axis="y")
88
ax.set_ylabel("Hourly heat production in MWh")
89
90
# plt.tight_layout()
91
# plt.savefig('intro_tut_dhs_1_hourly_heat_production.svg')
92
plt.show()
93
# %%[sec_8_end]
94
95
# %%[sec_9_start]
96
spec_inv_gas_boiler = 50000
97
cap_gas_boiler = 20
98
var_cost_gas_boiler = 1.10
99
100
invest_cost = spec_inv_gas_boiler * cap_gas_boiler
101
operation_cost = (
102
    var_cost_gas_boiler
103
    * data_heat_bus[(("gas boiler", "heat network"), "flow")].sum()
104
    + (
105
        data["gas price"]
106
        * data_gas_bus[(("gas network", "gas boiler"), "flow")]
107
    ).sum()
108
)
109
heat_produced = data_heat_bus[(("heat network", "heat sink"), "flow")].sum()
110
111
lcoh = LCOH(invest_cost, operation_cost, heat_produced)
112
print(f"LCOH: {lcoh:.2f} €/MWh")
113
# %%[sec_9_end]
114