From b8aaa658567e33c996921f9e5449287f2b1a9896 Mon Sep 17 00:00:00 2001 From: birgits Date: Fri, 13 Oct 2023 13:58:36 +0200 Subject: [PATCH 1/6] Remove copy_grid as it is not used anymore --- edisgo/flex_opt/reinforce_grid.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/edisgo/flex_opt/reinforce_grid.py b/edisgo/flex_opt/reinforce_grid.py index 0d0644df..6777adf8 100644 --- a/edisgo/flex_opt/reinforce_grid.py +++ b/edisgo/flex_opt/reinforce_grid.py @@ -864,12 +864,6 @@ def enhanced_reinforce_grid( The reinforced eDisGo object. """ - if kwargs.get("copy_grid", True): - edisgo_obj = copy.deepcopy(edisgo_object) - else: - edisgo_obj = edisgo_object - - kwargs["copy_grid"] = False kwargs.pop("skip_mv_reinforcement", False) num_lv_grids_standard_lines = 0 From ed703ae0a849e5598c7b1d9c6af2b0cb88de02f7 Mon Sep 17 00:00:00 2001 From: birgits Date: Fri, 13 Oct 2023 13:58:43 +0200 Subject: [PATCH 2/6] Minor doc fix --- edisgo/io/powermodels_io.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/edisgo/io/powermodels_io.py b/edisgo/io/powermodels_io.py index 3e8bbeda..ec88b574 100644 --- a/edisgo/io/powermodels_io.py +++ b/edisgo/io/powermodels_io.py @@ -1372,7 +1372,7 @@ def _build_dsm(edisgo_obj, psa_net, pm, s_base, flexible_loads): management strategy. Returns - ---------- + ---------- :numpy:`numpy.ndarray` or list Updated array containing all flexible loads that allow for application of demand side management strategy. From f7bb42e481f458e327c9be84f56db724962c10a5 Mon Sep 17 00:00:00 2001 From: birgits Date: Fri, 13 Oct 2023 16:48:56 +0200 Subject: [PATCH 3/6] Bug fix avoid error when inflexible loads don't have time series --- edisgo/io/powermodels_io.py | 83 +++++++++++++------------------------ 1 file changed, 28 insertions(+), 55 deletions(-) diff --git a/edisgo/io/powermodels_io.py b/edisgo/io/powermodels_io.py index ec88b574..16449bd1 100644 --- a/edisgo/io/powermodels_io.py +++ b/edisgo/io/powermodels_io.py @@ -1714,6 +1714,8 @@ def _build_component_timeseries( for storage in psa_net.storage_units.index if storage not in list(flexible_storage_units) ] + flex_loads = np.concatenate((flexible_hps, flexible_cps)) + inflexible_loads = [_ for _ in psa_net.loads.index if _ not in flex_loads] if kind == "gen": p_set2 = (psa_net.generators_t.p_set[disp_gens]).round(20) q_set2 = (psa_net.generators_t.q_set[disp_gens]).round(20) @@ -1797,61 +1799,32 @@ def _build_component_timeseries( "qg": q_set[comp].values.tolist(), } elif kind == "load": - flex_loads = np.concatenate((flexible_hps, flexible_cps)) - if len(flex_loads) == 0: - p_set = ( - pd.concat( - [ - psa_net.loads_t.p_set, - -1 - * psa_net.storage_units_t.p_set[inflexible_storage_units].clip( - upper=0 - ), - ], - axis=1, - ) - / s_base - ).round(20) - q_set = ( - pd.concat( - [ - psa_net.loads_t.q_set, - -1 - * psa_net.storage_units_t.q_set[inflexible_storage_units].clip( - lower=0 - ), - ], - axis=1, - ) - / s_base - ).round(20) - else: - p_set = ( - pd.concat( - [ - psa_net.loads_t.p_set.drop(columns=flex_loads), - -1 - * psa_net.storage_units_t.p_set[inflexible_storage_units].clip( - upper=0 - ), - ], - axis=1, - ) - / s_base - ).round(20) - q_set = ( - pd.concat( - [ - psa_net.loads_t.q_set.drop(columns=flex_loads), - -1 - * psa_net.storage_units_t.q_set[inflexible_storage_units].clip( - lower=0 - ), - ], - axis=1, - ) - / s_base - ).round(20) + p_set = ( + pd.concat( + [ + psa_net.loads_t.p_set.loc[:, inflexible_loads], + -1 + * psa_net.storage_units_t.p_set[inflexible_storage_units].clip( + upper=0 + ), + ], + axis=1, + ) + / s_base + ).round(20) + q_set = ( + pd.concat( + [ + psa_net.loads_t.q_set.loc[:, inflexible_loads], + -1 + * psa_net.storage_units_t.q_set[inflexible_storage_units].clip( + lower=0 + ), + ], + axis=1, + ) + / s_base + ).round(20) for comp in p_set.columns: comp_i = _mapping( psa_net, From 8df403d96d50ea285bd64deacb273d9c6df3dd01 Mon Sep 17 00:00:00 2001 From: birgits Date: Tue, 17 Oct 2023 13:02:32 +0200 Subject: [PATCH 4/6] Bug fix rename edisgo object --- edisgo/flex_opt/reinforce_grid.py | 68 ++++++++++++++++++------------- 1 file changed, 39 insertions(+), 29 deletions(-) diff --git a/edisgo/flex_opt/reinforce_grid.py b/edisgo/flex_opt/reinforce_grid.py index 6777adf8..18680bc5 100644 --- a/edisgo/flex_opt/reinforce_grid.py +++ b/edisgo/flex_opt/reinforce_grid.py @@ -1,6 +1,5 @@ from __future__ import annotations -import copy import datetime import logging @@ -874,12 +873,12 @@ def enhanced_reinforce_grid( "Separating lv grids. Set the parameter 'separate_lv_grids' to False if " "this is not desired." ) - run_separate_lv_grids(edisgo_obj, threshold=separation_threshold) + run_separate_lv_grids(edisgo_object, threshold=separation_threshold) logger.info("Run initial grid reinforcement for single LV grids.") - for lv_grid in list(edisgo_obj.topology.mv_grid.lv_grids): + for lv_grid in list(edisgo_object.topology.mv_grid.lv_grids): logger.info(f"Check initial convergence for {lv_grid=}.") - _, ts_not_converged = edisgo_obj.analyze( + _, ts_not_converged = edisgo_object.analyze( mode="lv", raise_not_converged=False, lv_grid_id=lv_grid.id ) if len(ts_not_converged) > 0: @@ -887,16 +886,18 @@ def enhanced_reinforce_grid( f"Not all time steps converged in initial power flow analysis for " f"{lv_grid=}. It is therefore tried to be split." ) - transformers_changes, lines_changes = separate_lv_grid(edisgo_obj, lv_grid) + transformers_changes, lines_changes = separate_lv_grid( + edisgo_object, lv_grid + ) if len(lines_changes) > 0: - _add_lines_changes_to_equipment_changes(edisgo_obj, lines_changes, 1) + _add_lines_changes_to_equipment_changes(edisgo_object, lines_changes, 1) if len(transformers_changes) > 0: _add_transformer_changes_to_equipment_changes( - edisgo_obj, transformers_changes, 1, "added" + edisgo_object, transformers_changes, 1, "added" ) try: logger.info(f"Try initial mode 'lv' reinforcement for {lv_grid=}.") - edisgo_obj.reinforce( + edisgo_object.reinforce( mode="lv", lv_grid_id=lv_grid.id, catch_convergence_problems=True, @@ -905,17 +906,20 @@ def enhanced_reinforce_grid( logger.info(f"Initial mode 'lv' reinforcement for {lv_grid} successful.") except (ValueError, RuntimeError, exceptions.MaximumIterationError): logger.warning(f"Initial mode 'lv' reinforcement for {lv_grid} failed.") + # ToDo catch convergence reinforcement versuchen try: logger.info("Try initial enhanced reinforcement.") - edisgo_obj.reinforce(mode=None, catch_convergence_problems=True, **kwargs) + edisgo_object.reinforce(mode=None, catch_convergence_problems=True, **kwargs) logger.info("Initial enhanced reinforcement succeeded.") except (ValueError, RuntimeError, exceptions.MaximumIterationError): logger.info("Initial enhanced reinforcement failed.") logger.info("Try mode 'mv' reinforcement.") try: - edisgo_obj.reinforce(mode="mv", catch_convergence_problems=True, **kwargs) + edisgo_object.reinforce( + mode="mv", catch_convergence_problems=True, **kwargs + ) logger.info("Mode 'mv' reinforcement succeeded.") except (ValueError, RuntimeError, exceptions.MaximumIterationError): logger.info("Mode 'mv' reinforcement failed.") @@ -923,14 +927,16 @@ def enhanced_reinforce_grid( logger.info("Try mode 'mvlv' reinforcement.") try: - edisgo_obj.reinforce(mode="mvlv", catch_convergence_problems=True, **kwargs) + edisgo_object.reinforce( + mode="mvlv", catch_convergence_problems=True, **kwargs + ) logger.info("Mode 'mvlv' reinforcement succeeded.") except (ValueError, RuntimeError, exceptions.MaximumIterationError): logger.info("Mode 'mvlv' reinforcement failed.") - for lv_grid in list(edisgo_obj.topology.mv_grid.lv_grids): + for lv_grid in list(edisgo_object.topology.mv_grid.lv_grids): logger.info(f"Check convergence for {lv_grid=}.") - _, ts_not_converged = edisgo_obj.analyze( + _, ts_not_converged = edisgo_object.analyze( mode="lv", raise_not_converged=False, lv_grid_id=lv_grid.id ) if len(ts_not_converged) > 0: @@ -939,19 +945,19 @@ def enhanced_reinforce_grid( f"{lv_grid=}. It is therefore tried to be split." ) transformers_changes, lines_changes = separate_lv_grid( - edisgo_obj, lv_grid + edisgo_object, lv_grid ) if len(lines_changes) > 0: _add_lines_changes_to_equipment_changes( - edisgo_obj, lines_changes, 1 + edisgo_object, lines_changes, 1 ) if len(transformers_changes) > 0: _add_transformer_changes_to_equipment_changes( - edisgo_obj, transformers_changes, 1, "added" + edisgo_object, transformers_changes, 1, "added" ) try: logger.info(f"Try mode 'lv' reinforcement for {lv_grid=}.") - edisgo_obj.reinforce( + edisgo_object.reinforce( mode="lv", lv_grid_id=lv_grid.id, catch_convergence_problems=True, @@ -965,20 +971,22 @@ def enhanced_reinforce_grid( logger.warning( f"Change all lines to standard type in {lv_grid=}." ) - edisgo_obj.results.measures = f"Standard lines in {lv_grid=}." + edisgo_object.results.measures = ( + f"Standard lines in {lv_grid=}." + ) num_lv_grids_standard_lines += 1 - lv_standard_line_type = edisgo_obj.config[ + lv_standard_line_type = edisgo_object.config[ "grid_expansion_standard_equipment" ]["lv_line"] lines = lv_grid.lines_df.index - edisgo_obj.topology.change_line_type( + edisgo_object.topology.change_line_type( lines, lv_standard_line_type ) lines_changes = {_: 1 for _ in lines} _add_lines_changes_to_equipment_changes( - edisgo_obj, lines_changes, 1 + edisgo_object, lines_changes, 1 ) - edisgo_obj.reinforce( + edisgo_object.reinforce( mode="lv", lv_grid_id=lv_grid.id, catch_convergence_problems=True, @@ -992,10 +1000,10 @@ def enhanced_reinforce_grid( logger.warning( f"Aggregate all nodes to station bus in {lv_grid=}." ) - edisgo_obj.results.measures = f"Aggregation of {lv_grid=}." + edisgo_object.results.measures = f"Aggregation of {lv_grid=}." num_lv_grids_aggregated += 1 try: - edisgo_obj.topology.aggregate_lv_grid_at_station( + edisgo_object.topology.aggregate_lv_grid_at_station( lv_grid_id=lv_grid.id ) logger.info( @@ -1009,7 +1017,9 @@ def enhanced_reinforce_grid( raise e try: - edisgo_obj.reinforce(mode=None, catch_convergence_problems=True, **kwargs) + edisgo_object.reinforce( + mode=None, catch_convergence_problems=True, **kwargs + ) logger.info("Enhanced reinforcement succeeded.") except Exception as e: logger.info("Enhanced reinforcement failed.") @@ -1022,23 +1032,23 @@ def enhanced_reinforce_grid( f"exchanged by standard lines." ) logger.warning(msg) - edisgo_obj.results.measures = msg + edisgo_object.results.measures = msg else: msg = ( "Enhanced reinforcement: No exchange of lines with standard lines or " "aggregation at MV/LV station needed." ) logger.info(msg) - edisgo_obj.results.measures = msg + edisgo_object.results.measures = msg if num_lv_grids_aggregated > 0: msg = ( f"Enhanced reinforcement: In {num_lv_grids_aggregated} LV grid(s) all " f"components were aggregated at the MV/LV station." ) logger.warning(msg) - edisgo_obj.results.measures = msg + edisgo_object.results.measures = msg - return edisgo_obj + return edisgo_object def run_separate_lv_grids(edisgo_obj: EDisGo, threshold: int | float = 2) -> None: From f50460c20ebb4b474f53728c80997e70230668bd Mon Sep 17 00:00:00 2001 From: birgits Date: Wed, 18 Oct 2023 14:47:52 +0200 Subject: [PATCH 5/6] Bug fix pop fails when timesteps_pfa is not provided --- edisgo/flex_opt/reinforce_grid.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/edisgo/flex_opt/reinforce_grid.py b/edisgo/flex_opt/reinforce_grid.py index 18680bc5..eaf38710 100644 --- a/edisgo/flex_opt/reinforce_grid.py +++ b/edisgo/flex_opt/reinforce_grid.py @@ -699,8 +699,7 @@ def reinforce(): logger.debug("Start 'catch-convergence' reinforcement.") # Get the timesteps from kwargs and then remove it to set it later manually - timesteps_pfa = kwargs.get("timesteps_pfa") - kwargs.pop("timesteps_pfa") + timesteps_pfa = kwargs.pop("timesteps_pfa", None) selected_timesteps = timesteps_pfa # Initial try From 563cb7c6cae5589c6ad4935b282ce81d544d430f Mon Sep 17 00:00:00 2001 From: birgits Date: Tue, 19 Dec 2023 14:48:56 -0800 Subject: [PATCH 6/6] Remove old ToDo --- edisgo/flex_opt/reinforce_grid.py | 1 - 1 file changed, 1 deletion(-) diff --git a/edisgo/flex_opt/reinforce_grid.py b/edisgo/flex_opt/reinforce_grid.py index eaf38710..89a0a651 100644 --- a/edisgo/flex_opt/reinforce_grid.py +++ b/edisgo/flex_opt/reinforce_grid.py @@ -905,7 +905,6 @@ def enhanced_reinforce_grid( logger.info(f"Initial mode 'lv' reinforcement for {lv_grid} successful.") except (ValueError, RuntimeError, exceptions.MaximumIterationError): logger.warning(f"Initial mode 'lv' reinforcement for {lv_grid} failed.") - # ToDo catch convergence reinforcement versuchen try: logger.info("Try initial enhanced reinforcement.")