Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove the inactive links when strict export/import constraints are defined #41

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
6 changes: 5 additions & 1 deletion scripts/pypsa-de/additional_functionality.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
61 changes: 42 additions & 19 deletions scripts/pypsa-de/modify_prenetwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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",
[
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down