From 37bbbc6225f8850c5caef6cded8a328722aa7af7 Mon Sep 17 00:00:00 2001 From: Micha Date: Thu, 13 Jun 2024 14:51:32 +0200 Subject: [PATCH] Fix grouping logic again --- config/config.default.yaml | 4 ++-- doc/release_notes.rst | 2 ++ scripts/add_existing_baseyear.py | 27 ++++++++++++++++----------- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/config/config.default.yaml b/config/config.default.yaml index 533c1e5d..ee61d366 100644 --- a/config/config.default.yaml +++ b/config/config.default.yaml @@ -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: diff --git a/doc/release_notes.rst b/doc/release_notes.rst index ae003d07..019a1f35 100644 --- a/doc/release_notes.rst +++ b/doc/release_notes.rst @@ -19,6 +19,8 @@ Upcoming Release `__. 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) ===================================== diff --git a/scripts/add_existing_baseyear.py b/scripts/add_existing_baseyear.py index a209e934..d5333675 100644 --- a/scripts/add_existing_baseyear.py +++ b/scripts/add_existing_baseyear.py @@ -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 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() + 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 + 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 @@ -464,6 +464,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) @@ -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 - _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()