adjust pipe retrofitting constraint to work with myopic

This commit is contained in:
lisazeyen 2022-01-07 16:59:14 +01:00
parent 5b30f0ece6
commit 9f8b54a3ce

View File

@ -189,25 +189,31 @@ def add_chp_constraints(n):
def add_pipe_retrofit_constraint(n):
"""Add constraint for retrofitting existing CH4 pipelines to H2 pipelines."""
gas_pipes_i = n.links[n.links.carrier=="gas pipeline"].index
h2_retrofitted_i = n.links[n.links.carrier=='H2 pipeline retrofitted'].index
gas_pipes_i = n.links[n.links.carrier=="gas pipeline"].query("p_nom_extendable").index
h2_retrofitted_i = n.links[n.links.carrier=='H2 pipeline retrofitted'].query("p_nom_extendable").index
h2_retrofitted_fixed_i = n.links[n.links.carrier=='H2 pipeline retrofitted'].index.difference(h2_retrofitted_i)
if h2_retrofitted_i.empty or gas_pipes_i.empty: return
link_p_nom = get_var(n, "Link", "p_nom")
pipe_capacity = n.links.loc[gas_pipes_i, 'p_nom']
CH4_per_H2 = 1 / n.config["sector"]["H2_retrofit_capacity_per_CH4"]
fr = "H2 pipeline retrofitted"
to = "gas pipeline"
pipe_capacity = n.links.loc[gas_pipes_i, 'p_nom'].rename(index=lambda x: x.split("-2")[0])
already_retrofitted = (n.links.loc[h2_retrofitted_fixed_i, 'p_nom']
.rename(index= lambda x: x.split("-2")[0]
.replace(fr, to)).groupby(level=0).sum())
remaining_capacity = pipe_capacity - CH4_per_H2 * already_retrofitted.reindex(index=pipe_capacity.index).fillna(0)
lhs = linexpr(
(CH4_per_H2, link_p_nom.loc[h2_retrofitted_i].rename(index=lambda x: x.replace(fr, to))),
(1, link_p_nom.loc[gas_pipes_i])
)
define_constraints(n, lhs, "=", pipe_capacity, 'Link', 'pipe_retrofit')
lhs.rename(index=lambda x: x.split("-2")[0], inplace=True)
define_constraints(n, lhs, "=", remaining_capacity, 'Link', 'pipe_retrofit')
def add_co2_sequestration_limit(n, sns):
@ -275,12 +281,13 @@ if __name__ == "__main__":
if 'snakemake' not in globals():
from helper import mock_snakemake
snakemake = mock_snakemake(
'solve_network',
'solve_network_myopic',
simpl='',
clusters=48,
opts="",
clusters="45",
lv=1.0,
sector_opts='Co2L0-168H-T-H-B-I-solar3-dist1',
planning_horizons=2050,
sector_opts='168H-T-H-B-I-A-solar+p3-dist1',
planning_horizons="2030",
)
logging.basicConfig(filename=snakemake.log.python,