@@ 7-69 (lines=63) @@ | ||
4 | from egon.data.datasets.power_plants.pv_rooftop_buildings import timer_func |
|
5 | import egon.data.config |
|
6 | ||
7 | def assign_bus_id(power_plants, cfg): |
|
8 | """Assigns bus_ids to power plants according to location and voltage level |
|
9 | ||
10 | Parameters |
|
11 | ---------- |
|
12 | power_plants : pandas.DataFrame |
|
13 | Power plants including voltage level |
|
14 | ||
15 | Returns |
|
16 | ------- |
|
17 | power_plants : pandas.DataFrame |
|
18 | Power plants including voltage level and bus_id |
|
19 | ||
20 | """ |
|
21 | ||
22 | mv_grid_districts = db.select_geodataframe( |
|
23 | f""" |
|
24 | SELECT * FROM {cfg['sources']['egon_mv_grid_district']} |
|
25 | """, |
|
26 | epsg=4326, |
|
27 | ) |
|
28 | ||
29 | ehv_grid_districts = db.select_geodataframe( |
|
30 | f""" |
|
31 | SELECT * FROM {cfg['sources']['ehv_voronoi']} |
|
32 | """, |
|
33 | epsg=4326, |
|
34 | ) |
|
35 | ||
36 | # Assign power plants in hv and below to hvmv bus |
|
37 | power_plants_hv = power_plants[power_plants.voltage_level >= 3].index |
|
38 | if len(power_plants_hv) > 0: |
|
39 | power_plants.loc[power_plants_hv, "bus_id"] = gpd.sjoin( |
|
40 | power_plants[power_plants.index.isin(power_plants_hv)], |
|
41 | mv_grid_districts, |
|
42 | ).bus_id |
|
43 | ||
44 | # Assign power plants in ehv to ehv bus |
|
45 | power_plants_ehv = power_plants[power_plants.voltage_level < 3].index |
|
46 | ||
47 | if len(power_plants_ehv) > 0: |
|
48 | ehv_join = gpd.sjoin( |
|
49 | power_plants[power_plants.index.isin(power_plants_ehv)], |
|
50 | ehv_grid_districts, |
|
51 | ) |
|
52 | ||
53 | if "bus_id_right" in ehv_join.columns: |
|
54 | power_plants.loc[power_plants_ehv, "bus_id"] = gpd.sjoin( |
|
55 | power_plants[power_plants.index.isin(power_plants_ehv)], |
|
56 | ehv_grid_districts, |
|
57 | ).bus_id_right |
|
58 | ||
59 | else: |
|
60 | power_plants.loc[power_plants_ehv, "bus_id"] = gpd.sjoin( |
|
61 | power_plants[power_plants.index.isin(power_plants_ehv)], |
|
62 | ehv_grid_districts, |
|
63 | ).bus_id |
|
64 | ||
65 | # Assert that all power plants have a bus_id |
|
66 | assert power_plants.bus_id.notnull().all(), f"""Some power plants are |
|
67 | not attached to a bus: {power_plants[power_plants.bus_id.isnull()]}""" |
|
68 | ||
69 | return power_plants |
|
70 | ||
71 | ||
72 | @timer_func |
@@ 525-590 (lines=66) @@ | ||
522 | return mastr_loc.voltage_level |
|
523 | ||
524 | ||
525 | def assign_bus_id(power_plants, cfg, drop_missing=False): |
|
526 | """Assigns bus_ids to power plants according to location and voltage level |
|
527 | ||
528 | Parameters |
|
529 | ---------- |
|
530 | power_plants : pandas.DataFrame |
|
531 | Power plants including voltage level |
|
532 | ||
533 | Returns |
|
534 | ------- |
|
535 | power_plants : pandas.DataFrame |
|
536 | Power plants including voltage level and bus_id |
|
537 | ||
538 | """ |
|
539 | ||
540 | mv_grid_districts = db.select_geodataframe( |
|
541 | f""" |
|
542 | SELECT * FROM {cfg['sources']['egon_mv_grid_district']} |
|
543 | """, |
|
544 | epsg=4326, |
|
545 | ) |
|
546 | ||
547 | ehv_grid_districts = db.select_geodataframe( |
|
548 | f""" |
|
549 | SELECT * FROM {cfg['sources']['ehv_voronoi']} |
|
550 | """, |
|
551 | epsg=4326, |
|
552 | ) |
|
553 | ||
554 | # Assign power plants in hv and below to hvmv bus |
|
555 | power_plants_hv = power_plants[power_plants.voltage_level >= 3].index |
|
556 | if len(power_plants_hv) > 0: |
|
557 | power_plants.loc[power_plants_hv, "bus_id"] = gpd.sjoin( |
|
558 | power_plants[power_plants.index.isin(power_plants_hv)], |
|
559 | mv_grid_districts, |
|
560 | ).bus_id |
|
561 | ||
562 | # Assign power plants in ehv to ehv bus |
|
563 | power_plants_ehv = power_plants[power_plants.voltage_level < 3].index |
|
564 | ||
565 | if len(power_plants_ehv) > 0: |
|
566 | ehv_join = gpd.sjoin( |
|
567 | power_plants[power_plants.index.isin(power_plants_ehv)], |
|
568 | ehv_grid_districts, |
|
569 | ) |
|
570 | ||
571 | if "bus_id_right" in ehv_join.columns: |
|
572 | power_plants.loc[power_plants_ehv, "bus_id"] = gpd.sjoin( |
|
573 | power_plants[power_plants.index.isin(power_plants_ehv)], |
|
574 | ehv_grid_districts, |
|
575 | ).bus_id_right |
|
576 | ||
577 | else: |
|
578 | power_plants.loc[power_plants_ehv, "bus_id"] = gpd.sjoin( |
|
579 | power_plants[power_plants.index.isin(power_plants_ehv)], |
|
580 | ehv_grid_districts, |
|
581 | ).bus_id |
|
582 | ||
583 | if drop_missing: |
|
584 | power_plants = power_plants[~power_plants.bus_id.isnull()] |
|
585 | ||
586 | # Assert that all power plants have a bus_id |
|
587 | assert power_plants.bus_id.notnull().all(), f"""Some power plants are |
|
588 | not attached to a bus: {power_plants[power_plants.bus_id.isnull()]}""" |
|
589 | ||
590 | return power_plants |
|
591 | ||
592 | ||
593 | def insert_hydro_biomass(): |