1
|
|
|
# coding: utf-8 |
2
|
|
|
import datetime |
3
|
|
|
import json |
4
|
|
|
|
5
|
|
|
from geoalchemy2.types import Geometry |
6
|
|
|
from shapely.geometry import LineString |
7
|
|
|
from sqlalchemy import schema # ??? |
8
|
|
|
from sqlalchemy import ( |
9
|
|
|
ARRAY, |
10
|
|
|
BigInteger, |
11
|
|
|
Boolean, |
12
|
|
|
Column, |
13
|
|
|
DateTime, |
14
|
|
|
Float, |
15
|
|
|
Integer, |
16
|
|
|
Numeric, |
17
|
|
|
String, |
18
|
|
|
Text, |
19
|
|
|
text, |
20
|
|
|
) |
21
|
|
|
from sqlalchemy.ext.declarative import declarative_base |
22
|
|
|
import geopandas as gpd |
23
|
|
|
import pandas as pd |
24
|
|
|
import pypsa |
25
|
|
|
|
26
|
|
|
from egon.data import db |
27
|
|
|
from egon.data.datasets import Dataset |
28
|
|
|
from egon.data.metadata import context, contributors, meta_metadata, sources |
29
|
|
|
|
30
|
|
|
Base = declarative_base() |
31
|
|
|
metadata = Base.metadata |
32
|
|
|
|
33
|
|
|
network = pypsa.Network() |
34
|
|
|
# add Storage key (called StorageUnit in PyPSA) |
35
|
|
|
network.component_attrs["Storage"] = network.component_attrs["StorageUnit"] |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
def get_pypsa_field_descriptors(component, timeseries=False): |
39
|
|
|
|
40
|
|
|
ident = component.lower() + "_id" |
41
|
|
|
|
42
|
|
|
data = network.component_attrs[component].rename({"name": ident}) |
43
|
|
|
data = data[data.status != "Output"] |
44
|
|
|
|
45
|
|
|
if timeseries: |
46
|
|
|
data = data[data["type"].str.contains("series")] |
47
|
|
|
data.loc["temp_id"] = [ |
48
|
|
|
"integer", |
49
|
|
|
"n/a", |
50
|
|
|
"n/a", |
51
|
|
|
"Unique identifyier of temporal index", |
52
|
|
|
"Input", |
53
|
|
|
] |
54
|
|
|
|
55
|
|
|
data.loc[ident, "type"] = "int" |
56
|
|
|
data.loc["scn_name"] = [ |
57
|
|
|
"string", |
58
|
|
|
"n/a", |
59
|
|
|
"n/a", |
60
|
|
|
"Name of the eGon scenario", |
61
|
|
|
"Input", |
62
|
|
|
] |
63
|
|
|
data.unit.fillna("none", inplace=True) |
64
|
|
|
data.default.fillna("n/a", inplace=True) |
65
|
|
|
return data |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
def get_meta( |
69
|
|
|
schema, |
70
|
|
|
component, |
71
|
|
|
description="TODO", |
72
|
|
|
source_list=[], |
73
|
|
|
license_list=[], |
74
|
|
|
contributor_list=[], |
75
|
|
|
timeseries=False, |
76
|
|
|
): |
77
|
|
|
|
78
|
|
|
table = "egon_etrago_" + component.lower() |
79
|
|
|
|
80
|
|
|
if timeseries: |
81
|
|
|
table = table + "_timeseries" |
82
|
|
|
fields = ( |
83
|
|
|
get_pypsa_field_descriptors(component, timeseries) |
84
|
|
|
.reset_index() |
85
|
|
|
.to_dict(orient="records") |
86
|
|
|
) |
87
|
|
|
# geometry column still missing |
88
|
|
|
|
89
|
|
|
meta = { |
90
|
|
|
"name": schema + "." + table, |
91
|
|
|
"title": component, |
92
|
|
|
"id": "WILL_BE_SET_AT_PUBLICATION", |
93
|
|
|
# no automatic description? PyPSA descriptions do not quite fit our |
94
|
|
|
# scope |
95
|
|
|
"description": description, |
96
|
|
|
"language": ["en-EN"], |
97
|
|
|
"publicationDate": datetime.date.today().isoformat(), |
98
|
|
|
"context": context(), |
99
|
|
|
"spatial": { |
100
|
|
|
"location": None, |
101
|
|
|
"extent": "Germany", |
102
|
|
|
"resolution": None, |
103
|
|
|
}, |
104
|
|
|
"sources": source_list, |
105
|
|
|
"licenses": license_list, |
106
|
|
|
"contributors": contributor_list, |
107
|
|
|
"resources": [ |
108
|
|
|
{ |
109
|
|
|
"profile": "tabular-data-resource", |
110
|
|
|
"name": schema + "." + table, |
111
|
|
|
"path": None, |
112
|
|
|
"format": "PostgreSQL", |
113
|
|
|
"encoding": "UTF-8", |
114
|
|
|
"schema": { |
115
|
|
|
"fields": fields, |
116
|
|
|
"primaryKey": ["scn_name", component.lower() + "_id"], |
117
|
|
|
"foreignKeys": [], |
118
|
|
|
}, |
119
|
|
|
"dialect": { |
120
|
|
|
"delimiter": "", |
121
|
|
|
"decimalSeparator": "" |
122
|
|
|
}, |
123
|
|
|
} |
124
|
|
|
], |
125
|
|
|
"metaMetadata": meta_metadata(), |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
# Create json dump |
129
|
|
|
meta_json = "'" + json.dumps(meta, indent=4, ensure_ascii=False) + "'" |
130
|
|
|
|
131
|
|
|
return meta_json |
132
|
|
|
|
133
|
|
|
|
134
|
|
|
class EtragoSetup(Dataset): |
135
|
|
|
def __init__(self, dependencies): |
136
|
|
|
super().__init__( |
137
|
|
|
name="EtragoSetup", |
138
|
|
|
version="0.0.11", |
139
|
|
|
dependencies=dependencies, |
140
|
|
|
tasks=(create_tables, {temp_resolution, insert_carriers}), |
141
|
|
|
) |
142
|
|
|
|
143
|
|
|
|
144
|
|
|
class EgonPfHvBus(Base): |
145
|
|
|
|
146
|
|
|
source_list = [ |
147
|
|
|
sources()["egon-data"], |
148
|
|
|
sources()["openstreetmap"], |
149
|
|
|
sources()["peta"], |
150
|
|
|
sources()["SciGRID_gas"], |
151
|
|
|
sources()["bgr_inspeeds_data_bundle"], |
152
|
|
|
] |
153
|
|
|
|
154
|
|
|
contributor_list = contributors(["ic", "cb", "ke", "an", "fw"]) |
155
|
|
|
contributor_list[0]["comment"] = "Added electricity substations" |
156
|
|
|
contributor_list[1]["comment"] = "Added heat buses" |
157
|
|
|
contributor_list[2]["comment"] = "Added DSM buses" |
158
|
|
|
contributor_list[3]["comment"] = "Added CH4 sector buses" |
159
|
|
|
contributor_list[4]["comment"] = "Added H2 sector buses" |
160
|
|
|
|
161
|
|
|
license_list = [data["licenses"][0] for data in source_list] |
162
|
|
|
|
163
|
|
|
__tablename__ = "egon_etrago_bus" |
164
|
|
|
__table_args__ = { |
165
|
|
|
"schema": "grid", |
166
|
|
|
"comment": get_meta( |
167
|
|
|
"grid", |
168
|
|
|
"Bus", |
169
|
|
|
source_list=source_list, |
170
|
|
|
license_list=license_list, |
171
|
|
|
contributor_list=contributor_list, |
172
|
|
|
), |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
scn_name = Column(String, primary_key=True, nullable=False) |
176
|
|
|
bus_id = Column(BigInteger, primary_key=True, nullable=False) |
177
|
|
|
v_nom = Column(Float(53), server_default="1.") |
178
|
|
|
type = Column(Text) |
179
|
|
|
carrier = Column(Text) |
180
|
|
|
v_mag_pu_set = Column(Float(53)) |
181
|
|
|
v_mag_pu_min = Column(Float(53), server_default="0.") |
182
|
|
|
v_mag_pu_max = Column(Float(53), server_default="inf") |
183
|
|
|
x = Column(Float(53), server_default="0.") |
184
|
|
|
y = Column(Float(53), server_default="0.") |
185
|
|
|
geom = Column(Geometry("POINT", 4326), index=True) |
186
|
|
|
country = Column(Text, server_default=text("'DE'::text")) |
187
|
|
|
|
188
|
|
|
|
189
|
|
View Code Duplication |
class EgonPfHvBusTimeseries(Base): |
|
|
|
|
190
|
|
|
|
191
|
|
|
source_list = [ |
192
|
|
|
sources()["egon-data"], |
193
|
|
|
] |
194
|
|
|
|
195
|
|
|
contributor_list = contributors(["cb"]) |
196
|
|
|
contributor_list[0]["comment"] = "Added metadata" |
197
|
|
|
|
198
|
|
|
license_list = [data["licenses"][0] for data in source_list] |
199
|
|
|
|
200
|
|
|
__tablename__ = "egon_etrago_bus_timeseries" |
201
|
|
|
__table_args__ = { |
202
|
|
|
"schema": "grid", |
203
|
|
|
"comment": get_meta( |
204
|
|
|
"grid", |
205
|
|
|
"Bus", |
206
|
|
|
source_list=source_list, |
207
|
|
|
license_list=license_list, |
208
|
|
|
contributor_list=contributor_list, |
209
|
|
|
timeseries=True, |
210
|
|
|
), |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
scn_name = Column(String, primary_key=True, nullable=False) |
214
|
|
|
bus_id = Column(BigInteger, primary_key=True, nullable=False) |
215
|
|
|
v_mag_pu_set = Column(ARRAY(Float(precision=53))) |
216
|
|
|
|
217
|
|
|
|
218
|
|
|
class EgonPfHvGenerator(Base): |
219
|
|
|
|
220
|
|
|
source_list = [ |
221
|
|
|
sources()["egon-data"], |
222
|
|
|
sources()["openstreetmap"], |
223
|
|
|
sources()["mastr"], |
224
|
|
|
sources()["nep2021"], |
225
|
|
|
sources()["tyndp"], |
226
|
|
|
sources()["SciGRID_gas"], |
227
|
|
|
sources()["Einspeiseatlas"], |
228
|
|
|
sources()["technology-data"], |
229
|
|
|
sources()["vg250"], |
230
|
|
|
] |
231
|
|
|
|
232
|
|
|
contributor_list = contributors(["ic", "cb", "ce", "an", "ke"]) |
233
|
|
|
contributor_list[0]["comment"] = "Added hydro and biomass plants" |
234
|
|
|
contributor_list[1]["comment"] = "Added solar and geothermal plants" |
235
|
|
|
contributor_list[2]["comment"] = "Added wind on- and offshore plants" |
236
|
|
|
contributor_list[3]["comment"] = "Added gas feedin generators" |
237
|
|
|
contributor_list[4]["comment"] = "Added pv ground mounted" |
238
|
|
|
|
239
|
|
|
license_list = [data["licenses"][0] for data in source_list] |
240
|
|
|
|
241
|
|
|
__tablename__ = "egon_etrago_generator" |
242
|
|
|
__table_args__ = { |
243
|
|
|
"schema": "grid", |
244
|
|
|
"comment": get_meta( |
245
|
|
|
"grid", |
246
|
|
|
"Generator", |
247
|
|
|
source_list=source_list, |
248
|
|
|
license_list=license_list, |
249
|
|
|
contributor_list=contributor_list, |
250
|
|
|
), |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
scn_name = Column(String, primary_key=True, nullable=False) |
254
|
|
|
generator_id = Column(BigInteger, primary_key=True, nullable=False) |
255
|
|
|
bus = Column(BigInteger) |
256
|
|
|
control = Column(Text) |
257
|
|
|
type = Column(Text) |
258
|
|
|
carrier = Column(Text) |
259
|
|
|
p_nom = Column(Float(53), server_default="0.") |
260
|
|
|
p_nom_extendable = Column(Boolean, server_default="False") |
261
|
|
|
p_nom_min = Column(Float(53), server_default="0.") |
262
|
|
|
p_nom_max = Column(Float(53), server_default="inf") |
263
|
|
|
p_min_pu = Column(Float(53), server_default="0.") |
264
|
|
|
p_max_pu = Column(Float(53), server_default="1.") |
265
|
|
|
p_set = Column(Float(53)) |
266
|
|
|
q_set = Column(Float(53)) |
267
|
|
|
sign = Column(Float(53), server_default="1.") |
268
|
|
|
marginal_cost = Column(Float(53), server_default="0.") |
269
|
|
|
build_year = Column(BigInteger, server_default="0") |
270
|
|
|
lifetime = Column(Float(53), server_default="inf") |
271
|
|
|
capital_cost = Column(Float(53), server_default="0.") |
272
|
|
|
efficiency = Column(Float(53), server_default="1.") |
273
|
|
|
committable = Column(Boolean, server_default="False") |
274
|
|
|
start_up_cost = Column(Float(53), server_default="0.") |
275
|
|
|
shut_down_cost = Column(Float(53), server_default="0.") |
276
|
|
|
min_up_time = Column(BigInteger, server_default="0") |
277
|
|
|
min_down_time = Column(BigInteger, server_default="0") |
278
|
|
|
up_time_before = Column(BigInteger, server_default="0") |
279
|
|
|
down_time_before = Column(BigInteger, server_default="0") |
280
|
|
|
ramp_limit_up = Column(Float(53), server_default="NaN") |
281
|
|
|
ramp_limit_down = Column(Float(53), server_default="NaN") |
282
|
|
|
ramp_limit_start_up = Column(Float(53), server_default="1.") |
283
|
|
|
ramp_limit_shut_down = Column(Float(53), server_default="1.") |
284
|
|
|
e_nom_max = Column( |
285
|
|
|
Float(53), server_default="inf" |
286
|
|
|
) # [MWh(/y)] Value to be used in eTraGo to set constraint for the production over the year |
287
|
|
|
|
288
|
|
|
|
289
|
|
|
class EgonPfHvGeneratorTimeseries(Base): |
290
|
|
|
|
291
|
|
|
source_list = [ |
292
|
|
|
sources()["egon-data"], |
293
|
|
|
sources()["era5"], |
294
|
|
|
] |
295
|
|
|
|
296
|
|
|
contributor_list = contributors(["cb"]) |
297
|
|
|
contributor_list[0][ |
298
|
|
|
"comment" |
299
|
|
|
] = "Added p_max_pu timeseries for pv and wind" |
300
|
|
|
|
301
|
|
|
license_list = [data["licenses"][0] for data in source_list] |
302
|
|
|
|
303
|
|
|
__tablename__ = "egon_etrago_generator_timeseries" |
304
|
|
|
__table_args__ = { |
305
|
|
|
"schema": "grid", |
306
|
|
|
"comment": get_meta( |
307
|
|
|
"grid", |
308
|
|
|
"Generator", |
309
|
|
|
source_list=source_list, |
310
|
|
|
license_list=license_list, |
311
|
|
|
contributor_list=contributor_list, |
312
|
|
|
timeseries=True, |
313
|
|
|
), |
314
|
|
|
} |
315
|
|
|
|
316
|
|
|
scn_name = Column(String, primary_key=True, nullable=False) |
317
|
|
|
generator_id = Column(Integer, primary_key=True, nullable=False) |
318
|
|
|
temp_id = Column(Integer, primary_key=True, nullable=False) |
319
|
|
|
p_set = Column(ARRAY(Float(precision=53))) |
320
|
|
|
q_set = Column(ARRAY(Float(precision=53))) |
321
|
|
|
p_min_pu = Column(ARRAY(Float(precision=53))) |
322
|
|
|
p_max_pu = Column(ARRAY(Float(precision=53))) |
323
|
|
|
marginal_cost = Column(ARRAY(Float(precision=53))) |
324
|
|
|
|
325
|
|
|
|
326
|
|
View Code Duplication |
class EgonPfHvLine(Base): |
|
|
|
|
327
|
|
|
|
328
|
|
|
source_list = [ |
329
|
|
|
sources()["egon-data"], |
330
|
|
|
sources()["openstreetmap"], |
331
|
|
|
] |
332
|
|
|
|
333
|
|
|
contributor_list = contributors(["ic", "cb"]) |
334
|
|
|
contributor_list[0]["comment"] = "Added lines from osmTGmod tables" |
335
|
|
|
contributor_list[1]["comment"] = "Added meta data" |
336
|
|
|
|
337
|
|
|
license_list = [data["licenses"][0] for data in source_list] |
338
|
|
|
|
339
|
|
|
__tablename__ = "egon_etrago_line" |
340
|
|
|
__table_args__ = { |
341
|
|
|
"schema": "grid", |
342
|
|
|
"comment": get_meta( |
343
|
|
|
"grid", |
344
|
|
|
"Line", |
345
|
|
|
source_list=source_list, |
346
|
|
|
license_list=license_list, |
347
|
|
|
contributor_list=contributor_list, |
348
|
|
|
), |
349
|
|
|
} |
350
|
|
|
|
351
|
|
|
scn_name = Column(String, primary_key=True, nullable=False) |
352
|
|
|
line_id = Column(BigInteger, primary_key=True, nullable=False) |
353
|
|
|
bus0 = Column(BigInteger) |
354
|
|
|
bus1 = Column(BigInteger) |
355
|
|
|
type = Column(Text) |
356
|
|
|
carrier = Column(Text) |
357
|
|
|
x = Column(Numeric, server_default="0.") |
358
|
|
|
r = Column(Numeric, server_default="0.") |
359
|
|
|
g = Column(Numeric, server_default="0.") |
360
|
|
|
b = Column(Numeric, server_default="0.") |
361
|
|
|
s_nom = Column(Numeric, server_default="0.") |
362
|
|
|
s_nom_extendable = Column(Boolean, server_default="False") |
363
|
|
|
s_nom_min = Column(Float(53), server_default="0.") |
364
|
|
|
s_nom_max = Column(Float(53), server_default="inf") |
365
|
|
|
s_max_pu = Column(Float(53), server_default="1.") |
366
|
|
|
build_year = Column(BigInteger, server_default="0") |
367
|
|
|
lifetime = Column(Float(53), server_default="inf") |
368
|
|
|
capital_cost = Column(Float(53), server_default="0.") |
369
|
|
|
length = Column(Float(53), server_default="0.") |
370
|
|
|
cables = Column(Integer) |
371
|
|
|
terrain_factor = Column(Float(53), server_default="1.") |
372
|
|
|
num_parallel = Column(Float(53), server_default="1.") |
373
|
|
|
v_ang_min = Column(Float(53), server_default="-inf") |
374
|
|
|
v_ang_max = Column(Float(53), server_default="inf") |
375
|
|
|
v_nom = Column(Float(53)) |
376
|
|
|
geom = Column(Geometry("MULTILINESTRING", 4326)) |
377
|
|
|
topo = Column(Geometry("LINESTRING", 4326)) |
378
|
|
|
|
379
|
|
|
|
380
|
|
|
class EgonPfHvLineTimeseries(Base): |
381
|
|
|
|
382
|
|
|
source_list = [ |
383
|
|
|
sources()["egon-data"], |
384
|
|
|
sources()["nep2021"], |
385
|
|
|
sources()["era5"], |
386
|
|
|
] |
387
|
|
|
|
388
|
|
|
contributor_list = contributors(["ce", "cb"]) |
389
|
|
|
contributor_list[0]["comment"] = "Added s_max_pu timeseries" |
390
|
|
|
contributor_list[1]["comment"] = "Added meta data" |
391
|
|
|
|
392
|
|
|
license_list = [data["licenses"][0] for data in source_list] |
393
|
|
|
|
394
|
|
|
__tablename__ = "egon_etrago_line_timeseries" |
395
|
|
|
__table_args__ = { |
396
|
|
|
"schema": "grid", |
397
|
|
|
"comment": get_meta( |
398
|
|
|
"grid", |
399
|
|
|
"Line", |
400
|
|
|
source_list=source_list, |
401
|
|
|
license_list=license_list, |
402
|
|
|
contributor_list=contributor_list, |
403
|
|
|
timeseries=True, |
404
|
|
|
), |
405
|
|
|
} |
406
|
|
|
|
407
|
|
|
scn_name = Column(String, primary_key=True, nullable=False) |
408
|
|
|
line_id = Column(BigInteger, primary_key=True, nullable=False) |
409
|
|
|
temp_id = Column(Integer, primary_key=True, nullable=False) |
410
|
|
|
s_max_pu = Column(ARRAY(Float(precision=53))) |
411
|
|
|
|
412
|
|
|
|
413
|
|
|
class EgonPfHvLink(Base): |
414
|
|
|
|
415
|
|
|
source_list = [ |
416
|
|
|
sources()["egon-data"], |
417
|
|
|
sources()["openstreetmap"], |
418
|
|
|
sources()["nep2021"], |
419
|
|
|
sources()["peta"], |
420
|
|
|
sources()["mastr"], |
421
|
|
|
sources()["SciGRID_gas"], |
422
|
|
|
sources()["pipeline_classification"], |
423
|
|
|
sources()["technology-data"], |
424
|
|
|
sources()["dsm-heitkoetter"], |
425
|
|
|
sources()["schmidt"], |
426
|
|
|
sources()["hotmaps_industrial_sites"], |
427
|
|
|
sources()["demandregio"], |
428
|
|
|
] |
429
|
|
|
|
430
|
|
|
contributor_list = contributors(["ic", "cb", "ke", "ja", "fw", "an"]) |
431
|
|
|
contributor_list[0]["comment"] = "Added DC lines from osmTGmod tables" |
432
|
|
|
contributor_list[1]["comment"] = "Added CHPs and heat links" |
433
|
|
|
contributor_list[2]["comment"] = "Added DSM links" |
434
|
|
|
contributor_list[3]["comment"] = "Added e-Mobility links" |
435
|
|
|
contributor_list[4]["comment"] = "Added H2 related links" |
436
|
|
|
contributor_list[5]["comment"] = "Added CH4 links" |
437
|
|
|
|
438
|
|
|
license_list = [data["licenses"][0] for data in source_list] |
439
|
|
|
|
440
|
|
|
__tablename__ = "egon_etrago_link" |
441
|
|
|
__table_args__ = { |
442
|
|
|
"schema": "grid", |
443
|
|
|
"comment": get_meta( |
444
|
|
|
"grid", |
445
|
|
|
"Link", |
446
|
|
|
source_list=source_list, |
447
|
|
|
license_list=license_list, |
448
|
|
|
contributor_list=contributor_list, |
449
|
|
|
), |
450
|
|
|
} |
451
|
|
|
|
452
|
|
|
__tablename__ = "egon_etrago_link" |
453
|
|
|
__table_args__ = {"schema": "grid", "comment": get_meta("grid", "Link")} |
454
|
|
|
|
455
|
|
|
scn_name = Column(String, primary_key=True, nullable=False) |
456
|
|
|
link_id = Column(BigInteger, primary_key=True, nullable=False) |
457
|
|
|
bus0 = Column(BigInteger) |
458
|
|
|
bus1 = Column(BigInteger) |
459
|
|
|
type = Column(Text) |
460
|
|
|
carrier = Column(Text) |
461
|
|
|
efficiency = Column(Float(53), server_default="1.") |
462
|
|
|
build_year = Column(BigInteger, server_default="0") |
463
|
|
|
lifetime = Column(Float(53), server_default="inf") |
464
|
|
|
p_nom = Column(Numeric, server_default="0.") |
465
|
|
|
p_nom_extendable = Column(Boolean, server_default="False") |
466
|
|
|
p_nom_min = Column(Float(53), server_default="0.") |
467
|
|
|
p_nom_max = Column(Float(53), server_default="inf") |
468
|
|
|
p_min_pu = Column(Float(53), server_default="0.") |
469
|
|
|
p_max_pu = Column(Float(53), server_default="1.") |
470
|
|
|
p_set = Column(Float(53)) |
471
|
|
|
capital_cost = Column(Float(53), server_default="0.") |
472
|
|
|
marginal_cost = Column(Float(53), server_default="0.") |
473
|
|
|
length = Column(Float(53), server_default="0.") |
474
|
|
|
terrain_factor = Column(Float(53), server_default="1.") |
475
|
|
|
geom = Column(Geometry("MULTILINESTRING", 4326)) |
476
|
|
|
topo = Column(Geometry("LINESTRING", 4326)) |
477
|
|
|
|
478
|
|
|
|
479
|
|
|
class EgonPfHvLinkTimeseries(Base): |
480
|
|
|
source_list = [ |
481
|
|
|
sources()["egon-data"], |
482
|
|
|
sources()["era5"], |
483
|
|
|
sources()["dsm-heitkoetter"], |
484
|
|
|
sources()["schmidt"], |
485
|
|
|
sources()["hotmaps_industrial_sites"], |
486
|
|
|
sources()["openstreetmap"], |
487
|
|
|
sources()["demandregio"], |
488
|
|
|
] |
489
|
|
|
|
490
|
|
|
contributor_list = contributors(["cb", "ke", "ja"]) |
491
|
|
|
contributor_list[0][ |
492
|
|
|
"comment" |
493
|
|
|
] = "Added efficiency timeseries for heat pumps" |
494
|
|
|
contributor_list[1]["comment"] = "Added dsm link timeseries" |
495
|
|
|
contributor_list[2]["comment"] = "Added e mobility link timeseries" |
496
|
|
|
|
497
|
|
|
license_list = [data["licenses"][0] for data in source_list] |
498
|
|
|
|
499
|
|
|
__tablename__ = "egon_etrago_link_timeseries" |
500
|
|
|
__table_args__ = { |
501
|
|
|
"schema": "grid", |
502
|
|
|
"comment": get_meta( |
503
|
|
|
"grid", |
504
|
|
|
"Link", |
505
|
|
|
source_list=source_list, |
506
|
|
|
license_list=license_list, |
507
|
|
|
contributor_list=contributor_list, |
508
|
|
|
timeseries=True, |
509
|
|
|
), |
510
|
|
|
} |
511
|
|
|
|
512
|
|
|
scn_name = Column(String, primary_key=True, nullable=False) |
513
|
|
|
link_id = Column(BigInteger, primary_key=True, nullable=False) |
514
|
|
|
temp_id = Column(Integer, primary_key=True, nullable=False) |
515
|
|
|
p_set = Column(ARRAY(Float(precision=53))) |
516
|
|
|
p_min_pu = Column(ARRAY(Float(precision=53))) |
517
|
|
|
p_max_pu = Column(ARRAY(Float(precision=53))) |
518
|
|
|
efficiency = Column(ARRAY(Float(precision=53))) |
519
|
|
|
marginal_cost = Column(ARRAY(Float(precision=53))) |
520
|
|
|
|
521
|
|
|
|
522
|
|
|
class EgonPfHvLoad(Base): |
523
|
|
|
|
524
|
|
|
source_list = [ |
525
|
|
|
sources()["egon-data"], |
526
|
|
|
sources()["demandregio"], |
527
|
|
|
sources()["nep2021"], |
528
|
|
|
sources()["peta"], |
529
|
|
|
sources()["schmidt"], |
530
|
|
|
sources()["hotmaps_industrial_sites"], |
531
|
|
|
sources()["openstreetmap"], |
532
|
|
|
sources()["openffe_gas"], |
533
|
|
|
sources()["tyndp"], |
534
|
|
|
] |
535
|
|
|
|
536
|
|
|
contributor_list = contributors(["ic", "cb", "an", "ja"]) |
537
|
|
|
contributor_list[0]["comment"] = "Added electrical demands" |
538
|
|
|
contributor_list[1]["comment"] = "Added heat deands" |
539
|
|
|
contributor_list[2]["comment"] = "Added gas demands" |
540
|
|
|
contributor_list[3]["comment"] = "Added mobility demands" |
541
|
|
|
|
542
|
|
|
license_list = [data["licenses"][0] for data in source_list] |
543
|
|
|
|
544
|
|
|
__tablename__ = "egon_etrago_load" |
545
|
|
|
__table_args__ = { |
546
|
|
|
"schema": "grid", |
547
|
|
|
"comment": get_meta( |
548
|
|
|
"grid", |
549
|
|
|
"Load", |
550
|
|
|
source_list=source_list, |
551
|
|
|
license_list=license_list, |
552
|
|
|
contributor_list=contributor_list, |
553
|
|
|
), |
554
|
|
|
} |
555
|
|
|
|
556
|
|
|
scn_name = Column(String, primary_key=True, nullable=False) |
557
|
|
|
load_id = Column(BigInteger, primary_key=True, nullable=False) |
558
|
|
|
bus = Column(BigInteger) |
559
|
|
|
type = Column(Text) |
560
|
|
|
carrier = Column(Text) |
561
|
|
|
p_set = Column(Float(53)) |
562
|
|
|
q_set = Column(Float(53)) |
563
|
|
|
sign = Column(Float(53), server_default="-1.") |
564
|
|
|
|
565
|
|
|
|
566
|
|
|
class EgonPfHvLoadTimeseries(Base): |
567
|
|
|
source_list = [ |
568
|
|
|
sources()["egon-data"], |
569
|
|
|
sources()["demandregio"], |
570
|
|
|
sources()["nep2021"], |
571
|
|
|
sources()["peta"], |
572
|
|
|
sources()["openffe_gas"], |
573
|
|
|
sources()["tyndp"], |
574
|
|
|
sources()["era5"], |
575
|
|
|
sources()["schmidt"], |
576
|
|
|
sources()["hotmaps_industrial_sites"], |
577
|
|
|
sources()["openstreetmap"], |
578
|
|
|
] |
579
|
|
|
|
580
|
|
|
contributor_list = contributors(["cb", "ic", "ja", "an"]) |
581
|
|
|
contributor_list[0]["comment"] = "Added heat load timeseries" |
582
|
|
|
contributor_list[1]["comment"] = "Added electricity load timeseries" |
583
|
|
|
contributor_list[2]["comment"] = "Added e mobility load timeseries" |
584
|
|
|
contributor_list[3]["comment"] = "Added gas load timeseries" |
585
|
|
|
|
586
|
|
|
license_list = [data["licenses"][0] for data in source_list] |
587
|
|
|
|
588
|
|
|
__tablename__ = "egon_etrago_load_timeseries" |
589
|
|
|
__table_args__ = { |
590
|
|
|
"schema": "grid", |
591
|
|
|
"comment": get_meta( |
592
|
|
|
"grid", |
593
|
|
|
"Load", |
594
|
|
|
source_list=source_list, |
595
|
|
|
license_list=license_list, |
596
|
|
|
contributor_list=contributor_list, |
597
|
|
|
timeseries=True, |
598
|
|
|
), |
599
|
|
|
} |
600
|
|
|
|
601
|
|
|
scn_name = Column(String, primary_key=True, nullable=False) |
602
|
|
|
load_id = Column(BigInteger, primary_key=True, nullable=False) |
603
|
|
|
temp_id = Column(Integer, primary_key=True, nullable=False) |
604
|
|
|
p_set = Column(ARRAY(Float(precision=53))) |
605
|
|
|
q_set = Column(ARRAY(Float(precision=53))) |
606
|
|
|
|
607
|
|
|
|
608
|
|
|
class EgonPfHvCarrier(Base): |
609
|
|
|
source_list = [ |
610
|
|
|
sources()["egon-data"], |
611
|
|
|
] |
612
|
|
|
|
613
|
|
|
contributor_list = contributors(["fw"]) |
614
|
|
|
contributor_list[0]["comment"] = "Added list of carriers" |
615
|
|
|
|
616
|
|
|
license_list = [data["licenses"][0] for data in source_list] |
617
|
|
|
|
618
|
|
|
__tablename__ = "egon_etrago_carrier" |
619
|
|
|
__table_args__ = { |
620
|
|
|
"schema": "grid", |
621
|
|
|
"comment": get_meta( |
622
|
|
|
"grid", |
623
|
|
|
"Carrier", |
624
|
|
|
source_list=source_list, |
625
|
|
|
license_list=license_list, |
626
|
|
|
contributor_list=contributor_list, |
627
|
|
|
), |
628
|
|
|
} |
629
|
|
|
|
630
|
|
|
name = Column(Text, primary_key=True, nullable=False) |
631
|
|
|
co2_emissions = Column(Float(53), server_default="0.") |
632
|
|
|
color = Column(Text) |
633
|
|
|
nice_name = Column(Text) |
634
|
|
|
commentary = Column(Text) |
635
|
|
|
|
636
|
|
|
|
637
|
|
|
class EgonPfHvStorage(Base): |
638
|
|
|
|
639
|
|
|
source_list = [ |
640
|
|
|
sources()["egon-data"], |
641
|
|
|
sources()["nep2021"], |
642
|
|
|
sources()["mastr"], |
643
|
|
|
sources()["technology-data"], |
644
|
|
|
] |
645
|
|
|
|
646
|
|
|
contributor_list = contributors(["ic"]) |
647
|
|
|
contributor_list[0][ |
648
|
|
|
"comment" |
649
|
|
|
] = "Added battery and pumped hydro storage units" |
650
|
|
|
|
651
|
|
|
license_list = [data["licenses"][0] for data in source_list] |
652
|
|
|
|
653
|
|
|
__tablename__ = "egon_etrago_storage" |
654
|
|
|
__table_args__ = { |
655
|
|
|
"schema": "grid", |
656
|
|
|
"comment": get_meta( |
657
|
|
|
"grid", |
658
|
|
|
"Storage", |
659
|
|
|
source_list=source_list, |
660
|
|
|
license_list=license_list, |
661
|
|
|
contributor_list=contributor_list, |
662
|
|
|
), |
663
|
|
|
} |
664
|
|
|
|
665
|
|
|
scn_name = Column(String, primary_key=True, nullable=False) |
666
|
|
|
storage_id = Column(BigInteger, primary_key=True, nullable=False) |
667
|
|
|
bus = Column(BigInteger) |
668
|
|
|
control = Column(Text) |
669
|
|
|
type = Column(Text) |
670
|
|
|
carrier = Column(Text) |
671
|
|
|
p_nom = Column(Float(53), server_default="0.") |
672
|
|
|
p_nom_extendable = Column((Boolean), server_default="False") |
673
|
|
|
p_nom_min = Column(Float(53), server_default="0.") |
674
|
|
|
p_nom_max = Column(Float(53), server_default="inf") |
675
|
|
|
p_min_pu = Column(Float(53), server_default="-1.") |
676
|
|
|
p_max_pu = Column(Float(53), server_default="1.") |
677
|
|
|
p_set = Column(Float(53)) |
678
|
|
|
q_set = Column(Float(53)) |
679
|
|
|
sign = Column(Float(53), server_default="1") |
680
|
|
|
marginal_cost = Column(Float(53), server_default="0.") |
681
|
|
|
capital_cost = Column(Float(53), server_default="0.") |
682
|
|
|
build_year = Column(BigInteger, server_default="0") |
683
|
|
|
lifetime = Column(Float(53), server_default="inf") |
684
|
|
|
state_of_charge_initial = Column(Float(53), server_default="0") |
685
|
|
|
cyclic_state_of_charge = Column(Boolean, server_default="False") |
686
|
|
|
state_of_charge_set = Column(Float(53)) |
687
|
|
|
max_hours = Column(Float(53), server_default="1") |
688
|
|
|
efficiency_store = Column(Float(53), server_default="1.") |
689
|
|
|
efficiency_dispatch = Column(Float(53), server_default="1.") |
690
|
|
|
standing_loss = Column(Float(53), server_default="0.") |
691
|
|
|
inflow = Column(Float(53), server_default="0.") |
692
|
|
|
|
693
|
|
|
|
694
|
|
|
class EgonPfHvStorageTimeseries(Base): |
695
|
|
|
source_list = [ |
696
|
|
|
sources()["egon-data"], |
697
|
|
|
] |
698
|
|
|
|
699
|
|
|
contributor_list = contributors(["cb"]) |
700
|
|
|
contributor_list[0]["comment"] = "Added metadata" |
701
|
|
|
|
702
|
|
|
license_list = [data["licenses"][0] for data in source_list] |
703
|
|
|
|
704
|
|
|
__tablename__ = "egon_etrago_storage_timeseries" |
705
|
|
|
__table_args__ = { |
706
|
|
|
"schema": "grid", |
707
|
|
|
"comment": get_meta( |
708
|
|
|
"grid", |
709
|
|
|
"Storage", |
710
|
|
|
source_list=source_list, |
711
|
|
|
license_list=license_list, |
712
|
|
|
contributor_list=contributor_list, |
713
|
|
|
timeseries=True, |
714
|
|
|
), |
715
|
|
|
} |
716
|
|
|
|
717
|
|
|
scn_name = Column(String, primary_key=True, nullable=False) |
718
|
|
|
storage_id = Column(BigInteger, primary_key=True, nullable=False) |
719
|
|
|
temp_id = Column(Integer, primary_key=True, nullable=False) |
720
|
|
|
p_set = Column(ARRAY(Float(precision=53))) |
721
|
|
|
q_set = Column(ARRAY(Float(precision=53))) |
722
|
|
|
p_min_pu = Column(ARRAY(Float(precision=53))) |
723
|
|
|
p_max_pu = Column(ARRAY(Float(precision=53))) |
724
|
|
|
state_of_charge_set = Column(ARRAY(Float(precision=53))) |
725
|
|
|
inflow = Column(ARRAY(Float(precision=53))) |
726
|
|
|
marginal_cost = Column(ARRAY(Float(precision=53))) |
727
|
|
|
|
728
|
|
|
|
729
|
|
|
class EgonPfHvStore(Base): |
730
|
|
|
source_dict = sources() |
731
|
|
|
|
732
|
|
|
source_list = [ |
733
|
|
|
source_dict["bgr_inspee"], |
734
|
|
|
source_dict["bgr_inspeeds"], |
735
|
|
|
source_dict["bgr_inspeeds_data_bundle"], |
736
|
|
|
source_dict["bgr_inspeeds_report"], |
737
|
|
|
source_dict["SciGRID_gas"], |
738
|
|
|
sources()["technology-data"], |
739
|
|
|
sources()["dsm-heitkoetter"], |
740
|
|
|
sources()["schmidt"], |
741
|
|
|
sources()["hotmaps_industrial_sites"], |
742
|
|
|
sources()["openstreetmap"], |
743
|
|
|
sources()["demandregio"], |
744
|
|
|
] |
745
|
|
|
contributor_list = contributors(["an", "fw", "ke", "cb", "ja"]) |
746
|
|
|
contributor_list[0]["comment"] = "Add H2 storage" |
747
|
|
|
contributor_list[1]["comment"] = "Add CH4 storage" |
748
|
|
|
contributor_list[2]["comment"] = "Add DSM storage" |
749
|
|
|
contributor_list[3]["comment"] = "Add heat storage" |
750
|
|
|
contributor_list[4]["comment"] = "Add e-mobility storage" |
751
|
|
|
|
752
|
|
|
license_list = [data["licenses"][0] for data in source_list] |
753
|
|
|
__tablename__ = "egon_etrago_store" |
754
|
|
|
__table_args__ = { |
755
|
|
|
"schema": "grid", |
756
|
|
|
"comment": get_meta( |
757
|
|
|
"grid", |
758
|
|
|
"Store", |
759
|
|
|
source_list=source_list, |
760
|
|
|
license_list=license_list, |
761
|
|
|
contributor_list=contributor_list, |
762
|
|
|
), |
763
|
|
|
} |
764
|
|
|
|
765
|
|
|
scn_name = Column(String, primary_key=True, nullable=False) |
766
|
|
|
store_id = Column(BigInteger, primary_key=True, nullable=False) |
767
|
|
|
bus = Column(BigInteger) |
768
|
|
|
type = Column(Text) |
769
|
|
|
carrier = Column(Text) |
770
|
|
|
e_nom = Column(Float(53), server_default="0.") |
771
|
|
|
e_nom_extendable = Column((Boolean), server_default="False") |
772
|
|
|
e_nom_min = Column(Float(53), server_default="0.") |
773
|
|
|
e_nom_max = Column(Float(53), server_default="inf") |
774
|
|
|
e_min_pu = Column(Float(53), server_default="0.") |
775
|
|
|
e_max_pu = Column(Float(53), server_default="1.") |
776
|
|
|
p_set = Column(Float(53)) |
777
|
|
|
q_set = Column(Float(53)) |
778
|
|
|
e_initial = Column(Float(53), server_default="0.") |
779
|
|
|
e_cyclic = Column(Boolean, server_default="False") |
780
|
|
|
sign = Column(Float(53), server_default="1") |
781
|
|
|
marginal_cost = Column(Float(53), server_default="0.") |
782
|
|
|
capital_cost = Column(Float(53), server_default="0.") |
783
|
|
|
standing_loss = Column(Float(53), server_default="0.") |
784
|
|
|
build_year = Column(BigInteger, server_default="0") |
785
|
|
|
lifetime = Column(Float(53), server_default="inf") |
786
|
|
|
|
787
|
|
|
|
788
|
|
|
class EgonPfHvStoreTimeseries(Base): |
789
|
|
|
source_dict = sources() |
790
|
|
|
# TODO: Add other sources for dsm |
791
|
|
|
source_list = [ |
792
|
|
|
sources()["technology-data"], |
793
|
|
|
sources()["dsm-heitkoetter"], |
794
|
|
|
sources()["schmidt"], |
795
|
|
|
sources()["hotmaps_industrial_sites"], |
796
|
|
|
sources()["openstreetmap"], |
797
|
|
|
sources()["demandregio"], |
798
|
|
|
] |
799
|
|
|
contributor_list = contributors(["ke", "ja"]) |
800
|
|
|
contributor_list[0]["comment"] = "Add DSM storage" |
801
|
|
|
contributor_list[1]["comment"] = "Add e-mobility storage" |
802
|
|
|
|
803
|
|
|
license_list = [data["licenses"][0] for data in source_list] |
804
|
|
|
__tablename__ = "egon_etrago_store_timeseries" |
805
|
|
|
__table_args__ = { |
806
|
|
|
"schema": "grid", |
807
|
|
|
"comment": get_meta( |
808
|
|
|
"grid", |
809
|
|
|
"Store", |
810
|
|
|
source_list=source_list, |
811
|
|
|
license_list=license_list, |
812
|
|
|
contributor_list=contributor_list, |
813
|
|
|
timeseries=True, |
814
|
|
|
), |
815
|
|
|
} |
816
|
|
|
scn_name = Column(String, primary_key=True, nullable=False) |
817
|
|
|
store_id = Column(BigInteger, primary_key=True, nullable=False) |
818
|
|
|
temp_id = Column(Integer, primary_key=True, nullable=False) |
819
|
|
|
p_set = Column(ARRAY(Float(precision=53))) |
820
|
|
|
q_set = Column(ARRAY(Float(precision=53))) |
821
|
|
|
e_min_pu = Column(ARRAY(Float(precision=53))) |
822
|
|
|
e_max_pu = Column(ARRAY(Float(precision=53))) |
823
|
|
|
marginal_cost = Column(ARRAY(Float(precision=53))) |
824
|
|
|
|
825
|
|
|
|
826
|
|
|
class EgonPfHvTempResolution(Base): |
827
|
|
|
__tablename__ = "egon_etrago_temp_resolution" |
828
|
|
|
__table_args__ = {"schema": "grid"} |
829
|
|
|
|
830
|
|
|
temp_id = Column(BigInteger, primary_key=True, nullable=False) |
831
|
|
|
timesteps = Column(BigInteger, nullable=False) |
832
|
|
|
resolution = Column(Text) |
833
|
|
|
start_time = Column(DateTime) |
834
|
|
|
|
835
|
|
|
|
836
|
|
View Code Duplication |
class EgonPfHvTransformer(Base): |
|
|
|
|
837
|
|
|
|
838
|
|
|
source_list = [ |
839
|
|
|
sources()["egon-data"], |
840
|
|
|
sources()["openstreetmap"], |
841
|
|
|
] |
842
|
|
|
|
843
|
|
|
contributor_list = contributors(["ic", "cb"]) |
844
|
|
|
contributor_list[0]["comment"] = "Added transformes from osmTGmod tables" |
845
|
|
|
contributor_list[1]["comment"] = "Added meta data" |
846
|
|
|
|
847
|
|
|
license_list = [data["licenses"][0] for data in source_list] |
848
|
|
|
|
849
|
|
|
__tablename__ = "egon_etrago_transformer" |
850
|
|
|
__table_args__ = { |
851
|
|
|
"schema": "grid", |
852
|
|
|
"comment": get_meta( |
853
|
|
|
"grid", |
854
|
|
|
"Transformer", |
855
|
|
|
source_list=source_list, |
856
|
|
|
license_list=license_list, |
857
|
|
|
contributor_list=contributor_list, |
858
|
|
|
), |
859
|
|
|
} |
860
|
|
|
|
861
|
|
|
scn_name = Column(String, primary_key=True, nullable=False) |
862
|
|
|
trafo_id = Column(BigInteger, primary_key=True, nullable=False) |
863
|
|
|
bus0 = Column(BigInteger) |
864
|
|
|
bus1 = Column(BigInteger) |
865
|
|
|
type = Column(Text) |
866
|
|
|
model = Column((Text), server_default="t") |
867
|
|
|
x = Column((Numeric), server_default="0.") |
868
|
|
|
r = Column((Numeric), server_default="0.") |
869
|
|
|
g = Column((Numeric), server_default="0.") |
870
|
|
|
b = Column((Numeric), server_default="0.") |
871
|
|
|
s_nom = Column(Float(53), server_default="0.") |
872
|
|
|
s_nom_extendable = Column((Boolean), server_default="False") |
873
|
|
|
s_nom_min = Column(Float(53), server_default="0.") |
874
|
|
|
s_nom_max = Column(Float(53), server_default="inf") |
875
|
|
|
s_max_pu = Column(Float(53), server_default="1.") |
876
|
|
|
tap_ratio = Column(Float(53), server_default="1.") |
877
|
|
|
tap_side = Column((BigInteger), server_default="0") |
878
|
|
|
tap_position = Column((BigInteger), server_default="0") |
879
|
|
|
phase_shift = Column(Float(53), server_default="0.") |
880
|
|
|
build_year = Column(BigInteger, server_default="0") |
881
|
|
|
lifetime = Column(Float(53), server_default="inf") |
882
|
|
|
v_ang_min = Column(Float(53), server_default="-inf") |
883
|
|
|
v_ang_max = Column(Float(53), server_default="inf") |
884
|
|
|
capital_cost = Column(Float(53), server_default="0.") |
885
|
|
|
num_parallel = Column(Float(53), server_default="1.") |
886
|
|
|
geom = Column(Geometry("MULTILINESTRING", 4326)) |
887
|
|
|
topo = Column(Geometry("LINESTRING", 4326)) |
888
|
|
|
|
889
|
|
|
|
890
|
|
View Code Duplication |
class EgonPfHvTransformerTimeseries(Base): |
|
|
|
|
891
|
|
|
source_list = [ |
892
|
|
|
sources()["egon-data"], |
893
|
|
|
] |
894
|
|
|
|
895
|
|
|
contributor_list = contributors(["cb"]) |
896
|
|
|
contributor_list[0]["comment"] = "Added meta data" |
897
|
|
|
|
898
|
|
|
license_list = [data["licenses"][0] for data in source_list] |
899
|
|
|
|
900
|
|
|
__tablename__ = "egon_etrago_transformer_timeseries" |
901
|
|
|
__table_args__ = { |
902
|
|
|
"schema": "grid", |
903
|
|
|
"comment": get_meta( |
904
|
|
|
"grid", |
905
|
|
|
"Transformer", |
906
|
|
|
source_list=source_list, |
907
|
|
|
license_list=license_list, |
908
|
|
|
contributor_list=contributor_list, |
909
|
|
|
timeseries=True, |
910
|
|
|
), |
911
|
|
|
} |
912
|
|
|
|
913
|
|
|
scn_name = Column(String, primary_key=True, nullable=False) |
914
|
|
|
trafo_id = Column(BigInteger, primary_key=True, nullable=False) |
915
|
|
|
temp_id = Column(Integer, primary_key=True, nullable=False) |
916
|
|
|
s_max_pu = Column(ARRAY(Float(precision=53))) |
917
|
|
|
|
918
|
|
|
|
919
|
|
|
class EgonPfHvBusmap(Base): |
920
|
|
|
__tablename__ = "egon_etrago_hv_busmap" |
921
|
|
|
__table_args__ = {"schema": "grid"} |
922
|
|
|
|
923
|
|
|
scn_name = Column(Text, primary_key=True, nullable=False) |
924
|
|
|
bus0 = Column(Text, primary_key=True, nullable=False) |
925
|
|
|
bus1 = Column(Text, primary_key=True, nullable=False) |
926
|
|
|
path_length = Column(Numeric) |
927
|
|
|
version = Column(Text, primary_key=True, nullable=False) |
928
|
|
|
|
929
|
|
|
|
930
|
|
|
def create_tables(): |
931
|
|
|
"""Create tables for eTraGo input data. |
932
|
|
|
Returns |
933
|
|
|
------- |
934
|
|
|
None. |
935
|
|
|
""" |
936
|
|
|
db.execute_sql("CREATE SCHEMA IF NOT EXISTS grid;") |
937
|
|
|
engine = db.engine() |
938
|
|
|
|
939
|
|
|
##################### drop tables with old names ######################### |
940
|
|
|
db.execute_sql( |
941
|
|
|
""" |
942
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_bus;""" |
943
|
|
|
) |
944
|
|
|
db.execute_sql( |
945
|
|
|
""" |
946
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_bus_timeseries;""" |
947
|
|
|
) |
948
|
|
|
db.execute_sql( |
949
|
|
|
""" |
950
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_carrier;""" |
951
|
|
|
) |
952
|
|
|
db.execute_sql( |
953
|
|
|
""" |
954
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_generator;""" |
955
|
|
|
) |
956
|
|
|
db.execute_sql( |
957
|
|
|
""" |
958
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_generator_timeseries;""" |
959
|
|
|
) |
960
|
|
|
db.execute_sql( |
961
|
|
|
""" |
962
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_line;""" |
963
|
|
|
) |
964
|
|
|
db.execute_sql( |
965
|
|
|
""" |
966
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_line_timeseries;""" |
967
|
|
|
) |
968
|
|
|
db.execute_sql( |
969
|
|
|
""" |
970
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_link;""" |
971
|
|
|
) |
972
|
|
|
db.execute_sql( |
973
|
|
|
""" |
974
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_link_timeseries;""" |
975
|
|
|
) |
976
|
|
|
db.execute_sql( |
977
|
|
|
""" |
978
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_load;""" |
979
|
|
|
) |
980
|
|
|
db.execute_sql( |
981
|
|
|
""" |
982
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_load_timeseries;""" |
983
|
|
|
) |
984
|
|
|
db.execute_sql( |
985
|
|
|
""" |
986
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_storage;""" |
987
|
|
|
) |
988
|
|
|
db.execute_sql( |
989
|
|
|
""" |
990
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_storage_timeseries;""" |
991
|
|
|
) |
992
|
|
|
db.execute_sql( |
993
|
|
|
""" |
994
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_store;""" |
995
|
|
|
) |
996
|
|
|
db.execute_sql( |
997
|
|
|
""" |
998
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_store_timeseries;""" |
999
|
|
|
) |
1000
|
|
|
db.execute_sql( |
1001
|
|
|
""" |
1002
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_temp_resolution;""" |
1003
|
|
|
) |
1004
|
|
|
db.execute_sql( |
1005
|
|
|
""" |
1006
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_transformer;""" |
1007
|
|
|
) |
1008
|
|
|
db.execute_sql( |
1009
|
|
|
""" |
1010
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_transformer_timeseries;""" |
1011
|
|
|
) |
1012
|
|
|
########################################################################## |
1013
|
|
|
|
1014
|
|
|
# Drop existing tables |
1015
|
|
|
EgonPfHvBus.__table__.drop(bind=engine, checkfirst=True) |
1016
|
|
|
EgonPfHvBusTimeseries.__table__.drop(bind=engine, checkfirst=True) |
1017
|
|
|
EgonPfHvGenerator.__table__.drop(bind=engine, checkfirst=True) |
1018
|
|
|
EgonPfHvGeneratorTimeseries.__table__.drop(bind=engine, checkfirst=True) |
1019
|
|
|
EgonPfHvLine.__table__.drop(bind=engine, checkfirst=True) |
1020
|
|
|
EgonPfHvLineTimeseries.__table__.drop(bind=engine, checkfirst=True) |
1021
|
|
|
EgonPfHvLink.__table__.drop(bind=engine, checkfirst=True) |
1022
|
|
|
EgonPfHvLinkTimeseries.__table__.drop(bind=engine, checkfirst=True) |
1023
|
|
|
EgonPfHvLoad.__table__.drop(bind=engine, checkfirst=True) |
1024
|
|
|
EgonPfHvLoadTimeseries.__table__.drop(bind=engine, checkfirst=True) |
1025
|
|
|
EgonPfHvCarrier.__table__.drop(bind=engine, checkfirst=True) |
1026
|
|
|
EgonPfHvStorage.__table__.drop(bind=engine, checkfirst=True) |
1027
|
|
|
EgonPfHvStorageTimeseries.__table__.drop(bind=engine, checkfirst=True) |
1028
|
|
|
EgonPfHvStore.__table__.drop(bind=engine, checkfirst=True) |
1029
|
|
|
EgonPfHvStoreTimeseries.__table__.drop(bind=engine, checkfirst=True) |
1030
|
|
|
EgonPfHvTempResolution.__table__.drop(bind=engine, checkfirst=True) |
1031
|
|
|
EgonPfHvTransformer.__table__.drop(bind=engine, checkfirst=True) |
1032
|
|
|
EgonPfHvTransformerTimeseries.__table__.drop(bind=engine, checkfirst=True) |
1033
|
|
|
EgonPfHvBusmap.__table__.drop(bind=engine, checkfirst=True) |
1034
|
|
|
# Create new tables |
1035
|
|
|
EgonPfHvBus.__table__.create(bind=engine, checkfirst=True) |
1036
|
|
|
EgonPfHvBusTimeseries.__table__.create(bind=engine, checkfirst=True) |
1037
|
|
|
EgonPfHvGenerator.__table__.create(bind=engine, checkfirst=True) |
1038
|
|
|
EgonPfHvGeneratorTimeseries.__table__.create(bind=engine, checkfirst=True) |
1039
|
|
|
EgonPfHvLine.__table__.create(bind=engine, checkfirst=True) |
1040
|
|
|
EgonPfHvLineTimeseries.__table__.create(bind=engine, checkfirst=True) |
1041
|
|
|
EgonPfHvLink.__table__.create(bind=engine, checkfirst=True) |
1042
|
|
|
EgonPfHvLinkTimeseries.__table__.create(bind=engine, checkfirst=True) |
1043
|
|
|
EgonPfHvLoad.__table__.create(bind=engine, checkfirst=True) |
1044
|
|
|
EgonPfHvLoadTimeseries.__table__.create(bind=engine, checkfirst=True) |
1045
|
|
|
EgonPfHvCarrier.__table__.create(bind=engine, checkfirst=True) |
1046
|
|
|
EgonPfHvStorage.__table__.create(bind=engine, checkfirst=True) |
1047
|
|
|
EgonPfHvStorageTimeseries.__table__.create(bind=engine, checkfirst=True) |
1048
|
|
|
EgonPfHvStore.__table__.create(bind=engine, checkfirst=True) |
1049
|
|
|
EgonPfHvStoreTimeseries.__table__.create(bind=engine, checkfirst=True) |
1050
|
|
|
EgonPfHvTempResolution.__table__.create(bind=engine, checkfirst=True) |
1051
|
|
|
EgonPfHvTransformer.__table__.create(bind=engine, checkfirst=True) |
1052
|
|
|
EgonPfHvTransformerTimeseries.__table__.create( |
1053
|
|
|
bind=engine, checkfirst=True |
1054
|
|
|
) |
1055
|
|
|
EgonPfHvBusmap.__table__.create(bind=engine, checkfirst=True) |
1056
|
|
|
|
1057
|
|
|
|
1058
|
|
|
def temp_resolution(): |
1059
|
|
|
"""Insert temporal resolution for etrago |
1060
|
|
|
|
1061
|
|
|
Returns |
1062
|
|
|
------- |
1063
|
|
|
None. |
1064
|
|
|
|
1065
|
|
|
""" |
1066
|
|
|
|
1067
|
|
|
db.execute_sql( |
1068
|
|
|
""" |
1069
|
|
|
INSERT INTO grid.egon_etrago_temp_resolution |
1070
|
|
|
(temp_id, timesteps, resolution, start_time) |
1071
|
|
|
SELECT 1, 8760, 'h', TIMESTAMP '2011-01-01 00:00:00'; |
1072
|
|
|
""" |
1073
|
|
|
) |
1074
|
|
|
|
1075
|
|
|
|
1076
|
|
|
def insert_carriers(): |
1077
|
|
|
"""Insert list of carriers into eTraGo table |
1078
|
|
|
|
1079
|
|
|
Returns |
1080
|
|
|
------- |
1081
|
|
|
None. |
1082
|
|
|
|
1083
|
|
|
""" |
1084
|
|
|
# Delete existing entries |
1085
|
|
|
db.execute_sql( |
1086
|
|
|
""" |
1087
|
|
|
DELETE FROM grid.egon_etrago_carrier |
1088
|
|
|
""" |
1089
|
|
|
) |
1090
|
|
|
|
1091
|
|
|
# List carrier names from all components |
1092
|
|
|
df = pd.DataFrame( |
1093
|
|
|
data={ |
1094
|
|
|
"name": [ |
1095
|
|
|
"biogas", |
1096
|
|
|
"biogas_feedin", |
1097
|
|
|
"biogas_to_gas", |
1098
|
|
|
"biomass", |
1099
|
|
|
"pv", |
1100
|
|
|
"wind_offshore", |
1101
|
|
|
"wind_onshore", |
1102
|
|
|
"central_heat_pump", |
1103
|
|
|
"central_resistive_heater", |
1104
|
|
|
"CH4", |
1105
|
|
|
"CH4_for_industry", |
1106
|
|
|
"CH4_system_boundary", |
1107
|
|
|
"CH4_to_H2", |
1108
|
|
|
"dsm", |
1109
|
|
|
"H2", |
1110
|
|
|
"H2_feedin", |
1111
|
|
|
"H2_for_industry", |
1112
|
|
|
"H2_grid", |
1113
|
|
|
"H2_gridextension", |
1114
|
|
|
"H2_hgv_load", |
1115
|
|
|
"H2_overground", |
1116
|
|
|
"H2_retrofit", |
1117
|
|
|
"H2_saltcavern", |
1118
|
|
|
"H2_system_boundary", |
1119
|
|
|
"H2_to_CH4", |
1120
|
|
|
"H2_to_power", |
1121
|
|
|
"H2_underground", |
1122
|
|
|
"rural_heat_pump", |
1123
|
|
|
"industrial_biomass_CHP", |
1124
|
|
|
"industrial_gas_CHP", |
1125
|
|
|
"central_biomass_CHP_heat", |
1126
|
|
|
"central_biomass_CHP", |
1127
|
|
|
"central_gas_CHP", |
1128
|
|
|
"central_gas_CHP_heat", |
1129
|
|
|
"power_to_H2", |
1130
|
|
|
"rural_gas_boiler", |
1131
|
|
|
"central_gas_boiler", |
1132
|
|
|
"solar_thermal_collector", |
1133
|
|
|
"geo_thermal", |
1134
|
|
|
"AC", |
1135
|
|
|
"central_heat", |
1136
|
|
|
"rural_heat", |
1137
|
|
|
"natural_gas_feedin", |
1138
|
|
|
"pumped_hydro", |
1139
|
|
|
"battery", |
1140
|
|
|
"OCGT", |
1141
|
|
|
] |
1142
|
|
|
} |
1143
|
|
|
) |
1144
|
|
|
|
1145
|
|
|
# Insert data into database |
1146
|
|
|
df.to_sql( |
1147
|
|
|
"egon_etrago_carrier", |
1148
|
|
|
schema="grid", |
1149
|
|
|
con=db.engine(), |
1150
|
|
|
if_exists="append", |
1151
|
|
|
index=False, |
1152
|
|
|
) |
1153
|
|
|
|
1154
|
|
|
|
1155
|
|
|
def check_carriers(): |
1156
|
|
|
"""Check if any eTraGo table has carriers not included in the carrier table. |
1157
|
|
|
|
1158
|
|
|
Raises |
1159
|
|
|
------ |
1160
|
|
|
ValueError if carriers that are not defined in the carriers table are |
1161
|
|
|
used in any eTraGo table. |
1162
|
|
|
""" |
1163
|
|
|
carriers = db.select_dataframe( |
1164
|
|
|
f""" |
1165
|
|
|
SELECT name FROM grid.egon_etrago_carrier |
1166
|
|
|
""" |
1167
|
|
|
) |
1168
|
|
|
unknown_carriers = {} |
1169
|
|
|
tables = ["bus", "store", "storage", "link", "line", "generator", "load"] |
1170
|
|
|
|
1171
|
|
|
for table in tables: |
1172
|
|
|
# Delete existing entries |
1173
|
|
|
data = db.select_dataframe( |
1174
|
|
|
f""" |
1175
|
|
|
SELECT carrier FROM grid.egon_etrago_{table} |
1176
|
|
|
""" |
1177
|
|
|
) |
1178
|
|
|
unknown_carriers[table] = data[~data["carrier"].isin(carriers)][ |
1179
|
|
|
"carrier" |
1180
|
|
|
].unique() |
1181
|
|
|
|
1182
|
|
|
if len(unknown_carriers) > 0: |
1183
|
|
|
msg = ( |
1184
|
|
|
"The eTraGo tables contain carriers, that are not included in the " |
1185
|
|
|
"carrier table:\n" |
1186
|
|
|
) |
1187
|
|
|
for table, carriers in unknown_carriers.items(): |
1188
|
|
|
carriers = [str(c) for c in carriers] |
1189
|
|
|
if len(carriers) > 0: |
1190
|
|
|
msg += table + ": '" + "', '".join(carriers) + "'\n" |
1191
|
|
|
|
1192
|
|
|
raise ValueError(msg) |
1193
|
|
|
|
1194
|
|
|
|
1195
|
|
|
def link_geom_from_buses(df, scn_name): |
1196
|
|
|
"""Add LineString geometry accoring to geometry of buses to links |
1197
|
|
|
|
1198
|
|
|
Parameters |
1199
|
|
|
---------- |
1200
|
|
|
df : pandas.DataFrame |
1201
|
|
|
List of eTraGo links with bus0 and bus1 but without topology |
1202
|
|
|
scn_name : str |
1203
|
|
|
Scenario name |
1204
|
|
|
|
1205
|
|
|
Returns |
1206
|
|
|
------- |
1207
|
|
|
gdf : geopandas.GeoDataFrame |
1208
|
|
|
List of eTraGo links with bus0 and bus1 but with topology |
1209
|
|
|
|
1210
|
|
|
""" |
1211
|
|
|
|
1212
|
|
|
geom_buses = db.select_geodataframe( |
1213
|
|
|
f""" |
1214
|
|
|
SELECT bus_id, geom |
1215
|
|
|
FROM grid.egon_etrago_bus |
1216
|
|
|
WHERE scn_name = '{scn_name}' |
1217
|
|
|
""", |
1218
|
|
|
index_col="bus_id", |
1219
|
|
|
epsg=4326, |
1220
|
|
|
) |
1221
|
|
|
|
1222
|
|
|
# Create geometry columns for bus0 and bus1 |
1223
|
|
|
df["geom_0"] = geom_buses.geom[df.bus0.values].values |
1224
|
|
|
df["geom_1"] = geom_buses.geom[df.bus1.values].values |
1225
|
|
|
|
1226
|
|
|
geometry = df.apply( |
1227
|
|
|
lambda x: LineString([x["geom_0"], x["geom_1"]]), axis=1 |
1228
|
|
|
) |
1229
|
|
|
df = df.drop(["geom_0", "geom_1"], axis=1) |
1230
|
|
|
|
1231
|
|
|
gdf = gpd.GeoDataFrame(df, geometry=geometry, crs=4326).rename_geometry( |
1232
|
|
|
"topo" |
1233
|
|
|
) |
1234
|
|
|
|
1235
|
|
|
return gdf |
1236
|
|
|
|