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..a606c85eb 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. @@ -406,11 +406,19 @@ 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" - ) - n.links.loc["DE renewable oil -> EU oil", "p_max_pu"] = 0 - + 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 + ): + 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", [ @@ -489,10 +497,18 @@ 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" - ) - n.links.loc["DE methanol -> EU methanol", "p_max_pu"] = 0 + 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 + ): + 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 +625,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. @@ -715,10 +731,18 @@ 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" - ) - n.links.loc["DE renewable gas -> EU gas", "p_max_pu"] = 0 + 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 + ): + 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 +1329,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 +1352,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,8 +1390,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) drop_duplicate_transmission_projects(n)