6
6
import egon .data .config
7
7
import geopandas as gpd
8
8
import pandas as pd
9
+ import numpy as np
9
10
from egon .data import db
10
11
from egon .data .datasets .electricity_demand .temporal import calc_load_curve
11
12
from sqlalchemy import ARRAY , Column , Float , Integer , String
14
15
Base = declarative_base ()
15
16
16
17
18
+ def identify_voltage_level (df ):
19
+
20
+ """Identify the voltage_level of a grid component based on its peak load and
21
+ defined thresholds.
22
+
23
+
24
+ Parameters
25
+ ----------
26
+ df : pandas.DataFrame
27
+ Data frame containing information about peak loads
28
+
29
+
30
+ Returns
31
+ -------
32
+ pandas.DataFrame
33
+ Data frame with an additional column with voltage level
34
+
35
+ """
36
+
37
+ df ['voltage_level' ]= np .nan
38
+
39
+ # Identify voltage_level for every demand area taking thresholds into account which were defined in the eGon project
40
+ df .loc [df ["peak_load" ] < 0.1 , "voltage_level" ] = 7
41
+ df .loc [df ["peak_load" ] > 0.1 , "voltage_level" ] = 6
42
+ df .loc [df ["peak_load" ] > 0.2 , "voltage_level" ] = 5
43
+ df .loc [df ["peak_load" ] > 5.5 , "voltage_level" ] = 4
44
+ df .loc [df ["peak_load" ] > 20 , "voltage_level" ] = 3
45
+ df .loc [df ["peak_load" ] > 120 , "voltage_level" ] = 1
46
+
47
+ return df
48
+
49
+
17
50
def identify_bus (load_curves , demand_area ):
18
51
"""Identify the grid connection point for a consumer by determining its grid level
19
52
based on the time series' peak load and the spatial intersection to mv
@@ -50,17 +83,11 @@ def identify_bus(load_curves, demand_area):
50
83
)
51
84
52
85
# Initialize dataframe to identify peak load per demand area (e.g. osm landuse area or industrial site)
53
- peak = pd .DataFrame (columns = ["id" , "peak_load" , "voltage_level" ])
86
+ peak = pd .DataFrame (columns = ["id" , "peak_load" ])
54
87
peak ["id" ] = load_curves .max (axis = 0 ).index
55
88
peak ["peak_load" ] = load_curves .max (axis = 0 ).values
56
89
57
- # Identify voltage_level for every demand area taking thresholds into account which were defined in the eGon project
58
- peak .loc [peak ["peak_load" ] < 0.1 , "voltage_level" ] = 7
59
- peak .loc [peak ["peak_load" ] > 0.1 , "voltage_level" ] = 6
60
- peak .loc [peak ["peak_load" ] > 0.2 , "voltage_level" ] = 5
61
- peak .loc [peak ["peak_load" ] > 5.5 , "voltage_level" ] = 4
62
- peak .loc [peak ["peak_load" ] > 20 , "voltage_level" ] = 3
63
- peak .loc [peak ["peak_load" ] > 120 , "voltage_level" ] = 1
90
+ peak = identify_voltage_level (peak )
64
91
65
92
# Assign bus_id to demand area by merging landuse and peak df
66
93
peak = pd .merge (demand_area , peak , right_on = "id" , left_index = True )
@@ -210,6 +237,14 @@ def insert_osm_ind_load():
210
237
"""
211
238
)
212
239
240
+ db .execute_sql (
241
+ f"""
242
+ DELETE FROM
243
+ { targets ['osm_load_individual' ]['schema' ]} .{ targets ['osm_load_individual' ]['table' ]}
244
+ WHERE scn_name = '{ scenario } '
245
+ """
246
+ )
247
+
213
248
# Calculate cts load curves per mv substation (hvmv bus)
214
249
data , curves_individual = calc_load_curves_ind_osm (scenario )
215
250
data .index = data .index .rename ("bus" )
@@ -225,6 +260,9 @@ def insert_osm_ind_load():
225
260
if_exists = "append" ,
226
261
)
227
262
263
+ curves_individual ['peak_load' ] = np .array (curves_individual ['p_set' ].values .tolist ()).max (axis = 1 )
264
+ curves_individual ['demand' ] = np .array (curves_individual ['p_set' ].values .tolist ()).sum (axis = 1 )
265
+ curves_individual = identify_voltage_level (curves_individual )
228
266
229
267
curves_individual .to_sql (
230
268
targets ["osm_load_individual" ]["table" ],
@@ -321,7 +359,16 @@ def calc_load_curves_ind_sites(scenario):
321
359
# Insert data for pf load timeseries table
322
360
load_ts_df .p_set = curves_bus .values .tolist ()
323
361
324
- return load_ts_df
362
+ # Create Dataframe to store time series individually
363
+ curves_individual_interim = (
364
+ curves_da .drop (["bus_id" , "geom" , "wz" ], axis = 1 ).fillna (0 )
365
+ ).set_index ("id" )
366
+ curves_individual = curves_da [["id" , "bus_id" ]]
367
+ curves_individual ["p_set" ] = curves_individual_interim .values .tolist ()
368
+ curves_individual ["scn_name" ]= scenario
369
+ curves_individual = curves_individual .rename (columns = {"id" : "site_id" }).set_index (['site_id' , 'scn_name' ])
370
+
371
+ return load_ts_df , curves_individual
325
372
326
373
327
374
def insert_sites_ind_load ():
@@ -348,8 +395,18 @@ def insert_sites_ind_load():
348
395
"""
349
396
)
350
397
398
+ # Delete existing data from database
399
+ db .execute_sql (
400
+ f"""
401
+ DELETE FROM
402
+ { targets ['sites_load_individual' ]['schema' ]} .
403
+ { targets ['sites_load_individual' ]['table' ]}
404
+ WHERE scn_name = '{ scenario } '
405
+ """
406
+ )
407
+
351
408
# Calculate industrial load curves per bus
352
- data = calc_load_curves_ind_sites (scenario )
409
+ data , curves_individual = calc_load_curves_ind_sites (scenario )
353
410
data .index = data .index .rename (["bus" , "wz" ])
354
411
data ["scn_name" ] = scenario
355
412
@@ -362,3 +419,14 @@ def insert_sites_ind_load():
362
419
con = db .engine (),
363
420
if_exists = "append" ,
364
421
)
422
+
423
+ curves_individual ['peak_load' ] = np .array (curves_individual ['p_set' ].values .tolist ()).max (axis = 1 )
424
+ curves_individual ['demand' ] = np .array (curves_individual ['p_set' ].values .tolist ()).sum (axis = 1 )
425
+ curves_individual = identify_voltage_level (curves_individual )
426
+
427
+ curves_individual .to_sql (
428
+ targets ["sites_load_individual" ]["table" ],
429
+ schema = targets ["sites_load_individual" ]["schema" ],
430
+ con = db .engine (),
431
+ if_exists = "append" ,
432
+ )
0 commit comments