From 2fec7166cafbd3937715befc0b1296b7a94600ec Mon Sep 17 00:00:00 2001 From: Bobby Xiong <36541459+bobbyxng@users.noreply.github.com> Date: Fri, 24 Jan 2025 14:13:24 +0100 Subject: [PATCH] Bug fix: Wrongfully dropped DC bus regions (regions_onshore_base) (#1507) * Fixed issue where DC bus regions where dropped due to missing converter busmap. * Fixed issue where DC bus regions where dropped due to missing converter busmap. * Added release notes for bugfix. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Undo changes in build_electricity.smk * [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: Fabian Neumann --- doc/release_notes.rst | 3 ++- rules/build_electricity.smk | 6 +++--- rules/retrieve.smk | 2 +- scripts/simplify_network.py | 11 +++++++++-- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/doc/release_notes.rst b/doc/release_notes.rst index d46ea2a08..0ad1686be 100644 --- a/doc/release_notes.rst +++ b/doc/release_notes.rst @@ -124,8 +124,9 @@ Upcoming Release * Update locations and capacities of ammonia plants. -* Updating all base shapes (country_shapes, europe_shape, nuts3_shapes, ...). The workflow has been modified to use higher resolution and more harmonised shapes (NUTS3 2021 01M data and OSM administration level 1 for non-NUTS3 countries, such as BA, MD, UA, and XK). Data sources for population and GDP p.c. have been updated to JRC ARDECO https://urban.jrc.ec.europa.eu/ardeco/ -- 2019 values are used. `build_gdp_pop_non_nuts3` (originally created to build regional GDP p.c. and population data for MD and UA) is now integrated into `build_shapes` and extended to build regional values for all non-NUTS3 countries using cutouts of the updated datasets `GDP_per_capita_PPP_1990_2015_v2.nc` and `ppp_2019_1km_Aggregated.tif`, +* Bugfix: Fixed issue where DC bus regions were dropped in `regions_onshore_base_s.geojson` and `regions_onshore_base_s_{clusters}.geojson` due to missing converter busmap. +* Updating all base shapes (country_shapes, europe_shape, nuts3_shapes, ...). The workflow has been modified to use higher resolution and more harmonised shapes (NUTS3 2021 01M data and OSM administration level 1 for non-NUTS3 countries, such as BA, MD, UA, and XK). Data sources for population and GDP p.c. have been updated to JRC ARDECO https://urban.jrc.ec.europa.eu/ardeco/ -- 2019 values are used. `build_gdp_pop_non_nuts3` (originally created to build regional GDP p.c. and population data for MD and UA) is now integrated into `build_shapes` and extended to build regional values for all non-NUTS3 countries using cutouts of the updated datasets `GDP_per_capita_PPP_1990_2015_v2.nc` and `ppp_2019_1km_Aggregated.tif`, PyPSA-Eur 0.13.0 (13th September 2024) diff --git a/rules/build_electricity.smk b/rules/build_electricity.smk index 2839f62f0..6cc16d5a7 100755 --- a/rules/build_electricity.smk +++ b/rules/build_electricity.smk @@ -21,7 +21,7 @@ rule build_electricity_demand: log: logs("build_electricity_demand.log"), benchmark: - benchmarks("build_electricity_demand"), + benchmarks("build_electricity_demand") resources: mem_mb=5000, conda: @@ -348,7 +348,7 @@ rule build_monthly_prices: log: logs("build_monthly_prices.log"), benchmark: - benchmarks("build_monthly_prices"), + benchmarks("build_monthly_prices") threads: 1 resources: mem_mb=5000, @@ -378,7 +378,7 @@ rule build_hydro_profile: log: logs("build_hydro_profile.log"), benchmark: - benchmarks("build_hydro_profile"), + benchmarks("build_hydro_profile") resources: mem_mb=5000, conda: diff --git a/rules/retrieve.smk b/rules/retrieve.smk index cfa52469c..e6f60b2f0 100755 --- a/rules/retrieve.smk +++ b/rules/retrieve.smk @@ -35,7 +35,7 @@ if config["enable"]["retrieve"] and config["enable"].get("retrieve_databundle", log: "logs/retrieve_databundle.log", benchmark: - "benchmarks/retrieve_databundle", + "benchmarks/retrieve_databundle" resources: mem_mb=1000, retries: 2 diff --git a/scripts/simplify_network.py b/scripts/simplify_network.py index 4486084d3..ae2f29a35 100644 --- a/scripts/simplify_network.py +++ b/scripts/simplify_network.py @@ -387,6 +387,9 @@ def remove_converters(n: pypsa.Network) -> pypsa.Network: ------- n (pypsa.Network): The network object with all converters removed. """ + # Initialise converter_map + converter_map = n.buses.index.to_series() + # Extract converters converters = n.links.query("carrier == ''")[["bus0", "bus1"]] converters["bus0_carrier"] = converters["bus0"].map(n.buses.carrier) @@ -402,6 +405,8 @@ def remove_converters(n: pypsa.Network) -> pypsa.Network: # Dictionary for remapping dict_dc_to_ac = dict(zip(converters["dc_bus"], converters["ac_bus"])) + # Update converter map + converter_map = converter_map.replace(dict_dc_to_ac) # Remap all buses that were originally connected to the converter to the connected AC bus n.links["bus0"] = n.links["bus0"].replace(dict_dc_to_ac) @@ -411,7 +416,7 @@ def remove_converters(n: pypsa.Network) -> pypsa.Network: n.links = n.links.loc[~n.links.index.isin(converters.index)] n.buses = n.buses.loc[~n.buses.index.isin(converters["dc_bus"])] - return n + return n, converter_map if __name__ == "__main__": @@ -432,7 +437,9 @@ def remove_converters(n: pypsa.Network) -> pypsa.Network: n, trafo_map = simplify_network_to_380(n, linetype_380) busmaps = [trafo_map] - n = remove_converters(n) + n, converter_map = remove_converters(n) + busmaps.append(converter_map) + n, simplify_links_map = simplify_links(n, params.p_max_pu) busmaps.append(simplify_links_map)