| @@ 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(): |
|
| @@ 806-855 (lines=50) @@ | ||
| 803 | } |
|
| 804 | ||
| 805 | ||
| 806 | def get_foreign_bus_id(scenario): |
|
| 807 | """Calculte the etrago bus id from Nodes of TYNDP based on the geometry |
|
| 808 | ||
| 809 | Returns |
|
| 810 | ------- |
|
| 811 | pandas.Series |
|
| 812 | List of mapped node_ids from TYNDP and etragos bus_id |
|
| 813 | ||
| 814 | """ |
|
| 815 | ||
| 816 | sources = config.datasets()["electrical_neighbours"]["sources"] |
|
| 817 | ||
| 818 | bus_id = db.select_geodataframe( |
|
| 819 | f"""SELECT bus_id, ST_Buffer(geom, 1) as geom, country |
|
| 820 | FROM grid.egon_etrago_bus |
|
| 821 | WHERE scn_name = '{scenario}' |
|
| 822 | AND carrier = 'AC' |
|
| 823 | AND v_nom = 380. |
|
| 824 | AND country != 'DE' |
|
| 825 | AND bus_id NOT IN ( |
|
| 826 | SELECT bus_i |
|
| 827 | FROM osmtgmod_results.bus_data) |
|
| 828 | """, |
|
| 829 | epsg=3035, |
|
| 830 | ) |
|
| 831 | ||
| 832 | # insert installed capacities |
|
| 833 | file = zipfile.ZipFile(f"tyndp/{sources['tyndp_capacities']}") |
|
| 834 | ||
| 835 | # Select buses in neighbouring countries as geodataframe |
|
| 836 | buses = pd.read_excel( |
|
| 837 | file.open("TYNDP-2020-Scenario-Datafile.xlsx").read(), |
|
| 838 | sheet_name="Nodes - Dict", |
|
| 839 | ).query("longitude==longitude") |
|
| 840 | buses = gpd.GeoDataFrame( |
|
| 841 | buses, |
|
| 842 | crs=4326, |
|
| 843 | geometry=gpd.points_from_xy(buses.longitude, buses.latitude), |
|
| 844 | ).to_crs(3035) |
|
| 845 | ||
| 846 | buses["bus_id"] = 0 |
|
| 847 | ||
| 848 | # Select bus_id from etrago with shortest distance to TYNDP node |
|
| 849 | for i, row in buses.iterrows(): |
|
| 850 | distance = bus_id.set_index("bus_id").geom.distance(row.geometry) |
|
| 851 | buses.loc[i, "bus_id"] = distance[ |
|
| 852 | distance == distance.min() |
|
| 853 | ].index.values[0] |
|
| 854 | ||
| 855 | return buses.set_index("node_id").bus_id |
|
| 856 | ||
| 857 | ||
| 858 | def calc_capacities(): |
|