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

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