Code Duplication    Length = 50-54 lines in 2 locations

src/egon/data/datasets/gas_neighbours/eGon2035.py 1 location

@@ 54-107 (lines=54) @@
51
]
52
53
54
def get_foreign_gas_bus_id(carrier="CH4"):
55
    """
56
    Calculate the etrago bus id based on the geometry
57
58
    Map node_ids from TYNDP and etragos bus_id
59
60
    Parameters
61
    ----------
62
    carrier : str
63
        Name of the carrier
64
65
    Returns
66
    -------
67
    pandas.Series
68
        List of mapped node_ids from TYNDP and etragos bus_id
69
70
    """
71
    sources = config.datasets()["gas_neighbours"]["sources"]
72
    scn_name = "eGon2035"
73
74
    bus_id = db.select_geodataframe(
75
        f"""
76
        SELECT bus_id, ST_Buffer(geom, 1) as geom, country
77
        FROM grid.egon_etrago_bus
78
        WHERE scn_name = '{scn_name}'
79
        AND carrier = '{carrier}'
80
        AND country != 'DE'
81
        """,
82
        epsg=3035,
83
    )
84
85
    # insert installed capacities
86
    file = zipfile.ZipFile(f"tyndp/{sources['tyndp_capacities']}")
87
88
    # Select buses in neighbouring countries as geodataframe
89
    buses = pd.read_excel(
90
        file.open("TYNDP-2020-Scenario-Datafile.xlsx").read(),
91
        sheet_name="Nodes - Dict",
92
    ).query("longitude==longitude")
93
    buses = gpd.GeoDataFrame(
94
        buses,
95
        crs=4326,
96
        geometry=gpd.points_from_xy(buses.longitude, buses.latitude),
97
    ).to_crs(3035)
98
99
    buses["bus_id"] = 0
100
101
    # Select bus_id from etrago with shortest distance to TYNDP node
102
    for i, row in buses.iterrows():
103
        distance = bus_id.set_index("bus_id").geom.distance(row.geometry)
104
        buses.loc[i, "bus_id"] = distance[
105
            distance == distance.min()
106
        ].index.values[0]
107
108
    return buses.set_index("node_id").bus_id
109
110

src/egon/data/datasets/electrical_neighbours.py 1 location

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