line rating assigned in add_electricity.py

This commit is contained in:
Philipp Glaum 2021-12-15 13:53:38 +01:00
parent 7e628f66c5
commit af4bccfb39
3 changed files with 19 additions and 7 deletions

View File

@ -221,7 +221,7 @@ if config['lines'].get('line_rating', False):
base_network="networks/base.nc", base_network="networks/base.nc",
cutout="cutouts/" + config["lines"]['cutout'] + ".nc" cutout="cutouts/" + config["lines"]['cutout'] + ".nc"
output: output:
output="networks/base_lr.nc" output="resources/line_rating.nc"
log: "logs/build_line_rating.log" log: "logs/build_line_rating.log"
benchmark: "benchmarks/build_line_rating" benchmark: "benchmarks/build_line_rating"
threads: 1 threads: 1
@ -230,9 +230,10 @@ if config['lines'].get('line_rating', False):
rule add_electricity: rule add_electricity:
input: input:
base_network = "networks/base_lr.nc" if config['lines'].get('line_rating', False) else "networks/base.nc", base_network = "networks/base.nc",
tech_costs=COSTS, tech_costs=COSTS,
regions="resources/regions_onshore.geojson", regions="resources/regions_onshore.geojson",
line_rating="resources/line_rating.nc" if config['lines'].get('line_rating', False) else None,
powerplants='resources/powerplants.csv', powerplants='resources/powerplants.csv',
hydro_capacities='data/bundle/hydro_capacities.csv', hydro_capacities='data/bundle/hydro_capacities.csv',
geth_hydro_capacities='data/geth2015_hydro_capacities.csv', geth_hydro_capacities='data/geth2015_hydro_capacities.csv',

View File

@ -539,6 +539,11 @@ def estimate_renewable_capacities(n, tech_map=None):
.where(lambda s: s>0.1, 0.)) # only capacities above 100kW .where(lambda s: s>0.1, 0.)) # only capacities above 100kW
n.generators.loc[tech_i, 'p_nom_min'] = n.generators.loc[tech_i, 'p_nom'] n.generators.loc[tech_i, 'p_nom_min'] = n.generators.loc[tech_i, 'p_nom']
def attach_line_rating(n):
if snakemake.config["lines"]["line_rating"]:
s=xr.open_dataarray(snakemake.input.line_rating)
n.lines_t.s_max_pu=s.to_pandas().transpose()/n.lines.s_nom
n.lines_t.s_max_pu.replace(np.inf, 1.0, inplace=True)
def add_nice_carrier_names(n, config=None): def add_nice_carrier_names(n, config=None):
if config is None: config = snakemake.config if config is None: config = snakemake.config
@ -575,9 +580,11 @@ if __name__ == "__main__":
attach_hydro(n, costs, ppl) attach_hydro(n, costs, ppl)
attach_extendable_generators(n, costs, ppl) attach_extendable_generators(n, costs, ppl)
estimate_renewable_capacities(n) estimate_renewable_capacities(n)
attach_OPSD_renewables(n) attach_OPSD_renewables(n)
update_p_nom_max(n) update_p_nom_max(n)
attach_line_rating(n)
add_nice_carrier_names(n) add_nice_carrier_names(n)

View File

@ -57,6 +57,7 @@ import numpy as np
import geopandas as gpd import geopandas as gpd
from shapely.geometry import Point, LineString as Line from shapely.geometry import Point, LineString as Line
import atlite import atlite
import xarray as xr
def add_line_rating(n): def add_line_rating(n):
@ -66,9 +67,12 @@ def add_line_rating(n):
shapes = [Line([Point(x[b0], y[b0]), Point(x[b1], y[b1])]) for (b0, b1) in buses] shapes = [Line([Point(x[b0], y[b0]), Point(x[b1], y[b1])]) for (b0, b1) in buses]
shapes = gpd.GeoSeries(shapes, index=n.lines.index) shapes = gpd.GeoSeries(shapes, index=n.lines.index)
cutout = atlite.Cutout(snakemake.input.cutout) cutout = atlite.Cutout(snakemake.input.cutout)
s = np.sqrt(3) * cutout.line_rating(shapes, n.lines.r/n.lines.length) * 1e3 # in MW da = xr.DataArray(data=np.sqrt(3) * cutout.line_rating(shapes, n.lines.r/n.lines.length) * 1e3,
n.lines_t.s_max_pu=s.to_pandas().transpose()/n.lines.s_nom attrs=dict(description="Maximal possible power for given line considering line rating")) # in MW
n.lines_t.s_max_pu.replace(np.inf, 1.0, inplace=True) return da
#import netcdf file in add electricity.py
#n.lines_t.s_max_pu=s.to_pandas().transpose()/n.lines.s_nom
#n.lines_t.s_max_pu.replace(np.inf, 1.0, inplace=True)
if __name__ == "__main__": if __name__ == "__main__":
@ -79,6 +83,6 @@ if __name__ == "__main__":
configure_logging(snakemake) configure_logging(snakemake)
n = pypsa.Network(snakemake.input.base_network) n = pypsa.Network(snakemake.input.base_network)
add_line_rating(n) da=add_line_rating(n)
n.export_to_netcdf(snakemake.output[0]) da.to_netcdf(snakemake.output[0])