Code Duplication    Length = 38-38 lines in 2 locations

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

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

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

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