From 7798e12f5039255877135b5d3873ff1b88142390 Mon Sep 17 00:00:00 2001 From: Amos Schledorn Date: Thu, 12 Sep 2024 15:24:40 +0200 Subject: [PATCH 01/22] feat: add temperature reduction to workflow --- config/config.default.yaml | 7 +- rules/build_sector.smk | 19 ++-- .../run.py | 91 +++++++++++++++++-- 3 files changed, 100 insertions(+), 17 deletions(-) diff --git a/config/config.default.yaml b/config/config.default.yaml index 246a15f47..be871afae 100644 --- a/config/config.default.yaml +++ b/config/config.default.yaml @@ -450,7 +450,7 @@ sector: 2050: 1.0 district_heating_loss: 0.15 supply_temperature_approximation: - max_forward_temperature: + max_forward_temperature_today: FR: 110 DK: 75 DE: 109 @@ -459,13 +459,14 @@ sector: PL: 130 SE: 102 IT: 90 - min_forward_temperature: + min_forward_temperature_today: DE: 82 - return_temperature: + return_temperature_today: DE: 58 lower_threshold_ambient_temperature: 0 upper_threshold_ambient_temperature: 10 rolling_window_ambient_temperature: 72 + relative_annual_temperature_reduction: 0.01 heat_source_cooling: 6 #K heat_pump_cop_approximation: refrigerant: ammonia diff --git a/rules/build_sector.smk b/rules/build_sector.smk index b3cfc4afa..9604a2363 100755 --- a/rules/build_sector.smk +++ b/rules/build_sector.smk @@ -214,23 +214,23 @@ rule build_temperature_profiles: rule build_central_heating_temperature_profiles: params: - max_forward_temperature_central_heating=config_provider( + max_forward_temperature_central_heating_today=config_provider( "sector", "district_heating", "supply_temperature_approximation", - "max_forward_temperature", + "max_forward_temperature_today", ), - min_forward_temperature_central_heating=config_provider( + min_forward_temperature_central_heating_today=config_provider( "sector", "district_heating", "supply_temperature_approximation", - "min_forward_temperature", + "min_forward_temperature_today", ), - return_temperature_central_heating=config_provider( + return_temperature_central_heating_today=config_provider( "sector", "district_heating", "supply_temperature_approximation", - "return_temperature", + "return_temperature_today", ), snapshots=config_provider("snapshots"), lower_threshold_ambient_temperature=config_provider( @@ -251,6 +251,13 @@ rule build_central_heating_temperature_profiles: "supply_temperature_approximation", "rolling_window_ambient_temperature", ), + relative_annual_temperature_reduction=config_provider( + "sector", + "district_heating", + "supply_temperature_approximation", + "relative_annual_temperature_reduction", + ), + energy_totals_year=config_provider("energy", "energy_totals_year"), input: temp_air_total=resources("temp_air_total_elec_s{simpl}_{clusters}.nc"), regions_onshore=resources("regions_onshore_elec_s{simpl}_{clusters}.geojson"), diff --git a/scripts/build_central_heating_temperature_profiles/run.py b/scripts/build_central_heating_temperature_profiles/run.py index feb4ab4f5..9f7373a76 100644 --- a/scripts/build_central_heating_temperature_profiles/run.py +++ b/scripts/build_central_heating_temperature_profiles/run.py @@ -130,6 +130,57 @@ def map_temperature_dict_to_onshore_regions( ) +def scale_temperature_to_investment_year( + temperature_today: dict, + relative_annual_temperature_reduction: float, + investment_year: int, + current_year: int, +) -> dict: + """ + Scale temperature for each country to investment year by constant exponential factor. + + Parameters + ---------- + temperature_today : dict + Dictionary with the current temperatures as values and country keys as keys. + relative_annual_temperature_reduction : float + The annual reduction rate of the temperature, must be between 0 and 1. + investment_year : int + The year in which the investment is planned. + current_year : int + The current year. + + Returns + ------- + dict + A dictionary with the temperature for each country in the investment year. + + Raises + ------ + ValueError + If the investment year is before the current year. + If the relative annual temperature reduction is not between 0 and 1. + """ + + if investment_year < current_year: + raise ValueError( + f"Error: Investment year {investment_year} is before current year {current_year}." + ) + if ( + relative_annual_temperature_reduction < 0 + or relative_annual_temperature_reduction > 1 + ): + raise ValueError( + f"Error: Relative annual temperature reduction must be between 0 and 1, but is {relative_annual_temperature_reduction}." + ) + + return { + key: temperature_today[key] * relative_annual_temperature_reduction + ^ (investment_year - current_year) + for key in temperature_today.keys() + } + + if __name__ == "__main__": if "snakemake" not in globals(): from _helpers import mock_snakemake @@ -138,17 +189,41 @@ def map_temperature_dict_to_onshore_regions( "build_cop_profiles", simpl="", clusters=48, + planning_horizons="2050", ) set_scenario_config(snakemake) - max_forward_temperature = snakemake.params.max_forward_temperature_central_heating - min_forward_temperature = extrapolate_missing_supply_temperatures_by_country( - extrapolate_from=max_forward_temperature, + # reduce temperatures to investment years by constant exponential factor + max_forward_temperature_investment_year = scale_temperature_to_investment_year( + temperature_today=snakemake.params.max_forward_temperature_today, + relative_annual_temperature_reduction=snakemake.params.relative_annual_temperature_reduction, + investment_year=int(snakemake.wildcards.planning_horizons[:-4]), + current_year=int(snakemake.params.energy_totals_year), + ) + + min_forward_temperature_investment_year = scale_temperature_to_investment_year( + temperature_today=snakemake.params.min_forward_temperature_today, + relative_annual_temperature_reduction=snakemake.params.relative_annual_temperature_reduction, + investment_year=int(snakemake.wildcards.planning_horizons[:-4]), + current_year=int(snakemake.params.energy_totals_year), + ) + + return_temperature_investment_year = scale_temperature_to_investment_year( + temperature_today=snakemake.params.return_temperature_today, + relative_annual_temperature_reduction=snakemake.params.relative_annual_temperature_reduction, + investment_year=int(snakemake.wildcards.planning_horizons[:-4]), + current_year=int(snakemake.params.energy_totals_year), + ) + + # min_forward_temperature and return_temperature contain only values for Germany by default + # extrapolate missing values based on ratio between max_forward_temperature and min_forward_temperature / return_temperature for Germany (or other countries provided in min_forward_temperature_today and return_temperature_today) + min_forward_temperature_investment_year = extrapolate_missing_supply_temperatures_by_country( + extrapolate_from=max_forward_temperature_investment_year, extrapolate_to=snakemake.params.min_forward_temperature_central_heating, ) - return_temperature = extrapolate_missing_supply_temperatures_by_country( - extrapolate_from=max_forward_temperature, + return_temperature_investment_year = extrapolate_missing_supply_temperatures_by_country( + extrapolate_from=max_forward_temperature_investment_year, extrapolate_to=snakemake.params.return_temperature_central_heating, ) @@ -157,19 +232,19 @@ def map_temperature_dict_to_onshore_regions( snapshots = pd.date_range(freq="h", **snakemake.params.snapshots) max_forward_temperature_central_heating_by_node_and_time: xr.DataArray = ( map_temperature_dict_to_onshore_regions( - supply_temperature_by_country=max_forward_temperature, + supply_temperature_by_country=max_forward_temperature_investment_year, regions_onshore=regions_onshore, ) ) min_forward_temperature_central_heating_by_node_and_time: xr.DataArray = ( map_temperature_dict_to_onshore_regions( - supply_temperature_by_country=min_forward_temperature, + supply_temperature_by_country=min_forward_temperature_investment_year, regions_onshore=regions_onshore, ) ) return_temperature_central_heating_by_node_and_time: xr.DataArray = ( map_temperature_dict_to_onshore_regions( - supply_temperature_by_country=return_temperature, + supply_temperature_by_country=return_temperature_investment_year, regions_onshore=regions_onshore, ) ) From c252d178a9257f369cef9c109bba6237828d2c5e Mon Sep 17 00:00:00 2001 From: Amos Schledorn Date: Thu, 12 Sep 2024 17:23:54 +0200 Subject: [PATCH 02/22] chore: fix name change issues --- rules/build_sector.smk | 8 ++++---- .../run.py | 20 ++++++++++--------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/rules/build_sector.smk b/rules/build_sector.smk index 9604a2363..0d0b02de9 100755 --- a/rules/build_sector.smk +++ b/rules/build_sector.smk @@ -263,17 +263,17 @@ rule build_central_heating_temperature_profiles: regions_onshore=resources("regions_onshore_elec_s{simpl}_{clusters}.geojson"), output: central_heating_forward_temperature_profiles=resources( - "central_heating_forward_temperature_profiles_elec_s{simpl}_{clusters}.nc" + "central_heating_forward_temperature_profiles_elec_s{simpl}_{clusters}_{planning_horizons}.nc" ), central_heating_return_temperature_profiles=resources( - "central_heating_return_temperature_profiles_elec_s{simpl}_{clusters}.nc" + "central_heating_return_temperature_profiles_elec_s{simpl}_{clusters}_{planning_horizons}.nc" ), resources: mem_mb=20000, log: - logs("build_central_heating_temperature_profiles_s{simpl}_{clusters}.log"), + logs("build_central_heating_temperature_profiles_s{simpl}_{clusters}_{planning_horizons}.log"), benchmark: - benchmarks("build_central_heating_temperature_profiles/s{simpl}_{clusters}") + benchmarks("build_central_heating_temperature_profiles/s{simpl}_{clusters}_{planning_horizons}") conda: "../envs/environment.yaml" script: diff --git a/scripts/build_central_heating_temperature_profiles/run.py b/scripts/build_central_heating_temperature_profiles/run.py index 9f7373a76..5182a2ee8 100644 --- a/scripts/build_central_heating_temperature_profiles/run.py +++ b/scripts/build_central_heating_temperature_profiles/run.py @@ -176,7 +176,7 @@ def scale_temperature_to_investment_year( return { key: temperature_today[key] * relative_annual_temperature_reduction - ^ (investment_year - current_year) + ** (investment_year - current_year) for key in temperature_today.keys() } @@ -194,37 +194,39 @@ def scale_temperature_to_investment_year( set_scenario_config(snakemake) + # investment_year = int(snakemake.wildcards.planning_horizons[-4:]) # reduce temperatures to investment years by constant exponential factor max_forward_temperature_investment_year = scale_temperature_to_investment_year( - temperature_today=snakemake.params.max_forward_temperature_today, + temperature_today=snakemake.params.max_forward_temperature_central_heating_today, relative_annual_temperature_reduction=snakemake.params.relative_annual_temperature_reduction, - investment_year=int(snakemake.wildcards.planning_horizons[:-4]), + investment_year=int(snakemake.wildcards.planning_horizons[-4:]), current_year=int(snakemake.params.energy_totals_year), ) min_forward_temperature_investment_year = scale_temperature_to_investment_year( - temperature_today=snakemake.params.min_forward_temperature_today, + temperature_today=snakemake.params.min_forward_temperature_central_heating_today, relative_annual_temperature_reduction=snakemake.params.relative_annual_temperature_reduction, - investment_year=int(snakemake.wildcards.planning_horizons[:-4]), + investment_year=int(snakemake.wildcards.planning_horizons[-4:]), current_year=int(snakemake.params.energy_totals_year), ) return_temperature_investment_year = scale_temperature_to_investment_year( - temperature_today=snakemake.params.return_temperature_today, + temperature_today=snakemake.params.return_temperature_central_heating_today, relative_annual_temperature_reduction=snakemake.params.relative_annual_temperature_reduction, - investment_year=int(snakemake.wildcards.planning_horizons[:-4]), + investment_year=int(snakemake.wildcards.planning_horizons[-4:]), current_year=int(snakemake.params.energy_totals_year), ) + # min_forward_temperature and return_temperature contain only values for Germany by default # extrapolate missing values based on ratio between max_forward_temperature and min_forward_temperature / return_temperature for Germany (or other countries provided in min_forward_temperature_today and return_temperature_today) min_forward_temperature_investment_year = extrapolate_missing_supply_temperatures_by_country( extrapolate_from=max_forward_temperature_investment_year, - extrapolate_to=snakemake.params.min_forward_temperature_central_heating, + extrapolate_to=min_forward_temperature_investment_year, ) return_temperature_investment_year = extrapolate_missing_supply_temperatures_by_country( extrapolate_from=max_forward_temperature_investment_year, - extrapolate_to=snakemake.params.return_temperature_central_heating, + extrapolate_to=return_temperature_investment_year, ) # map forward and return temperatures specified on country-level to onshore regions From a83909cfc78cfa52728cd3b9241e95259cbb2bd7 Mon Sep 17 00:00:00 2001 From: Amos Schledorn Date: Thu, 12 Sep 2024 17:26:03 +0200 Subject: [PATCH 03/22] feat: update input/output of dependent rules --- rules/build_sector.smk | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/rules/build_sector.smk b/rules/build_sector.smk index 0d0b02de9..5c29159b3 100755 --- a/rules/build_sector.smk +++ b/rules/build_sector.smk @@ -295,22 +295,22 @@ rule build_cop_profiles: snapshots=config_provider("snapshots"), input: central_heating_forward_temperature_profiles=resources( - "central_heating_forward_temperature_profiles_elec_s{simpl}_{clusters}.nc" + "central_heating_forward_temperature_profiles_elec_s{simpl}_{clusters}_{planning_horizons}.nc" ), central_heating_return_temperature_profiles=resources( - "central_heating_return_temperature_profiles_elec_s{simpl}_{clusters}.nc" + "central_heating_return_temperature_profiles_elec_s{simpl}_{clusters}_{planning_horizons}.nc" ), temp_soil_total=resources("temp_soil_total_elec_s{simpl}_{clusters}.nc"), temp_air_total=resources("temp_air_total_elec_s{simpl}_{clusters}.nc"), regions_onshore=resources("regions_onshore_elec_s{simpl}_{clusters}.geojson"), output: - cop_profiles=resources("cop_profiles_elec_s{simpl}_{clusters}.nc"), + cop_profiles=resources("cop_profiles_elec_s{simpl}_{clusters}_{planning_horizons}.nc"), resources: mem_mb=20000, log: - logs("build_cop_profiles_s{simpl}_{clusters}.log"), + logs("build_cop_profiles_s{simpl}_{clusters}_{planning_horizons}.log"), benchmark: - benchmarks("build_cop_profiles/s{simpl}_{clusters}") + benchmarks("build_cop_profiles/s{simpl}_{clusters}_{planning_horizons}") conda: "../envs/environment.yaml" script: @@ -1104,7 +1104,7 @@ rule prepare_sector_network: heating_efficiencies=resources("heating_efficiencies.csv"), temp_soil_total=resources("temp_soil_total_elec_s{simpl}_{clusters}.nc"), temp_air_total=resources("temp_air_total_elec_s{simpl}_{clusters}.nc"), - cop_profiles=resources("cop_profiles_elec_s{simpl}_{clusters}.nc"), + cop_profiles=resources("cop_profiles_elec_s{simpl}_{clusters}_{planning_horizons}.nc"), solar_thermal_total=lambda w: ( resources("solar_thermal_total_elec_s{simpl}_{clusters}.nc") if config_provider("sector", "solar_thermal")(w) From 31e6e3a7f9da201360c897bb073d8668fc8570d8 Mon Sep 17 00:00:00 2001 From: Amos Schledorn Date: Thu, 12 Sep 2024 17:28:36 +0200 Subject: [PATCH 04/22] feat: add {planning _horizons} wildcard to COP input in myopic rules --- rules/solve_myopic.smk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rules/solve_myopic.smk b/rules/solve_myopic.smk index 6340787ad..c36209e25 100644 --- a/rules/solve_myopic.smk +++ b/rules/solve_myopic.smk @@ -23,7 +23,7 @@ rule add_existing_baseyear: config_provider("scenario", "planning_horizons", 0)(w) ) ), - cop_profiles=resources("cop_profiles_elec_s{simpl}_{clusters}.nc"), + cop_profiles=resources("cop_profiles_elec_s{simpl}_{clusters}_{planning_horizons}.nc"), existing_heating_distribution=resources( "existing_heating_distribution_elec_s{simpl}_{clusters}_{planning_horizons}.csv" ), @@ -80,7 +80,7 @@ rule add_brownfield: + "prenetworks/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}.nc", network_p=solved_previous_horizon, #solved network at previous time step costs=resources("costs_{planning_horizons}.csv"), - cop_profiles=resources("cop_profiles_elec_s{simpl}_{clusters}.nc"), + cop_profiles=resources("cop_profiles_elec_s{simpl}_{clusters}_{planning_horizons}.nc"), output: RESULTS + "prenetworks-brownfield/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}.nc", From 85656c09e854253f6bfc1077c879ea36b53db250 Mon Sep 17 00:00:00 2001 From: Amos Schledorn Date: Thu, 12 Sep 2024 17:35:30 +0200 Subject: [PATCH 05/22] fix: exponential temperature reduction --- .../run.py | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/scripts/build_central_heating_temperature_profiles/run.py b/scripts/build_central_heating_temperature_profiles/run.py index 5182a2ee8..f90b74226 100644 --- a/scripts/build_central_heating_temperature_profiles/run.py +++ b/scripts/build_central_heating_temperature_profiles/run.py @@ -175,8 +175,11 @@ def scale_temperature_to_investment_year( ) return { - key: temperature_today[key] * relative_annual_temperature_reduction - ** (investment_year - current_year) + key: temperature_today[key] + * ( + (1 - relative_annual_temperature_reduction) + ** (investment_year - current_year) + ) for key in temperature_today.keys() } @@ -217,16 +220,19 @@ def scale_temperature_to_investment_year( current_year=int(snakemake.params.energy_totals_year), ) - # min_forward_temperature and return_temperature contain only values for Germany by default # extrapolate missing values based on ratio between max_forward_temperature and min_forward_temperature / return_temperature for Germany (or other countries provided in min_forward_temperature_today and return_temperature_today) - min_forward_temperature_investment_year = extrapolate_missing_supply_temperatures_by_country( - extrapolate_from=max_forward_temperature_investment_year, - extrapolate_to=min_forward_temperature_investment_year, + min_forward_temperature_investment_year = ( + extrapolate_missing_supply_temperatures_by_country( + extrapolate_from=max_forward_temperature_investment_year, + extrapolate_to=min_forward_temperature_investment_year, + ) ) - return_temperature_investment_year = extrapolate_missing_supply_temperatures_by_country( - extrapolate_from=max_forward_temperature_investment_year, - extrapolate_to=return_temperature_investment_year, + return_temperature_investment_year = ( + extrapolate_missing_supply_temperatures_by_country( + extrapolate_from=max_forward_temperature_investment_year, + extrapolate_to=return_temperature_investment_year, + ) ) # map forward and return temperatures specified on country-level to onshore regions From 881cf011f647eb6c9c4f8ce6dc556736a2a373f2 Mon Sep 17 00:00:00 2001 From: Amos Schledorn Date: Thu, 12 Sep 2024 17:35:54 +0200 Subject: [PATCH 06/22] feat: add {planning_horizons} wildcard to solve_perfect --- rules/solve_perfect.smk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rules/solve_perfect.smk b/rules/solve_perfect.smk index f1ec9966e..2bfca7b22 100644 --- a/rules/solve_perfect.smk +++ b/rules/solve_perfect.smk @@ -21,7 +21,7 @@ rule add_existing_baseyear: config_provider("scenario", "planning_horizons", 0)(w) ) ), - cop_profiles=resources("cop_profiles_elec_s{simpl}_{clusters}.nc"), + cop_profiles=resources("cop_profiles_elec_s{simpl}_{clusters}_{planning_horizons}.nc"), existing_heating_distribution=resources( "existing_heating_distribution_elec_s{simpl}_{clusters}_{planning_horizons}.csv" ), From cdfcf231b0ddf43cf47c043a30272442ff2a0239 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 12 Sep 2024 15:44:29 +0000 Subject: [PATCH 07/22] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- rules/build_sector.smk | 16 ++++++++++++---- rules/solve_myopic.smk | 8 ++++++-- rules/solve_perfect.smk | 4 +++- .../run.py | 3 ++- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/rules/build_sector.smk b/rules/build_sector.smk index 5c29159b3..6974eab92 100755 --- a/rules/build_sector.smk +++ b/rules/build_sector.smk @@ -271,9 +271,13 @@ rule build_central_heating_temperature_profiles: resources: mem_mb=20000, log: - logs("build_central_heating_temperature_profiles_s{simpl}_{clusters}_{planning_horizons}.log"), + logs( + "build_central_heating_temperature_profiles_s{simpl}_{clusters}_{planning_horizons}.log" + ), benchmark: - benchmarks("build_central_heating_temperature_profiles/s{simpl}_{clusters}_{planning_horizons}") + benchmarks( + "build_central_heating_temperature_profiles/s{simpl}_{clusters}_{planning_horizons}" + ) conda: "../envs/environment.yaml" script: @@ -304,7 +308,9 @@ rule build_cop_profiles: temp_air_total=resources("temp_air_total_elec_s{simpl}_{clusters}.nc"), regions_onshore=resources("regions_onshore_elec_s{simpl}_{clusters}.geojson"), output: - cop_profiles=resources("cop_profiles_elec_s{simpl}_{clusters}_{planning_horizons}.nc"), + cop_profiles=resources( + "cop_profiles_elec_s{simpl}_{clusters}_{planning_horizons}.nc" + ), resources: mem_mb=20000, log: @@ -1104,7 +1110,9 @@ rule prepare_sector_network: heating_efficiencies=resources("heating_efficiencies.csv"), temp_soil_total=resources("temp_soil_total_elec_s{simpl}_{clusters}.nc"), temp_air_total=resources("temp_air_total_elec_s{simpl}_{clusters}.nc"), - cop_profiles=resources("cop_profiles_elec_s{simpl}_{clusters}_{planning_horizons}.nc"), + cop_profiles=resources( + "cop_profiles_elec_s{simpl}_{clusters}_{planning_horizons}.nc" + ), solar_thermal_total=lambda w: ( resources("solar_thermal_total_elec_s{simpl}_{clusters}.nc") if config_provider("sector", "solar_thermal")(w) diff --git a/rules/solve_myopic.smk b/rules/solve_myopic.smk index c36209e25..e90feea41 100644 --- a/rules/solve_myopic.smk +++ b/rules/solve_myopic.smk @@ -23,7 +23,9 @@ rule add_existing_baseyear: config_provider("scenario", "planning_horizons", 0)(w) ) ), - cop_profiles=resources("cop_profiles_elec_s{simpl}_{clusters}_{planning_horizons}.nc"), + cop_profiles=resources( + "cop_profiles_elec_s{simpl}_{clusters}_{planning_horizons}.nc" + ), existing_heating_distribution=resources( "existing_heating_distribution_elec_s{simpl}_{clusters}_{planning_horizons}.csv" ), @@ -80,7 +82,9 @@ rule add_brownfield: + "prenetworks/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}.nc", network_p=solved_previous_horizon, #solved network at previous time step costs=resources("costs_{planning_horizons}.csv"), - cop_profiles=resources("cop_profiles_elec_s{simpl}_{clusters}_{planning_horizons}.nc"), + cop_profiles=resources( + "cop_profiles_elec_s{simpl}_{clusters}_{planning_horizons}.nc" + ), output: RESULTS + "prenetworks-brownfield/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}.nc", diff --git a/rules/solve_perfect.smk b/rules/solve_perfect.smk index 2bfca7b22..209eefa98 100644 --- a/rules/solve_perfect.smk +++ b/rules/solve_perfect.smk @@ -21,7 +21,9 @@ rule add_existing_baseyear: config_provider("scenario", "planning_horizons", 0)(w) ) ), - cop_profiles=resources("cop_profiles_elec_s{simpl}_{clusters}_{planning_horizons}.nc"), + cop_profiles=resources( + "cop_profiles_elec_s{simpl}_{clusters}_{planning_horizons}.nc" + ), existing_heating_distribution=resources( "existing_heating_distribution_elec_s{simpl}_{clusters}_{planning_horizons}.csv" ), diff --git a/scripts/build_central_heating_temperature_profiles/run.py b/scripts/build_central_heating_temperature_profiles/run.py index f90b74226..d64ef1247 100644 --- a/scripts/build_central_heating_temperature_profiles/run.py +++ b/scripts/build_central_heating_temperature_profiles/run.py @@ -137,7 +137,8 @@ def scale_temperature_to_investment_year( current_year: int, ) -> dict: """ - Scale temperature for each country to investment year by constant exponential factor. + Scale temperature for each country to investment year by constant + exponential factor. Parameters ---------- From 69cad8e23f8afaf290af648a943d8846276827ac Mon Sep 17 00:00:00 2001 From: Amos Schledorn Date: Thu, 12 Sep 2024 17:50:00 +0200 Subject: [PATCH 08/22] style: "_today" -> "_baseyear" --- rules/build_sector.smk | 12 ++++++------ .../run.py | 16 ++++++++-------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/rules/build_sector.smk b/rules/build_sector.smk index 5c29159b3..f61546aae 100755 --- a/rules/build_sector.smk +++ b/rules/build_sector.smk @@ -214,23 +214,23 @@ rule build_temperature_profiles: rule build_central_heating_temperature_profiles: params: - max_forward_temperature_central_heating_today=config_provider( + max_forward_temperature_central_heating_baseyear=config_provider( "sector", "district_heating", "supply_temperature_approximation", - "max_forward_temperature_today", + "max_forward_temperature_baseyear", ), - min_forward_temperature_central_heating_today=config_provider( + min_forward_temperature_central_heating_baseyear=config_provider( "sector", "district_heating", "supply_temperature_approximation", - "min_forward_temperature_today", + "min_forward_temperature_baseyear", ), - return_temperature_central_heating_today=config_provider( + return_temperature_central_heating_baseyear=config_provider( "sector", "district_heating", "supply_temperature_approximation", - "return_temperature_today", + "return_temperature_baseyear", ), snapshots=config_provider("snapshots"), lower_threshold_ambient_temperature=config_provider( diff --git a/scripts/build_central_heating_temperature_profiles/run.py b/scripts/build_central_heating_temperature_profiles/run.py index f90b74226..84af4ca5e 100644 --- a/scripts/build_central_heating_temperature_profiles/run.py +++ b/scripts/build_central_heating_temperature_profiles/run.py @@ -131,7 +131,7 @@ def map_temperature_dict_to_onshore_regions( def scale_temperature_to_investment_year( - temperature_today: dict, + temperature_baseyear: dict, relative_annual_temperature_reduction: float, investment_year: int, current_year: int, @@ -141,7 +141,7 @@ def scale_temperature_to_investment_year( Parameters ---------- - temperature_today : dict + temperature_baseyear : dict Dictionary with the current temperatures as values and country keys as keys. relative_annual_temperature_reduction : float The annual reduction rate of the temperature, must be between 0 and 1. @@ -175,12 +175,12 @@ def scale_temperature_to_investment_year( ) return { - key: temperature_today[key] + key: temperature_baseyear[key] * ( (1 - relative_annual_temperature_reduction) ** (investment_year - current_year) ) - for key in temperature_today.keys() + for key in temperature_baseyear.keys() } @@ -200,28 +200,28 @@ def scale_temperature_to_investment_year( # investment_year = int(snakemake.wildcards.planning_horizons[-4:]) # reduce temperatures to investment years by constant exponential factor max_forward_temperature_investment_year = scale_temperature_to_investment_year( - temperature_today=snakemake.params.max_forward_temperature_central_heating_today, + temperature_baseyear=snakemake.params.max_forward_temperature_central_heating_baseyear, relative_annual_temperature_reduction=snakemake.params.relative_annual_temperature_reduction, investment_year=int(snakemake.wildcards.planning_horizons[-4:]), current_year=int(snakemake.params.energy_totals_year), ) min_forward_temperature_investment_year = scale_temperature_to_investment_year( - temperature_today=snakemake.params.min_forward_temperature_central_heating_today, + temperature_baseyear=snakemake.params.min_forward_temperature_central_heating_baseyear, relative_annual_temperature_reduction=snakemake.params.relative_annual_temperature_reduction, investment_year=int(snakemake.wildcards.planning_horizons[-4:]), current_year=int(snakemake.params.energy_totals_year), ) return_temperature_investment_year = scale_temperature_to_investment_year( - temperature_today=snakemake.params.return_temperature_central_heating_today, + temperature_baseyear=snakemake.params.return_temperature_central_heating_baseyear, relative_annual_temperature_reduction=snakemake.params.relative_annual_temperature_reduction, investment_year=int(snakemake.wildcards.planning_horizons[-4:]), current_year=int(snakemake.params.energy_totals_year), ) # min_forward_temperature and return_temperature contain only values for Germany by default - # extrapolate missing values based on ratio between max_forward_temperature and min_forward_temperature / return_temperature for Germany (or other countries provided in min_forward_temperature_today and return_temperature_today) + # extrapolate missing values based on ratio between max_forward_temperature and min_forward_temperature / return_temperature for Germany (or other countries provided in min_forward_temperature_baseyear and return_temperature_baseyear) min_forward_temperature_investment_year = ( extrapolate_missing_supply_temperatures_by_country( extrapolate_from=max_forward_temperature_investment_year, From 39ae475223599610ddb942c9f2d2992b48923f84 Mon Sep 17 00:00:00 2001 From: Amos Schledorn Date: Thu, 12 Sep 2024 17:52:14 +0200 Subject: [PATCH 09/22] doc: update configtables --- doc/configtables/sector.csv | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/doc/configtables/sector.csv b/doc/configtables/sector.csv index 000927ced..73882b9d5 100644 --- a/doc/configtables/sector.csv +++ b/doc/configtables/sector.csv @@ -10,12 +10,13 @@ district_heating,--,,`prepare_sector_network.py Date: Thu, 12 Sep 2024 17:52:35 +0200 Subject: [PATCH 10/22] style: "_today" -> "_baseyear" (config) --- config/config.default.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/config.default.yaml b/config/config.default.yaml index be871afae..98af48ccd 100644 --- a/config/config.default.yaml +++ b/config/config.default.yaml @@ -450,7 +450,7 @@ sector: 2050: 1.0 district_heating_loss: 0.15 supply_temperature_approximation: - max_forward_temperature_today: + max_forward_temperature_baseyear: FR: 110 DK: 75 DE: 109 @@ -459,9 +459,9 @@ sector: PL: 130 SE: 102 IT: 90 - min_forward_temperature_today: + min_forward_temperature_baseyear: DE: 82 - return_temperature_today: + return_temperature_baseyear: DE: 58 lower_threshold_ambient_temperature: 0 upper_threshold_ambient_temperature: 10 From a109899195dc82a25c39023c799f727f4b362468 Mon Sep 17 00:00:00 2001 From: Amos Schledorn Date: Fri, 13 Sep 2024 16:53:33 +0200 Subject: [PATCH 11/22] feat: update heat pump efficiency in add_brownfield --- rules/solve_myopic.smk | 3 --- scripts/add_brownfield.py | 9 +++++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/rules/solve_myopic.smk b/rules/solve_myopic.smk index e90feea41..d53a84a42 100644 --- a/rules/solve_myopic.smk +++ b/rules/solve_myopic.smk @@ -82,9 +82,6 @@ rule add_brownfield: + "prenetworks/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}.nc", network_p=solved_previous_horizon, #solved network at previous time step costs=resources("costs_{planning_horizons}.csv"), - cop_profiles=resources( - "cop_profiles_elec_s{simpl}_{clusters}_{planning_horizons}.nc" - ), output: RESULTS + "prenetworks-brownfield/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}.nc", diff --git a/scripts/add_brownfield.py b/scripts/add_brownfield.py index 72dd1c88e..55b78130c 100644 --- a/scripts/add_brownfield.py +++ b/scripts/add_brownfield.py @@ -216,6 +216,13 @@ def adjust_renewable_profiles(n, input_profiles, params, year): n.generators_t.p_max_pu.loc[:, p_max_pu.columns] = p_max_pu +def update_heat_pump_efficiency(n: pypsa.Network, n_p: pypsa.Network, year: int): + + for link_name_p in n_p.links.index: + if "heat pump" in link_name_p: + link_name = link_name_p.replace(link_name_p[-4:], str(year)) + n_p.links_t["efficiency"][link_name_p] = n.links_t["efficiency"][link_name] + if __name__ == "__main__": if "snakemake" not in globals(): from _helpers import mock_snakemake @@ -247,6 +254,8 @@ def adjust_renewable_profiles(n, input_profiles, params, year): n_p = pypsa.Network(snakemake.input.network_p) + update_heat_pump_efficiency(n, n_p, year) + add_brownfield(n, n_p, year) disable_grid_expansion_if_limit_hit(n) From a5be8b48af0588e5789c7165b149733c5b3822ec Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 17 Sep 2024 08:25:00 +0000 Subject: [PATCH 12/22] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- rules/build_sector.smk | 8 ++------ rules/solve_myopic.smk | 4 +--- rules/solve_perfect.smk | 4 +--- scripts/add_brownfield.py | 9 +++++---- 4 files changed, 9 insertions(+), 16 deletions(-) diff --git a/rules/build_sector.smk b/rules/build_sector.smk index 96c0b9e69..43dd72746 100755 --- a/rules/build_sector.smk +++ b/rules/build_sector.smk @@ -308,9 +308,7 @@ rule build_cop_profiles: temp_air_total=resources("temp_air_total_base_s_{clusters}.nc"), regions_onshore=resources("regions_onshore_base_s_{clusters}.geojson"), output: - cop_profiles=resources( - "cop_profiles_base_s_{clusters}_{planning_horizons}.nc" - ), + cop_profiles=resources("cop_profiles_base_s_{clusters}_{planning_horizons}.nc"), resources: mem_mb=20000, log: @@ -1104,9 +1102,7 @@ rule prepare_sector_network: heating_efficiencies=resources("heating_efficiencies.csv"), temp_soil_total=resources("temp_soil_total_base_s_{clusters}.nc"), temp_air_total=resources("temp_air_total_base_s_{clusters}.nc"), - cop_profiles=resources( - "cop_profiles_base_s_{clusters}_{planning_horizons}.nc" - ), + cop_profiles=resources("cop_profiles_base_s_{clusters}_{planning_horizons}.nc"), solar_thermal_total=lambda w: ( resources("solar_thermal_total_base_s_{clusters}.nc") if config_provider("sector", "solar_thermal")(w) diff --git a/rules/solve_myopic.smk b/rules/solve_myopic.smk index 7ba3ec445..7f9bc58c7 100644 --- a/rules/solve_myopic.smk +++ b/rules/solve_myopic.smk @@ -23,9 +23,7 @@ rule add_existing_baseyear: config_provider("scenario", "planning_horizons", 0)(w) ) ), - cop_profiles=resources( - "cop_profiles_base_s_{clusters}_{planning_horizons}.nc" - ), + cop_profiles=resources("cop_profiles_base_s_{clusters}_{planning_horizons}.nc"), existing_heating_distribution=resources( "existing_heating_distribution_base_s_{clusters}_{planning_horizons}.csv" ), diff --git a/rules/solve_perfect.smk b/rules/solve_perfect.smk index 5171c4686..00deb475f 100644 --- a/rules/solve_perfect.smk +++ b/rules/solve_perfect.smk @@ -21,9 +21,7 @@ rule add_existing_baseyear: config_provider("scenario", "planning_horizons", 0)(w) ) ), - cop_profiles=resources( - "cop_profiles_base_s_{clusters}_{planning_horizons}.nc" - ), + cop_profiles=resources("cop_profiles_base_s_{clusters}_{planning_horizons}.nc"), existing_heating_distribution=resources( "existing_heating_distribution_base_s_{clusters}_{planning_horizons}.csv" ), diff --git a/scripts/add_brownfield.py b/scripts/add_brownfield.py index 7eda590a1..9592f0c8b 100644 --- a/scripts/add_brownfield.py +++ b/scripts/add_brownfield.py @@ -204,12 +204,13 @@ def adjust_renewable_profiles(n, input_profiles, params, year): def update_heat_pump_efficiency(n: pypsa.Network, n_p: pypsa.Network, year: int): - - for link_name_p in n_p.links.index: - if "heat pump" in link_name_p: + + for link_name_p in n_p.links.index: + if "heat pump" in link_name_p: link_name = link_name_p.replace(link_name_p[-4:], str(year)) n_p.links_t["efficiency"][link_name_p] = n.links_t["efficiency"][link_name] - + + if __name__ == "__main__": if "snakemake" not in globals(): from _helpers import mock_snakemake From 7bf57ad2bceda3129436e59f75d8205893cfb0e0 Mon Sep 17 00:00:00 2001 From: Amos Schledorn Date: Tue, 17 Sep 2024 14:43:21 +0200 Subject: [PATCH 13/22] fix: pass planning_horizons to add_brownfield --- rules/solve_myopic.smk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rules/solve_myopic.smk b/rules/solve_myopic.smk index 7f9bc58c7..1da678e61 100644 --- a/rules/solve_myopic.smk +++ b/rules/solve_myopic.smk @@ -80,7 +80,7 @@ rule add_brownfield: + "prenetworks/base_s_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}.nc", network_p=solved_previous_horizon, #solved network at previous time step costs=resources("costs_{planning_horizons}.csv"), - cop_profiles=resources("cop_profiles_base_s_{clusters}.nc"), + cop_profiles=resources("cop_profiles_base_s_{clusters}_{planning_horizons}.nc"), output: RESULTS + "prenetworks-brownfield/base_s_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}.nc", From 8871a2d932f0d5bc100c393586a2c0c6c6d36eb1 Mon Sep 17 00:00:00 2001 From: Amos Schledorn Date: Tue, 17 Sep 2024 15:38:51 +0200 Subject: [PATCH 14/22] feat: update COPs for perfect foresight --- scripts/add_brownfield.py | 17 ++++++++++++++++ scripts/prepare_perfect_foresight.py | 30 ++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/scripts/add_brownfield.py b/scripts/add_brownfield.py index 9592f0c8b..e0f3e0248 100644 --- a/scripts/add_brownfield.py +++ b/scripts/add_brownfield.py @@ -204,6 +204,23 @@ def adjust_renewable_profiles(n, input_profiles, params, year): def update_heat_pump_efficiency(n: pypsa.Network, n_p: pypsa.Network, year: int): + """ + Update the efficiency of heat pumps from previous years to current year (e.g. 2030 heat pumps receive 2040 heat pump COPs in 2030). + + Parameters + ---------- + n : pypsa.Network + The original network. + n_p : pypsa.Network + The network with the updated parameters. + year : int + The year for which the efficiency is being updated. + + Returns + ------- + None + This function updates the efficiency in place and does not return a value. + """ for link_name_p in n_p.links.index: if "heat pump" in link_name_p: diff --git a/scripts/prepare_perfect_foresight.py b/scripts/prepare_perfect_foresight.py index f35019138..6d4071c83 100644 --- a/scripts/prepare_perfect_foresight.py +++ b/scripts/prepare_perfect_foresight.py @@ -7,6 +7,7 @@ """ import logging +from typing import List import numpy as np import pandas as pd @@ -486,6 +487,32 @@ def apply_time_segmentation_perfect( return n +def update_heat_pump_efficiency(n: pypsa.Network, years: List[int]): + """ + Update the efficiency of heat pumps from previous years to current year (e.g. 2030 heat pumps receive 2040 heat pump COPs in 2030). + + Note: this also updates the efficiency of heat pumps in preceding years for previous years, which should have no effect (e.g. 2040 heat pumps receive 2030 COPs in 2030). + + Parameters + ---------- + n : pypsa.Network + The concatenated network. + years : List[int] + List of planning horizon years. + + Returns + ------- + None + This function updates the efficiency in place and does not return a value. + """ + + for link_name in n.links.index: + if "heat pump" in link_name: + heat_pump_name = link_name[:-4] + for year in years: + correct_efficiency = n.links_t["efficiency"].loc[(year, slice(None)), heat_pump_name+str(year)] + n.links_t["efficiency"].loc[(year, slice(None)), link_name] = correct_efficiency + if __name__ == "__main__": if "snakemake" not in globals(): @@ -538,5 +565,8 @@ def apply_time_segmentation_perfect( # update meta n.meta = dict(snakemake.config, **dict(wildcards=dict(snakemake.wildcards))) + # update heat pump efficiency + update_heat_pump_efficiency(n=n, years=years) + # export network n.export_to_netcdf(snakemake.output[0]) From 4107e316283a66b1a66b5ea2da245975671df5c6 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 17 Sep 2024 13:39:40 +0000 Subject: [PATCH 15/22] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- scripts/add_brownfield.py | 3 ++- scripts/prepare_perfect_foresight.py | 12 +++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/scripts/add_brownfield.py b/scripts/add_brownfield.py index e0f3e0248..12db7c403 100644 --- a/scripts/add_brownfield.py +++ b/scripts/add_brownfield.py @@ -205,7 +205,8 @@ def adjust_renewable_profiles(n, input_profiles, params, year): def update_heat_pump_efficiency(n: pypsa.Network, n_p: pypsa.Network, year: int): """ - Update the efficiency of heat pumps from previous years to current year (e.g. 2030 heat pumps receive 2040 heat pump COPs in 2030). + Update the efficiency of heat pumps from previous years to current year + (e.g. 2030 heat pumps receive 2040 heat pump COPs in 2030). Parameters ---------- diff --git a/scripts/prepare_perfect_foresight.py b/scripts/prepare_perfect_foresight.py index 6d4071c83..77f1062f5 100644 --- a/scripts/prepare_perfect_foresight.py +++ b/scripts/prepare_perfect_foresight.py @@ -487,9 +487,11 @@ def apply_time_segmentation_perfect( return n + def update_heat_pump_efficiency(n: pypsa.Network, years: List[int]): """ - Update the efficiency of heat pumps from previous years to current year (e.g. 2030 heat pumps receive 2040 heat pump COPs in 2030). + Update the efficiency of heat pumps from previous years to current year + (e.g. 2030 heat pumps receive 2040 heat pump COPs in 2030). Note: this also updates the efficiency of heat pumps in preceding years for previous years, which should have no effect (e.g. 2040 heat pumps receive 2030 COPs in 2030). @@ -510,8 +512,12 @@ def update_heat_pump_efficiency(n: pypsa.Network, years: List[int]): if "heat pump" in link_name: heat_pump_name = link_name[:-4] for year in years: - correct_efficiency = n.links_t["efficiency"].loc[(year, slice(None)), heat_pump_name+str(year)] - n.links_t["efficiency"].loc[(year, slice(None)), link_name] = correct_efficiency + correct_efficiency = n.links_t["efficiency"].loc[ + (year, slice(None)), heat_pump_name + str(year) + ] + n.links_t["efficiency"].loc[ + (year, slice(None)), link_name + ] = correct_efficiency if __name__ == "__main__": From 30f7dce7850ee6dbd45a6907e9a0088530b1bd28 Mon Sep 17 00:00:00 2001 From: Amos Schledorn Date: Tue, 17 Sep 2024 17:31:22 +0200 Subject: [PATCH 16/22] update release notes --- doc/release_notes.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/release_notes.rst b/doc/release_notes.rst index dca98d379..2e77498a1 100644 --- a/doc/release_notes.rst +++ b/doc/release_notes.rst @@ -11,6 +11,7 @@ Release Notes Upcoming Release ================ +* Added option to reduce central heating forward temperatures by annual percentage (see rule `build_central_heating_temperature_profiles`). This makes COP profiles and heat pump efficiencies planning-horizon-dependent. Myopic and perfect foresight modes were adjusted accordingly to update COPs of existing heat pumps in preceding years. * Rearranged workflow to cluster the electricity network before calculating renewable profiles and adding further electricity system components. From 635d3d6712cdef45c81cc7fbd12f27945adac341 Mon Sep 17 00:00:00 2001 From: Amos Schledorn <60692940+amos-schledorn@users.noreply.github.com> Date: Mon, 30 Sep 2024 10:42:23 +0200 Subject: [PATCH 17/22] Update doc/release_notes.rst Co-authored-by: Fabian Neumann --- doc/release_notes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/release_notes.rst b/doc/release_notes.rst index 2e77498a1..e5a2c37a7 100644 --- a/doc/release_notes.rst +++ b/doc/release_notes.rst @@ -11,7 +11,7 @@ Release Notes Upcoming Release ================ -* Added option to reduce central heating forward temperatures by annual percentage (see rule `build_central_heating_temperature_profiles`). This makes COP profiles and heat pump efficiencies planning-horizon-dependent. Myopic and perfect foresight modes were adjusted accordingly to update COPs of existing heat pumps in preceding years. +* Added option to reduce central heating forward temperatures by annual percentage (see rule :mod:`build_central_heating_temperature_profiles`). This makes COP profiles and heat pump efficiencies planning-horizon-dependent. Myopic and perfect foresight modes were adjusted accordingly to update COPs of existing heat pumps in preceding years to adjusted temperatures. * Rearranged workflow to cluster the electricity network before calculating renewable profiles and adding further electricity system components. From f1f0d20b5ff2e4d269c41bb301e87765f84d119c Mon Sep 17 00:00:00 2001 From: Amos Schledorn <60692940+amos-schledorn@users.noreply.github.com> Date: Mon, 30 Sep 2024 10:42:47 +0200 Subject: [PATCH 18/22] Update scripts/build_central_heating_temperature_profiles/run.py Co-authored-by: Fabian Neumann --- scripts/build_central_heating_temperature_profiles/run.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/build_central_heating_temperature_profiles/run.py b/scripts/build_central_heating_temperature_profiles/run.py index cdabbea9d..ab9d72ca0 100644 --- a/scripts/build_central_heating_temperature_profiles/run.py +++ b/scripts/build_central_heating_temperature_profiles/run.py @@ -202,7 +202,7 @@ def scale_temperature_to_investment_year( max_forward_temperature_investment_year = scale_temperature_to_investment_year( temperature_baseyear=snakemake.params.max_forward_temperature_central_heating_baseyear, relative_annual_temperature_reduction=snakemake.params.relative_annual_temperature_reduction, - investment_year=int(snakemake.wildcards.planning_horizons[-4:]), + investment_year=int(snakemake.wildcards.planning_horizons), current_year=int(snakemake.params.energy_totals_year), ) From ecbb228a08f19f408b941cd6d206bf0866117c1c Mon Sep 17 00:00:00 2001 From: Amos Schledorn <60692940+amos-schledorn@users.noreply.github.com> Date: Mon, 30 Sep 2024 10:43:06 +0200 Subject: [PATCH 19/22] Update scripts/build_central_heating_temperature_profiles/run.py Co-authored-by: Fabian Neumann --- scripts/build_central_heating_temperature_profiles/run.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/build_central_heating_temperature_profiles/run.py b/scripts/build_central_heating_temperature_profiles/run.py index ab9d72ca0..49576b4b2 100644 --- a/scripts/build_central_heating_temperature_profiles/run.py +++ b/scripts/build_central_heating_temperature_profiles/run.py @@ -216,7 +216,7 @@ def scale_temperature_to_investment_year( return_temperature_investment_year = scale_temperature_to_investment_year( temperature_baseyear=snakemake.params.return_temperature_central_heating_baseyear, relative_annual_temperature_reduction=snakemake.params.relative_annual_temperature_reduction, - investment_year=int(snakemake.wildcards.planning_horizons[-4:]), + investment_year=int(snakemake.wildcards.planning_horizons), current_year=int(snakemake.params.energy_totals_year), ) From 85a878b68bdc198f911f578b80a7950bc07a8418 Mon Sep 17 00:00:00 2001 From: Amos Schledorn Date: Mon, 30 Sep 2024 10:55:32 +0200 Subject: [PATCH 20/22] Update build_central_heating_temperature_profiles.run --- scripts/build_central_heating_temperature_profiles/run.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/build_central_heating_temperature_profiles/run.py b/scripts/build_central_heating_temperature_profiles/run.py index 49576b4b2..c04c96b55 100644 --- a/scripts/build_central_heating_temperature_profiles/run.py +++ b/scripts/build_central_heating_temperature_profiles/run.py @@ -197,7 +197,6 @@ def scale_temperature_to_investment_year( set_scenario_config(snakemake) - # investment_year = int(snakemake.wildcards.planning_horizons[-4:]) # reduce temperatures to investment years by constant exponential factor max_forward_temperature_investment_year = scale_temperature_to_investment_year( temperature_baseyear=snakemake.params.max_forward_temperature_central_heating_baseyear, @@ -209,7 +208,7 @@ def scale_temperature_to_investment_year( min_forward_temperature_investment_year = scale_temperature_to_investment_year( temperature_baseyear=snakemake.params.min_forward_temperature_central_heating_baseyear, relative_annual_temperature_reduction=snakemake.params.relative_annual_temperature_reduction, - investment_year=int(snakemake.wildcards.planning_horizons[-4:]), + investment_year=int(snakemake.wildcards.planning_horizons), current_year=int(snakemake.params.energy_totals_year), ) From b27227f3ed610bbecf734e18b308345e313825e3 Mon Sep 17 00:00:00 2001 From: Amos Schledorn Date: Mon, 30 Sep 2024 17:44:47 +0200 Subject: [PATCH 21/22] style: simplify update_heat_pump_efficiency functions --- scripts/add_brownfield.py | 11 +++++++---- scripts/prepare_perfect_foresight.py | 24 ++++++++++++++---------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/scripts/add_brownfield.py b/scripts/add_brownfield.py index bc4a48e77..0f3cb318c 100644 --- a/scripts/add_brownfield.py +++ b/scripts/add_brownfield.py @@ -241,10 +241,13 @@ def update_heat_pump_efficiency(n: pypsa.Network, n_p: pypsa.Network, year: int) This function updates the efficiency in place and does not return a value. """ - for link_name_p in n_p.links.index: - if "heat pump" in link_name_p: - link_name = link_name_p.replace(link_name_p[-4:], str(year)) - n_p.links_t["efficiency"][link_name_p] = n.links_t["efficiency"][link_name] + # get names of heat pumps in previous iteration + heat_pump_idx_previous_iteration = n_p.links.index[n_p.links.index.str.contains("heat pump")] + # construct names of same-technology heat pumps in the current iteration + corresponding_idx_this_iteration = heat_pump_idx_previous_iteration.str[:-4] + str(year) + # update efficiency of heat pumps in previous iteration in-place to efficiency in this iteration + n_p.links_t["efficiency"].loc[:, heat_pump_idx_previous_iteration] = n.links_t["efficiency"].loc[:, corresponding_idx_this_iteration].values + if __name__ == "__main__": diff --git a/scripts/prepare_perfect_foresight.py b/scripts/prepare_perfect_foresight.py index 77f1062f5..50992d4c6 100644 --- a/scripts/prepare_perfect_foresight.py +++ b/scripts/prepare_perfect_foresight.py @@ -508,16 +508,20 @@ def update_heat_pump_efficiency(n: pypsa.Network, years: List[int]): This function updates the efficiency in place and does not return a value. """ - for link_name in n.links.index: - if "heat pump" in link_name: - heat_pump_name = link_name[:-4] - for year in years: - correct_efficiency = n.links_t["efficiency"].loc[ - (year, slice(None)), heat_pump_name + str(year) - ] - n.links_t["efficiency"].loc[ - (year, slice(None)), link_name - ] = correct_efficiency + # get names of all heat pumps + heat_pump_idx = n.links.index[n.links.index.str.contains("heat pump")] + for year in years: + # for each heat pump type, correct efficiency is the efficiency of that technology built in + correct_efficiency = n.links_t["efficiency"].loc[ + (year, slice(None)), heat_pump_idx.str[:-4] + str(year) + ] + # in , set the efficiency of all heat pumps to the correct efficiency + n.links_t["efficiency"].loc[ + (year, slice(None)), heat_pump_idx + ] = correct_efficiency.values + + + if __name__ == "__main__": From a9853b097aba6a25189f8a7824dd8fbaf4d04380 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 30 Sep 2024 15:46:45 +0000 Subject: [PATCH 22/22] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- scripts/add_brownfield.py | 13 +++++++++---- scripts/prepare_perfect_foresight.py | 3 --- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/scripts/add_brownfield.py b/scripts/add_brownfield.py index 0f3cb318c..c1be48968 100644 --- a/scripts/add_brownfield.py +++ b/scripts/add_brownfield.py @@ -242,12 +242,17 @@ def update_heat_pump_efficiency(n: pypsa.Network, n_p: pypsa.Network, year: int) """ # get names of heat pumps in previous iteration - heat_pump_idx_previous_iteration = n_p.links.index[n_p.links.index.str.contains("heat pump")] + heat_pump_idx_previous_iteration = n_p.links.index[ + n_p.links.index.str.contains("heat pump") + ] # construct names of same-technology heat pumps in the current iteration - corresponding_idx_this_iteration = heat_pump_idx_previous_iteration.str[:-4] + str(year) + corresponding_idx_this_iteration = heat_pump_idx_previous_iteration.str[:-4] + str( + year + ) # update efficiency of heat pumps in previous iteration in-place to efficiency in this iteration - n_p.links_t["efficiency"].loc[:, heat_pump_idx_previous_iteration] = n.links_t["efficiency"].loc[:, corresponding_idx_this_iteration].values - + n_p.links_t["efficiency"].loc[:, heat_pump_idx_previous_iteration] = ( + n.links_t["efficiency"].loc[:, corresponding_idx_this_iteration].values + ) if __name__ == "__main__": diff --git a/scripts/prepare_perfect_foresight.py b/scripts/prepare_perfect_foresight.py index 50992d4c6..53895d0a2 100644 --- a/scripts/prepare_perfect_foresight.py +++ b/scripts/prepare_perfect_foresight.py @@ -521,9 +521,6 @@ def update_heat_pump_efficiency(n: pypsa.Network, years: List[int]): ] = correct_efficiency.values - - - if __name__ == "__main__": if "snakemake" not in globals(): from _helpers import mock_snakemake