@@ 741-790 (lines=50) @@ | ||
738 | } |
|
739 | ||
740 | ||
741 | def get_foreign_bus_id(): |
|
742 | """Calculte the etrago bus id from Nodes of TYNDP based on the geometry |
|
743 | ||
744 | Returns |
|
745 | ------- |
|
746 | pandas.Series |
|
747 | List of mapped node_ids from TYNDP and etragos bus_id |
|
748 | ||
749 | """ |
|
750 | ||
751 | sources = config.datasets()["electrical_neighbours"]["sources"] |
|
752 | ||
753 | bus_id = db.select_geodataframe( |
|
754 | """SELECT bus_id, ST_Buffer(geom, 1) as geom, country |
|
755 | FROM grid.egon_etrago_bus |
|
756 | WHERE scn_name = 'eGon2035' |
|
757 | AND carrier = 'AC' |
|
758 | AND v_nom = 380. |
|
759 | AND country != 'DE' |
|
760 | AND bus_id NOT IN ( |
|
761 | SELECT bus_i |
|
762 | FROM osmtgmod_results.bus_data) |
|
763 | """, |
|
764 | epsg=3035, |
|
765 | ) |
|
766 | ||
767 | # insert installed capacities |
|
768 | file = zipfile.ZipFile(f"tyndp/{sources['tyndp_capacities']}") |
|
769 | ||
770 | # Select buses in neighbouring countries as geodataframe |
|
771 | buses = pd.read_excel( |
|
772 | file.open("TYNDP-2020-Scenario-Datafile.xlsx").read(), |
|
773 | sheet_name="Nodes - Dict", |
|
774 | ).query("longitude==longitude") |
|
775 | buses = gpd.GeoDataFrame( |
|
776 | buses, |
|
777 | crs=4326, |
|
778 | geometry=gpd.points_from_xy(buses.longitude, buses.latitude), |
|
779 | ).to_crs(3035) |
|
780 | ||
781 | buses["bus_id"] = 0 |
|
782 | ||
783 | # Select bus_id from etrago with shortest distance to TYNDP node |
|
784 | for i, row in buses.iterrows(): |
|
785 | distance = bus_id.set_index("bus_id").geom.distance(row.geometry) |
|
786 | buses.loc[i, "bus_id"] = distance[ |
|
787 | distance == distance.min() |
|
788 | ].index.values[0] |
|
789 | ||
790 | return buses.set_index("node_id").bus_id |
|
791 | ||
792 | ||
793 | def calc_capacities(): |
@@ 42-95 (lines=54) @@ | ||
39 | ] |
|
40 | ||
41 | ||
42 | def get_foreign_gas_bus_id(carrier="CH4"): |
|
43 | """Calculate the etrago bus id based on the geometry |
|
44 | ||
45 | Map node_ids from TYNDP and etragos bus_id |
|
46 | ||
47 | Parameters |
|
48 | ---------- |
|
49 | carrier : str |
|
50 | Name of the carrier |
|
51 | ||
52 | Returns |
|
53 | ------- |
|
54 | pandas.Series |
|
55 | List of mapped node_ids from TYNDP and etragos bus_id |
|
56 | ||
57 | """ |
|
58 | sources = config.datasets()["gas_neighbours"]["sources"] |
|
59 | scn_name = "eGon2035" |
|
60 | ||
61 | bus_id = db.select_geodataframe( |
|
62 | f""" |
|
63 | SELECT bus_id, ST_Buffer(geom, 1) as geom, country |
|
64 | FROM grid.egon_etrago_bus |
|
65 | WHERE scn_name = '{scn_name}' |
|
66 | AND carrier = '{carrier}' |
|
67 | AND country != 'DE' |
|
68 | """, |
|
69 | epsg=3035, |
|
70 | ) |
|
71 | ||
72 | # insert installed capacities |
|
73 | file = zipfile.ZipFile(f"tyndp/{sources['tyndp_capacities']}") |
|
74 | ||
75 | # Select buses in neighbouring countries as geodataframe |
|
76 | buses = pd.read_excel( |
|
77 | file.open("TYNDP-2020-Scenario-Datafile.xlsx").read(), |
|
78 | sheet_name="Nodes - Dict", |
|
79 | ).query("longitude==longitude") |
|
80 | buses = gpd.GeoDataFrame( |
|
81 | buses, |
|
82 | crs=4326, |
|
83 | geometry=gpd.points_from_xy(buses.longitude, buses.latitude), |
|
84 | ).to_crs(3035) |
|
85 | ||
86 | buses["bus_id"] = 0 |
|
87 | ||
88 | # Select bus_id from etrago with shortest distance to TYNDP node |
|
89 | for i, row in buses.iterrows(): |
|
90 | distance = bus_id.set_index("bus_id").geom.distance(row.geometry) |
|
91 | buses.loc[i, "bus_id"] = distance[ |
|
92 | distance == distance.min() |
|
93 | ].index.values[0] |
|
94 | ||
95 | return buses.set_index("node_id").bus_id |
|
96 | ||
97 | ||
98 | def read_LNG_capacities(): |