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

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