From 840d253a99ffb167143c31280419408d23716a7d Mon Sep 17 00:00:00 2001 From: Michael Lindner Date: Thu, 6 Feb 2025 12:17:06 +0100 Subject: [PATCH 1/2] completely remove the inactive links when strict export/import constraints are defined --- Snakefile | 1 + scripts/pypsa-de/additional_functionality.py | 6 +++- scripts/pypsa-de/modify_prenetwork.py | 37 ++++++++++++++------ 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/Snakefile b/Snakefile index 1f46f2265..17c8961d1 100644 --- a/Snakefile +++ b/Snakefile @@ -281,6 +281,7 @@ rule modify_district_heat_share: rule modify_prenetwork: params: + solving=config_provider("solving"), efuel_export_ban=config_provider("solving", "constraints", "efuel_export_ban"), enable_kernnetz=config_provider("wasserstoff_kernnetz", "enable"), costs=config_provider("costs"), diff --git a/scripts/pypsa-de/additional_functionality.py b/scripts/pypsa-de/additional_functionality.py index d10cb4acc..e0c7d2021 100644 --- a/scripts/pypsa-de/additional_functionality.py +++ b/scripts/pypsa-de/additional_functionality.py @@ -624,7 +624,11 @@ def add_h2_derivate_limit(n, investment_year, limits_volume_max): limit = limits_volume_max["h2_derivate_import"][ct][investment_year] * 1e6 logger.info(f"limiting H2 derivate imports in {ct} to {limit / 1e6} TWh/a") - + if not n.links.loc["EU renewable oil -> DE oil", "active"]: + logger.warning( + "EU renewable oil -> DE oil link not active. Cannot limit H2 derivate imports." + ) + return incoming = n.links.loc[ [ "EU renewable oil -> DE oil", diff --git a/scripts/pypsa-de/modify_prenetwork.py b/scripts/pypsa-de/modify_prenetwork.py index cb9dc5032..9000a97bc 100644 --- a/scripts/pypsa-de/modify_prenetwork.py +++ b/scripts/pypsa-de/modify_prenetwork.py @@ -307,7 +307,7 @@ def add_wasserstoff_kernnetz(n, wkn, costs): # from 2030 onwards all pipes are extendable (except from the ones the model build up before and the kernnetz lines) -def unravel_carbonaceous_fuels(n): +def unravel_carbonaceous_fuels(n, current_year): """ Unravel European carbonaceous buses and if necessary their loads to enable energy balances for import and export of carbonaceous fuels. @@ -407,10 +407,15 @@ def unravel_carbonaceous_fuels(n): if snakemake.params.efuel_export_ban: logger.info( - "Efuel export ban: Setting p_max_pu to 0 for DE renewable oil -> EU oil" + "Efuel export ban: Deactivating link DE renewable oil -> EU oil" ) - n.links.loc["DE renewable oil -> EU oil", "p_max_pu"] = 0 + n.links.loc["DE renewable oil -> EU oil", "active"] = False + if snakemake.params.solving["constraints"]["limits_volume_max"]["h2_derivate_import"]["DE"][current_year] == 0: + logger.info( + "Efuel export ban and H2 derivate import == 0: Deactivating link DE renewable oil -> EU oil" + ) + n.links.loc["EU renewable oil -> DE oil", "active"] = False n.add( "Link", [ @@ -490,9 +495,14 @@ def unravel_carbonaceous_fuels(n): if snakemake.params.efuel_export_ban: logger.info( - "Efuel export ban: Setting p_max_pu to 0 for DE methanol -> EU methanol" + "Efuel export ban: Deactivating link DE methanol -> EU methanol" ) - n.links.loc["DE methanol -> EU methanol", "p_max_pu"] = 0 + n.links.loc["DE methanol -> EU methanol", "active"] = False + if snakemake.params.solving["constraints"]["limits_volume_max"]["h2_derivate_import"]["DE"][current_year] == 0: + logger.info( + "Efuel export ban and H2 derivate import == 0: Deactivating link EU methanol -> DE methanol" + ) + n.links.loc["EU methanol -> DE methanol", "active"] = False # add stores EU_meoh_store = n.stores.loc["EU methanol Store"].copy() @@ -609,7 +619,7 @@ def unravel_carbonaceous_fuels(n): ) -def unravel_gasbus(n, costs): +def unravel_gasbus(n, costs, current_year): """ Unravel European gas bus to enable energy balances for import of gas products. @@ -716,9 +726,14 @@ def unravel_gasbus(n, costs): if snakemake.params.efuel_export_ban: logger.info( - "Efuel export ban: Setting p_max_pu to 0 for DE renewable gas -> EU gas" + "Efuel export ban: Deactivating link DE renewable gas -> EU gas" ) - n.links.loc["DE renewable gas -> EU gas", "p_max_pu"] = 0 + n.links.loc["DE renewable gas -> EU gas", "active"] = False + if snakemake.params.solving["constraints"]["limits_volume_max"]["h2_derivate_import"]["DE"][current_year] == 0: + logger.info( + "Efuel export ban and H2 derivate import == 0: Deactivating link EU renewable gas -> DE gas" + ) + n.links.loc["EU renewable gas -> DE gas", "active"] = False ### add links between renewable and fossil gas buses n.add( @@ -1305,6 +1320,7 @@ def scale_capacity(n, scaling): n = pypsa.Network(snakemake.input.network) nhours = n.snapshot_weightings.generators.sum() nyears = nhours / 8760 + current_year = int(snakemake.wildcards.planning_horizons) costs = prepare_costs( snakemake.input.costs, @@ -1327,10 +1343,10 @@ def scale_capacity(n, scaling): first_technology_occurrence(n) if not snakemake.config["run"]["debug_unravel_oilbus"]: - unravel_carbonaceous_fuels(n) + unravel_carbonaceous_fuels(n, current_year) if not snakemake.config["run"]["debug_unravel_gasbus"]: - unravel_gasbus(n, costs) + unravel_gasbus(n, costs, current_year) if snakemake.params.enable_kernnetz: fn = snakemake.input.wkn @@ -1365,7 +1381,6 @@ def scale_capacity(n, scaling): ): force_retrofit(n, snakemake.params.H2_plants) - current_year = int(snakemake.wildcards.planning_horizons) enforce_transmission_project_build_years(n, current_year) From b441409878395090efa3ea30454ca92f6149662d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 6 Feb 2025 11:22:35 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- scripts/pypsa-de/modify_prenetwork.py | 34 +++++++++++++++++---------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/scripts/pypsa-de/modify_prenetwork.py b/scripts/pypsa-de/modify_prenetwork.py index 9000a97bc..a606c85eb 100644 --- a/scripts/pypsa-de/modify_prenetwork.py +++ b/scripts/pypsa-de/modify_prenetwork.py @@ -406,12 +406,15 @@ def unravel_carbonaceous_fuels(n, current_year): ) if snakemake.params.efuel_export_ban: - logger.info( - "Efuel export ban: Deactivating link DE renewable oil -> EU oil" - ) + logger.info("Efuel export ban: Deactivating link DE renewable oil -> EU oil") n.links.loc["DE renewable oil -> EU oil", "active"] = False - if snakemake.params.solving["constraints"]["limits_volume_max"]["h2_derivate_import"]["DE"][current_year] == 0: + if ( + snakemake.params.solving["constraints"]["limits_volume_max"][ + "h2_derivate_import" + ]["DE"][current_year] + == 0 + ): logger.info( "Efuel export ban and H2 derivate import == 0: Deactivating link DE renewable oil -> EU oil" ) @@ -494,11 +497,14 @@ def unravel_carbonaceous_fuels(n, current_year): ) if snakemake.params.efuel_export_ban: - logger.info( - "Efuel export ban: Deactivating link DE methanol -> EU methanol" - ) + logger.info("Efuel export ban: Deactivating link DE methanol -> EU methanol") n.links.loc["DE methanol -> EU methanol", "active"] = False - if snakemake.params.solving["constraints"]["limits_volume_max"]["h2_derivate_import"]["DE"][current_year] == 0: + if ( + snakemake.params.solving["constraints"]["limits_volume_max"][ + "h2_derivate_import" + ]["DE"][current_year] + == 0 + ): logger.info( "Efuel export ban and H2 derivate import == 0: Deactivating link EU methanol -> DE methanol" ) @@ -725,11 +731,14 @@ def unravel_gasbus(n, costs, current_year): ) if snakemake.params.efuel_export_ban: - logger.info( - "Efuel export ban: Deactivating link DE renewable gas -> EU gas" - ) + logger.info("Efuel export ban: Deactivating link DE renewable gas -> EU gas") n.links.loc["DE renewable gas -> EU gas", "active"] = False - if snakemake.params.solving["constraints"]["limits_volume_max"]["h2_derivate_import"]["DE"][current_year] == 0: + if ( + snakemake.params.solving["constraints"]["limits_volume_max"][ + "h2_derivate_import" + ]["DE"][current_year] + == 0 + ): logger.info( "Efuel export ban and H2 derivate import == 0: Deactivating link EU renewable gas -> DE gas" ) @@ -1381,7 +1390,6 @@ def scale_capacity(n, scaling): ): force_retrofit(n, snakemake.params.H2_plants) - enforce_transmission_project_build_years(n, current_year) drop_duplicate_transmission_projects(n)