From 835bfc0f6a46d483c95ad03bb9dfbe67190625b3 Mon Sep 17 00:00:00 2001 From: Fabian Neumann Date: Tue, 1 Feb 2022 08:51:47 +0100 Subject: [PATCH 1/3] bugfix: access right config variables in build renewable profiles --- scripts/build_renewable_profiles.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/scripts/build_renewable_profiles.py b/scripts/build_renewable_profiles.py index b37e6825..36845da5 100644 --- a/scripts/build_renewable_profiles.py +++ b/scripts/build_renewable_profiles.py @@ -206,12 +206,12 @@ if __name__ == '__main__': noprogress = not snakemake.config['atlite'].get('show_progress', True) config = snakemake.config['renewable'][snakemake.wildcards.technology] resource = config['resource'] # pv panel config / wind turbine config - correction_factor = snakemake.config.get('correction_factor', 1.) + correction_factor = config.get('correction_factor', 1.) capacity_per_sqkm = config['capacity_per_sqkm'] - p_nom_max_meth = snakemake.config.get('potential', 'conservative') + p_nom_max_meth = config.get('potential', 'conservative') if isinstance(config.get("corine", {}), list): - snakemake.config['corine'] = {'grid_codes': config['corine']} + config['corine'] = {'grid_codes': config['corine']} if correction_factor != 1.: logger.info(f'correction_factor is set as {correction_factor}') @@ -226,7 +226,7 @@ if __name__ == '__main__': if config['natura']: excluder.add_raster(snakemake.input.natura, nodata=0, allow_no_overlap=True) - corine = snakemake.config.get("corine", {}) + corine = config.get("corine", {}) if "grid_codes" in corine: codes = corine["grid_codes"] excluder.add_raster(snakemake.input.corine, codes=codes, invert=True, crs=3035) @@ -326,11 +326,11 @@ if __name__ == '__main__': ds['underwater_fraction'] = xr.DataArray(underwater_fraction, [buses]) # select only buses with some capacity and minimal capacity factor - ds = ds.sel(bus=((ds['profile'].mean('time') > snakemake.config.get('min_p_max_pu', 0.)) & - (ds['p_nom_max'] > snakemake.config.get('min_p_nom_max', 0.)))) + ds = ds.sel(bus=((ds['profile'].mean('time') > config.get('min_p_max_pu', 0.)) & + (ds['p_nom_max'] > config.get('min_p_nom_max', 0.)))) - if 'clip_p_max_pu' in snakemake.config: - min_p_max_pu = snakemake.config['clip_p_max_pu'] + if 'clip_p_max_pu' in config: + min_p_max_pu = config['clip_p_max_pu'] ds['profile'] = ds['profile'].where(ds['profile'] >= min_p_max_pu, 0) ds.to_netcdf(snakemake.output.profile) From f7ee47238a87e400655a5bd17090c73a4679caea Mon Sep 17 00:00:00 2001 From: Koen van Greevenbroek Date: Thu, 10 Feb 2022 15:57:16 +0100 Subject: [PATCH 2/3] Fix random state for kmean clustering When the kmeans algorithm is used to cluster networks, this is not deterministic by default. The result is that repeated runs of the `simplify_network` and `cluster_network` rules can and usually do produce different results that vary somewhat randomly. This makes results less reproducible when given only a pypsa-eur configuration file. The fix is to supply a fixed random state to the k-means algorithm. --- scripts/cluster_network.py | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/cluster_network.py b/scripts/cluster_network.py index 525196fc..99d428d4 100644 --- a/scripts/cluster_network.py +++ b/scripts/cluster_network.py @@ -226,6 +226,7 @@ def busmap_for_n_clusters(n, n_clusters, solver_name, focus_weights=None, algori algorithm_kwds.setdefault('n_init', 1000) algorithm_kwds.setdefault('max_iter', 30000) algorithm_kwds.setdefault('tol', 1e-6) + algorithm_kwds.setdefault('random_state', 0) n.determine_network_topology() From a2d3edd82b7bfdafa3a389994d6cd8ec5f19d924 Mon Sep 17 00:00:00 2001 From: Koen van Greevenbroek Date: Thu, 10 Feb 2022 16:07:31 +0100 Subject: [PATCH 3/3] Document the k-means random state fix --- doc/release_notes.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/release_notes.rst b/doc/release_notes.rst index d1b7b356..c7d89c04 100644 --- a/doc/release_notes.rst +++ b/doc/release_notes.rst @@ -24,6 +24,8 @@ Upcoming Release * Resource definitions for memory usage now follow [Snakemake standard resource definition](https://snakemake.readthedocs.io/en/stable/snakefiles/rules.html#standard-resources) ```mem_mb`` rather than ``mem``. +* Network building is made deterministic by supplying a fixed random state to network clustering routines. + PyPSA-Eur 0.4.0 (22th September 2021) =====================================