Merge pull request #1102 from PyPSA/fix-grouping-logic-again-master

Fix grouping logic again
This commit is contained in:
lisazeyen 2024-06-13 15:46:57 +02:00 committed by GitHub
commit 72af49a78d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 20 additions and 13 deletions

View File

@ -390,8 +390,8 @@ solar_thermal:
# docs in https://pypsa-eur.readthedocs.io/en/latest/configuration.html#existing-capacities # docs in https://pypsa-eur.readthedocs.io/en/latest/configuration.html#existing-capacities
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_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, 2020] # heat grouping years >= baseyear will be ignored grouping_years_heat: [1980, 1985, 1990, 1995, 2000, 2005, 2010, 2015, 2019] # heat grouping years >= baseyear will be ignored
threshold_capacity: 10 threshold_capacity: 10
default_heating_lifetime: 20 default_heating_lifetime: 20
conventional_carriers: conventional_carriers:

View File

@ -19,6 +19,8 @@ Upcoming Release
<https://www.sciencedirect.com/science/article/pii/S0306261920312551>`__. <https://www.sciencedirect.com/science/article/pii/S0306261920312551>`__.
See configuration ``sector: enhanced_geothermal`` for details; by default switched off. See configuration ``sector: enhanced_geothermal`` for details; by default switched off.
* 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) PyPSA-Eur 0.11.0 (25th May 2024)
===================================== =====================================

View File

@ -201,19 +201,19 @@ def add_power_capacities_installed_before_baseyear(n, grouping_years, costs, bas
phased_out = df_agg[df_agg["DateOut"] < baseyear].index phased_out = df_agg[df_agg["DateOut"] < baseyear].index
df_agg.drop(phased_out, inplace=True) df_agg.drop(phased_out, inplace=True)
older_assets = (df_agg.DateIn < min(grouping_years)).sum() newer_assets = (df_agg.DateIn > max(grouping_years)).sum()
if older_assets: if newer_assets:
logger.warning( logger.warning(
f"There are {older_assets} assets with build year " f"There are {newer_assets} assets with build year "
f"before first power grouping year {min(grouping_years)}. " f"after last power grouping year {max(grouping_years)}. "
"These assets are dropped and not considered." "These assets are dropped and not considered."
"Consider to redefine the grouping years to keep them." "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.drop(to_drop, inplace=True)
df_agg["grouping_year"] = np.take( 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 # calculate (adjusted) remaining lifetime before phase-out (+1 because assuming
@ -464,6 +464,11 @@ def add_heating_capacities_installed_before_baseyear(
else: else:
efficiency = costs.at[costs_name, "efficiency"] 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( valid_grouping_years = pd.Series(
[ [
int(grouping_year) int(grouping_year)
@ -473,12 +478,12 @@ def add_heating_capacities_installed_before_baseyear(
] ]
) )
assert valid_grouping_years.is_monotonic_increasing
# get number of years of each interval # get number of years of each interval
_years = ( _years = valid_grouping_years.diff()
valid_grouping_years.diff() # Fill NA from .diff() with value for the first interval
.shift(-1) _years[0] = valid_grouping_years[0] - baseyear + default_lifetime
.fillna(baseyear - valid_grouping_years.iloc[-1])
)
# Installation is assumed to be linear for the past # Installation is assumed to be linear for the past
ratios = _years / _years.sum() ratios = _years / _years.sum()