From 1df85468aa6b7b36b68e530e751949d21a955595 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20H=C3=B6rsch?= Date: Mon, 22 Oct 2018 23:22:34 +0200 Subject: [PATCH] add_electricity, prepare_network: Enable lv='inf' and remove converter link costs --- Snakefile | 2 +- scripts/add_electricity.py | 18 +++++++++++------- scripts/prepare_network.py | 25 ++++++++++++++++--------- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/Snakefile b/Snakefile index 9b0e14e1..dfd92b3b 100644 --- a/Snakefile +++ b/Snakefile @@ -195,7 +195,7 @@ rule cluster_network: # script: "scripts/add_sectors.py" rule prepare_network: - input: 'networks/{network}_s{simpl}_{clusters}.nc' + input: 'networks/{network}_s{simpl}_{clusters}.nc', tech_costs='data/costs.csv' output: 'networks/{network}_s{simpl}_{clusters}_lv{lv}_{opts}.nc' threads: 1 resources: mem=1000 diff --git a/scripts/add_electricity.py b/scripts/add_electricity.py index 27e0d28b..2a460db1 100644 --- a/scripts/add_electricity.py +++ b/scripts/add_electricity.py @@ -137,17 +137,21 @@ def attach_load(n): ### Set line costs -def update_transmission_costs(n, costs, length_factor=1.0): +def update_transmission_costs(n, costs, length_factor=1.0, simple_hvdc_costs=False): n.lines['capital_cost'] = (n.lines['length'] * length_factor * costs.at['HVAC overhead', 'capital_cost']) dc_b = n.links.carrier == 'DC' - n.links.loc[dc_b, 'capital_cost'] = (n.links.loc[dc_b, 'length'] * length_factor * - ((1. - n.links.loc[dc_b, 'underwater_fraction']) * - costs.at['HVDC overhead', 'capital_cost'] + - n.links.loc[dc_b, 'underwater_fraction'] * - costs.at['HVDC submarine', 'capital_cost']) + - costs.at['HVDC inverter pair', 'capital_cost']) + if simple_hvdc_costs: + n.links.loc[dc_b, 'capital_cost'] = (n.links.loc[dc_b, 'length'] * length_factor * + costs.at['HVDC overhead', 'capital_cost']) + else: + n.links.loc[dc_b, 'capital_cost'] = (n.links.loc[dc_b, 'length'] * length_factor * + ((1. - n.links.loc[dc_b, 'underwater_fraction']) * + costs.at['HVDC overhead', 'capital_cost'] + + n.links.loc[dc_b, 'underwater_fraction'] * + costs.at['HVDC submarine', 'capital_cost']) + + costs.at['HVDC inverter pair', 'capital_cost']) # ### Generators diff --git a/scripts/prepare_network.py b/scripts/prepare_network.py index de52ce69..129ca04f 100644 --- a/scripts/prepare_network.py +++ b/scripts/prepare_network.py @@ -14,6 +14,7 @@ from six import iteritems import geopandas as gpd import pypsa +from add_electricity import load_costs, update_transmission_costs def add_co2limit(n, Nyears=1.): n.add("GlobalConstraint", "CO2Limit", @@ -41,9 +42,16 @@ def set_line_s_max_pu(n): n.links.loc[dc_b, 'p_min_pu'] = - s_max_pu def set_line_volume_limit(n, lv): - # Either line_volume cap or cost - n.lines['capital_cost'] = 0. - n.links['capital_cost'] = 0. + links_dc_b = n.links.carrier == 'DC' + + if np.isinf(lv): + costs = load_costs(Nyears, snakemake.input.tech_costs, + snakemake.config['costs'], snakemake.config['electricity']) + update_transmission_costs(n, costs, simple_hvdc_costs=True) + else: + # Either line_volume cap or cost + n.lines['capital_cost'] = 0. + n.links.loc[links_dc_b, 'capital_cost'] = 0. if lv > 1.0: lines_s_nom = n.lines.s_nom.where( @@ -54,13 +62,13 @@ def set_line_volume_limit(n, lv): ) n.lines['s_nom_min'] = lines_s_nom - n.links['p_nom_min'] = n.links['p_nom'] - n.lines['s_nom_extendable'] = True - n.links['p_nom_extendable'] = True + + n.links.loc[links_dc_b, 'p_nom_min'] = n.links.loc[links_dc_b, 'p_nom'] + n.links.loc[links_dc_b, 'p_nom_extendable'] = True n.line_volume_limit = lv * ((lines_s_nom * n.lines['length']).sum() + - n.links.loc[n.links.carrier=='DC'].eval('p_nom * length').sum()) + n.links.loc[links_dc_b].eval('p_nom * length').sum()) return n @@ -115,7 +123,6 @@ if __name__ == "__main__": # if 'Ep' in opts: # add_emission_prices(n) - if snakemake.wildcards.lv != 'inf': - set_line_volume_limit(n, float(snakemake.wildcards.lv)) + set_line_volume_limit(n, float(snakemake.wildcards.lv)) n.export_to_netcdf(snakemake.output[0])