|
1
|
|
|
"""The central module containing all code dealing with fixing ehv subnetworks |
|
2
|
|
|
""" |
|
3
|
|
|
import geopandas as gpd |
|
4
|
|
|
import numpy as np |
|
5
|
|
|
import pandas as pd |
|
6
|
|
|
|
|
7
|
|
|
from egon.data import db |
|
8
|
|
|
from egon.data.config import settings |
|
9
|
|
|
from egon.data.datasets import Dataset |
|
10
|
|
|
from egon.data.datasets.etrago_setup import link_geom_from_buses |
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
class FixEhvSubnetworks(Dataset): |
|
14
|
|
|
def __init__(self, dependencies): |
|
15
|
|
|
super().__init__( |
|
16
|
|
|
name="FixEhvSubnetworks", |
|
17
|
|
|
version="0.0.1", |
|
18
|
|
|
dependencies=dependencies, |
|
19
|
|
|
tasks=run, |
|
20
|
|
|
) |
|
21
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
def select_bus_id(x, y, v_nom, scn_name, carrier): |
|
24
|
|
|
|
|
25
|
|
|
bus_id = db.select_dataframe( |
|
26
|
|
|
f""" |
|
27
|
|
|
SELECT bus_id |
|
28
|
|
|
FROM grid.egon_etrago_bus |
|
29
|
|
|
WHERE x = {x} |
|
30
|
|
|
AND y = {y} |
|
31
|
|
|
AND v_nom = {v_nom} |
|
32
|
|
|
AND scn_name = '{scn_name}' |
|
33
|
|
|
AND carrier = '{carrier}' |
|
34
|
|
|
""" |
|
35
|
|
|
) |
|
36
|
|
|
|
|
37
|
|
|
if bus_id.empty: |
|
38
|
|
|
return None |
|
39
|
|
|
else: |
|
40
|
|
|
return bus_id.bus_id[0] |
|
41
|
|
|
|
|
42
|
|
|
|
|
43
|
|
|
def add_bus(x, y, v_nom, scn_name): |
|
44
|
|
|
df = pd.DataFrame( |
|
45
|
|
|
index=[db.next_etrago_id("bus")], |
|
46
|
|
|
data={ |
|
47
|
|
|
"scn_name": scn_name, |
|
48
|
|
|
"v_nom": v_nom, |
|
49
|
|
|
"x": x, |
|
50
|
|
|
"y": y, |
|
51
|
|
|
"carrier": "AC", |
|
52
|
|
|
}, |
|
53
|
|
|
) |
|
54
|
|
|
gdf = gpd.GeoDataFrame( |
|
55
|
|
|
df, geometry=gpd.points_from_xy(df.x, df.y, crs=4326) |
|
56
|
|
|
).rename_geometry("geom") |
|
57
|
|
|
|
|
58
|
|
|
gdf.index.name = "bus_id" |
|
59
|
|
|
|
|
60
|
|
|
gdf.reset_index().to_postgis( |
|
61
|
|
|
"egon_etrago_bus", schema="grid", con=db.engine(), if_exists="append" |
|
62
|
|
|
) |
|
63
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
def drop_bus(x, y, v_nom, scn_name): |
|
66
|
|
|
bus = select_bus_id(x, y, v_nom, scn_name, carrier="AC") |
|
67
|
|
|
|
|
68
|
|
|
if bus != None: |
|
69
|
|
|
db.execute_sql( |
|
70
|
|
|
f""" |
|
71
|
|
|
DELETE FROM grid.egon_etrago_bus |
|
72
|
|
|
WHERE |
|
73
|
|
|
scn_name = '{scn_name}' |
|
74
|
|
|
AND bus_id = {bus} |
|
75
|
|
|
AND v_nom = {v_nom} |
|
76
|
|
|
AND carrier = 'AC' |
|
77
|
|
|
""" |
|
78
|
|
|
) |
|
79
|
|
|
|
|
80
|
|
|
|
|
81
|
|
|
def add_line(x0, y0, x1, y1, v_nom, scn_name, cables): |
|
82
|
|
|
bus0 = select_bus_id(x0, y0, v_nom, scn_name, carrier="AC") |
|
83
|
|
|
bus1 = select_bus_id(x1, y1, v_nom, scn_name, carrier="AC") |
|
84
|
|
|
|
|
85
|
|
|
df = pd.DataFrame( |
|
86
|
|
|
index=[db.next_etrago_id("line")], |
|
87
|
|
|
data={ |
|
88
|
|
|
"bus0": bus0, |
|
89
|
|
|
"bus1": bus1, |
|
90
|
|
|
"scn_name": scn_name, |
|
91
|
|
|
"v_nom": v_nom, |
|
92
|
|
|
"cables": cables, |
|
93
|
|
|
"carrier": "AC", |
|
94
|
|
|
}, |
|
95
|
|
|
) |
|
96
|
|
|
|
|
97
|
|
|
gdf = link_geom_from_buses(df, scn_name) |
|
98
|
|
|
|
|
99
|
|
|
gdf["length"] = gdf.to_crs(3035).topo.length.mul(1e-3) |
|
100
|
|
|
|
|
101
|
|
|
if v_nom == 220: |
|
102
|
|
|
s_nom = 520 |
|
103
|
|
|
x_per_km = 0.001 * 2 * np.pi * 50 |
|
104
|
|
|
|
|
105
|
|
|
elif v_nom == 380: |
|
106
|
|
|
s_nom = 1790 |
|
107
|
|
|
x_per_km = 0.0008 * 2 * np.pi * 50 |
|
108
|
|
|
|
|
109
|
|
|
gdf["s_nom"] = s_nom * gdf["cables"] / 3 |
|
|
|
|
|
|
110
|
|
|
|
|
111
|
|
|
gdf["x"] = (x_per_km * gdf["length"]) / (gdf["cables"] / 3) |
|
|
|
|
|
|
112
|
|
|
|
|
113
|
|
|
gdf.index.name = "line_id" |
|
114
|
|
|
|
|
115
|
|
|
gdf.reset_index().to_postgis( |
|
116
|
|
|
"egon_etrago_line", schema="grid", con=db.engine(), if_exists="append" |
|
117
|
|
|
) |
|
118
|
|
|
|
|
119
|
|
|
|
|
120
|
|
|
def drop_line(x0, y0, x1, y1, v_nom, scn_name): |
|
121
|
|
|
bus0 = select_bus_id(x0, y0, v_nom, scn_name, carrier="AC") |
|
122
|
|
|
bus1 = select_bus_id(x1, y1, v_nom, scn_name, carrier="AC") |
|
123
|
|
|
|
|
124
|
|
|
if (bus0 != None) and (bus1 != None): |
|
125
|
|
|
db.execute_sql( |
|
126
|
|
|
f""" |
|
127
|
|
|
DELETE FROM grid.egon_etrago_line |
|
128
|
|
|
WHERE |
|
129
|
|
|
scn_name = '{scn_name}' |
|
130
|
|
|
AND bus0 = {bus0} |
|
131
|
|
|
AND bus1 = {bus1} |
|
132
|
|
|
AND v_nom = {v_nom} |
|
133
|
|
|
""" |
|
134
|
|
|
) |
|
135
|
|
|
|
|
136
|
|
|
|
|
137
|
|
|
def add_trafo(x, y, v_nom0, v_nom1, scn_name, n=1): |
|
138
|
|
|
|
|
139
|
|
|
bus0 = select_bus_id(x, y, v_nom0, scn_name, carrier="AC") |
|
140
|
|
|
bus1 = select_bus_id(x, y, v_nom1, scn_name, carrier="AC") |
|
141
|
|
|
|
|
142
|
|
|
df = pd.DataFrame( |
|
143
|
|
|
index=[db.next_etrago_id("line")], |
|
144
|
|
|
data={ |
|
145
|
|
|
"bus0": bus0, |
|
146
|
|
|
"bus1": bus1, |
|
147
|
|
|
"scn_name": scn_name, |
|
148
|
|
|
}, |
|
149
|
|
|
) |
|
150
|
|
|
|
|
151
|
|
|
gdf = link_geom_from_buses(df, scn_name) |
|
152
|
|
|
|
|
153
|
|
|
if (v_nom0 == 220) & (v_nom1 == 380): |
|
154
|
|
|
s_nom = 600 |
|
155
|
|
|
x = 0.0002 |
|
156
|
|
|
|
|
157
|
|
|
gdf["s_nom"] = s_nom * n |
|
|
|
|
|
|
158
|
|
|
|
|
159
|
|
|
gdf["x"] = x / n |
|
160
|
|
|
|
|
161
|
|
|
gdf.index.name = "trafo_id" |
|
162
|
|
|
|
|
163
|
|
|
gdf.reset_index().to_postgis( |
|
164
|
|
|
"egon_etrago_transformer", |
|
165
|
|
|
schema="grid", |
|
166
|
|
|
con=db.engine(), |
|
167
|
|
|
if_exists="append", |
|
168
|
|
|
) |
|
169
|
|
|
|
|
170
|
|
|
|
|
171
|
|
|
def drop_trafo(x, y, v_nom0, v_nom1, scn_name): |
|
172
|
|
|
|
|
173
|
|
|
bus0 = select_bus_id(x, y, v_nom0, scn_name, carrier="AC") |
|
174
|
|
|
bus1 = select_bus_id(x, y, v_nom1, scn_name, carrier="AC") |
|
175
|
|
|
|
|
176
|
|
|
if (bus0 != None) and (bus1 != None): |
|
177
|
|
|
db.execute_sql( |
|
178
|
|
|
f""" |
|
179
|
|
|
DELETE FROM grid.egon_etrago_transformer |
|
180
|
|
|
WHERE |
|
181
|
|
|
scn_name = '{scn_name}' |
|
182
|
|
|
AND bus0 = {bus0} |
|
183
|
|
|
AND bus1 = {bus1} |
|
184
|
|
|
""" |
|
185
|
|
|
) |
|
186
|
|
|
|
|
187
|
|
|
|
|
188
|
|
|
def fix_subnetworks(scn_name): |
|
189
|
|
|
|
|
190
|
|
|
# Missing 220kV line to Lübeck Siems |
|
191
|
|
|
# add 220kV bus at substation Lübeck Siems |
|
192
|
|
|
add_bus(10.760835327266625, 53.90974536547805, 220, scn_name) |
|
193
|
|
|
# add 220/380kV transformer at substation Lübeck Siems |
|
194
|
|
|
add_trafo(10.760835327266625, 53.90974536547805, 220, 380, scn_name) |
|
195
|
|
|
|
|
196
|
|
|
# add 220kV line from Umspannwerk Lübeck to Lübeck Siems |
|
197
|
|
|
add_line( |
|
198
|
|
|
10.760835327266625, # Lübeck Siems |
|
199
|
|
|
53.90974536547805, |
|
200
|
|
|
10.640952461335745, # Umspannwerk Lübeck |
|
201
|
|
|
53.91944427801032, |
|
202
|
|
|
220, |
|
203
|
|
|
scn_name, |
|
204
|
|
|
3, |
|
205
|
|
|
) |
|
206
|
|
|
|
|
207
|
|
|
# Missing 220kV line from Audorf to Kiel |
|
208
|
|
|
add_line( |
|
209
|
|
|
# Audorf |
|
210
|
|
|
9.726992766257577, |
|
211
|
|
|
54.291420962253234, |
|
212
|
|
|
# Kiel |
|
213
|
|
|
9.9572075, |
|
214
|
|
|
54.321589, |
|
215
|
|
|
220, |
|
216
|
|
|
scn_name, |
|
217
|
|
|
6, |
|
218
|
|
|
) |
|
219
|
|
|
|
|
220
|
|
|
if settings()["egon-data"]["--dataset-boundary"] == "Everything": |
|
221
|
|
|
|
|
222
|
|
|
# Missing line from USW Uchtelfangen to 'Kraftwerk Weiher' |
|
223
|
|
|
add_line( |
|
224
|
|
|
7.032657738999395, # Kraftwerk Weiher |
|
225
|
|
|
49.33473737285781, |
|
226
|
|
|
6.996454674906, # Umspannwerk Uchtelfangen |
|
227
|
|
|
49.3754149606116, |
|
228
|
|
|
220, |
|
229
|
|
|
scn_name, |
|
230
|
|
|
6, |
|
231
|
|
|
) |
|
232
|
|
|
|
|
233
|
|
|
# Missing 380kV line near Elsfleth |
|
234
|
|
|
add_line( |
|
235
|
|
|
# Line |
|
236
|
|
|
8.419326700000001, |
|
237
|
|
|
53.229867000000006, |
|
238
|
|
|
# Schaltanlage Elsfleth/West |
|
239
|
|
|
8.402976949446648, |
|
240
|
|
|
53.2371468322213, |
|
241
|
|
|
380, |
|
242
|
|
|
scn_name, |
|
243
|
|
|
6, |
|
244
|
|
|
) |
|
245
|
|
|
|
|
246
|
|
|
# Missing 380kV line near Magdala |
|
247
|
|
|
add_line( |
|
248
|
|
|
# Line north south |
|
249
|
|
|
11.4298432, |
|
250
|
|
|
50.9117467, |
|
251
|
|
|
# Line east |
|
252
|
|
|
11.4295305, |
|
253
|
|
|
50.9115176, |
|
254
|
|
|
380, |
|
255
|
|
|
scn_name, |
|
256
|
|
|
3, |
|
257
|
|
|
) |
|
258
|
|
|
|
|
259
|
|
|
# Missing 220kV line near Frimmersdorf |
|
260
|
|
|
add_line( |
|
261
|
|
|
# Line west |
|
262
|
|
|
6.585418000000001, |
|
263
|
|
|
51.0495723, |
|
264
|
|
|
# Line east |
|
265
|
|
|
6.5867616, |
|
266
|
|
|
51.0520915, |
|
267
|
|
|
220, |
|
268
|
|
|
scn_name, |
|
269
|
|
|
6, |
|
270
|
|
|
) |
|
271
|
|
|
|
|
272
|
|
|
# Missing 220kV line from Wolmirstedt to Stendal |
|
273
|
|
|
add_line( |
|
274
|
|
|
# Wolmirstedt |
|
275
|
|
|
11.637225336209951, |
|
276
|
|
|
52.26707328151311, |
|
277
|
|
|
# Stendal |
|
278
|
|
|
11.7689, |
|
279
|
|
|
52.505533, |
|
280
|
|
|
220, |
|
281
|
|
|
scn_name, |
|
282
|
|
|
6, |
|
283
|
|
|
) |
|
284
|
|
|
|
|
285
|
|
|
# Plattling |
|
286
|
|
|
# Update way for osmTGmod in |
|
287
|
|
|
# 'LINESTRING (12.85328076018362 48.76616932172957, |
|
288
|
|
|
# 12.85221826521118 48.76597882857125, |
|
289
|
|
|
# 12.85092755963579 48.76451816626182, |
|
290
|
|
|
# 12.85081583430311 48.76336597271223, |
|
291
|
|
|
# 12.85089191559093 48.76309793961921, |
|
292
|
|
|
# 12.85171674549663 48.76313124988151, |
|
293
|
|
|
# 12.85233496021983 48.76290980724934, |
|
294
|
|
|
# 12.85257485139349 48.76326650768988, |
|
295
|
|
|
# 12.85238077788078 48.76354965879587, |
|
296
|
|
|
# 12.85335698387775 48.76399030383004, |
|
297
|
|
|
# 12.85444925633996 48.76422235417385, |
|
298
|
|
|
# 12.853289544662 48.76616304929393)' |
|
299
|
|
|
|
|
300
|
|
|
# Lamspringe 380kV lines |
|
301
|
|
|
drop_line( |
|
302
|
|
|
9.988215035677026, |
|
303
|
|
|
51.954230057487926, |
|
304
|
|
|
9.991477300000001, |
|
305
|
|
|
51.939711, |
|
306
|
|
|
380, |
|
307
|
|
|
scn_name, |
|
308
|
|
|
) |
|
309
|
|
|
|
|
310
|
|
|
drop_line( |
|
311
|
|
|
9.995589, |
|
312
|
|
|
51.969716000000005, |
|
313
|
|
|
9.988215035677026, |
|
314
|
|
|
51.954230057487926, |
|
315
|
|
|
380, |
|
316
|
|
|
scn_name, |
|
317
|
|
|
) |
|
318
|
|
|
|
|
319
|
|
|
drop_line( |
|
320
|
|
|
9.982829, |
|
321
|
|
|
51.985980000000005, |
|
322
|
|
|
9.995589, |
|
323
|
|
|
51.969716000000005, |
|
324
|
|
|
380, |
|
325
|
|
|
scn_name, |
|
326
|
|
|
) |
|
327
|
|
|
|
|
328
|
|
|
drop_line( |
|
329
|
|
|
10.004865, |
|
330
|
|
|
51.999120000000005, |
|
331
|
|
|
9.982829, |
|
332
|
|
|
51.985980000000005, |
|
333
|
|
|
380, |
|
334
|
|
|
scn_name, |
|
335
|
|
|
) |
|
336
|
|
|
|
|
337
|
|
|
drop_line( |
|
338
|
|
|
10.174395, |
|
339
|
|
|
52.036448, |
|
340
|
|
|
9.988215035677026, |
|
341
|
|
|
51.954230057487926, |
|
342
|
|
|
380, |
|
343
|
|
|
scn_name, |
|
344
|
|
|
) |
|
345
|
|
|
|
|
346
|
|
|
drop_line( |
|
347
|
|
|
10.195144702845797, |
|
348
|
|
|
52.079851837273964, |
|
349
|
|
|
10.174395, |
|
350
|
|
|
52.036448, |
|
351
|
|
|
380, |
|
352
|
|
|
scn_name, |
|
353
|
|
|
) |
|
354
|
|
|
|
|
355
|
|
|
drop_trafo(9.988215035677026, 51.954230057487926, 110, 380, scn_name) |
|
356
|
|
|
|
|
357
|
|
|
drop_bus(9.988215035677026, 51.954230057487926, 380, scn_name) |
|
358
|
|
|
drop_bus(9.991477300000001, 51.939711, 380, scn_name) |
|
359
|
|
|
drop_bus(9.995589, 51.969716000000005, 380, scn_name) |
|
360
|
|
|
drop_bus(9.982829, 51.985980000000005, 380, scn_name) |
|
361
|
|
|
drop_bus(10.174395, 52.036448, 380, scn_name) |
|
362
|
|
|
drop_bus(10.195144702845797, 52.079851837273964, 380, scn_name) |
|
363
|
|
|
|
|
364
|
|
|
drop_bus(10.004865, 51.999120000000005, 380, scn_name) |
|
365
|
|
|
|
|
366
|
|
|
# Umspannwerk Vieselbach |
|
367
|
|
|
# delete isolated bus and trafo |
|
368
|
|
|
drop_bus(11.121774798935334, 51.00038603925895, 380, scn_name) |
|
369
|
|
|
drop_trafo(11.121774798935334, 51.00038603925895, 220, 380, scn_name) |
|
370
|
|
|
|
|
371
|
|
|
# Umspannwerk Waldlaubersheim |
|
372
|
|
|
# delete isolated bus and trafo |
|
373
|
|
|
drop_bus(7.815993836091339, 49.92211102637183, 380, scn_name) |
|
374
|
|
|
drop_trafo(7.815993836091339, 49.92211102637183, 110, 380, scn_name) |
|
375
|
|
|
|
|
376
|
|
|
|
|
377
|
|
|
def run(): |
|
378
|
|
|
fix_subnetworks("eGon2035") |
|
379
|
|
|
fix_subnetworks("eGon100RE") |
|
380
|
|
|
|