Code Duplication    Length = 38-38 lines in 2 locations

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

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

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

@@ 2332-2369 (lines=38) @@
2329
    return buildings_gdf
2330
2331
2332
def infer_voltage_level(
2333
    units_gdf: gpd.GeoDataFrame,
2334
) -> gpd.GeoDataFrame:
2335
    """
2336
    Infer nan values in voltage level derived from generator capacity to
2337
    the power plants.
2338
2339
    Parameters
2340
    -----------
2341
    units_gdf : geopandas.GeoDataFrame
2342
        GeoDataFrame containing units with voltage levels from MaStR
2343
    Returnsunits_gdf: gpd.GeoDataFrame
2344
    -------
2345
    geopandas.GeoDataFrame
2346
        GeoDataFrame containing units all having assigned a voltage level.
2347
    """
2348
2349
    def voltage_levels(p: float) -> int:
2350
        if p <= 0.1:
2351
            return 7
2352
        elif p <= 0.2:
2353
            return 6
2354
        elif p <= 5.5:
2355
            return 5
2356
        elif p <= 20:
2357
            return 4
2358
        elif p <= 120:
2359
            return 3
2360
        return 1
2361
2362
    units_gdf["voltage_level_inferred"] = False
2363
    mask = units_gdf.voltage_level.isna()
2364
    units_gdf.loc[mask, "voltage_level_inferred"] = True
2365
    units_gdf.loc[mask, "voltage_level"] = units_gdf.loc[mask].capacity.apply(
2366
        voltage_levels
2367
    )
2368
2369
    return units_gdf
2370
2371
2372
def pv_rooftop_to_buildings():