Code Duplication    Length = 38-38 lines in 2 locations

src/egon/data/datasets/power_plants/mastr.py 1 location

@@ 121-158 (lines=38) @@
118
    return standort, found
119
120
121
def infer_voltage_level(
122
    units_gdf: gpd.GeoDataFrame,
123
) -> gpd.GeoDataFrame:
124
    """
125
    Infer nan values in voltage level derived from generator capacity to
126
    the power plants.
127
128
    Parameters
129
    -----------
130
    units_gdf : geopandas.GeoDataFrame
131
        GeoDataFrame containing units with voltage levels from MaStR
132
    Returns
133
    -------
134
    geopandas.GeoDataFrame
135
        GeoDataFrame containing units all having assigned a voltage level.
136
    """
137
138
    def voltage_levels(p: float) -> int:
139
        if p <= 100:
140
            return 7
141
        elif p <= 200:
142
            return 6
143
        elif p <= 5500:
144
            return 5
145
        elif p <= 20000:
146
            return 4
147
        elif p <= 120000:
148
            return 3
149
        return 1
150
151
    units_gdf["voltage_level_inferred"] = False
152
    mask = units_gdf.voltage_level.isna()
153
    units_gdf.loc[mask, "voltage_level_inferred"] = True
154
    units_gdf.loc[mask, "voltage_level"] = units_gdf.loc[
155
        mask
156
    ].Nettonennleistung.apply(voltage_levels)
157
158
    return units_gdf
159
160
161
def import_mastr() -> None:

src/egon/data/datasets/power_plants/pv_rooftop_buildings.py 1 location

@@ 2364-2401 (lines=38) @@
2361
    return buildings_gdf
2362
2363
2364
def infer_voltage_level(
2365
    units_gdf: gpd.GeoDataFrame,
2366
) -> gpd.GeoDataFrame:
2367
    """
2368
    Infer nan values in voltage level derived from generator capacity to
2369
    the power plants.
2370
2371
    Parameters
2372
    -----------
2373
    units_gdf : geopandas.GeoDataFrame
2374
        GeoDataFrame containing units with voltage levels from MaStR
2375
    Returnsunits_gdf: gpd.GeoDataFrame
2376
    -------
2377
    geopandas.GeoDataFrame
2378
        GeoDataFrame containing units all having assigned a voltage level.
2379
    """
2380
2381
    def voltage_levels(p: float) -> int:
2382
        if p <= 0.1:
2383
            return 7
2384
        elif p <= 0.2:
2385
            return 6
2386
        elif p <= 5.5:
2387
            return 5
2388
        elif p <= 20:
2389
            return 4
2390
        elif p <= 120:
2391
            return 3
2392
        return 1
2393
2394
    units_gdf["voltage_level_inferred"] = False
2395
    mask = units_gdf.voltage_level.isna()
2396
    units_gdf.loc[mask, "voltage_level_inferred"] = True
2397
    units_gdf.loc[mask, "voltage_level"] = units_gdf.loc[mask].capacity.apply(
2398
        voltage_levels
2399
    )
2400
2401
    return units_gdf
2402
2403
2404
def pv_rooftop_to_buildings():