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

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