From 16b0f35cd85f84b1721d017d25cbb51e395e9409 Mon Sep 17 00:00:00 2001 From: Bobby Xiong <36541459+bobbyxng@users.noreply.github.com> Date: Thu, 12 Sep 2024 17:53:25 +0200 Subject: [PATCH] Bug fixes in add_existing_baseyear: Defaults and missing empty space (#1289) * Bug fixes in add_existing baseyear. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: lisazeyen <35347358+lisazeyen@users.noreply.github.com> --- scripts/add_existing_baseyear.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/scripts/add_existing_baseyear.py b/scripts/add_existing_baseyear.py index 84d20b72..7eff0e2e 100644 --- a/scripts/add_existing_baseyear.py +++ b/scripts/add_existing_baseyear.py @@ -597,7 +597,7 @@ def add_heating_capacities_installed_before_baseyear( n.madd( "Link", nodes, - suffix=f"{heat_system} gas boiler-{grouping_year}", + suffix=f" {heat_system} gas boiler-{grouping_year}", bus0="EU gas" if "EU gas" in spatial.gas.nodes else nodes + " gas", bus1=nodes + " " + heat_system.value + " heat", bus2="co2 atmosphere", @@ -666,6 +666,22 @@ def add_heating_capacities_installed_before_baseyear( ) +def set_defaults(n): + """ + Set default values for missing values in the network. + + Parameters: + n (pypsa.Network): The network object. + Returns: + None + """ + if "Link" in n.components: + if "reversed" in n.links.columns: + # Replace NA values with default value False + n.links.loc[n.links.reversed.isna(), "reversed"] = False + n.links.reversed = n.links.reversed.astype(bool) + + # %% if __name__ == "__main__": if "snakemake" not in globals(): @@ -734,6 +750,9 @@ if __name__ == "__main__": ), ) + # Set defaults for missing missing values + set_defaults(n) + if options.get("cluster_heat_buses", False): cluster_heat_buses(n)