From f4d0415cf0fb4563d3c90305f7a24ad76f716937 Mon Sep 17 00:00:00 2001 From: Fabian Date: Wed, 8 Feb 2023 18:19:31 +0100 Subject: [PATCH] solve_network: activate co2 seq constraint Snakefile: retrieve data bundle from pypsaeur function --- Snakefile | 6 +++--- scripts/solve_network.py | 22 ++++++++++++---------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/Snakefile b/Snakefile index 90fcfb56..58fe149f 100644 --- a/Snakefile +++ b/Snakefile @@ -252,9 +252,9 @@ rule build_biomass_potentials: enspreso_biomass=HTTP.remote("https://cidportal.jrc.ec.europa.eu/ftp/jrc-opendata/ENSPRESO/ENSPRESO_BIOMASS.xlsx", keep_local=True), nuts2="data/nuts/NUTS_RG_10M_2013_4326_LEVL_2.geojson", # https://gisco-services.ec.europa.eu/distribution/v2/nuts/download/#nuts21 regions_onshore=pypsaeur("resources/regions_onshore_elec_s{simpl}_{clusters}.geojson"), - nuts3_population="../pypsa-eur/data/bundle/nama_10r_3popgdp.tsv.gz", - swiss_cantons="../pypsa-eur/data/bundle/ch_cantons.csv", - swiss_population="../pypsa-eur/data/bundle/je-e-21.03.02.xls", + nuts3_population=pypsaeur("data/bundle/nama_10r_3popgdp.tsv.gz"), + swiss_cantons=pypsaeur("data/bundle/ch_cantons.csv"), + swiss_population=pypsaeur("data/bundle/je-e-21.03.02.xls"), country_shapes=pypsaeur('resources/country_shapes.geojson') output: biomass_potentials_all='resources/biomass_potentials_all_s{simpl}_{clusters}.csv', diff --git a/scripts/solve_network.py b/scripts/solve_network.py index e1cfc3d5..f3e51c84 100644 --- a/scripts/solve_network.py +++ b/scripts/solve_network.py @@ -100,16 +100,18 @@ def prepare_network(n, solve_opts=None): def add_battery_constraints(n): """ - Add constraints to ensure that the ratio between the charger and - discharger. - 1 * charger_size - efficiency * discharger_size = 0 + Add constraint ensuring that charger = discharger: + 1 * charger_size - efficiency * discharger_size = 0 """ - nodes = n.buses.index[n.buses.carrier == "battery"] - if nodes.empty: - return - link_p_nom = n.model["Link-p_nom"] - eff = n.links.efficiency[nodes + " discharger"].values - lhs = link_p_nom.loc[nodes + ' charger'] - link_p_nom.loc[nodes + ' discharger'] * eff + discharger_bool = n.links.index.str.contains("battery discharger") + charger_bool = n.links.index.str.contains("battery charger") + + dischargers_ext= n.links[discharger_bool].query("p_nom_extendable").index + chargers_ext= n.links[charger_bool].query("p_nom_extendable").index + + eff = n.links.efficiency[dischargers_ext].values + lhs = n.model["Link-p_nom"].loc[chargers_ext] - n.model["Link-p_nom"].loc[dischargers_ext] * eff + n.model.add_constraints(lhs == 0, name="Link-charger_ratio") @@ -194,7 +196,7 @@ def add_co2_sequestration_limit(n, sns): def extra_functionality(n, snapshots): add_battery_constraints(n) add_pipe_retrofit_constraint(n) - # add_co2_sequestration_limit(n, snapshots) + add_co2_sequestration_limit(n, snapshots) def solve_network(n, config, opts="", **kwargs):