build_line_rating: apply black style
This commit is contained in:
parent
75b695eed4
commit
1d975bb814
@ -61,6 +61,7 @@ import atlite
|
||||
import xarray as xr
|
||||
import re
|
||||
|
||||
|
||||
def calculate_resistance(T, R_ref, T_ref=293, alpha=0.00403):
|
||||
"""
|
||||
Calculates the resistance at other temperatures than the reference temperature.
|
||||
@ -79,9 +80,10 @@ def calculate_resistance(T, R_ref, T_ref=293, alpha=0.00403):
|
||||
-------
|
||||
Resistance of at given temperature.
|
||||
"""
|
||||
R=R_ref*(1+alpha*(T-T_ref))
|
||||
R = R_ref * (1 + alpha * (T - T_ref))
|
||||
return R
|
||||
|
||||
|
||||
def calculate_line_rating(n):
|
||||
"""
|
||||
Calculates the maximal allowed power flow in each line for each time step considering the maximal temperature.
|
||||
@ -94,7 +96,7 @@ def calculate_line_rating(n):
|
||||
-------
|
||||
xarray DataArray object with maximal power.
|
||||
"""
|
||||
relevant_lines=n.lines[(n.lines['underground']==False)]
|
||||
relevant_lines = n.lines[(n.lines["underground"] == False)]
|
||||
buses = relevant_lines[["bus0", "bus1"]].values
|
||||
x = n.buses.x
|
||||
y = n.buses.y
|
||||
@ -102,28 +104,48 @@ def calculate_line_rating(n):
|
||||
shapes = gpd.GeoSeries(shapes, index=relevant_lines.index)
|
||||
cutout = atlite.Cutout(snakemake.input.cutout)
|
||||
if relevant_lines.r_pu.eq(0).all():
|
||||
#Overwrite standard line resistance with line resistance obtained from line type
|
||||
R=relevant_lines.join(n.line_types["r_per_length"], on=["type"])['r_per_length']/1000 #in meters
|
||||
#If line type with bundles is given retrieve number of conductors per bundle
|
||||
relevant_lines["n_bundle"]=relevant_lines["type"].where(relevant_lines["type"].str.contains("bundle")).dropna().apply(lambda x: int(re.findall(r"(\d+)-bundle", x)[0]))
|
||||
#Set default number of bundles per line
|
||||
# Overwrite standard line resistance with line resistance obtained from line type
|
||||
r_per_length = n.line_types["r_per_length"]
|
||||
R = (
|
||||
relevant_lines.join(r_per_length, on=["type"])["r_per_length"] / 1000
|
||||
) # in meters
|
||||
# If line type with bundles is given retrieve number of conductors per bundle
|
||||
relevant_lines["n_bundle"] = (
|
||||
relevant_lines["type"]
|
||||
.where(relevant_lines["type"].str.contains("bundle"))
|
||||
.dropna()
|
||||
.apply(lambda x: int(re.findall(r"(\d+)-bundle", x)[0]))
|
||||
)
|
||||
# Set default number of bundles per line
|
||||
relevant_lines["n_bundle"].fillna(1, inplace=True)
|
||||
R*=relevant_lines["n_bundle"]
|
||||
R=calculate_resistance(T=353, R_ref=R)
|
||||
Imax=cutout.line_rating(shapes, R, D=0.0218 ,Ts=353 , epsilon=0.8, alpha=0.8)
|
||||
line_factor= relevant_lines.eval("v_nom * n_bundle * num_parallel")/1e3 #in mW
|
||||
da = xr.DataArray(data=np.sqrt(3) * Imax * line_factor.values.reshape(-1,1),
|
||||
attrs=dict(description="Maximal possible power in MW for given line considering line rating"))
|
||||
R *= relevant_lines["n_bundle"]
|
||||
R = calculate_resistance(T=353, R_ref=R)
|
||||
Imax = cutout.line_rating(shapes, R, D=0.0218, Ts=353, epsilon=0.8, alpha=0.8)
|
||||
line_factor = relevant_lines.eval("v_nom * n_bundle * num_parallel") / 1e3 # in mW
|
||||
da = xr.DataArray(
|
||||
data=np.sqrt(3) * Imax * line_factor.values.reshape(-1, 1),
|
||||
attrs=dict(
|
||||
description="Maximal possible power in MW for given line considering line rating"
|
||||
),
|
||||
)
|
||||
return da
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if 'snakemake' not in globals():
|
||||
if "snakemake" not in globals():
|
||||
from _helpers import mock_snakemake
|
||||
snakemake = mock_snakemake('build_line_rating', network='elec', simpl='',
|
||||
clusters='40', ll='v1.0', opts='Co2L-4H')
|
||||
|
||||
snakemake = mock_snakemake(
|
||||
"build_line_rating",
|
||||
network="elec",
|
||||
simpl="",
|
||||
clusters="40",
|
||||
ll="v1.0",
|
||||
opts="Co2L-4H",
|
||||
)
|
||||
configure_logging(snakemake)
|
||||
|
||||
n = pypsa.Network(snakemake.input.base_network)
|
||||
|
||||
da=calculate_line_rating(n)
|
||||
da.to_netcdf(snakemake.output[0])
|
||||
da = calculate_line_rating(n)
|
||||
da.to_netcdf(snakemake.output[0])
|
||||
|
Loading…
Reference in New Issue
Block a user