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

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