From 7c30a2835fbe0f8435ca38b38c45a155bc3554c8 Mon Sep 17 00:00:00 2001 From: Michael Lindner Date: Thu, 14 Mar 2024 13:44:15 +0100 Subject: [PATCH 1/8] group existing capacities to the earlier grouping_year for consistency with optimized capacities --- config/config.default.yaml | 2 +- doc/release_notes.rst | 1 + scripts/add_existing_baseyear.py | 20 ++++++++++++-------- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/config/config.default.yaml b/config/config.default.yaml index d438c51f7..0d40bafc9 100644 --- a/config/config.default.yaml +++ b/config/config.default.yaml @@ -361,7 +361,7 @@ 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_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: diff --git a/doc/release_notes.rst b/doc/release_notes.rst index d42b149f8..cdad3fa0f 100644 --- a/doc/release_notes.rst +++ b/doc/release_notes.rst @@ -9,6 +9,7 @@ Release Notes Upcoming Release ================ +* Group existing capacities to the earlier grouping_year for consistency with optimized capacities * Include gas and oil fields and saline aquifers in estimation of CO2 sequestration potential. diff --git a/scripts/add_existing_baseyear.py b/scripts/add_existing_baseyear.py index f445efe34..75d83e385 100644 --- a/scripts/add_existing_baseyear.py +++ b/scripts/add_existing_baseyear.py @@ -190,8 +190,8 @@ def add_power_capacities_installed_before_baseyear(n, grouping_years, costs, bas df_agg.drop(phased_out, 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 # phase out date at the end of the year) @@ -444,12 +444,16 @@ 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 - - # installation is assumed to be linear for the past default_lifetime years - ratio = (int(grouping_year) - int(grouping_years[i - 1])) / default_lifetime + valid_grouping_years = pd.Series( + [int(gy) for gy in grouping_years if + int(baseyear) - default_lifetime <= int(gy) < int(baseyear)]) + # Installation is assumed to be linear for the past + _intervals = pd.concat( + [valid_grouping_years[1:], pd.Series(baseyear)], + ignore_index=True) - valid_grouping_years + ratios = _intervals / _intervals.sum() + + for ratio, grouping_year in zip(ratios, valid_grouping_years): n.madd( "Link", From 700b0e912a31c14e67db0ff4cc504590d7242448 Mon Sep 17 00:00:00 2001 From: Michael Lindner Date: Thu, 14 Mar 2024 16:13:40 +0100 Subject: [PATCH 2/8] add more grouping years to avoid errors --- config/config.default.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/config.default.yaml b/config/config.default.yaml index 0d40bafc9..42132f226 100644 --- a/config/config.default.yaml +++ b/config/config.default.yaml @@ -360,7 +360,7 @@ 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_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 From 3a0e3563821b4f3cded77c28ce57f23223751e4c Mon Sep 17 00:00:00 2001 From: lisazeyen <35347358+lisazeyen@users.noreply.github.com> Date: Thu, 11 Apr 2024 08:54:15 +0200 Subject: [PATCH 3/8] add check if minimum grouping year< min build year --- scripts/add_existing_baseyear.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/scripts/add_existing_baseyear.py b/scripts/add_existing_baseyear.py index 75d83e385..01870a26b 100644 --- a/scripts/add_existing_baseyear.py +++ b/scripts/add_existing_baseyear.py @@ -189,6 +189,15 @@ 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 Date: Thu, 11 Apr 2024 09:26:30 +0200 Subject: [PATCH 4/8] adjust valid_grouping_years change sign, split up conditions for better readibility --- scripts/add_existing_baseyear.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/scripts/add_existing_baseyear.py b/scripts/add_existing_baseyear.py index 01870a26b..75375565b 100644 --- a/scripts/add_existing_baseyear.py +++ b/scripts/add_existing_baseyear.py @@ -454,14 +454,22 @@ def add_heating_capacities_installed_before_baseyear( efficiency = costs.at[costs_name, "efficiency"] valid_grouping_years = pd.Series( - [int(gy) for gy in grouping_years if - int(baseyear) - default_lifetime <= int(gy) < int(baseyear)]) + [ + int(grouping_year) + for grouping_year in grouping_years + if int(grouping_year) + default_lifetime > int(baseyear) + and int(grouping_year) < int(baseyear) + ] + ) # Installation is assumed to be linear for the past - _intervals = pd.concat( - [valid_grouping_years[1:], pd.Series(baseyear)], - ignore_index=True) - valid_grouping_years + _intervals = ( + pd.concat( + [valid_grouping_years[1:], pd.Series(baseyear)], ignore_index=True + ) + - valid_grouping_years + ) ratios = _intervals / _intervals.sum() - + for ratio, grouping_year in zip(ratios, valid_grouping_years): n.madd( From 7773f7c84ebbbbdd8dd9bd5e3b2f8e1ed6edbc7d Mon Sep 17 00:00:00 2001 From: Micha Date: Thu, 11 Apr 2024 09:37:36 +0200 Subject: [PATCH 5/8] Add release note for serendipitous bugfix --- doc/release_notes.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/release_notes.rst b/doc/release_notes.rst index cdad3fa0f..079648d50 100644 --- a/doc/release_notes.rst +++ b/doc/release_notes.rst @@ -9,7 +9,9 @@ Release Notes Upcoming Release ================ -* Group existing capacities to the earlier grouping_year for consistency with optimized capacities +* 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. From e9c9d08107967119539b3fa7202b3f670868d092 Mon Sep 17 00:00:00 2001 From: lisazeyen <35347358+lisazeyen@users.noreply.github.com> Date: Thu, 11 Apr 2024 09:52:17 +0200 Subject: [PATCH 6/8] rename _intervals to _years, shorten definition --- scripts/add_existing_baseyear.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/scripts/add_existing_baseyear.py b/scripts/add_existing_baseyear.py index 75375565b..d70afb485 100644 --- a/scripts/add_existing_baseyear.py +++ b/scripts/add_existing_baseyear.py @@ -461,14 +461,12 @@ def add_heating_capacities_installed_before_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 - _intervals = ( - pd.concat( - [valid_grouping_years[1:], pd.Series(baseyear)], ignore_index=True - ) - - valid_grouping_years - ) - ratios = _intervals / _intervals.sum() + ratios = _years / _years.sum() for ratio, grouping_year in zip(ratios, valid_grouping_years): From a72388b989d1d667ec7e44d66f6c3b494b46d000 Mon Sep 17 00:00:00 2001 From: lisazeyen <35347358+lisazeyen@users.noreply.github.com> Date: Thu, 11 Apr 2024 13:54:33 +0200 Subject: [PATCH 7/8] define active assets consitently --- scripts/add_brownfield.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/add_brownfield.py b/scripts/add_brownfield.py index 7e49031b7..16b4e0870 100644 --- a/scripts/add_brownfield.py +++ b/scripts/add_brownfield.py @@ -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 From f8b33e8eb28982b424e3637c96fa53f44bb2b8cb Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 11 Apr 2024 12:21:43 +0000 Subject: [PATCH 8/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- scripts/add_existing_baseyear.py | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/scripts/add_existing_baseyear.py b/scripts/add_existing_baseyear.py index d70afb485..8a8a78a4a 100644 --- a/scripts/add_existing_baseyear.py +++ b/scripts/add_existing_baseyear.py @@ -189,18 +189,20 @@ 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