-
Notifications
You must be signed in to change notification settings - Fork 0
/
auslegung.py
265 lines (220 loc) · 7.79 KB
/
auslegung.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
"""
This script is used to find the optimal parameters for the scaling of a battery storage
The household data is taken from the [*Standard Battery Application Profiles (SBAP) paper*](https://doi.org/10.1016/j.est.2019.101077)
"""
import pandas as pd
from tqdm import tqdm
def electricity_costs(grid_profile, electricity_price, feedin_tariff):
grid_sell = (
grid_profile.loc[grid_profile < 0].sum() * 0.25 * feedin_tariff * -1
) # negative sign
grid_buy = grid_profile.loc[grid_profile > 0].sum() * 0.25 * electricity_price
return grid_buy - grid_sell
def self_consumption(grid_profile, pv_profile):
feedin = grid_profile[grid_profile < 0].sum() * -1
pv = pv_profile.sum()
return 1 - (feedin / pv)
def self_sufficiency(grid_profile, load_profile):
gridbuy = grid_profile[grid_profile > 0].sum()
load = load_profile.sum()
return 1 - (gridbuy / load)
def print_results(
results,
simulation,
total_demand,
total_generation,
capacity,
max_power_charging,
max_power_discharging,
costs,
ssr,
scr,
):
print("Simulation: " + simulation)
print(f"Total demand: {total_demand:.0f} kWh")
print(f"Total generation: {total_generation:.0f} kWh")
print(f"Capacity: {capacity:.3f} kWh")
print(f"Max Power Charging:{max_power_charging:.3f} kW")
print(f"Max Power Discharging: {max_power_discharging:.3f} kW")
print(f"Electricity costs: {costs:.2f} €")
print(f"Self-sufficiency: {ssr*100:.2f} %")
print(f"Self-consumption: {scr*100:.2f} %")
results.loc[len(results)] = {
"simulation": simulation,
"total_demand": total_demand,
"total_generation": total_generation,
"capacity": capacity,
"max_power_charging": max_power_charging,
"max_power_discharging": max_power_discharging,
"costs": costs,
"ssr": ssr,
"scr": scr,
}
def greedy_strategy(
profile,
capacity,
max_power_charge,
max_power_discharge,
eff_charge,
eff_discharge,
initial_soc,
dt,
):
df = profile.copy() # make a new copy of the dataframe
# add new empty columns to the dataframe
df["grid"] = 0.0 # grid power in kW
df["power"] = 0.0 # battery power in kW
df["soc"] = 0.0 # battery SOC in p.u.
soc = initial_soc
for time, residual in profile["residual"].items():
if residual < 0:
# charge
power = min(abs(residual), max_power_charge)
soc_new = min(soc + (power * dt * eff_charge) / capacity, 1.0)
power_real = -(soc_new - soc) * capacity / dt * (1 / eff_charge)
else:
# discharge
power = min(abs(residual), max_power_discharge)
soc_new = max(soc - (power * dt * (1 / eff_discharge)) / capacity, 0.0)
power_real = -(soc_new - soc) * capacity / dt * eff_discharge
grid = residual - power_real
soc = soc_new
df.loc[time, "grid"] = grid
df.loc[time, "power"] = power_real
df.loc[time, "soc"] = soc
return df
if __name__ == "__main__":
pd.options.plotting.backend = "plotly"
template = "plotly_white"
electricity_price = 0.40
feedin_tariff = 0.00
eff_charge = 0.85
eff_discharge = 0.8
initial_soc = 0.5
dt = 0.25
# Choose Simulation here:
"""processed
name = "Simulation1"
max_power_charge = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1]
max_power_discharge = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1]
capacity = [0.5, 0.75, 1, 1.25, 1.5, 1.75, 2, 2.25, 2.5, 2.75, 3]
"""
"""processed
name = "Simulation2"
max_power_charge = [0.4, 0.5, 0.6, 0.7]
max_power_discharge = [0.1, 0.2, 0.3, 0.4]
capacity = [0.9, 1, 1.1, 1.2]
"""
"""processed
name = "Simulation3"
max_power_charge = [0.6]
max_power_discharge = [0.3]
capacity = [0.25, 0.5, 0.75, 1, 1.25, 1.5, 1.75, 2, 2.25, 2.5, 2.75, 3, 3.5, 4.0]
"""
"""processed
name = "Simulation4"
max_power_charge = [0.4, 0.5, 0.6, 0.7, 0.8]
max_power_discharge = [0.4, 0.5, 0.6, 0.7, 0.8]
capacity = [0.75, 1, 1.25, 1.5]
"""
"""processed
name = "Simulation5"
max_power_charge = [0.4, 0.5, 0.6, 0.7, 0.8]
max_power_discharge = [0.1, 0.2, 0.3, 0.4, 0.5]
capacity = [1]
"""
"""processed
name = "Simulation6"
max_power_charge = [0.5, 0.6, 0.7, 0.8]
max_power_discharge = [0.2, 0.3, 0.4, 0.5]
capacity = [1]
"""
#"""processed
name = "Simulation7"
max_power_charge = [0.1, 0.3, 0.5, 0.7, 0.9, 1.1]
max_power_discharge = [0.1, 0.3, 0.5, 0.7, 0.9, 1.1]
capacity = [0.5, 0.75, 1, 1.25, 1.5, 1.75, 2, 2.25, 2.5]
#"""
# Original data
profile = pd.read_csv("./data/household_profile.csv", index_col=0, parse_dates=True)
# profile.plot(template=template, labels={"value": "Power [kW]"})
# Data for 600 Wp PV and 2 Person household
profile["pv"] = profile["pv"] / 8
profile["load"] = profile["load"] / 2
# profile.plot(template=template, labels={"value": "Power [kW]"})
profile["residual"] = profile["load"] - profile["pv"]
# profile["residual"].plot(template=template, labels={"value": "Power [kW]"})
simulation = "Without Storage"
# demand/consumption
total_demand = profile["load"].sum() * dt
total_generation = profile["pv"].sum() * dt
# electricity costs
costs = electricity_costs(profile["residual"], electricity_price, feedin_tariff)
# self-consumption / self-sufficiency
ssr = self_sufficiency(profile["residual"], profile["load"])
scr = self_consumption(profile["residual"], profile["pv"])
results = pd.DataFrame(
columns=[
"simulation",
"total_demand",
"total_generation",
"capacity",
"max_power_charging",
"max_power_discharging",
"costs",
"ssr",
"scr",
]
)
print_results(
results=results,
simulation=simulation,
total_demand=total_demand,
total_generation=total_generation,
capacity=0,
max_power_charging=0,
max_power_discharging=0,
costs=costs,
ssr=ssr,
scr=scr,
)
with tqdm(
total=len(capacity) * len(max_power_charge) * len(max_power_discharge)
) as pbar:
for x in capacity:
for y in max_power_charge:
for z in max_power_discharge:
df_greedy = greedy_strategy(
profile,
x,
y,
z,
eff_charge,
eff_discharge,
initial_soc,
dt,
)
# df_greedy[["residual", "power"]].plot(template=template, labels={"value": "Power [kW]"})
# df_greedy["soc"].plot(template=template, labels={"value": "SOC"})
costs = electricity_costs(
df_greedy["grid"], electricity_price, feedin_tariff
)
ssr = self_sufficiency(df_greedy["grid"], df_greedy["load"])
scr = self_consumption(df_greedy["grid"], df_greedy["pv"])
simulation = "Greedy"
print_results(
results,
simulation,
total_demand,
total_generation,
x,
y,
z,
costs,
ssr,
scr,
)
pbar.update(1)
print("\n")
results.to_csv("./results/auslegung/auslegung" + name + ".csv")
print(results)