diff --git a/Snakefile b/Snakefile index b02e4f33..61872920 100644 --- a/Snakefile +++ b/Snakefile @@ -221,7 +221,7 @@ if config['lines'].get('line_rating', False): base_network="networks/base.nc", cutout="cutouts/" + config["lines"]['cutout'] + ".nc" output: - output="networks/base_lr.nc" + output="resources/line_rating.nc" log: "logs/build_line_rating.log" benchmark: "benchmarks/build_line_rating" threads: 1 @@ -230,9 +230,10 @@ if config['lines'].get('line_rating', False): rule add_electricity: 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, regions="resources/regions_onshore.geojson", + line_rating="resources/line_rating.nc" if config['lines'].get('line_rating', False) else None, powerplants='resources/powerplants.csv', hydro_capacities='data/bundle/hydro_capacities.csv', geth_hydro_capacities='data/geth2015_hydro_capacities.csv', diff --git a/scripts/add_electricity.py b/scripts/add_electricity.py index 08a32a26..bced1efc 100755 --- a/scripts/add_electricity.py +++ b/scripts/add_electricity.py @@ -539,6 +539,11 @@ def estimate_renewable_capacities(n, tech_map=None): .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'] +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): if config is None: config = snakemake.config @@ -575,9 +580,11 @@ if __name__ == "__main__": attach_hydro(n, costs, ppl) attach_extendable_generators(n, costs, ppl) + estimate_renewable_capacities(n) attach_OPSD_renewables(n) update_p_nom_max(n) + attach_line_rating(n) add_nice_carrier_names(n) diff --git a/scripts/build_line_rating.py b/scripts/build_line_rating.py index 62291326..a52ca524 100644 --- a/scripts/build_line_rating.py +++ b/scripts/build_line_rating.py @@ -57,6 +57,7 @@ import numpy as np import geopandas as gpd from shapely.geometry import Point, LineString as Line import atlite +import xarray as xr 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 = gpd.GeoSeries(shapes, index=n.lines.index) cutout = atlite.Cutout(snakemake.input.cutout) - s = np.sqrt(3) * cutout.line_rating(shapes, n.lines.r/n.lines.length) * 1e3 # in MW - 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) + da = xr.DataArray(data=np.sqrt(3) * cutout.line_rating(shapes, n.lines.r/n.lines.length) * 1e3, + attrs=dict(description="Maximal possible power for given line considering line rating")) # in MW + 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__": @@ -79,6 +83,6 @@ if __name__ == "__main__": configure_logging(snakemake) n = pypsa.Network(snakemake.input.base_network) - add_line_rating(n) + da=add_line_rating(n) - n.export_to_netcdf(snakemake.output[0]) \ No newline at end of file + da.to_netcdf(snakemake.output[0]) \ No newline at end of file