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

Fix grouping logic again #1091

Merged
merged 12 commits into from
Jun 13, 2024
5 changes: 2 additions & 3 deletions config/config.default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,8 @@ solar_thermal:

# docs in https://pypsa-eur.readthedocs.io/en/latest/configuration.html#existing-capacities
existing_capacities:
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
grouping_years_power: [1920, 1950, 1955, 1960, 1965, 1970, 1975, 1980, 1985, 1990, 1995, 2000, 2005, 2010, 2015, 2020, 2025]
grouping_years_heat: [1980, 1985, 1990, 1995, 2000, 2005, 2010, 2015, 2019] # heat grouping years >= baseyear will be ignored
threshold_capacity: 10
default_heating_lifetime: 20
conventional_carriers:
Expand Down Expand Up @@ -1024,7 +1024,6 @@ plotting:
solid biomass for industry co2 from atmosphere: '#736412'
solid biomass for industry co2 to stored: '#47411c'
urban central solid biomass CHP: '#9d9042'
solid biomass: '#9d9042'
solid biomass OP: '#9d9042'
urban central solid biomass CHP CC: '#6c5d28'
biomass boiler: '#8A9A5B'
Expand Down
4 changes: 4 additions & 0 deletions doc/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ Release Notes

.. Upcoming Release
.. ================

* Partially revert https://github.com/PyPSA/pypsa-eur/pull/967 to return to old grouping year logic (which was mostly correct)


PyPSA-Eur 0.11.0 (25th May 2024)
=====================================

Expand Down
46 changes: 20 additions & 26 deletions scripts/add_existing_baseyear.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,30 +224,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:
newer_assets = (df_agg.DateIn > max(grouping_years)).sum()
lindnemi marked this conversation as resolved.
Show resolved Hide resolved
if newer_assets:
logger.warning(
f"There are {older_assets} assets with build year "
f"before first power grouping year {min(grouping_years)}. "
f"There are {newer_assets} assets with build year "
f"after last power grouping year {max(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)

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
to_drop = df_agg[df_agg.DateIn > max(grouping_years)].index
df_agg.drop(to_drop, inplace=True)

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

# calculate (adjusted) remaining lifetime before phase-out (+1 because assuming
Expand Down Expand Up @@ -306,9 +295,9 @@ def add_power_capacities_installed_before_baseyear(n, grouping_years, costs, bas

# this is for the year 2020
if not already_build.empty:
n.generators.loc[already_build, "p_nom_min"] = capacity.loc[
already_build.str.replace(name_suffix, "")
].values
n.generators.loc[already_build, "p_nom"] = n.generators.loc[
already_build, "p_nom_min"
] = capacity.loc[already_build.str.replace(name_suffix, "")].values
new_capacity = capacity.loc[new_build.str.replace(name_suffix, "")]

if "m" in snakemake.wildcards.clusters:
Expand Down Expand Up @@ -484,7 +473,6 @@ def add_chp_plants(n, grouping_years, costs, baseyear, clustermaps):

# calculate remaining lifetime before phase-out (+1 because assuming
# phase out date at the end of the year)
chp["lifetime"] = chp.DateOut - chp.DateIn + 1
chp.Fueltype = chp.Fueltype.map(rename_fuel)

# assign clustered bus
Expand All @@ -494,6 +482,7 @@ def add_chp_plants(n, grouping_years, costs, baseyear, clustermaps):
chp["grouping_year"] = np.take(
grouping_years, np.digitize(chp.DateIn, grouping_years, right=True)
)
chp["lifetime"] = chp.DateOut - chp["grouping_year"] + 1

# check if the CHPs were read in from MaStR for Germany
if "Capacity_thermal" in chp.columns:
Expand Down Expand Up @@ -727,6 +716,11 @@ def add_heating_capacities_installed_before_baseyear(
else:
efficiency = costs.at[costs_name, "efficiency"]

too_large_grouping_years = [gy for gy in grouping_years if gy >= int(baseyear)]
if too_large_grouping_years:
logger.warning(
f"Grouping years >= baseyear are ignored. Dropping {too_large_grouping_years}."
)
valid_grouping_years = pd.Series(
[
int(grouping_year)
Expand All @@ -736,12 +730,12 @@ def add_heating_capacities_installed_before_baseyear(
]
)

assert valid_grouping_years.is_monotonic_increasing

# get number of years of each interval
_years = (
valid_grouping_years.diff()
.shift(-1)
.fillna(baseyear - valid_grouping_years.iloc[-1])
)
_years = valid_grouping_years.diff()
# Fill NA from .diff() with value for the first interval
_years[0] = valid_grouping_years[0] - baseyear + default_lifetime
# Installation is assumed to be linear for the past
ratios = _years / _years.sum()

Expand Down
4 changes: 0 additions & 4 deletions scripts/solve_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,6 @@ def _add_land_use_constraint(n):
"offwind-dc",
"offwind-float",
]:
extendable_i = (n.generators.carrier == carrier) & n.generators.p_nom_extendable
n.generators.loc[extendable_i, "p_nom_min"] = 0

ext_i = (n.generators.carrier == carrier) & ~n.generators.p_nom_extendable
existing = (
Expand Down Expand Up @@ -174,8 +172,6 @@ def _add_land_use_constraint_m(n, planning_horizons, config):
"offwind-ac",
"offwind-dc",
]:
extendable_i = (n.generators.carrier == carrier) & n.generators.p_nom_extendable
n.generators.loc[extendable_i, "p_nom_min"] = 0

existing = n.generators.loc[n.generators.carrier == carrier, "p_nom"]
ind = list(
Expand Down