|
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, ensure_ascii=False) + "'" |
|
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
|
|
|
contributor_list = contributors(["an", "fw"]) |
|
395
|
|
|
contributor_list[0]["comment"] = "Add H2 storage" |
|
396
|
|
|
contributor_list[1]["comment"] = "Add CH4 storage" |
|
397
|
|
|
license_list = [data["license"] for data in source_list] |
|
398
|
|
|
__tablename__ = "egon_etrago_store" |
|
399
|
|
|
__table_args__ = { |
|
400
|
|
|
"schema": "grid", |
|
401
|
|
|
"comment": get_meta( |
|
402
|
|
|
"grid", |
|
403
|
|
|
"Store", |
|
404
|
|
|
source_list=source_list, |
|
405
|
|
|
license_list=license_list, |
|
406
|
|
|
contributor_list=contributor_list, |
|
407
|
|
|
), |
|
408
|
|
|
} |
|
409
|
|
|
|
|
410
|
|
|
scn_name = Column(String, primary_key=True, nullable=False) |
|
411
|
|
|
store_id = Column(BigInteger, primary_key=True, nullable=False) |
|
412
|
|
|
bus = Column(BigInteger) |
|
413
|
|
|
type = Column(Text) |
|
414
|
|
|
carrier = Column(Text) |
|
415
|
|
|
e_nom = Column(Float(53), server_default="0.") |
|
416
|
|
|
e_nom_extendable = Column((Boolean), server_default="False") |
|
417
|
|
|
e_nom_min = Column(Float(53), server_default="0.") |
|
418
|
|
|
e_nom_max = Column(Float(53), server_default="inf") |
|
419
|
|
|
e_min_pu = Column(Float(53), server_default="0.") |
|
420
|
|
|
e_max_pu = Column(Float(53), server_default="1.") |
|
421
|
|
|
p_set = Column(Float(53)) |
|
422
|
|
|
q_set = Column(Float(53)) |
|
423
|
|
|
e_initial = Column(Float(53), server_default="0.") |
|
424
|
|
|
e_cyclic = Column(Boolean, server_default="False") |
|
425
|
|
|
sign = Column(Float(53), server_default="1") |
|
426
|
|
|
marginal_cost = Column(Float(53), server_default="0.") |
|
427
|
|
|
capital_cost = Column(Float(53), server_default="0.") |
|
428
|
|
|
standing_loss = Column(Float(53), server_default="0.") |
|
429
|
|
|
build_year = Column(BigInteger, server_default="0") |
|
430
|
|
|
lifetime = Column(Float(53), server_default="inf") |
|
431
|
|
|
|
|
432
|
|
|
|
|
433
|
|
|
class EgonPfHvStoreTimeseries(Base): |
|
434
|
|
|
__tablename__ = "egon_etrago_store_timeseries" |
|
435
|
|
|
__table_args__ = {"schema": "grid"} |
|
436
|
|
|
|
|
437
|
|
|
scn_name = Column(String, primary_key=True, nullable=False) |
|
438
|
|
|
store_id = Column(BigInteger, primary_key=True, nullable=False) |
|
439
|
|
|
temp_id = Column(Integer, primary_key=True, nullable=False) |
|
440
|
|
|
p_set = Column(ARRAY(Float(precision=53))) |
|
441
|
|
|
q_set = Column(ARRAY(Float(precision=53))) |
|
442
|
|
|
e_min_pu = Column(ARRAY(Float(precision=53))) |
|
443
|
|
|
e_max_pu = Column(ARRAY(Float(precision=53))) |
|
444
|
|
|
marginal_cost = Column(ARRAY(Float(precision=53))) |
|
445
|
|
|
|
|
446
|
|
|
|
|
447
|
|
|
class EgonPfHvTempResolution(Base): |
|
448
|
|
|
__tablename__ = "egon_etrago_temp_resolution" |
|
449
|
|
|
__table_args__ = {"schema": "grid"} |
|
450
|
|
|
|
|
451
|
|
|
temp_id = Column(BigInteger, primary_key=True, nullable=False) |
|
452
|
|
|
timesteps = Column(BigInteger, nullable=False) |
|
453
|
|
|
resolution = Column(Text) |
|
454
|
|
|
start_time = Column(DateTime) |
|
455
|
|
|
|
|
456
|
|
|
|
|
457
|
|
|
class EgonPfHvTransformer(Base): |
|
458
|
|
|
__tablename__ = "egon_etrago_transformer" |
|
459
|
|
|
__table_args__ = { |
|
460
|
|
|
"schema": "grid", |
|
461
|
|
|
"comment": get_meta("grid", "Transformer"), |
|
462
|
|
|
} |
|
463
|
|
|
|
|
464
|
|
|
scn_name = Column(String, primary_key=True, nullable=False) |
|
465
|
|
|
trafo_id = Column(BigInteger, primary_key=True, nullable=False) |
|
466
|
|
|
bus0 = Column(BigInteger) |
|
467
|
|
|
bus1 = Column(BigInteger) |
|
468
|
|
|
type = Column(Text) |
|
469
|
|
|
model = Column((Text), server_default="t") |
|
470
|
|
|
x = Column((Numeric), server_default="0.") |
|
471
|
|
|
r = Column((Numeric), server_default="0.") |
|
472
|
|
|
g = Column((Numeric), server_default="0.") |
|
473
|
|
|
b = Column((Numeric), server_default="0.") |
|
474
|
|
|
s_nom = Column(Float(53), server_default="0.") |
|
475
|
|
|
s_nom_extendable = Column((Boolean), server_default="False") |
|
476
|
|
|
s_nom_min = Column(Float(53), server_default="0.") |
|
477
|
|
|
s_nom_max = Column(Float(53), server_default="inf") |
|
478
|
|
|
s_max_pu = Column(Float(53), server_default="1.") |
|
479
|
|
|
tap_ratio = Column(Float(53), server_default="1.") |
|
480
|
|
|
tap_side = Column((BigInteger), server_default="0") |
|
481
|
|
|
tap_position = Column((BigInteger), server_default="0") |
|
482
|
|
|
phase_shift = Column(Float(53), server_default="0.") |
|
483
|
|
|
build_year = Column(BigInteger, server_default="0") |
|
484
|
|
|
lifetime = Column(Float(53), server_default="inf") |
|
485
|
|
|
v_ang_min = Column(Float(53), server_default="-inf") |
|
486
|
|
|
v_ang_max = Column(Float(53), server_default="inf") |
|
487
|
|
|
capital_cost = Column(Float(53), server_default="0.") |
|
488
|
|
|
num_parallel = Column(Float(53), server_default="1.") |
|
489
|
|
|
geom = Column(Geometry("MULTILINESTRING", 4326)) |
|
490
|
|
|
topo = Column(Geometry("LINESTRING", 4326)) |
|
491
|
|
|
|
|
492
|
|
|
|
|
493
|
|
|
class EgonPfHvTransformerTimeseries(Base): |
|
494
|
|
|
__tablename__ = "egon_etrago_transformer_timeseries" |
|
495
|
|
|
__table_args__ = {"schema": "grid"} |
|
496
|
|
|
|
|
497
|
|
|
scn_name = Column(String, primary_key=True, nullable=False) |
|
498
|
|
|
trafo_id = Column(BigInteger, primary_key=True, nullable=False) |
|
499
|
|
|
temp_id = Column(Integer, primary_key=True, nullable=False) |
|
500
|
|
|
s_max_pu = Column(ARRAY(Float(precision=53))) |
|
501
|
|
|
|
|
502
|
|
|
|
|
503
|
|
|
class EgonPfHvBusmap(Base): |
|
504
|
|
|
__tablename__ = "egon_etrago_hv_busmap" |
|
505
|
|
|
__table_args__ = {"schema": "grid"} |
|
506
|
|
|
|
|
507
|
|
|
scn_name = Column(Text, primary_key=True, nullable=False) |
|
508
|
|
|
bus0 = Column(Text, primary_key=True, nullable=False) |
|
509
|
|
|
bus1 = Column(Text, primary_key=True, nullable=False) |
|
510
|
|
|
path_length = Column(Numeric) |
|
511
|
|
|
version = Column(Text, primary_key=True, nullable=False) |
|
512
|
|
|
|
|
513
|
|
|
|
|
514
|
|
|
def create_tables(): |
|
515
|
|
|
"""Create tables for eTraGo input data. |
|
516
|
|
|
Returns |
|
517
|
|
|
------- |
|
518
|
|
|
None. |
|
519
|
|
|
""" |
|
520
|
|
|
db.execute_sql("CREATE SCHEMA IF NOT EXISTS grid;") |
|
521
|
|
|
engine = db.engine() |
|
522
|
|
|
|
|
523
|
|
|
##################### drop tables with old names ######################### |
|
524
|
|
|
db.execute_sql( |
|
525
|
|
|
""" |
|
526
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_bus;""" |
|
527
|
|
|
) |
|
528
|
|
|
db.execute_sql( |
|
529
|
|
|
""" |
|
530
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_bus_timeseries;""" |
|
531
|
|
|
) |
|
532
|
|
|
db.execute_sql( |
|
533
|
|
|
""" |
|
534
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_carrier;""" |
|
535
|
|
|
) |
|
536
|
|
|
db.execute_sql( |
|
537
|
|
|
""" |
|
538
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_generator;""" |
|
539
|
|
|
) |
|
540
|
|
|
db.execute_sql( |
|
541
|
|
|
""" |
|
542
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_generator_timeseries;""" |
|
543
|
|
|
) |
|
544
|
|
|
db.execute_sql( |
|
545
|
|
|
""" |
|
546
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_line;""" |
|
547
|
|
|
) |
|
548
|
|
|
db.execute_sql( |
|
549
|
|
|
""" |
|
550
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_line_timeseries;""" |
|
551
|
|
|
) |
|
552
|
|
|
db.execute_sql( |
|
553
|
|
|
""" |
|
554
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_link;""" |
|
555
|
|
|
) |
|
556
|
|
|
db.execute_sql( |
|
557
|
|
|
""" |
|
558
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_link_timeseries;""" |
|
559
|
|
|
) |
|
560
|
|
|
db.execute_sql( |
|
561
|
|
|
""" |
|
562
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_load;""" |
|
563
|
|
|
) |
|
564
|
|
|
db.execute_sql( |
|
565
|
|
|
""" |
|
566
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_load_timeseries;""" |
|
567
|
|
|
) |
|
568
|
|
|
db.execute_sql( |
|
569
|
|
|
""" |
|
570
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_storage;""" |
|
571
|
|
|
) |
|
572
|
|
|
db.execute_sql( |
|
573
|
|
|
""" |
|
574
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_storage_timeseries;""" |
|
575
|
|
|
) |
|
576
|
|
|
db.execute_sql( |
|
577
|
|
|
""" |
|
578
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_store;""" |
|
579
|
|
|
) |
|
580
|
|
|
db.execute_sql( |
|
581
|
|
|
""" |
|
582
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_store_timeseries;""" |
|
583
|
|
|
) |
|
584
|
|
|
db.execute_sql( |
|
585
|
|
|
""" |
|
586
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_temp_resolution;""" |
|
587
|
|
|
) |
|
588
|
|
|
db.execute_sql( |
|
589
|
|
|
""" |
|
590
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_transformer;""" |
|
591
|
|
|
) |
|
592
|
|
|
db.execute_sql( |
|
593
|
|
|
""" |
|
594
|
|
|
DROP TABLE IF EXISTS grid.egon_pf_hv_transformer_timeseries;""" |
|
595
|
|
|
) |
|
596
|
|
|
########################################################################## |
|
597
|
|
|
|
|
598
|
|
|
# Drop existing tables |
|
599
|
|
|
EgonPfHvBus.__table__.drop(bind=engine, checkfirst=True) |
|
600
|
|
|
EgonPfHvBusTimeseries.__table__.drop(bind=engine, checkfirst=True) |
|
601
|
|
|
EgonPfHvGenerator.__table__.drop(bind=engine, checkfirst=True) |
|
602
|
|
|
EgonPfHvGeneratorTimeseries.__table__.drop(bind=engine, checkfirst=True) |
|
603
|
|
|
EgonPfHvLine.__table__.drop(bind=engine, checkfirst=True) |
|
604
|
|
|
EgonPfHvLineTimeseries.__table__.drop(bind=engine, checkfirst=True) |
|
605
|
|
|
EgonPfHvLink.__table__.drop(bind=engine, checkfirst=True) |
|
606
|
|
|
EgonPfHvLinkTimeseries.__table__.drop(bind=engine, checkfirst=True) |
|
607
|
|
|
EgonPfHvLoad.__table__.drop(bind=engine, checkfirst=True) |
|
608
|
|
|
EgonPfHvLoadTimeseries.__table__.drop(bind=engine, checkfirst=True) |
|
609
|
|
|
EgonPfHvCarrier.__table__.drop(bind=engine, checkfirst=True) |
|
610
|
|
|
EgonPfHvStorage.__table__.drop(bind=engine, checkfirst=True) |
|
611
|
|
|
EgonPfHvStorageTimeseries.__table__.drop(bind=engine, checkfirst=True) |
|
612
|
|
|
EgonPfHvStore.__table__.drop(bind=engine, checkfirst=True) |
|
613
|
|
|
EgonPfHvStoreTimeseries.__table__.drop(bind=engine, checkfirst=True) |
|
614
|
|
|
EgonPfHvTempResolution.__table__.drop(bind=engine, checkfirst=True) |
|
615
|
|
|
EgonPfHvTransformer.__table__.drop(bind=engine, checkfirst=True) |
|
616
|
|
|
EgonPfHvTransformerTimeseries.__table__.drop(bind=engine, checkfirst=True) |
|
617
|
|
|
EgonPfHvBusmap.__table__.drop(bind=engine, checkfirst=True) |
|
618
|
|
|
# Create new tables |
|
619
|
|
|
EgonPfHvBus.__table__.create(bind=engine, checkfirst=True) |
|
620
|
|
|
EgonPfHvBusTimeseries.__table__.create(bind=engine, checkfirst=True) |
|
621
|
|
|
EgonPfHvGenerator.__table__.create(bind=engine, checkfirst=True) |
|
622
|
|
|
EgonPfHvGeneratorTimeseries.__table__.create(bind=engine, checkfirst=True) |
|
623
|
|
|
EgonPfHvLine.__table__.create(bind=engine, checkfirst=True) |
|
624
|
|
|
EgonPfHvLineTimeseries.__table__.create(bind=engine, checkfirst=True) |
|
625
|
|
|
EgonPfHvLink.__table__.create(bind=engine, checkfirst=True) |
|
626
|
|
|
EgonPfHvLinkTimeseries.__table__.create(bind=engine, checkfirst=True) |
|
627
|
|
|
EgonPfHvLoad.__table__.create(bind=engine, checkfirst=True) |
|
628
|
|
|
EgonPfHvLoadTimeseries.__table__.create(bind=engine, checkfirst=True) |
|
629
|
|
|
EgonPfHvCarrier.__table__.create(bind=engine, checkfirst=True) |
|
630
|
|
|
EgonPfHvStorage.__table__.create(bind=engine, checkfirst=True) |
|
631
|
|
|
EgonPfHvStorageTimeseries.__table__.create(bind=engine, checkfirst=True) |
|
632
|
|
|
EgonPfHvStore.__table__.create(bind=engine, checkfirst=True) |
|
633
|
|
|
EgonPfHvStoreTimeseries.__table__.create(bind=engine, checkfirst=True) |
|
634
|
|
|
EgonPfHvTempResolution.__table__.create(bind=engine, checkfirst=True) |
|
635
|
|
|
EgonPfHvTransformer.__table__.create(bind=engine, checkfirst=True) |
|
636
|
|
|
EgonPfHvTransformerTimeseries.__table__.create( |
|
637
|
|
|
bind=engine, checkfirst=True |
|
638
|
|
|
) |
|
639
|
|
|
EgonPfHvBusmap.__table__.create(bind=engine, checkfirst=True) |
|
640
|
|
|
|
|
641
|
|
|
|
|
642
|
|
|
def temp_resolution(): |
|
643
|
|
|
"""Insert temporal resolution for etrago |
|
644
|
|
|
|
|
645
|
|
|
Returns |
|
646
|
|
|
------- |
|
647
|
|
|
None. |
|
648
|
|
|
|
|
649
|
|
|
""" |
|
650
|
|
|
|
|
651
|
|
|
db.execute_sql( |
|
652
|
|
|
""" |
|
653
|
|
|
INSERT INTO grid.egon_etrago_temp_resolution |
|
654
|
|
|
(temp_id, timesteps, resolution, start_time) |
|
655
|
|
|
SELECT 1, 8760, 'h', TIMESTAMP '2011-01-01 00:00:00'; |
|
656
|
|
|
""" |
|
657
|
|
|
) |
|
658
|
|
|
|
|
659
|
|
|
|
|
660
|
|
|
def insert_carriers(): |
|
661
|
|
|
"""Insert list of carriers into eTraGo table |
|
662
|
|
|
|
|
663
|
|
|
Returns |
|
664
|
|
|
------- |
|
665
|
|
|
None. |
|
666
|
|
|
|
|
667
|
|
|
""" |
|
668
|
|
|
# Delete existing entries |
|
669
|
|
|
db.execute_sql( |
|
670
|
|
|
""" |
|
671
|
|
|
DELETE FROM grid.egon_etrago_carrier |
|
672
|
|
|
""" |
|
673
|
|
|
) |
|
674
|
|
|
|
|
675
|
|
|
# List carrier names from all components |
|
676
|
|
|
df = pd.DataFrame( |
|
677
|
|
|
data={ |
|
678
|
|
|
"name": [ |
|
679
|
|
|
"biogas", |
|
680
|
|
|
"biogas_feedin", |
|
681
|
|
|
"biogas_to_gas", |
|
682
|
|
|
"biomass", |
|
683
|
|
|
"pv", |
|
684
|
|
|
"wind_offshore", |
|
685
|
|
|
"wind_onshore", |
|
686
|
|
|
"central_heat_pump", |
|
687
|
|
|
"central_resistive_heater", |
|
688
|
|
|
"CH4", |
|
689
|
|
|
"CH4_for_industry", |
|
690
|
|
|
"CH4_system_boundary", |
|
691
|
|
|
"CH4_to_H2", |
|
692
|
|
|
"dsm", |
|
693
|
|
|
"H2", |
|
694
|
|
|
"H2_feedin", |
|
695
|
|
|
"H2_for_industry", |
|
696
|
|
|
"H2_grid", |
|
697
|
|
|
"H2_gridextension", |
|
698
|
|
|
"H2_hgv_load", |
|
699
|
|
|
"H2_overground", |
|
700
|
|
|
"H2_retrofit", |
|
701
|
|
|
"H2_saltcavern", |
|
702
|
|
|
"H2_system_boundary", |
|
703
|
|
|
"H2_to_CH4", |
|
704
|
|
|
"H2_to_power", |
|
705
|
|
|
"H2_underground", |
|
706
|
|
|
"rural_heat_pump", |
|
707
|
|
|
"industrial_biomass_CHP", |
|
708
|
|
|
"industrial_gas_CHP", |
|
709
|
|
|
"central_biomass_CHP_heat", |
|
710
|
|
|
"central_biomass_CHP", |
|
711
|
|
|
"central_gas_CHP", |
|
712
|
|
|
"central_gas_CHP_heat", |
|
713
|
|
|
"power_to_H2", |
|
714
|
|
|
"rural_gas_boiler", |
|
715
|
|
|
"central_gas_boiler", |
|
716
|
|
|
"solar_thermal_collector", |
|
717
|
|
|
"geo_thermal", |
|
718
|
|
|
"AC", |
|
719
|
|
|
"central_heat", |
|
720
|
|
|
"rural_heat", |
|
721
|
|
|
"natural_gas_feedin", |
|
722
|
|
|
"pumped_hydro", |
|
723
|
|
|
"battery", |
|
724
|
|
|
"OCGT", |
|
725
|
|
|
] |
|
726
|
|
|
} |
|
727
|
|
|
) |
|
728
|
|
|
|
|
729
|
|
|
# Insert data into database |
|
730
|
|
|
df.to_sql( |
|
731
|
|
|
"egon_etrago_carrier", |
|
732
|
|
|
schema="grid", |
|
733
|
|
|
con=db.engine(), |
|
734
|
|
|
if_exists="append", |
|
735
|
|
|
index=False, |
|
736
|
|
|
) |
|
737
|
|
|
|
|
738
|
|
|
|
|
739
|
|
|
def check_carriers(): |
|
740
|
|
|
"""Check if any eTraGo table has carriers not included in the carrier table. |
|
741
|
|
|
|
|
742
|
|
|
Raises |
|
743
|
|
|
------ |
|
744
|
|
|
ValueError if carriers that are not defined in the carriers table are |
|
745
|
|
|
used in any eTraGo table. |
|
746
|
|
|
""" |
|
747
|
|
|
carriers = db.select_dataframe( |
|
748
|
|
|
f""" |
|
749
|
|
|
SELECT name FROM grid.egon_etrago_carrier |
|
750
|
|
|
""" |
|
751
|
|
|
) |
|
752
|
|
|
unknown_carriers = {} |
|
753
|
|
|
tables = ["bus", "store", "storage", "link", "line", "generator", "load"] |
|
754
|
|
|
|
|
755
|
|
|
for table in tables: |
|
756
|
|
|
# Delete existing entries |
|
757
|
|
|
data = db.select_dataframe( |
|
758
|
|
|
f""" |
|
759
|
|
|
SELECT carrier FROM grid.egon_etrago_{table} |
|
760
|
|
|
""" |
|
761
|
|
|
) |
|
762
|
|
|
unknown_carriers[table] = data[~data["carrier"].isin(carriers)][ |
|
763
|
|
|
"carrier" |
|
764
|
|
|
].unique() |
|
765
|
|
|
|
|
766
|
|
|
if len(unknown_carriers) > 0: |
|
767
|
|
|
msg = ( |
|
768
|
|
|
"The eTraGo tables contain carriers, that are not included in the " |
|
769
|
|
|
"carrier table:\n" |
|
770
|
|
|
) |
|
771
|
|
|
for table, carriers in unknown_carriers.items(): |
|
772
|
|
|
carriers = [str(c) for c in carriers] |
|
773
|
|
|
if len(carriers) > 0: |
|
774
|
|
|
msg += table + ": '" + "', '".join(carriers) + "'\n" |
|
775
|
|
|
|
|
776
|
|
|
raise ValueError(msg) |
|
777
|
|
|
|
|
778
|
|
|
|
|
779
|
|
|
def link_geom_from_buses(df, scn_name): |
|
780
|
|
|
"""Add LineString geometry accoring to geometry of buses to links |
|
781
|
|
|
|
|
782
|
|
|
Parameters |
|
783
|
|
|
---------- |
|
784
|
|
|
df : pandas.DataFrame |
|
785
|
|
|
List of eTraGo links with bus0 and bus1 but without topology |
|
786
|
|
|
scn_name : str |
|
787
|
|
|
Scenario name |
|
788
|
|
|
|
|
789
|
|
|
Returns |
|
790
|
|
|
------- |
|
791
|
|
|
gdf : geopandas.GeoDataFrame |
|
792
|
|
|
List of eTraGo links with bus0 and bus1 but with topology |
|
793
|
|
|
|
|
794
|
|
|
""" |
|
795
|
|
|
|
|
796
|
|
|
geom_buses = db.select_geodataframe( |
|
797
|
|
|
f""" |
|
798
|
|
|
SELECT bus_id, geom |
|
799
|
|
|
FROM grid.egon_etrago_bus |
|
800
|
|
|
WHERE scn_name = '{scn_name}' |
|
801
|
|
|
""", |
|
802
|
|
|
index_col="bus_id", |
|
803
|
|
|
epsg=4326, |
|
804
|
|
|
) |
|
805
|
|
|
|
|
806
|
|
|
# Create geometry columns for bus0 and bus1 |
|
807
|
|
|
df["geom_0"] = geom_buses.geom[df.bus0.values].values |
|
808
|
|
|
df["geom_1"] = geom_buses.geom[df.bus1.values].values |
|
809
|
|
|
|
|
810
|
|
|
geometry = df.apply( |
|
811
|
|
|
lambda x: LineString([x["geom_0"], x["geom_1"]]), axis=1 |
|
812
|
|
|
) |
|
813
|
|
|
df = df.drop(["geom_0", "geom_1"], axis=1) |
|
814
|
|
|
|
|
815
|
|
|
gdf = gpd.GeoDataFrame(df, geometry=geometry, crs=4326).rename_geometry( |
|
816
|
|
|
"topo" |
|
817
|
|
|
) |
|
818
|
|
|
|
|
819
|
|
|
return gdf |
|
820
|
|
|
|