Skip to content

Commit

Permalink
Merge pull request #1019 from PyPSA/reform-grouping-year-logic
Browse files Browse the repository at this point in the history
Reform grouping year logic
  • Loading branch information
lisazeyen authored Apr 11, 2024
2 parents 5ecd56d + f8b33e8 commit a043637
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
4 changes: 2 additions & 2 deletions config/config.default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,8 @@ solar_thermal:

# docs in https://pypsa-eur.readthedocs.io/en/latest/configuration.html#existing-capacities
existing_capacities:
grouping_years_power: [1960, 1965, 1970, 1975, 1980, 1985, 1990, 1995, 2000, 2005, 2010, 2015, 2020, 2025, 2030]
grouping_years_heat: [1980, 1985, 1990, 1995, 2000, 2005, 2010, 2015, 2019] # these should not extend 2020
grouping_years_power: [1895, 1920, 1950, 1955, 1960, 1965, 1970, 1975, 1980, 1985, 1990, 1995, 2000, 2005, 2010, 2015, 2020, 2025, 2030]
grouping_years_heat: [1980, 1985, 1990, 1995, 2000, 2005, 2010, 2015, 2020] # heat grouping years >= baseyear will be ignored
threshold_capacity: 10
default_heating_lifetime: 20
conventional_carriers:
Expand Down
3 changes: 3 additions & 0 deletions doc/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ Release Notes

Upcoming Release
================
* Group existing capacities to the earlier grouping_year for consistency with optimized capacities.

* bugfix: installed heating capacities were 5% lower than existing heating capacities

* Include gas and oil fields and saline aquifers in estimation of CO2 sequestration potential.

Expand Down
4 changes: 2 additions & 2 deletions scripts/add_brownfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ def add_brownfield(n, n_p, year):
# CO2 or global EU values since these are already in n
n_p.mremove(c.name, c.df.index[c.df.lifetime == np.inf])

# remove assets whose build_year + lifetime < year
n_p.mremove(c.name, c.df.index[c.df.build_year + c.df.lifetime < year])
# remove assets whose build_year + lifetime <= year
n_p.mremove(c.name, c.df.index[c.df.build_year + c.df.lifetime <= year])

# remove assets if their optimized nominal capacity is lower than a threshold
# since CHP heat Link is proportional to CHP electric Link, make sure threshold is compatible
Expand Down
36 changes: 30 additions & 6 deletions scripts/add_existing_baseyear.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,19 @@ def add_power_capacities_installed_before_baseyear(n, grouping_years, costs, bas
phased_out = df_agg[df_agg["DateOut"] < baseyear].index
df_agg.drop(phased_out, inplace=True)

older_assets = (df_agg.DateIn < min(grouping_years)).sum()
if older_assets:
logger.warning(
f"There are {older_assets} assets with build year "
f"before first power grouping year {min(grouping_years)}. "
"These assets are dropped and not considered."
"Consider to redefine the grouping years to keep them."
)
to_drop = df_agg[df_agg.DateIn < min(grouping_years)].index
df_agg.drop(to_drop, inplace=True)

df_agg["grouping_year"] = np.take(
grouping_years, np.digitize(df_agg.DateIn, grouping_years, right=True)
grouping_years[::-1], np.digitize(df_agg.DateIn, grouping_years[::-1])
)

# calculate (adjusted) remaining lifetime before phase-out (+1 because assuming
Expand Down Expand Up @@ -444,12 +455,25 @@ def add_heating_capacities_installed_before_baseyear(
else:
efficiency = costs.at[costs_name, "efficiency"]

for i, grouping_year in enumerate(grouping_years):
if int(grouping_year) + default_lifetime <= int(baseyear):
continue
valid_grouping_years = pd.Series(
[
int(grouping_year)
for grouping_year in grouping_years
if int(grouping_year) + default_lifetime > int(baseyear)
and int(grouping_year) < int(baseyear)
]
)

# get number of years of each interval
_years = (
valid_grouping_years.diff()
.shift(-1)
.fillna(baseyear - valid_grouping_years.iloc[-1])
)
# Installation is assumed to be linear for the past
ratios = _years / _years.sum()

# installation is assumed to be linear for the past default_lifetime years
ratio = (int(grouping_year) - int(grouping_years[i - 1])) / default_lifetime
for ratio, grouping_year in zip(ratios, valid_grouping_years):

n.madd(
"Link",
Expand Down

0 comments on commit a043637

Please sign in to comment.