From 9e61e30ff45a13da92dbce2f0c7f69721d480e99 Mon Sep 17 00:00:00 2001 From: Max Parzen Date: Fri, 16 Dec 2022 11:00:39 +0000 Subject: [PATCH 1/5] Fix EQ constraint in case no hydro exist --- scripts/solve_network.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/scripts/solve_network.py b/scripts/solve_network.py index d1331b0d..575cd078 100755 --- a/scripts/solve_network.py +++ b/scripts/solve_network.py @@ -216,18 +216,21 @@ def add_EQ_constraints(n, o, scaling=1e-1): .T.groupby(ggrouper, axis=1) .apply(join_exprs) ) - lhs_spill = ( - linexpr( - ( - -n.snapshot_weightings.stores * scaling, - get_var(n, "StorageUnit", "spill").T, + if not n.storage_units_t.inflow.empty: + lhs_spill = ( + linexpr( + ( + -n.snapshot_weightings.stores * scaling, + get_var(n, "StorageUnit", "spill").T, + ) ) + .T.groupby(sgrouper, axis=1) + .apply(join_exprs) ) - .T.groupby(sgrouper, axis=1) - .apply(join_exprs) - ) - lhs_spill = lhs_spill.reindex(lhs_gen.index).fillna("") - lhs = lhs_gen + lhs_spill + lhs_spill = lhs_spill.reindex(lhs_gen.index).fillna("") + lhs = lhs_gen + lhs_spill + else: + lhs = lhs_gen define_constraints(n, lhs, ">=", rhs, "equity", "min") From 17a8bc3c3999ab58af20eea8d4e61ab2267cd62b Mon Sep 17 00:00:00 2001 From: Max Parzen Date: Fri, 16 Dec 2022 11:06:36 +0000 Subject: [PATCH 2/5] Update release_notes.rst --- doc/release_notes.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/release_notes.rst b/doc/release_notes.rst index 812712bc..2d2eae23 100644 --- a/doc/release_notes.rst +++ b/doc/release_notes.rst @@ -12,6 +12,8 @@ Upcoming Release * Carriers of generators can now be excluded from aggregation in clustering network and simplify network. +* Fix EQ constraint for the case no hydro inflow is available + PyPSA-Eur 0.6.1 (20th September 2022) ===================================== From 0cf6d47afbac9d273f27e37f84592c5fb4b430db Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 10 Jan 2023 21:56:40 +0000 Subject: [PATCH 3/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- scripts/simplify_network.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/simplify_network.py b/scripts/simplify_network.py index 42f7daac..7ed17923 100644 --- a/scripts/simplify_network.py +++ b/scripts/simplify_network.py @@ -395,8 +395,10 @@ def simplify_links(n, costs, config, output, aggregation_strategies=dict()): def remove_stubs(n, costs, config, output, aggregation_strategies=dict()): logger.info("Removing stubs") - across_borders = config["clustering"]["simplify_network"].get("remove_stubs_across_borders", True) - matching_attrs = [] if across_borders else ['country'] + across_borders = config["clustering"]["simplify_network"].get( + "remove_stubs_across_borders", True + ) + matching_attrs = [] if across_borders else ["country"] busmap = busmap_by_stubs(n, matching_attrs) connection_costs_to_bus = _compute_connection_costs_to_bus(n, busmap, costs, config) From db51a6eba08914474a366a93f3d33b3a5ec9acc6 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 23 Jan 2023 21:25:31 +0000 Subject: [PATCH 4/5] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/PyCQA/docformatter: v1.5.1 → v1.6.0.rc1](https://github.com/PyCQA/docformatter/compare/v1.5.1...v1.6.0.rc1) - [github.com/macisamuele/language-formatters-pre-commit-hooks: v2.5.0 → v2.6.0](https://github.com/macisamuele/language-formatters-pre-commit-hooks/compare/v2.5.0...v2.6.0) --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bb48c2db..1b3a4dfc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -39,7 +39,7 @@ repos: # Make docstrings PEP 257 compliant - repo: https://github.com/PyCQA/docformatter - rev: v1.5.1 + rev: v1.6.0.rc1 hooks: - id: docformatter args: ["--in-place", "--make-summary-multi-line", "--pre-summary-newline"] @@ -67,7 +67,7 @@ repos: # Do YAML formatting (before the linter checks it for misses) - repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks - rev: v2.5.0 + rev: v2.6.0 hooks: - id: pretty-format-yaml args: [--autofix, --indent, "2", --preserve-quotes] From 8bdba5653a51e42ac1651b8def36f1b4a3a0999a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 23 Jan 2023 21:27:19 +0000 Subject: [PATCH 5/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- scripts/_helpers.py | 1 - scripts/add_electricity.py | 1 - scripts/build_bus_regions.py | 1 - scripts/build_load_data.py | 1 - scripts/cluster_network.py | 1 - scripts/make_summary.py | 2 -- scripts/simplify_network.py | 18 ++++++++++++------ scripts/solve_network.py | 1 - 8 files changed, 12 insertions(+), 14 deletions(-) diff --git a/scripts/_helpers.py b/scripts/_helpers.py index ba88efb2..127e42a8 100644 --- a/scripts/_helpers.py +++ b/scripts/_helpers.py @@ -28,7 +28,6 @@ def configure_logging(snakemake, skip_handlers=False): skip_handlers : True | False (default) Do (not) skip the default handlers created for redirecting output to STDERR and file. """ - import logging kwargs = snakemake.config.get("logging", dict()).copy() diff --git a/scripts/add_electricity.py b/scripts/add_electricity.py index 3d9babfd..85391a64 100755 --- a/scripts/add_electricity.py +++ b/scripts/add_electricity.py @@ -111,7 +111,6 @@ def calculate_annuity(n, r): discount rate of r, e.g. annuity(20, 0.05) * 20 = 1.6 """ - if isinstance(r, pd.Series): return pd.Series(1 / n, index=r.index).where( r == 0, r / (1.0 - 1.0 / (1.0 + r) ** n) diff --git a/scripts/build_bus_regions.py b/scripts/build_bus_regions.py index 6e6fdd32..ef4cc396 100644 --- a/scripts/build_bus_regions.py +++ b/scripts/build_bus_regions.py @@ -69,7 +69,6 @@ def voronoi_partition_pts(points, outline): ------- polygons : N - ndarray[dtype=Polygon|MultiPolygon] """ - points = np.asarray(points) if len(points) == 1: diff --git a/scripts/build_load_data.py b/scripts/build_load_data.py index 482256ba..780a651e 100755 --- a/scripts/build_load_data.py +++ b/scripts/build_load_data.py @@ -189,7 +189,6 @@ def manual_adjustment(load, fn_load, powerstatistics): Manual adjusted and interpolated load time-series with UTC timestamps x ISO-2 countries """ - if powerstatistics: if "MK" in load.columns: if "AL" not in load.columns or load.AL.isnull().values.all(): diff --git a/scripts/cluster_network.py b/scripts/cluster_network.py index 63fec077..80998b20 100644 --- a/scripts/cluster_network.py +++ b/scripts/cluster_network.py @@ -222,7 +222,6 @@ def distribute_clusters(n, n_clusters, focus_weights=None, solver_name="cbc"): """ Determine the number of clusters per country. """ - L = ( n.loads_t.p_set.mean() .groupby(n.loads.bus) diff --git a/scripts/make_summary.py b/scripts/make_summary.py index 0d12a04c..4c3c675a 100644 --- a/scripts/make_summary.py +++ b/scripts/make_summary.py @@ -235,7 +235,6 @@ def calculate_supply(n, label, supply): calculate the max dispatch of each component at the buses where the loads are attached. """ - load_types = n.buses.carrier.unique() for i in load_types: @@ -296,7 +295,6 @@ def calculate_supply_energy(n, label, supply_energy): calculate the total dispatch of each component at the buses where the loads are attached. """ - load_types = n.buses.carrier.unique() for i in load_types: diff --git a/scripts/simplify_network.py b/scripts/simplify_network.py index 42f7daac..7aa7a732 100644 --- a/scripts/simplify_network.py +++ b/scripts/simplify_network.py @@ -111,11 +111,15 @@ def simplify_network_to_380(n): """ Fix all lines to a voltage level of 380 kV and remove all transformers. - The function preserves the transmission capacity for each line while updating - its voltage level, line type and number of parallel bundles (num_parallel). + The function preserves the transmission capacity for each line while + updating + its voltage level, line type and number of parallel bundles + (num_parallel). - Transformers are removed and connected components are moved from their - starting bus to their ending bus. The corresponding starting buses are + Transformers are removed and connected components are moved from + their + starting bus to their ending bus. The corresponding starting buses + are removed as well. """ logger.info("Mapping all network lines onto a single 380kV layer") @@ -395,8 +399,10 @@ def simplify_links(n, costs, config, output, aggregation_strategies=dict()): def remove_stubs(n, costs, config, output, aggregation_strategies=dict()): logger.info("Removing stubs") - across_borders = config["clustering"]["simplify_network"].get("remove_stubs_across_borders", True) - matching_attrs = [] if across_borders else ['country'] + across_borders = config["clustering"]["simplify_network"].get( + "remove_stubs_across_borders", True + ) + matching_attrs = [] if across_borders else ["country"] busmap = busmap_by_stubs(n, matching_attrs) connection_costs_to_bus = _compute_connection_costs_to_bus(n, busmap, costs, config) diff --git a/scripts/solve_network.py b/scripts/solve_network.py index bcb786f0..5124852f 100755 --- a/scripts/solve_network.py +++ b/scripts/solve_network.py @@ -321,7 +321,6 @@ def add_operational_reserve_margin(n, sns, config): Build reserve margin constraints based on the formulation given in https://genxproject.github.io/GenX/dev/core/#Reserves. """ - define_variables(n, 0, np.inf, "Generator", "r", axes=[sns, n.generators.index]) add_operational_reserve_margin_constraint(n, config)