Code Duplication    Length = 50-54 lines in 2 locations

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

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

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

@@ 740-789 (lines=50) @@
737
    }
738
739
740
def get_foreign_bus_id():
741
    """Calculte the etrago bus id from Nodes of TYNDP based on the geometry
742
743
    Returns
744
    -------
745
    pandas.Series
746
        List of mapped node_ids from TYNDP and etragos bus_id
747
748
    """
749
750
    sources = config.datasets()["electrical_neighbours"]["sources"]
751
752
    bus_id = db.select_geodataframe(
753
        """SELECT bus_id, ST_Buffer(geom, 1) as geom, country
754
        FROM grid.egon_etrago_bus
755
        WHERE scn_name = 'eGon2035'
756
        AND carrier = 'AC'
757
        AND v_nom = 380.
758
        AND country != 'DE'
759
        AND bus_id NOT IN (
760
            SELECT bus_i
761
            FROM osmtgmod_results.bus_data)
762
        """,
763
        epsg=3035,
764
    )
765
766
    # insert installed capacities
767
    file = zipfile.ZipFile(f"tyndp/{sources['tyndp_capacities']}")
768
769
    # Select buses in neighbouring countries as geodataframe
770
    buses = pd.read_excel(
771
        file.open("TYNDP-2020-Scenario-Datafile.xlsx").read(),
772
        sheet_name="Nodes - Dict",
773
    ).query("longitude==longitude")
774
    buses = gpd.GeoDataFrame(
775
        buses,
776
        crs=4326,
777
        geometry=gpd.points_from_xy(buses.longitude, buses.latitude),
778
    ).to_crs(3035)
779
780
    buses["bus_id"] = 0
781
782
    # Select bus_id from etrago with shortest distance to TYNDP node
783
    for i, row in buses.iterrows():
784
        distance = bus_id.set_index("bus_id").geom.distance(row.geometry)
785
        buses.loc[i, "bus_id"] = distance[
786
            distance == distance.min()
787
        ].index.values[0]
788
789
    return buses.set_index("node_id").bus_id
790
791
792
def calc_capacities():