Merge branch 'Climact-feature/fix-gas-retrofit'

This commit is contained in:
Fabian Neumann 2024-05-13 18:05:41 +02:00
commit d559ed78dd
2 changed files with 38 additions and 36 deletions

View File

@ -256,6 +256,8 @@ Upcoming Release
* The ``{sector_opts}`` wildcard is now not used by default. All scenario definitions are now done in the ``config.yaml`` file. * The ``{sector_opts}`` wildcard is now not used by default. All scenario definitions are now done in the ``config.yaml`` file.
* Fix gas network retrofitting in `add_brownfield`.
PyPSA-Eur 0.10.0 (19th February 2024) PyPSA-Eur 0.10.0 (19th February 2024)
===================================== =====================================

View File

@ -86,43 +86,43 @@ def add_brownfield(n, n_p, year):
for tattr in n.component_attrs[c.name].index[selection]: for tattr in n.component_attrs[c.name].index[selection]:
n.import_series_from_dataframe(c.pnl[tattr], c.name, tattr) n.import_series_from_dataframe(c.pnl[tattr], c.name, tattr)
# deal with gas network # deal with gas network
pipe_carrier = ["gas pipeline"] pipe_carrier = ["gas pipeline"]
if snakemake.params.H2_retrofit: if snakemake.params.H2_retrofit:
# drop capacities of previous year to avoid duplicating # drop capacities of previous year to avoid duplicating
to_drop = n.links.carrier.isin(pipe_carrier) & (n.links.build_year != year) to_drop = n.links.carrier.isin(pipe_carrier) & (n.links.build_year != year)
n.mremove("Link", n.links.loc[to_drop].index) n.mremove("Link", n.links.loc[to_drop].index)
# subtract the already retrofitted from today's gas grid capacity # subtract the already retrofitted from today's gas grid capacity
h2_retrofitted_fixed_i = n.links[ h2_retrofitted_fixed_i = n.links[
(n.links.carrier == "H2 pipeline retrofitted") (n.links.carrier == "H2 pipeline retrofitted")
& (n.links.build_year != year) & (n.links.build_year != year)
].index ].index
gas_pipes_i = n.links[n.links.carrier.isin(pipe_carrier)].index gas_pipes_i = n.links[n.links.carrier.isin(pipe_carrier)].index
CH4_per_H2 = 1 / snakemake.params.H2_retrofit_capacity_per_CH4 CH4_per_H2 = 1 / snakemake.params.H2_retrofit_capacity_per_CH4
fr = "H2 pipeline retrofitted" fr = "H2 pipeline retrofitted"
to = "gas pipeline" to = "gas pipeline"
# today's pipe capacity # today's pipe capacity
pipe_capacity = n.links.loc[gas_pipes_i, "p_nom"] pipe_capacity = n.links.loc[gas_pipes_i, "p_nom"]
# already retrofitted capacity from gas -> H2 # already retrofitted capacity from gas -> H2
already_retrofitted = ( already_retrofitted = (
n.links.loc[h2_retrofitted_fixed_i, "p_nom"] n.links.loc[h2_retrofitted_fixed_i, "p_nom"]
.rename(lambda x: x.split("-2")[0].replace(fr, to)) .rename(lambda x: x.split("-2")[0].replace(fr, to) + f"-{year}")
.groupby(level=0) .groupby(level=0)
.sum() .sum()
) )
remaining_capacity = ( remaining_capacity = (
pipe_capacity pipe_capacity
- CH4_per_H2 - CH4_per_H2
* already_retrofitted.reindex(index=pipe_capacity.index).fillna(0) * already_retrofitted.reindex(index=pipe_capacity.index).fillna(0)
) )
n.links.loc[gas_pipes_i, "p_nom"] = remaining_capacity n.links.loc[gas_pipes_i, "p_nom"] = remaining_capacity
else: else:
new_pipes = n.links.carrier.isin(pipe_carrier) & ( new_pipes = n.links.carrier.isin(pipe_carrier) & (
n.links.build_year == year n.links.build_year == year
) )
n.links.loc[new_pipes, "p_nom"] = 0.0 n.links.loc[new_pipes, "p_nom"] = 0.0
n.links.loc[new_pipes, "p_nom_min"] = 0.0 n.links.loc[new_pipes, "p_nom_min"] = 0.0
def disable_grid_expansion_if_limit_hit(n): def disable_grid_expansion_if_limit_hit(n):