| @@ 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(): |
|
| @@ 908-957 (lines=50) @@ | ||
| 905 | } |
|
| 906 | ||
| 907 | ||
| 908 | def get_foreign_bus_id(scenario): |
|
| 909 | """Calculte the etrago bus id from Nodes of TYNDP based on the geometry |
|
| 910 | ||
| 911 | Returns |
|
| 912 | ------- |
|
| 913 | pandas.Series |
|
| 914 | List of mapped node_ids from TYNDP and etragos bus_id |
|
| 915 | ||
| 916 | """ |
|
| 917 | ||
| 918 | sources = config.datasets()["electrical_neighbours"]["sources"] |
|
| 919 | ||
| 920 | bus_id = db.select_geodataframe( |
|
| 921 | f"""SELECT bus_id, ST_Buffer(geom, 1) as geom, country |
|
| 922 | FROM grid.egon_etrago_bus |
|
| 923 | WHERE scn_name = '{scenario}' |
|
| 924 | AND carrier = 'AC' |
|
| 925 | AND v_nom = 380. |
|
| 926 | AND country != 'DE' |
|
| 927 | AND bus_id NOT IN ( |
|
| 928 | SELECT bus_i |
|
| 929 | FROM osmtgmod_results.bus_data) |
|
| 930 | """, |
|
| 931 | epsg=3035, |
|
| 932 | ) |
|
| 933 | ||
| 934 | # insert installed capacities |
|
| 935 | file = zipfile.ZipFile(f"tyndp/{sources['tyndp_capacities']}") |
|
| 936 | ||
| 937 | # Select buses in neighbouring countries as geodataframe |
|
| 938 | buses = pd.read_excel( |
|
| 939 | file.open("TYNDP-2020-Scenario-Datafile.xlsx").read(), |
|
| 940 | sheet_name="Nodes - Dict", |
|
| 941 | ).query("longitude==longitude") |
|
| 942 | buses = gpd.GeoDataFrame( |
|
| 943 | buses, |
|
| 944 | crs=4326, |
|
| 945 | geometry=gpd.points_from_xy(buses.longitude, buses.latitude), |
|
| 946 | ).to_crs(3035) |
|
| 947 | ||
| 948 | buses["bus_id"] = 0 |
|
| 949 | ||
| 950 | # Select bus_id from etrago with shortest distance to TYNDP node |
|
| 951 | for i, row in buses.iterrows(): |
|
| 952 | distance = bus_id.set_index("bus_id").geom.distance(row.geometry) |
|
| 953 | buses.loc[i, "bus_id"] = distance[ |
|
| 954 | distance == distance.min() |
|
| 955 | ].index.values[0] |
|
| 956 | ||
| 957 | return buses.set_index("node_id").bus_id |
|
| 958 | ||
| 959 | ||
| 960 | def calc_capacities(): |
|