From cd8001116dcd2bb553c5f981a59b33a36b2769e3 Mon Sep 17 00:00:00 2001 From: Thomas Gilon Date: Thu, 11 Jan 2024 14:11:25 +0100 Subject: [PATCH 01/20] Add warning when negative bev availability profile values --- doc/release_notes.rst | 3 ++- scripts/build_transport_demand.py | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/doc/release_notes.rst b/doc/release_notes.rst index be6be9fd8..a6a1b4853 100644 --- a/doc/release_notes.rst +++ b/doc/release_notes.rst @@ -12,7 +12,8 @@ Upcoming Release * New configuration option ``everywhere_powerplants`` to build conventional powerplants everywhere, irrespective of existing powerplants locations, in the network (https://github.com/PyPSA/pypsa-eur/pull/850). -* Remove option for wave energy as technology data is not maintained. +* Remove option for wave energy as technology data is not maintained. +* Add warning when BEV availability weekly profile has negative values in `build_transport_demand`. PyPSA-Eur 0.9.0 (5th January 2024) diff --git a/scripts/build_transport_demand.py b/scripts/build_transport_demand.py index 0bcfb7ed6..be8ad4141 100644 --- a/scripts/build_transport_demand.py +++ b/scripts/build_transport_demand.py @@ -8,11 +8,17 @@ availability and demand-side management constraints. """ +import logging + import numpy as np import pandas as pd import xarray as xr + +from _helpers import configure_logging from _helpers import generate_periodic_profiles +logger = logging.getLogger(__name__) + def build_nodal_transport_data(fn, pop_layout): transport_data = pd.read_csv(fn, index_col=0) @@ -130,6 +136,10 @@ def bev_availability_profile(fn, snapshots, nodes, options): traffic.mean() - traffic.min() ) + if not avail[avail < 0].empty: + logger.warning("The BEV availability weekly profile has negative values which can " + "lead to infeasibility.") + return generate_periodic_profiles( dt_index=snapshots, nodes=nodes, @@ -160,6 +170,7 @@ def bev_dsm_profile(snapshots, nodes, options): simpl="", clusters=48, ) + configure_logging(snakemake) pop_layout = pd.read_csv(snakemake.input.clustered_pop_layout, index_col=0) From 97d51a63fe963bd22394aca6bb6e1f774e53a44f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 15 Jan 2024 18:14:11 +0000 Subject: [PATCH 02/20] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/snakemake/snakefmt: v0.8.5 → v0.9.0](https://github.com/snakemake/snakefmt/compare/v0.8.5...v0.9.0) --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 78e70b579..02d360d37 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -74,7 +74,7 @@ repos: # Format Snakemake rule / workflow files - repo: https://github.com/snakemake/snakefmt - rev: v0.8.5 + rev: v0.9.0 hooks: - id: snakefmt From 68421e6aabbe676982b448ab2759b8f1f7691d31 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 15 Jan 2024 18:14:31 +0000 Subject: [PATCH 03/20] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- doc/release_notes.rst | 2 +- rules/retrieve.smk | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/release_notes.rst b/doc/release_notes.rst index be6be9fd8..52b2ddc27 100644 --- a/doc/release_notes.rst +++ b/doc/release_notes.rst @@ -12,7 +12,7 @@ Upcoming Release * New configuration option ``everywhere_powerplants`` to build conventional powerplants everywhere, irrespective of existing powerplants locations, in the network (https://github.com/PyPSA/pypsa-eur/pull/850). -* Remove option for wave energy as technology data is not maintained. +* Remove option for wave energy as technology data is not maintained. PyPSA-Eur 0.9.0 (5th January 2024) diff --git a/rules/retrieve.smk b/rules/retrieve.smk index 7a180e220..5e1e3e598 100644 --- a/rules/retrieve.smk +++ b/rules/retrieve.smk @@ -191,7 +191,7 @@ if config["enable"]["retrieve"]: input: HTTP.remote( "data.open-power-system-data.org/time_series/{version}/time_series_60min_singleindex.csv".format( - version="2019-06-05" + version="2019-06-05" if config["snapshots"]["end"] < "2019" else "2020-10-06" ), From e51e405d6e7886220556b97ed6d444f2b41624dd Mon Sep 17 00:00:00 2001 From: lisazeyen <35347358+lisazeyen@users.noreply.github.com> Date: Tue, 16 Jan 2024 11:51:55 +0100 Subject: [PATCH 04/20] add clipping for links --- scripts/solve_network.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/solve_network.py b/scripts/solve_network.py index 1c0f6505c..9fbd1eafe 100644 --- a/scripts/solve_network.py +++ b/scripts/solve_network.py @@ -341,6 +341,8 @@ def prepare_network( for df in ( n.generators_t.p_max_pu, n.generators_t.p_min_pu, + n.links_t.p_max_pu, + n.links_t.p_min_pu, n.storage_units_t.inflow, ): df.where(df > solve_opts["clip_p_max_pu"], other=0.0, inplace=True) From 3f8a55992c76769a29362b29a5989c2a62293579 Mon Sep 17 00:00:00 2001 From: Michael Lindner Date: Tue, 16 Jan 2024 16:50:54 +0100 Subject: [PATCH 05/20] locate project dir if pypsa-eur is a submodule --- scripts/_helpers.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/scripts/_helpers.py b/scripts/_helpers.py index 03bde8407..70eb4df24 100644 --- a/scripts/_helpers.py +++ b/scripts/_helpers.py @@ -223,7 +223,12 @@ def update_to(b=1, bsize=1, tsize=None): urllib.request.urlretrieve(url, file, reporthook=update_to) -def mock_snakemake(rulename, root_dir=None, configfiles=[], **wildcards): +def mock_snakemake( + rulename, + root_dir=None, + configfiles=[], + submodule_dir="workflow/submodules/pypsa-eur", + **wildcards): """ This function is expected to be executed from the 'scripts'-directory of ' the snakemake project. It returns a snakemake.script.Snakemake object, @@ -239,6 +244,9 @@ def mock_snakemake(rulename, root_dir=None, configfiles=[], **wildcards): path to the root directory of the snakemake project configfiles: list, str list of configfiles to be used to update the config + submodule_dir: str, Path + in case PyPSA-Eur is used as a submodule, submodule_dir is + the path of pypsa-eur relative to the project directory. **wildcards: keyword arguments fixing the wildcards. Only necessary if wildcards are needed. @@ -257,7 +265,10 @@ def mock_snakemake(rulename, root_dir=None, configfiles=[], **wildcards): root_dir = Path(root_dir).resolve() user_in_script_dir = Path.cwd().resolve() == script_dir - if user_in_script_dir: + if str(submodule_dir) in __file__: + # the submodule_dir path is only need to locate the project dir + os.chdir(Path(__file__[:__file__.find(str(submodule_dir))])) + elif user_in_script_dir: os.chdir(root_dir) elif Path.cwd().resolve() != root_dir: raise RuntimeError( From 21a223262f145476065e2dd9dd30943bfd24594e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 16 Jan 2024 15:53:15 +0000 Subject: [PATCH 06/20] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- scripts/_helpers.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/scripts/_helpers.py b/scripts/_helpers.py index 70eb4df24..e0982fd46 100644 --- a/scripts/_helpers.py +++ b/scripts/_helpers.py @@ -224,11 +224,12 @@ def update_to(b=1, bsize=1, tsize=None): def mock_snakemake( - rulename, - root_dir=None, - configfiles=[], - submodule_dir="workflow/submodules/pypsa-eur", - **wildcards): + rulename, + root_dir=None, + configfiles=[], + submodule_dir="workflow/submodules/pypsa-eur", + **wildcards, +): """ This function is expected to be executed from the 'scripts'-directory of ' the snakemake project. It returns a snakemake.script.Snakemake object, @@ -245,7 +246,7 @@ def mock_snakemake( configfiles: list, str list of configfiles to be used to update the config submodule_dir: str, Path - in case PyPSA-Eur is used as a submodule, submodule_dir is + in case PyPSA-Eur is used as a submodule, submodule_dir is the path of pypsa-eur relative to the project directory. **wildcards: keyword arguments fixing the wildcards. Only necessary if wildcards are @@ -267,7 +268,7 @@ def mock_snakemake( user_in_script_dir = Path.cwd().resolve() == script_dir if str(submodule_dir) in __file__: # the submodule_dir path is only need to locate the project dir - os.chdir(Path(__file__[:__file__.find(str(submodule_dir))])) + os.chdir(Path(__file__[: __file__.find(str(submodule_dir))])) elif user_in_script_dir: os.chdir(root_dir) elif Path.cwd().resolve() != root_dir: From 55eddb6e1d0588ea8e6c2d335d0af52d44471d14 Mon Sep 17 00:00:00 2001 From: martacki Date: Tue, 16 Jan 2024 20:13:28 +0100 Subject: [PATCH 07/20] Norway currently ignored when building energy totals --- scripts/build_energy_totals.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/build_energy_totals.py b/scripts/build_energy_totals.py index 67b864663..80c5d442d 100644 --- a/scripts/build_energy_totals.py +++ b/scripts/build_energy_totals.py @@ -479,7 +479,7 @@ def build_energy_totals(countries, eurostat, swiss, idees): # The main heating source for about 73 per cent of the households is based on electricity # => 26% is non-electric - if "NO" in df: + if "NO" in df.index: elec_fraction = 0.73 no_norway = df.drop("NO") From a74c7b69c80d1c0b15c1203872e9799dbd69de6f Mon Sep 17 00:00:00 2001 From: Fabian Neumann Date: Wed, 17 Jan 2024 10:02:51 +0100 Subject: [PATCH 08/20] add release note --- doc/release_notes.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/release_notes.rst b/doc/release_notes.rst index 52b2ddc27..ee8858a47 100644 --- a/doc/release_notes.rst +++ b/doc/release_notes.rst @@ -14,6 +14,8 @@ Upcoming Release * Remove option for wave energy as technology data is not maintained. +* Bugfix: Assure entering of code block which corrects Norwegian heat demand. + PyPSA-Eur 0.9.0 (5th January 2024) ================================== From 228ff44f75de10d4174409776cca7328185815ab Mon Sep 17 00:00:00 2001 From: Thomas Kouroughli Date: Wed, 17 Jan 2024 13:50:32 +0000 Subject: [PATCH 09/20] :recycle: address pandas FutureWarning --- scripts/build_electricity_production.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/build_electricity_production.py b/scripts/build_electricity_production.py index beb859bdf..e89ad78b0 100644 --- a/scripts/build_electricity_production.py +++ b/scripts/build_electricity_production.py @@ -58,7 +58,7 @@ gen = client.query_generation(country, start=start, end=end, nett=True) gen = gen.tz_localize(None).resample("1h").mean() gen = gen.loc[start.tz_localize(None) : end.tz_localize(None)] - gen = gen.rename(columns=carrier_grouper).groupby(level=0, axis=1).sum() + gen = gen.rename(columns=carrier_grouper).T.groupby(level=0).sum().T generation.append(gen) except NoMatchingDataError: unavailable_countries.append(country) From aaa587d34f84dc22f7662d7f5855ae1e1f2161fa Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 17 Jan 2024 13:51:03 +0000 Subject: [PATCH 10/20] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- scripts/build_transport_demand.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/build_transport_demand.py b/scripts/build_transport_demand.py index be8ad4141..33c8faaef 100644 --- a/scripts/build_transport_demand.py +++ b/scripts/build_transport_demand.py @@ -13,9 +13,7 @@ import numpy as np import pandas as pd import xarray as xr - -from _helpers import configure_logging -from _helpers import generate_periodic_profiles +from _helpers import configure_logging, generate_periodic_profiles logger = logging.getLogger(__name__) @@ -137,8 +135,10 @@ def bev_availability_profile(fn, snapshots, nodes, options): ) if not avail[avail < 0].empty: - logger.warning("The BEV availability weekly profile has negative values which can " - "lead to infeasibility.") + logger.warning( + "The BEV availability weekly profile has negative values which can " + "lead to infeasibility." + ) return generate_periodic_profiles( dt_index=snapshots, From 4cfb06c55f96c619a5ff18df1f435d75eb147e28 Mon Sep 17 00:00:00 2001 From: Michael Lindner Date: Wed, 17 Jan 2024 17:07:19 +0100 Subject: [PATCH 11/20] group storage with duplicate labels --- scripts/plot_network.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/scripts/plot_network.py b/scripts/plot_network.py index 674811208..650a24efb 100644 --- a/scripts/plot_network.py +++ b/scripts/plot_network.py @@ -273,7 +273,7 @@ def plot_h2_map(network, regions): h2_storage = n.stores.query("carrier == 'H2'") regions["H2"] = h2_storage.rename( index=h2_storage.bus.map(n.buses.location) - ).e_nom_opt.div( + ).e_nom_opt.groupby(level=0).sum().div( 1e6 ) # TWh regions["H2"] = regions["H2"].where(regions["H2"] > 0.1) @@ -1068,9 +1068,10 @@ def plot_map_perfect( "plot_network", simpl="", opts="", - clusters="37", - ll="v1.0", - sector_opts="4380H-T-H-B-I-A-solar+p3-dist1", + clusters="22", + ll="v1.2", + sector_opts="365H-T-H-B-I-A-solar+p3-linemaxext15", + planning_horizons="2040", ) logging.basicConfig(level=snakemake.config["logging"]["level"]) From e07f0e5c2b5bb34e8fcfb3b127ac9e30109beedc Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 17 Jan 2024 16:09:36 +0000 Subject: [PATCH 12/20] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- scripts/plot_network.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/scripts/plot_network.py b/scripts/plot_network.py index 650a24efb..31e722890 100644 --- a/scripts/plot_network.py +++ b/scripts/plot_network.py @@ -271,10 +271,11 @@ def plot_h2_map(network, regions): assign_location(n) h2_storage = n.stores.query("carrier == 'H2'") - regions["H2"] = h2_storage.rename( - index=h2_storage.bus.map(n.buses.location) - ).e_nom_opt.groupby(level=0).sum().div( - 1e6 + regions["H2"] = ( + h2_storage.rename(index=h2_storage.bus.map(n.buses.location)) + .e_nom_opt.groupby(level=0) + .sum() + .div(1e6) ) # TWh regions["H2"] = regions["H2"].where(regions["H2"] > 0.1) From fec871c1ccce766b8c710c67f35f4d407278a443 Mon Sep 17 00:00:00 2001 From: Michael Lindner Date: Wed, 17 Jan 2024 18:28:37 +0100 Subject: [PATCH 13/20] eliminate a few future warnings --- scripts/make_summary.py | 15 +++++++-------- scripts/plot_summary.py | 6 +++--- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/scripts/make_summary.py b/scripts/make_summary.py index fb13e91ea..9da915ef2 100644 --- a/scripts/make_summary.py +++ b/scripts/make_summary.py @@ -522,8 +522,8 @@ def calculate_weighted_prices(n, label, weighted_prices): if not names.empty: load += ( n.links_t.p0[names] - .groupby(n.links.loc[names, "bus0"], axis=1) - .sum() + .T.groupby(n.links.loc[names, "bus0"]) + .sum().T ) # Add H2 Store when charging @@ -560,14 +560,13 @@ def calculate_market_values(n, label, market_values): for tech in techs: gens = generators[n.generators.loc[generators, "carrier"] == tech] - + dispatch = ( n.generators_t.p[gens] - .groupby(n.generators.loc[gens, "bus"], axis=1) - .sum() + .T.groupby(n.generators.loc[gens, "bus"]) + .sum().T .reindex(columns=buses, fill_value=0.0) ) - revenue = dispatch * n.buses_t.marginal_price[buses] market_values.at[tech, label] = revenue.sum().sum() / dispatch.sum().sum() @@ -586,8 +585,8 @@ def calculate_market_values(n, label, market_values): dispatch = ( n.links_t["p" + i][links] - .groupby(n.links.loc[links, "bus" + i], axis=1) - .sum() + .T.groupby(n.links.loc[links, "bus" + i]) + .sum().T .reindex(columns=buses, fill_value=0.0) ) diff --git a/scripts/plot_summary.py b/scripts/plot_summary.py index 67ac9b553..e0067d7f9 100644 --- a/scripts/plot_summary.py +++ b/scripts/plot_summary.py @@ -154,7 +154,7 @@ def plot_costs(): df = df.drop(to_drop) - logger.info(f"Total system cost of {round(df.sum()[0])} EUR billion per year") + logger.info(f"Total system cost of {round(df.sum().iloc[0])} EUR billion per year") new_index = preferred_order.intersection(df.index).append( df.index.difference(preferred_order) @@ -214,7 +214,7 @@ def plot_energy(): df = df.drop(to_drop) - logger.info(f"Total energy of {round(df.sum()[0])} TWh/a") + logger.info(f"Total energy of {round(df.sum().iloc[0])} TWh/a") if df.empty: fig, ax = plt.subplots(figsize=(12, 8)) @@ -304,7 +304,7 @@ def plot_balances(): df = df.drop(to_drop) - logger.debug(f"Total energy balance for {v} of {round(df.sum()[0],2)} {units}") + logger.debug(f"Total energy balance for {v} of {round(df.sum().iloc[0],2)} {units}") if df.empty: continue From 213c4b025e9b53a8ed56a4745e0410baa86dbb2f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 17 Jan 2024 17:29:45 +0000 Subject: [PATCH 14/20] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- scripts/make_summary.py | 14 ++++++-------- scripts/plot_summary.py | 4 +++- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/scripts/make_summary.py b/scripts/make_summary.py index 9da915ef2..7223f4d56 100644 --- a/scripts/make_summary.py +++ b/scripts/make_summary.py @@ -521,9 +521,7 @@ def calculate_weighted_prices(n, label, weighted_prices): if not names.empty: load += ( - n.links_t.p0[names] - .T.groupby(n.links.loc[names, "bus0"]) - .sum().T + n.links_t.p0[names].T.groupby(n.links.loc[names, "bus0"]).sum().T ) # Add H2 Store when charging @@ -560,12 +558,12 @@ def calculate_market_values(n, label, market_values): for tech in techs: gens = generators[n.generators.loc[generators, "carrier"] == tech] - + dispatch = ( n.generators_t.p[gens] .T.groupby(n.generators.loc[gens, "bus"]) - .sum().T - .reindex(columns=buses, fill_value=0.0) + .sum() + .T.reindex(columns=buses, fill_value=0.0) ) revenue = dispatch * n.buses_t.marginal_price[buses] @@ -586,8 +584,8 @@ def calculate_market_values(n, label, market_values): dispatch = ( n.links_t["p" + i][links] .T.groupby(n.links.loc[links, "bus" + i]) - .sum().T - .reindex(columns=buses, fill_value=0.0) + .sum() + .T.reindex(columns=buses, fill_value=0.0) ) revenue = dispatch * n.buses_t.marginal_price[buses] diff --git a/scripts/plot_summary.py b/scripts/plot_summary.py index e0067d7f9..2a6c9f15c 100644 --- a/scripts/plot_summary.py +++ b/scripts/plot_summary.py @@ -304,7 +304,9 @@ def plot_balances(): df = df.drop(to_drop) - logger.debug(f"Total energy balance for {v} of {round(df.sum().iloc[0],2)} {units}") + logger.debug( + f"Total energy balance for {v} of {round(df.sum().iloc[0],2)} {units}" + ) if df.empty: continue From dd8db719accb6faf71fd194227211cedd1bb9950 Mon Sep 17 00:00:00 2001 From: Michael Lindner Date: Thu, 18 Jan 2024 13:53:59 +0100 Subject: [PATCH 15/20] revert accidental changes --- scripts/plot_network.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/scripts/plot_network.py b/scripts/plot_network.py index 31e722890..63b5d8480 100644 --- a/scripts/plot_network.py +++ b/scripts/plot_network.py @@ -1069,10 +1069,9 @@ def plot_map_perfect( "plot_network", simpl="", opts="", - clusters="22", - ll="v1.2", - sector_opts="365H-T-H-B-I-A-solar+p3-linemaxext15", - planning_horizons="2040", + clusters="37", + ll="v1.0", + sector_opts="4380H-T-H-B-I-A-solar+p3-dist1", ) logging.basicConfig(level=snakemake.config["logging"]["level"]) From ecb0a1f79f97db73c49a225f9832c66b5cdab9cc Mon Sep 17 00:00:00 2001 From: euronion <42553970+euronion@users.noreply.github.com> Date: Thu, 18 Jan 2024 14:12:17 +0100 Subject: [PATCH 16/20] Log unhandled exceptions stacktraces in log files --- doc/release_notes.rst | 2 ++ scripts/_helpers.py | 11 ++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/doc/release_notes.rst b/doc/release_notes.rst index 44cea086f..a48d1a4ed 100644 --- a/doc/release_notes.rst +++ b/doc/release_notes.rst @@ -18,6 +18,8 @@ Upcoming Release * Add warning when BEV availability weekly profile has negative values in `build_transport_demand`. +* Stacktrace of uncaught exceptions should now be correctly included inside log files (via `configure_logging(..)`). + PyPSA-Eur 0.9.0 (5th January 2024) ================================== diff --git a/scripts/_helpers.py b/scripts/_helpers.py index e0982fd46..beca3f4ff 100644 --- a/scripts/_helpers.py +++ b/scripts/_helpers.py @@ -80,6 +80,7 @@ def configure_logging(snakemake, skip_handlers=False): Do (not) skip the default handlers created for redirecting output to STDERR and file. """ import logging + import sys kwargs = snakemake.config.get("logging", dict()).copy() kwargs.setdefault("level", "INFO") @@ -102,7 +103,15 @@ def configure_logging(snakemake, skip_handlers=False): } ) logging.basicConfig(**kwargs) - + + # Setup a function to handle uncaught exceptions and include them with their stacktrace into logfiles + def handle_exception(exc_type, exc_value, exc_traceback): + # Log the exception + logger = logging.getLogger() + logger.error("Uncaught exception", + exc_info=(exc_type, exc_value, exc_traceback)) + + sys.excepthook = handle_exception def update_p_nom_max(n): # if extendable carriers (solar/onwind/...) have capacity >= 0, From 35f1c06f75a4a4e540277bd760c96ec7b3bd4083 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 18 Jan 2024 13:18:25 +0000 Subject: [PATCH 17/20] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- scripts/_helpers.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/scripts/_helpers.py b/scripts/_helpers.py index beca3f4ff..c5c96db91 100644 --- a/scripts/_helpers.py +++ b/scripts/_helpers.py @@ -103,16 +103,18 @@ def configure_logging(snakemake, skip_handlers=False): } ) logging.basicConfig(**kwargs) - + # Setup a function to handle uncaught exceptions and include them with their stacktrace into logfiles def handle_exception(exc_type, exc_value, exc_traceback): # Log the exception logger = logging.getLogger() - logger.error("Uncaught exception", - exc_info=(exc_type, exc_value, exc_traceback)) + logger.error( + "Uncaught exception", exc_info=(exc_type, exc_value, exc_traceback) + ) sys.excepthook = handle_exception + def update_p_nom_max(n): # if extendable carriers (solar/onwind/...) have capacity >= 0, # e.g. existing assets from the OPSD project are included to the network, From 682d3d857b3ff9908b77c3ef57b562fa339a39bc Mon Sep 17 00:00:00 2001 From: Fabian Neumann Date: Thu, 18 Jan 2024 17:25:05 +0100 Subject: [PATCH 18/20] cluster heat buses by default --- config/config.default.yaml | 2 +- doc/release_notes.rst | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/config/config.default.yaml b/config/config.default.yaml index 1d28223f7..661f855e5 100644 --- a/config/config.default.yaml +++ b/config/config.default.yaml @@ -376,7 +376,7 @@ sector: 2045: 0.8 2050: 1.0 district_heating_loss: 0.15 - cluster_heat_buses: false + cluster_heat_buses: true bev_dsm_restriction_value: 0.75 bev_dsm_restriction_time: 7 transport_heating_deadband_upper: 20. diff --git a/doc/release_notes.rst b/doc/release_notes.rst index 44cea086f..7b0b8c335 100644 --- a/doc/release_notes.rst +++ b/doc/release_notes.rst @@ -18,6 +18,7 @@ Upcoming Release * Add warning when BEV availability weekly profile has negative values in `build_transport_demand`. +* Cluster residential and services heat buses by default. Can be disabled with ``cluster_heat_buses: false``. PyPSA-Eur 0.9.0 (5th January 2024) ================================== From 7c23ef08c5a1b42017dc625e0cc20d555aee9720 Mon Sep 17 00:00:00 2001 From: Thomas Kouroughli Date: Thu, 18 Jan 2024 17:04:22 +0000 Subject: [PATCH 19/20] :bug: fix key_error in validation plots --- scripts/plot_validation_electricity_production.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/plot_validation_electricity_production.py b/scripts/plot_validation_electricity_production.py index 5c5569d03..e95a81262 100644 --- a/scripts/plot_validation_electricity_production.py +++ b/scripts/plot_validation_electricity_production.py @@ -45,6 +45,12 @@ header=[0, 1], parse_dates=True, ) + subset_technologies = ["Geothermal", "Nuclear", "Biomass", "Lignite", "Oil", "Coal"] + lowercase_technologies = [ + technology.lower() if technology in subset_technologies else technology + for technology in historic.columns.levels[1] + ] + historic.columns = historic.columns.set_levels(lowercase_technologies, level=1) colors = n.carriers.set_index("nice_name").color.where( lambda s: s != "", "lightgrey" From 4d74be9588cac870c4341fc7e7f15cab5178df75 Mon Sep 17 00:00:00 2001 From: Thomas Kouroughli Date: Thu, 18 Jan 2024 17:12:39 +0000 Subject: [PATCH 20/20] :memo: add release notes for PR. --- doc/release_notes.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/release_notes.rst b/doc/release_notes.rst index 7b0b8c335..4cc89a7a8 100644 --- a/doc/release_notes.rst +++ b/doc/release_notes.rst @@ -10,6 +10,8 @@ Release Notes Upcoming Release ================ +* Bugfix: Correct technology keys for the electricity production plotting to work out the box. + * New configuration option ``everywhere_powerplants`` to build conventional powerplants everywhere, irrespective of existing powerplants locations, in the network (https://github.com/PyPSA/pypsa-eur/pull/850). * Remove option for wave energy as technology data is not maintained.