diff --git a/scripts/add_electricity.py b/scripts/add_electricity.py index 09ec340a..249341ca 100755 --- a/scripts/add_electricity.py +++ b/scripts/add_electricity.py @@ -700,19 +700,30 @@ def estimate_renewable_capacities(n, config): expansion_limit * n.generators.loc[tech_i, "p_nom_min"] ) -def attach_line_rating(n, rating, s_max_pu, correction_factor, max_voltage_difference, max_line_rating): + +def attach_line_rating( + n, rating, s_max_pu, correction_factor, max_voltage_difference, max_line_rating +): # TODO: Only considers overhead lines - n.lines_t.s_max_pu = (rating / n.lines.s_nom[rating.columns]) * correction_factor + n.lines_t.s_max_pu = (rating / n.lines.s_nom[rating.columns]) * correction_factor if max_voltage_difference: - x_pu = n.lines.type.map(n.line_types["x_per_length"])*n.lines.length/(n.lines.v_nom**2) - # need to clip here as cap values might be below 1 + x_pu = ( + n.lines.type.map(n.line_types["x_per_length"]) + * n.lines.length + / (n.lines.v_nom**2) + ) + # need to clip here as cap values might be below 1 # -> would mean the line cannot be operated at actual given pessimistic ampacity - s_max_pu_cap = (np.deg2rad(max_voltage_difference) / ( x_pu * n.lines.s_nom)).clip(lower=1) - n.lines_t.s_max_pu = n.lines_t.s_max_pu.clip(lower=1, upper=s_max_pu_cap, axis=1) + s_max_pu_cap = ( + np.deg2rad(max_voltage_difference) / (x_pu * n.lines.s_nom) + ).clip(lower=1) + n.lines_t.s_max_pu = n.lines_t.s_max_pu.clip( + lower=1, upper=s_max_pu_cap, axis=1 + ) if max_line_rating: n.lines_t.s_max_pu = n.lines_t.s_max_pu.clip(upper=max_line_rating) n.lines_t.s_max_pu *= s_max_pu - + def add_nice_carrier_names(n, config): carrier_i = n.carriers.index @@ -864,18 +875,18 @@ if __name__ == "__main__": line_rating_config = snakemake.config["lines"]["dynamic_line_rating"] if line_rating_config["activate"]: rating = xr.open_dataarray(snakemake.input.line_rating).to_pandas().transpose() - s_max_pu = snakemake.config["lines"]["s_max_pu"] - correction_factor = line_rating_config['correction_factor'] - max_voltage_difference = line_rating_config['max_voltage_difference'] - max_line_rating = line_rating_config['max_line_rating'] + s_max_pu = snakemake.config["lines"]["s_max_pu"] + correction_factor = line_rating_config["correction_factor"] + max_voltage_difference = line_rating_config["max_voltage_difference"] + max_line_rating = line_rating_config["max_line_rating"] attach_line_rating( - n, - rating, - s_max_pu, - correction_factor, - max_voltage_difference, - max_line_rating + n, + rating, + s_max_pu, + correction_factor, + max_voltage_difference, + max_line_rating, ) add_nice_carrier_names(n, snakemake.config) diff --git a/scripts/build_line_rating.py b/scripts/build_line_rating.py index fa97b251..38ac933d 100755 --- a/scripts/build_line_rating.py +++ b/scripts/build_line_rating.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- # SPDX-FileCopyrightText: : 2017-2020 The PyPSA-Eur Authors # # SPDX-License-Identifier: MIT @@ -50,21 +51,23 @@ the maximal possible capacity factor "s_max_pu" for each transmission line at ea """ import logging -from _helpers import configure_logging - -import pypsa -import pandas as pd -import numpy as np -import geopandas as gpd -from shapely.geometry import Point, LineString as Line -import atlite -import xarray as xr import re +import atlite +import geopandas as gpd +import numpy as np +import pandas as pd +import pypsa +import xarray as xr +from _helpers import configure_logging +from shapely.geometry import LineString as Line +from shapely.geometry import Point + def calculate_resistance(T, R_ref, T_ref=293, alpha=0.00403): """ - Calculates the resistance at other temperatures than the reference temperature. + Calculates the resistance at other temperatures than the reference + temperature. Parameters ---------- @@ -86,7 +89,8 @@ def calculate_resistance(T, R_ref, T_ref=293, alpha=0.00403): def calculate_line_rating(n, cutout): """ - Calculates the maximal allowed power flow in each line for each time step considering the maximal temperature. + Calculates the maximal allowed power flow in each line for each time step + considering the maximal temperature. Parameters ----------