Code Duplication    Length = 38-38 lines in 2 locations

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

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

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

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