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 ( |
29
|
|
|
context, |
30
|
|
|
contributors, |
31
|
|
|
generate_resource_fields_from_sqla_model, |
32
|
|
|
license_ccby, |
33
|
|
|
meta_metadata, |
34
|
|
|
sources, |
35
|
|
|
) |
36
|
|
|
|
37
|
|
|
Base = declarative_base() |
38
|
|
|
metadata = Base.metadata |
39
|
|
|
|
40
|
|
|
network = pypsa.Network() |
41
|
|
|
# add Storage key (called StorageUnit in PyPSA) |
42
|
|
|
network.component_attrs["Storage"] = network.component_attrs["StorageUnit"] |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
def get_pypsa_field_descriptors(component): |
46
|
|
|
|
47
|
|
|
ident = component.lower() + "_id" |
48
|
|
|
|
49
|
|
|
data = network.component_attrs[component].rename({"name": ident}) |
50
|
|
|
data.loc[ident, "type"] = "int" |
51
|
|
|
data.loc["scn_name"] = [ |
52
|
|
|
"string", |
53
|
|
|
"n/a", |
54
|
|
|
"n/a", |
55
|
|
|
"Name of the eGon scenario", |
56
|
|
|
"Input", |
57
|
|
|
] |
58
|
|
|
|
59
|
|
|
return data |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
def get_meta( |
63
|
|
|
schema, |
64
|
|
|
component, |
65
|
|
|
description="TODO", |
66
|
|
|
source_list=[], |
67
|
|
|
license_list=[], |
68
|
|
|
contributor_list=[], |
69
|
|
|
): |
70
|
|
|
|
71
|
|
|
table = "egon_etrago_" + component.lower() |
72
|
|
|
fields = ( |
73
|
|
|
get_pypsa_field_descriptors(component) |
74
|
|
|
.reset_index() |
75
|
|
|
.to_dict(orient="records") |
76
|
|
|
) |
77
|
|
|
# geometry column still missing |
78
|
|
|
|
79
|
|
|
meta = { |
80
|
|
|
"name": schema + "." + table, |
81
|
|
|
"title": component, |
82
|
|
|
"id": "WILL_BE_SET_AT_PUBLICATION", |
83
|
|
|
# no automatic description? PyPSA descriptions do not quite fit our |
84
|
|
|
# scope |
85
|
|
|
"description": description, |
86
|
|
|
"language": ["en-EN"], |
87
|
|
|
"publicationDate": datetime.date.today().isoformat(), |
88
|
|
|
"context": context(), |
89
|
|
|
"spatial": { |
90
|
|
|
"location": None, |
91
|
|
|
"extent": "Germany", |
92
|
|
|
"resolution": None, |
93
|
|
|
}, |
94
|
|
|
"sources": source_list, |
95
|
|
|
"licenses": license_list, |
96
|
|
|
"contributors": contributor_list, |
97
|
|
|
"resources": [ |
98
|
|
|
{ |
99
|
|
|
"profile": "tabular-data-resource", |
100
|
|
|
"name": schema + "." + table, |
101
|
|
|
"path": None, |
102
|
|
|
"format": "PostgreSQL", |
103
|
|
|
"encoding": "UTF-8", |
104
|
|
|
"schema": { |
105
|
|
|
"fields": fields, |
106
|
|
|
"primaryKey": ["scn_name", component.lower() + "_id"], |
107
|
|
|
"foreignKeys": [], |
108
|
|
|
}, |
109
|
|
|
"dialect": {"delimiter": None, "decimalSeparator": "."}, |
110
|
|
|
} |
111
|
|
|
], |
112
|
|
|
"metaMetadata": meta_metadata(), |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
# Create json dump |
116
|
|
|
meta_json = "'" + json.dumps(meta, indent=4) + "'" |
117
|
|
|
|
118
|
|
|
return meta_json |
119
|
|
|
|
120
|
|
|
|
121
|
|
|
class EtragoSetup(Dataset): |
122
|
|
|
def __init__(self, dependencies): |
123
|
|
|
super().__init__( |
124
|
|
|
name="EtragoSetup", |
125
|
|
|
version="0.0.11", |
126
|
|
|
dependencies=dependencies, |
127
|
|
|
tasks=(create_tables, {temp_resolution, insert_carriers}), |
128
|
|
|
) |
129
|
|
|
|
130
|
|
|
|
131
|
|
|
class EgonPfHvBus(Base): |
132
|
|
|
__tablename__ = "egon_etrago_bus" |
133
|
|
|
__table_args__ = {"schema": "grid", "comment": get_meta("grid", "Bus")} |
134
|
|
|
|
135
|
|
|
scn_name = Column(String, primary_key=True, nullable=False) |
136
|
|
|
bus_id = Column(BigInteger, primary_key=True, nullable=False) |
137
|
|
|
v_nom = Column(Float(53), server_default="1.") |
138
|
|
|
type = Column(Text) |
139
|
|
|
carrier = Column(Text) |
140
|
|
|
v_mag_pu_set = Column(Float(53)) |
141
|
|
|
v_mag_pu_min = Column(Float(53), server_default="0.") |
142
|
|
|
v_mag_pu_max = Column(Float(53), server_default="inf") |
143
|
|
|
x = Column(Float(53), server_default="0.") |
144
|
|
|
y = Column(Float(53), server_default="0.") |
145
|
|
|
geom = Column(Geometry("POINT", 4326), index=True) |
146
|
|
|
country = Column(Text, server_default=text("'DE'::text")) |
147
|
|
|
|
148
|
|
|
|
149
|
|
|
class EgonPfHvBusTimeseries(Base): |
150
|
|
|
__tablename__ = "egon_etrago_bus_timeseries" |
151
|
|
|
__table_args__ = {"schema": "grid"} |
152
|
|
|
|
153
|
|
|
scn_name = Column(String, primary_key=True, nullable=False) |
154
|
|
|
bus_id = Column(BigInteger, primary_key=True, nullable=False) |
155
|
|
|
v_mag_pu_set = Column(ARRAY(Float(precision=53))) |
156
|
|
|
|
157
|
|
|
|
158
|
|
|
class EgonPfHvGenerator(Base): |
159
|
|
|
__tablename__ = "egon_etrago_generator" |
160
|
|
|
__table_args__ = { |
161
|
|
|
"schema": "grid", |
162
|
|
|
"comment": get_meta("grid", "Generator"), |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
scn_name = Column(String, primary_key=True, nullable=False) |
166
|
|
|
generator_id = Column(BigInteger, primary_key=True, nullable=False) |
167
|
|
|
bus = Column(BigInteger) |
168
|
|
|
control = Column(Text) |
169
|
|
|
type = Column(Text) |
170
|
|
|
carrier = Column(Text) |
171
|
|
|
p_nom = Column(Float(53), server_default="0.") |
172
|
|
|
p_nom_extendable = Column(Boolean, server_default="False") |
173
|
|
|
p_nom_min = Column(Float(53), server_default="0.") |
174
|
|
|
p_nom_max = Column(Float(53), server_default="inf") |
175
|
|
|
p_min_pu = Column(Float(53), server_default="0.") |
176
|
|
|
p_max_pu = Column(Float(53), server_default="1.") |
177
|
|
|
p_set = Column(Float(53)) |
178
|
|
|
q_set = Column(Float(53)) |
179
|
|
|
sign = Column(Float(53), server_default="1.") |
180
|
|
|
marginal_cost = Column(Float(53), server_default="0.") |
181
|
|
|
build_year = Column(BigInteger, server_default="0") |
182
|
|
|
lifetime = Column(Float(53), server_default="inf") |
183
|
|
|
capital_cost = Column(Float(53), server_default="0.") |
184
|
|
|
efficiency = Column(Float(53), server_default="1.") |
185
|
|
|
committable = Column(Boolean, server_default="False") |
186
|
|
|
start_up_cost = Column(Float(53), server_default="0.") |
187
|
|
|
shut_down_cost = Column(Float(53), server_default="0.") |
188
|
|
|
min_up_time = Column(BigInteger, server_default="0") |
189
|
|
|
min_down_time = Column(BigInteger, server_default="0") |
190
|
|
|
up_time_before = Column(BigInteger, server_default="0") |
191
|
|
|
down_time_before = Column(BigInteger, server_default="0") |
192
|
|
|
ramp_limit_up = Column(Float(53), server_default="NaN") |
193
|
|
|
ramp_limit_down = Column(Float(53), server_default="NaN") |
194
|
|
|
ramp_limit_start_up = Column(Float(53), server_default="1.") |
195
|
|
|
ramp_limit_shut_down = Column(Float(53), server_default="1.") |
196
|
|
|
e_nom_max = Column( |
197
|
|
|
Float(53), server_default="inf" |
198
|
|
|
) # [MWh(/y)] Value to be used in eTraGo to set constraint for the production over the year |
199
|
|
|
|
200
|
|
|
|
201
|
|
View Code Duplication |
class EgonPfHvGeneratorTimeseries(Base): |
|
|
|
|
202
|
|
|
__tablename__ = "egon_etrago_generator_timeseries" |
203
|
|
|
__table_args__ = {"schema": "grid"} |
204
|
|
|
|
205
|
|
|
scn_name = Column(String, primary_key=True, nullable=False) |
206
|
|
|
generator_id = Column(Integer, primary_key=True, nullable=False) |
207
|
|
|
temp_id = Column(Integer, primary_key=True, nullable=False) |
208
|
|
|
p_set = Column(ARRAY(Float(precision=53))) |
209
|
|
|
q_set = Column(ARRAY(Float(precision=53))) |
210
|
|
|
p_min_pu = Column(ARRAY(Float(precision=53))) |
211
|
|
|
p_max_pu = Column(ARRAY(Float(precision=53))) |
212
|
|
|
marginal_cost = Column(ARRAY(Float(precision=53))) |
213
|
|
|
|
214
|
|
|
|
215
|
|
|
class EgonPfHvLine(Base): |
216
|
|
|
__tablename__ = "egon_etrago_line" |
217
|
|
|
__table_args__ = {"schema": "grid", "comment": get_meta("grid", "Line")} |
218
|
|
|
|
219
|
|
|
scn_name = Column(String, primary_key=True, nullable=False) |
220
|
|
|
line_id = Column(BigInteger, primary_key=True, nullable=False) |
221
|
|
|
bus0 = Column(BigInteger) |
222
|
|
|
bus1 = Column(BigInteger) |
223
|
|
|
type = Column(Text) |
224
|
|
|
carrier = Column(Text) |
225
|
|
|
x = Column(Numeric, server_default="0.") |
226
|
|
|
r = Column(Numeric, server_default="0.") |
227
|
|
|
g = Column(Numeric, server_default="0.") |
228
|
|
|
b = Column(Numeric, server_default="0.") |
229
|
|
|
s_nom = Column(Numeric, server_default="0.") |
230
|
|
|
s_nom_extendable = Column(Boolean, server_default="False") |
231
|
|
|
s_nom_min = Column(Float(53), server_default="0.") |
232
|
|
|
s_nom_max = Column(Float(53), server_default="inf") |
233
|
|
|
s_max_pu = Column(Float(53), server_default="1.") |
234
|
|
|
build_year = Column(BigInteger, server_default="0") |
235
|
|
|
lifetime = Column(Float(53), server_default="inf") |
236
|
|
|
capital_cost = Column(Float(53), server_default="0.") |
237
|
|
|
length = Column(Float(53), server_default="0.") |
238
|
|
|
cables = Column(Integer) |
239
|
|
|
terrain_factor = Column(Float(53), server_default="1.") |
240
|
|
|
num_parallel = Column(Float(53), server_default="1.") |
241
|
|
|
v_ang_min = Column(Float(53), server_default="-inf") |
242
|
|
|
v_ang_max = Column(Float(53), server_default="inf") |
243
|
|
|
v_nom = Column(Float(53)) |
244
|
|
|
geom = Column(Geometry("MULTILINESTRING", 4326)) |
245
|
|
|
topo = Column(Geometry("LINESTRING", 4326)) |
246
|
|
|
|
247
|
|
|
|
248
|
|
|
class EgonPfHvLineTimeseries(Base): |
249
|
|
|
__tablename__ = "egon_etrago_line_timeseries" |
250
|
|
|
__table_args__ = {"schema": "grid"} |
251
|
|
|
|
252
|
|
|
scn_name = Column(String, primary_key=True, nullable=False) |
253
|
|
|
line_id = Column(BigInteger, primary_key=True, nullable=False) |
254
|
|
|
temp_id = Column(Integer, primary_key=True, nullable=False) |
255
|
|
|
s_max_pu = Column(ARRAY(Float(precision=53))) |
256
|
|
|
|
257
|
|
|
|
258
|
|
|
class EgonPfHvLink(Base): |
259
|
|
|
__tablename__ = "egon_etrago_link" |
260
|
|
|
__table_args__ = {"schema": "grid", "comment": get_meta("grid", "Link")} |
261
|
|
|
|
262
|
|
|
scn_name = Column(String, primary_key=True, nullable=False) |
263
|
|
|
link_id = Column(BigInteger, primary_key=True, nullable=False) |
264
|
|
|
bus0 = Column(BigInteger) |
265
|
|
|
bus1 = Column(BigInteger) |
266
|
|
|
type = Column(Text) |
267
|
|
|
carrier = Column(Text) |
268
|
|
|
efficiency = Column(Float(53), server_default="1.") |
269
|
|
|
build_year = Column(BigInteger, server_default="0") |
270
|
|
|
lifetime = Column(Float(53), server_default="inf") |
271
|
|
|
p_nom = Column(Numeric, server_default="0.") |
272
|
|
|
p_nom_extendable = Column(Boolean, server_default="False") |
273
|
|
|
p_nom_min = Column(Float(53), server_default="0.") |
274
|
|
|
p_nom_max = Column(Float(53), server_default="inf") |
275
|
|
|
p_min_pu = Column(Float(53), server_default="0.") |
276
|
|
|
p_max_pu = Column(Float(53), server_default="1.") |
277
|
|
|
p_set = Column(Float(53)) |
278
|
|
|
capital_cost = Column(Float(53), server_default="0.") |
279
|
|
|
marginal_cost = Column(Float(53), server_default="0.") |
280
|
|
|
length = Column(Float(53), server_default="0.") |
281
|
|
|
terrain_factor = Column(Float(53), server_default="1.") |
282
|
|
|
geom = Column(Geometry("MULTILINESTRING", 4326)) |
283
|
|
|
topo = Column(Geometry("LINESTRING", 4326)) |
284
|
|
|
|
285
|
|
|
|
286
|
|
View Code Duplication |
class EgonPfHvLinkTimeseries(Base): |
|
|
|
|
287
|
|
|
__tablename__ = "egon_etrago_link_timeseries" |
288
|
|
|
__table_args__ = {"schema": "grid"} |
289
|
|
|
|
290
|
|
|
scn_name = Column(String, primary_key=True, nullable=False) |
291
|
|
|
link_id = Column(BigInteger, primary_key=True, nullable=False) |
292
|
|
|
temp_id = Column(Integer, primary_key=True, nullable=False) |
293
|
|
|
p_set = Column(ARRAY(Float(precision=53))) |
294
|
|
|
p_min_pu = Column(ARRAY(Float(precision=53))) |
295
|
|
|
p_max_pu = Column(ARRAY(Float(precision=53))) |
296
|
|
|
efficiency = Column(ARRAY(Float(precision=53))) |
297
|
|
|
marginal_cost = Column(ARRAY(Float(precision=53))) |
298
|
|
|
|
299
|
|
|
|
300
|
|
|
class EgonPfHvLoad(Base): |
301
|
|
|
__tablename__ = "egon_etrago_load" |
302
|
|
|
__table_args__ = {"schema": "grid", "comment": get_meta("grid", "Load")} |
303
|
|
|
|
304
|
|
|
scn_name = Column(String, primary_key=True, nullable=False) |
305
|
|
|
load_id = Column(BigInteger, primary_key=True, nullable=False) |
306
|
|
|
bus = Column(BigInteger) |
307
|
|
|
type = Column(Text) |
308
|
|
|
carrier = Column(Text) |
309
|
|
|
p_set = Column(Float(53)) |
310
|
|
|
q_set = Column(Float(53)) |
311
|
|
|
sign = Column(Float(53), server_default="-1.") |
312
|
|
|
|
313
|
|
|
|
314
|
|
|
class EgonPfHvLoadTimeseries(Base): |
315
|
|
|
__tablename__ = "egon_etrago_load_timeseries" |
316
|
|
|
__table_args__ = {"schema": "grid"} |
317
|
|
|
|
318
|
|
|
scn_name = Column(String, primary_key=True, nullable=False) |
319
|
|
|
load_id = Column(BigInteger, primary_key=True, nullable=False) |
320
|
|
|
temp_id = Column(Integer, primary_key=True, nullable=False) |
321
|
|
|
p_set = Column(ARRAY(Float(precision=53))) |
322
|
|
|
q_set = Column(ARRAY(Float(precision=53))) |
323
|
|
|
|
324
|
|
|
|
325
|
|
|
class EgonPfHvCarrier(Base): |
326
|
|
|
__tablename__ = "egon_etrago_carrier" |
327
|
|
|
__table_args__ = {"schema": "grid"} |
328
|
|
|
|
329
|
|
|
name = Column(Text, primary_key=True, nullable=False) |
330
|
|
|
co2_emissions = Column(Float(53), server_default="0.") |
331
|
|
|
color = Column(Text) |
332
|
|
|
nice_name = Column(Text) |
333
|
|
|
commentary = Column(Text) |
334
|
|
|
|
335
|
|
|
|
336
|
|
|
class EgonPfHvStorage(Base): |
337
|
|
|
__tablename__ = "egon_etrago_storage" |
338
|
|
|
__table_args__ = {"schema": "grid", "comment": get_meta("grid", "Storage")} |
339
|
|
|
|
340
|
|
|
scn_name = Column(String, primary_key=True, nullable=False) |
341
|
|
|
storage_id = Column(BigInteger, primary_key=True, nullable=False) |
342
|
|
|
bus = Column(BigInteger) |
343
|
|
|
control = Column(Text) |
344
|
|
|
type = Column(Text) |
345
|
|
|
carrier = Column(Text) |
346
|
|
|
p_nom = Column(Float(53), server_default="0.") |
347
|
|
|
p_nom_extendable = Column((Boolean), server_default="False") |
348
|
|
|
p_nom_min = Column(Float(53), server_default="0.") |
349
|
|
|
p_nom_max = Column(Float(53), server_default="inf") |
350
|
|
|
p_min_pu = Column(Float(53), server_default="-1.") |
351
|
|
|
p_max_pu = Column(Float(53), server_default="1.") |
352
|
|
|
p_set = Column(Float(53)) |
353
|
|
|
q_set = Column(Float(53)) |
354
|
|
|
sign = Column(Float(53), server_default="1") |
355
|
|
|
marginal_cost = Column(Float(53), server_default="0.") |
356
|
|
|
capital_cost = Column(Float(53), server_default="0.") |
357
|
|
|
build_year = Column(BigInteger, server_default="0") |
358
|
|
|
lifetime = Column(Float(53), server_default="inf") |
359
|
|
|
state_of_charge_initial = Column(Float(53), server_default="0") |
360
|
|
|
cyclic_state_of_charge = Column(Boolean, server_default="False") |
361
|
|
|
state_of_charge_set = Column(Float(53)) |
362
|
|
|
max_hours = Column(Float(53), server_default="1") |
363
|
|
|
efficiency_store = Column(Float(53), server_default="1.") |
364
|
|
|
efficiency_dispatch = Column(Float(53), server_default="1.") |
365
|
|
|
standing_loss = Column(Float(53), server_default="0.") |
366
|
|
|
inflow = Column(Float(53), server_default="0.") |
367
|
|
|
|
368
|
|
|
|
369
|
|
|
class EgonPfHvStorageTimeseries(Base): |
370
|
|
|
__tablename__ = "egon_etrago_storage_timeseries" |
371
|
|
|
__table_args__ = {"schema": "grid"} |
372
|
|
|
|
373
|
|
|
scn_name = Column(String, primary_key=True, nullable=False) |
374
|
|
|
storage_id = Column(BigInteger, primary_key=True, nullable=False) |
375
|
|
|
temp_id = Column(Integer, primary_key=True, nullable=False) |
376
|
|
|
p_set = Column(ARRAY(Float(precision=53))) |
377
|
|
|
q_set = Column(ARRAY(Float(precision=53))) |
378
|
|
|
p_min_pu = Column(ARRAY(Float(precision=53))) |
379
|
|
|
p_max_pu = Column(ARRAY(Float(precision=53))) |
380
|
|
|
state_of_charge_set = Column(ARRAY(Float(precision=53))) |
381
|
|
|
inflow = Column(ARRAY(Float(precision=53))) |
382
|
|
|
marginal_cost = Column(ARRAY(Float(precision=53))) |
383
|
|
|
|
384
|
|
|
|
385
|
|
|
class EgonPfHvStore(Base): |
386
|
|
|
source_dict = sources() |
387
|
|
|
source_list = [ |
388
|
|
|
source_dict["bgr_inspee"], |
389
|
|
|
source_dict["bgr_inspeeds"], |
390
|
|
|
source_dict["bgr_inspeeds_data_bundle"], |
391
|
|
|
source_dict["bgr_inspeeds_data_bundle"], |
392
|
|
|
source_dict["bgr_inspeeds_report"], |
393
|
|
|
] |
394
|
|
|
contributors_dict = contributors() |
395
|
|
|
contributor_list = [ |
396
|
|
|
{key: value for key, value in contributors_dict[author]} |
397
|
|
|
for author in ["an", "fw"] |
398
|
|
|
] |
399
|
|
|
|
400
|
|
|
contributor_list[0]["comment"] = "Add H2 storage" |
401
|
|
|
contributor_list[1]["comment"] = "Add CH4 storage" |
402
|
|
|
license_list = [data["license"] for data in source_list] |
403
|
|
|
__tablename__ = "egon_etrago_store" |
404
|
|
|
__table_args__ = { |
405
|
|
|
"schema": "grid", |
406
|
|
|
"comment": get_meta( |
407
|
|
|
"grid", "Store", source_list, license_list, contributor_list |
408
|
|
|
), |
409
|
|
|
} |
410
|
|
|
|
411
|
|
|
scn_name = Column(String, primary_key=True, nullable=False) |
412
|
|
|
store_id = Column(BigInteger, primary_key=True, nullable=False) |
413
|
|
|
bus = Column(BigInteger) |
414
|
|
|
type = Column(Text) |
415
|
|
|
carrier = Column(Text) |
416
|
|
|
e_nom = Column(Float(53), server_default="0.") |
417
|
|
|
e_nom_extendable = Column((Boolean), server_default="False") |
418
|
|
|
e_nom_min = Column(Float(53), server_default="0.") |
419
|
|
|
e_nom_max = Column(Float(53), server_default="inf") |
420
|
|
|
e_min_pu = Column(Float(53), server_default="0.") |
421
|
|
|
e_max_pu = Column(Float(53), server_default="1.") |
422
|
|
|
p_set = Column(Float(53)) |
423
|
|
|
q_set = Column(Float(53)) |
424
|
|
|
e_initial = Column(Float(53), server_default="0.") |
425
|
|
|
e_cyclic = Column(Boolean, server_default="False") |
426
|
|
|
sign = Column(Float(53), server_default="1") |
427
|
|
|
marginal_cost = Column(Float(53), server_default="0.") |
428
|
|
|
capital_cost = Column(Float(53), server_default="0.") |
429
|
|
|
standing_loss = Column(Float(53), server_default="0.") |
430
|
|
|
build_year = Column(BigInteger, server_default="0") |
431
|
|
|
lifetime = Column(Float(53), server_default="inf") |
432
|
|
|
|
433
|
|
|
|
434
|
|
|
class EgonPfHvStoreTimeseries(Base): |
435
|
|
|
__tablename__ = "egon_etrago_store_timeseries" |
436
|
|
|
__table_args__ = {"schema": "grid"} |
437
|
|
|
|
438
|
|
|
scn_name = Column(String, primary_key=True, nullable=False) |
439
|
|
|
store_id = Column(BigInteger, primary_key=True, nullable=False) |
440
|
|
|
temp_id = Column(Integer, primary_key=True, nullable=False) |
441
|
|
|
p_set = Column(ARRAY(Float(precision=53))) |
442
|
|
|
q_set = Column(ARRAY(Float(precision=53))) |
443
|
|
|
e_min_pu = Column(ARRAY(Float(precision=53))) |
444
|
|
|
e_max_pu = Column(ARRAY(Float(precision=53))) |
445
|
|
|
marginal_cost = Column(ARRAY(Float(precision=53))) |
446
|
|
|
|
447
|
|
|
|
448
|
|
|
class EgonPfHvTempResolution(Base): |
449
|
|
|
__tablename__ = "egon_etrago_temp_resolution" |
450
|
|
|
__table_args__ = {"schema": "grid"} |
451
|
|
|
|
452
|
|
|
temp_id = Column(BigInteger, primary_key=True, nullable=False) |
453
|
|
|
timesteps = Column(BigInteger, nullable=False) |
454
|
|
|
resolution = Column(Text) |
455
|
|
|
start_time = Column(DateTime) |
456
|
|
|
|
457
|
|
|
|
458
|
|
|
class EgonPfHvTransformer(Base): |
459
|
|
|
__tablename__ = "egon_etrago_transformer" |
460
|
|
|
__table_args__ = { |
461
|
|
|
"schema": "grid", |
462
|
|
|
"comment": get_meta("grid", "Transformer"), |
463
|
|
|
} |
464
|
|
|
|
465
|
|
|
scn_name = Column(String, primary_key=True, nullable=False) |
466
|
|
|
trafo_id = Column(BigInteger, primary_key=True, nullable=False) |
467
|
|
|
bus0 = Column(BigInteger) |
468
|
|
|
bus1 = Column(BigInteger) |
469
|
|
|
type = Column(Text) |
470
|
|
|
model = Column((Text), server_default="t") |
471
|
|
|
x = Column((Numeric), server_default="0.") |
472
|
|
|
r = Column((Numeric), server_default="0.") |
473
|
|
|
g = Column((Numeric), server_default="0.") |
474
|
|
|
b = Column((Numeric), server_default="0.") |
475
|
|
|
s_nom = Column(Float(53), server_default="0.") |
476
|
|
|
s_nom_extendable = Column((Boolean), server_default="False") |
477
|
|
|
s_nom_min = Column(Float(53), server_default="0.") |
478
|
|
|
s_nom_max = Column(Float(53), server_default="inf") |
479
|
|
|
s_max_pu = Column(Float(53), server_default="1.") |
480
|
|
|
tap_ratio = Column(Float(53), server_default="1.") |
481
|
|
|
tap_side = Column((BigInteger), server_default="0") |
482
|
|
|
tap_position = Column((BigInteger), server_default="0") |
483
|
|
|
phase_shift = Column(Float(53), server_default="0.") |
484
|
|
|
build_year = Column(BigInteger, server_default="0") |
485
|
|
|
lifetime = Column(Float(53), server_default="inf") |
486
|
|
|
v_ang_min = Column(Float(53), server_default="-inf") |
487
|
|
|
v_ang_max = Column(Float(53), server_default="inf") |
488
|
|
|
capital_cost = Column(Float(53), server_default="0.") |
489
|
|
|
num_parallel = Column(Float(53), server_default="1.") |
490
|
|
|
geom = Column(Geometry("MULTILINESTRING", 4326)) |
491
|
|
|
topo = Column(Geometry("LINESTRING", 4326)) |
492
|
|
|
|
493
|
|
|
|
494
|
|
|
class EgonPfHvTransformerTimeseries(Base): |
495
|
|
|
__tablename__ = "egon_etrago_transformer_timeseries" |
496
|
|
|
__table_args__ = {"schema": "grid"} |
497
|
|
|
|
498
|
|
|
scn_name = Column(String, primary_key=True, nullable=False) |
499
|
|
|
trafo_id = Column(BigInteger, primary_key=True, nullable=False) |
500
|
|
|
temp_id = Column(Integer, primary_key=True, nullable=False) |
501
|
|
|
s_max_pu = Column(ARRAY(Float(precision=53))) |
502
|
|
|
|
503
|
|
|
|
504
|
|
|
class EgonPfHvBusmap(Base): |
505
|
|
|
__tablename__ = "egon_etrago_hv_busmap" |
506
|
|
|
__table_args__ = {"schema": "grid"} |
507
|
|
|
|
508
|
|
|
scn_name = Column(Text, primary_key=True, nullable=False) |
509
|
|
|
bus0 = Column(Text, primary_key=True, nullable=False) |
510
|
|
|
bus1 = Column(Text, primary_key=True, nullable=False) |
511
|
|
|
path_length = Column(Numeric) |
512
|
|
|
version = Column(Text, primary_key=True, nullable=False) |
513
|
|
|
|
514
|
|
|
|
515
|
|
|
def create_tables(): |
516
|
|
|
"""Create tables for eTraGo input data. |
517
|
|
|
Returns |
518
|
|
|
------- |
519
|
|
|
None. |
520
|
|
|
""" |
521
|
|
|
db.execute_sql("CREATE SCHEMA IF NOT EXISTS grid;") |
522
|
|
|
engine = db.engine() |
523
|
|
|
|
524
|
|
|
##################### drop tables with old names ######################### |
525
|
|
|
db.execute_sql( |
526
|
|
|
""" |
527
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_bus;""" |
528
|
|
|
) |
529
|
|
|
db.execute_sql( |
530
|
|
|
""" |
531
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_bus_timeseries;""" |
532
|
|
|
) |
533
|
|
|
db.execute_sql( |
534
|
|
|
""" |
535
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_carrier;""" |
536
|
|
|
) |
537
|
|
|
db.execute_sql( |
538
|
|
|
""" |
539
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_generator;""" |
540
|
|
|
) |
541
|
|
|
db.execute_sql( |
542
|
|
|
""" |
543
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_generator_timeseries;""" |
544
|
|
|
) |
545
|
|
|
db.execute_sql( |
546
|
|
|
""" |
547
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_line;""" |
548
|
|
|
) |
549
|
|
|
db.execute_sql( |
550
|
|
|
""" |
551
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_line_timeseries;""" |
552
|
|
|
) |
553
|
|
|
db.execute_sql( |
554
|
|
|
""" |
555
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_link;""" |
556
|
|
|
) |
557
|
|
|
db.execute_sql( |
558
|
|
|
""" |
559
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_link_timeseries;""" |
560
|
|
|
) |
561
|
|
|
db.execute_sql( |
562
|
|
|
""" |
563
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_load;""" |
564
|
|
|
) |
565
|
|
|
db.execute_sql( |
566
|
|
|
""" |
567
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_load_timeseries;""" |
568
|
|
|
) |
569
|
|
|
db.execute_sql( |
570
|
|
|
""" |
571
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_storage;""" |
572
|
|
|
) |
573
|
|
|
db.execute_sql( |
574
|
|
|
""" |
575
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_storage_timeseries;""" |
576
|
|
|
) |
577
|
|
|
db.execute_sql( |
578
|
|
|
""" |
579
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_store;""" |
580
|
|
|
) |
581
|
|
|
db.execute_sql( |
582
|
|
|
""" |
583
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_store_timeseries;""" |
584
|
|
|
) |
585
|
|
|
db.execute_sql( |
586
|
|
|
""" |
587
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_temp_resolution;""" |
588
|
|
|
) |
589
|
|
|
db.execute_sql( |
590
|
|
|
""" |
591
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_transformer;""" |
592
|
|
|
) |
593
|
|
|
db.execute_sql( |
594
|
|
|
""" |
595
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_transformer_timeseries;""" |
596
|
|
|
) |
597
|
|
|
########################################################################## |
598
|
|
|
|
599
|
|
|
# Drop existing tables |
600
|
|
|
EgonPfHvBus.__table__.drop(bind=engine, checkfirst=True) |
601
|
|
|
EgonPfHvBusTimeseries.__table__.drop(bind=engine, checkfirst=True) |
602
|
|
|
EgonPfHvGenerator.__table__.drop(bind=engine, checkfirst=True) |
603
|
|
|
EgonPfHvGeneratorTimeseries.__table__.drop(bind=engine, checkfirst=True) |
604
|
|
|
EgonPfHvLine.__table__.drop(bind=engine, checkfirst=True) |
605
|
|
|
EgonPfHvLineTimeseries.__table__.drop(bind=engine, checkfirst=True) |
606
|
|
|
EgonPfHvLink.__table__.drop(bind=engine, checkfirst=True) |
607
|
|
|
EgonPfHvLinkTimeseries.__table__.drop(bind=engine, checkfirst=True) |
608
|
|
|
EgonPfHvLoad.__table__.drop(bind=engine, checkfirst=True) |
609
|
|
|
EgonPfHvLoadTimeseries.__table__.drop(bind=engine, checkfirst=True) |
610
|
|
|
EgonPfHvCarrier.__table__.drop(bind=engine, checkfirst=True) |
611
|
|
|
EgonPfHvStorage.__table__.drop(bind=engine, checkfirst=True) |
612
|
|
|
EgonPfHvStorageTimeseries.__table__.drop(bind=engine, checkfirst=True) |
613
|
|
|
EgonPfHvStore.__table__.drop(bind=engine, checkfirst=True) |
614
|
|
|
EgonPfHvStoreTimeseries.__table__.drop(bind=engine, checkfirst=True) |
615
|
|
|
EgonPfHvTempResolution.__table__.drop(bind=engine, checkfirst=True) |
616
|
|
|
EgonPfHvTransformer.__table__.drop(bind=engine, checkfirst=True) |
617
|
|
|
EgonPfHvTransformerTimeseries.__table__.drop(bind=engine, checkfirst=True) |
618
|
|
|
EgonPfHvBusmap.__table__.drop(bind=engine, checkfirst=True) |
619
|
|
|
# Create new tables |
620
|
|
|
EgonPfHvBus.__table__.create(bind=engine, checkfirst=True) |
621
|
|
|
EgonPfHvBusTimeseries.__table__.create(bind=engine, checkfirst=True) |
622
|
|
|
EgonPfHvGenerator.__table__.create(bind=engine, checkfirst=True) |
623
|
|
|
EgonPfHvGeneratorTimeseries.__table__.create(bind=engine, checkfirst=True) |
624
|
|
|
EgonPfHvLine.__table__.create(bind=engine, checkfirst=True) |
625
|
|
|
EgonPfHvLineTimeseries.__table__.create(bind=engine, checkfirst=True) |
626
|
|
|
EgonPfHvLink.__table__.create(bind=engine, checkfirst=True) |
627
|
|
|
EgonPfHvLinkTimeseries.__table__.create(bind=engine, checkfirst=True) |
628
|
|
|
EgonPfHvLoad.__table__.create(bind=engine, checkfirst=True) |
629
|
|
|
EgonPfHvLoadTimeseries.__table__.create(bind=engine, checkfirst=True) |
630
|
|
|
EgonPfHvCarrier.__table__.create(bind=engine, checkfirst=True) |
631
|
|
|
EgonPfHvStorage.__table__.create(bind=engine, checkfirst=True) |
632
|
|
|
EgonPfHvStorageTimeseries.__table__.create(bind=engine, checkfirst=True) |
633
|
|
|
EgonPfHvStore.__table__.create(bind=engine, checkfirst=True) |
634
|
|
|
EgonPfHvStoreTimeseries.__table__.create(bind=engine, checkfirst=True) |
635
|
|
|
EgonPfHvTempResolution.__table__.create(bind=engine, checkfirst=True) |
636
|
|
|
EgonPfHvTransformer.__table__.create(bind=engine, checkfirst=True) |
637
|
|
|
EgonPfHvTransformerTimeseries.__table__.create( |
638
|
|
|
bind=engine, checkfirst=True |
639
|
|
|
) |
640
|
|
|
EgonPfHvBusmap.__table__.create(bind=engine, checkfirst=True) |
641
|
|
|
|
642
|
|
|
|
643
|
|
|
def temp_resolution(): |
644
|
|
|
"""Insert temporal resolution for etrago |
645
|
|
|
|
646
|
|
|
Returns |
647
|
|
|
------- |
648
|
|
|
None. |
649
|
|
|
|
650
|
|
|
""" |
651
|
|
|
|
652
|
|
|
db.execute_sql( |
653
|
|
|
""" |
654
|
|
|
INSERT INTO grid.egon_etrago_temp_resolution |
655
|
|
|
(temp_id, timesteps, resolution, start_time) |
656
|
|
|
SELECT 1, 8760, 'h', TIMESTAMP '2011-01-01 00:00:00'; |
657
|
|
|
""" |
658
|
|
|
) |
659
|
|
|
|
660
|
|
|
|
661
|
|
|
def insert_carriers(): |
662
|
|
|
"""Insert list of carriers into eTraGo table |
663
|
|
|
|
664
|
|
|
Returns |
665
|
|
|
------- |
666
|
|
|
None. |
667
|
|
|
|
668
|
|
|
""" |
669
|
|
|
# Delete existing entries |
670
|
|
|
db.execute_sql( |
671
|
|
|
""" |
672
|
|
|
DELETE FROM grid.egon_etrago_carrier |
673
|
|
|
""" |
674
|
|
|
) |
675
|
|
|
|
676
|
|
|
# List carrier names from all components |
677
|
|
|
df = pd.DataFrame( |
678
|
|
|
data={ |
679
|
|
|
"name": [ |
680
|
|
|
"biogas", |
681
|
|
|
"biogas_feedin", |
682
|
|
|
"biogas_to_gas", |
683
|
|
|
"biomass", |
684
|
|
|
"pv", |
685
|
|
|
"wind_offshore", |
686
|
|
|
"wind_onshore", |
687
|
|
|
"central_heat_pump", |
688
|
|
|
"central_resistive_heater", |
689
|
|
|
"CH4", |
690
|
|
|
"CH4_for_industry", |
691
|
|
|
"CH4_system_boundary", |
692
|
|
|
"CH4_to_H2", |
693
|
|
|
"dsm", |
694
|
|
|
"H2", |
695
|
|
|
"H2_feedin", |
696
|
|
|
"H2_for_industry", |
697
|
|
|
"H2_grid", |
698
|
|
|
"H2_gridextension", |
699
|
|
|
"H2_hgv_load", |
700
|
|
|
"H2_overground", |
701
|
|
|
"H2_retrofit", |
702
|
|
|
"H2_saltcavern", |
703
|
|
|
"H2_system_boundary", |
704
|
|
|
"H2_to_CH4", |
705
|
|
|
"H2_to_power", |
706
|
|
|
"H2_underground", |
707
|
|
|
"rural_heat_pump", |
708
|
|
|
"industrial_biomass_CHP", |
709
|
|
|
"industrial_gas_CHP", |
710
|
|
|
"central_biomass_CHP_heat", |
711
|
|
|
"central_biomass_CHP", |
712
|
|
|
"central_gas_CHP", |
713
|
|
|
"central_gas_CHP_heat", |
714
|
|
|
"power_to_H2", |
715
|
|
|
"rural_gas_boiler", |
716
|
|
|
"central_gas_boiler", |
717
|
|
|
"solar_thermal_collector", |
718
|
|
|
"geo_thermal", |
719
|
|
|
"AC", |
720
|
|
|
"central_heat", |
721
|
|
|
"rural_heat", |
722
|
|
|
"natural_gas_feedin", |
723
|
|
|
"pumped_hydro", |
724
|
|
|
"battery", |
725
|
|
|
"OCGT", |
726
|
|
|
] |
727
|
|
|
} |
728
|
|
|
) |
729
|
|
|
|
730
|
|
|
# Insert data into database |
731
|
|
|
df.to_sql( |
732
|
|
|
"egon_etrago_carrier", |
733
|
|
|
schema="grid", |
734
|
|
|
con=db.engine(), |
735
|
|
|
if_exists="append", |
736
|
|
|
index=False, |
737
|
|
|
) |
738
|
|
|
|
739
|
|
|
|
740
|
|
|
def check_carriers(): |
741
|
|
|
"""Check if any eTraGo table has carriers not included in the carrier table. |
742
|
|
|
|
743
|
|
|
Raises |
744
|
|
|
------ |
745
|
|
|
ValueError if carriers that are not defined in the carriers table are |
746
|
|
|
used in any eTraGo table. |
747
|
|
|
""" |
748
|
|
|
carriers = db.select_dataframe( |
749
|
|
|
f""" |
750
|
|
|
SELECT name FROM grid.egon_etrago_carrier |
751
|
|
|
""" |
752
|
|
|
) |
753
|
|
|
unknown_carriers = {} |
754
|
|
|
tables = ["bus", "store", "storage", "link", "line", "generator", "load"] |
755
|
|
|
|
756
|
|
|
for table in tables: |
757
|
|
|
# Delete existing entries |
758
|
|
|
data = db.select_dataframe( |
759
|
|
|
f""" |
760
|
|
|
SELECT carrier FROM grid.egon_etrago_{table} |
761
|
|
|
""" |
762
|
|
|
) |
763
|
|
|
unknown_carriers[table] = data[~data["carrier"].isin(carriers)][ |
764
|
|
|
"carrier" |
765
|
|
|
].unique() |
766
|
|
|
|
767
|
|
|
if len(unknown_carriers) > 0: |
768
|
|
|
msg = ( |
769
|
|
|
"The eTraGo tables contain carriers, that are not included in the " |
770
|
|
|
"carrier table:\n" |
771
|
|
|
) |
772
|
|
|
for table, carriers in unknown_carriers.items(): |
773
|
|
|
carriers = [str(c) for c in carriers] |
774
|
|
|
if len(carriers) > 0: |
775
|
|
|
msg += table + ": '" + "', '".join(carriers) + "'\n" |
776
|
|
|
|
777
|
|
|
raise ValueError(msg) |
778
|
|
|
|
779
|
|
|
|
780
|
|
|
def link_geom_from_buses(df, scn_name): |
781
|
|
|
"""Add LineString geometry accoring to geometry of buses to links |
782
|
|
|
|
783
|
|
|
Parameters |
784
|
|
|
---------- |
785
|
|
|
df : pandas.DataFrame |
786
|
|
|
List of eTraGo links with bus0 and bus1 but without topology |
787
|
|
|
scn_name : str |
788
|
|
|
Scenario name |
789
|
|
|
|
790
|
|
|
Returns |
791
|
|
|
------- |
792
|
|
|
gdf : geopandas.GeoDataFrame |
793
|
|
|
List of eTraGo links with bus0 and bus1 but with topology |
794
|
|
|
|
795
|
|
|
""" |
796
|
|
|
|
797
|
|
|
geom_buses = db.select_geodataframe( |
798
|
|
|
f""" |
799
|
|
|
SELECT bus_id, geom |
800
|
|
|
FROM grid.egon_etrago_bus |
801
|
|
|
WHERE scn_name = '{scn_name}' |
802
|
|
|
""", |
803
|
|
|
index_col="bus_id", |
804
|
|
|
epsg=4326, |
805
|
|
|
) |
806
|
|
|
|
807
|
|
|
# Create geometry columns for bus0 and bus1 |
808
|
|
|
df["geom_0"] = geom_buses.geom[df.bus0.values].values |
809
|
|
|
df["geom_1"] = geom_buses.geom[df.bus1.values].values |
810
|
|
|
|
811
|
|
|
geometry = df.apply( |
812
|
|
|
lambda x: LineString([x["geom_0"], x["geom_1"]]), axis=1 |
813
|
|
|
) |
814
|
|
|
df = df.drop(["geom_0", "geom_1"], axis=1) |
815
|
|
|
|
816
|
|
|
gdf = gpd.GeoDataFrame(df, geometry=geometry, crs=4326).rename_geometry( |
817
|
|
|
"topo" |
818
|
|
|
) |
819
|
|
|
|
820
|
|
|
return gdf |
821
|
|
|
|