From b54ebc986fbb649ee158468b399e51e9076c1123 Mon Sep 17 00:00:00 2001 From: birgits Date: Sun, 22 Oct 2023 18:11:13 +0200 Subject: [PATCH] Allow not running an inital analyze when using reduced analysis --- edisgo/edisgo.py | 5 ++++ edisgo/flex_opt/reinforce_grid.py | 8 ++++++ edisgo/tools/temporal_complexity_reduction.py | 28 ++++++++++++------- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/edisgo/edisgo.py b/edisgo/edisgo.py index 4c5e9297..e41ba99c 100755 --- a/edisgo/edisgo.py +++ b/edisgo/edisgo.py @@ -1323,6 +1323,11 @@ def reinforce( The most critical time steps are then determined based on the power flow results with the reduced load and feed-in. If False, an error will be raised in case time steps do not converge. Default: True. + run_initial_analyze : bool + In case `reduced_analysis` is set to True, this parameter can be + used to specify whether to run an initial analyze to determine most + critical time steps or to use existing results. If set to False, + `use_troubleshooting_mode` is ignored. Default: True. Returns -------- diff --git a/edisgo/flex_opt/reinforce_grid.py b/edisgo/flex_opt/reinforce_grid.py index c6f88b94..d33bbf90 100644 --- a/edisgo/flex_opt/reinforce_grid.py +++ b/edisgo/flex_opt/reinforce_grid.py @@ -106,6 +106,11 @@ def reinforce_grid( to specify how to handle non-convergence issues in the power flow analysis. See parameter `use_troubleshooting_mode` in function :attr:`~.EDisGo.reinforce` for more information. Default: True. + run_initial_analyze : bool + In case `reduced_analysis` is set to True, this parameter can be + used to specify whether to run an initial analyze to determine most + critical time steps or to use existing results. If set to False, + `use_troubleshooting_mode` is ignored. Default: True. Returns ------- @@ -178,6 +183,7 @@ def reinforce_grid( num_steps_voltage=kwargs.get("num_steps_voltage", None), percentage=kwargs.get("percentage", 1.0), use_troubleshooting_mode=kwargs.get("use_troubleshooting_mode", True), + run_initial_analyze=kwargs.get("run_initial_analyze", True), ) edisgo.analyze( @@ -929,6 +935,7 @@ def enhanced_reinforce_grid( mode="lv", lv_grid_id=lv_grid.id, catch_convergence_problems=False, + run_initial_analyze=False, **kwargs, ) logger.info(f"Initial mode 'lv' reinforcement for {lv_grid} successful.") @@ -1008,6 +1015,7 @@ def enhanced_reinforce_grid( mode="lv", lv_grid_id=lv_grid.id, catch_convergence_problems=False, + run_initial_analyze=False, **kwargs, ) logger.info(f"Mode 'lv' reinforcement for {lv_grid} successful.") diff --git a/edisgo/tools/temporal_complexity_reduction.py b/edisgo/tools/temporal_complexity_reduction.py index 69bf70af..9703a157 100644 --- a/edisgo/tools/temporal_complexity_reduction.py +++ b/edisgo/tools/temporal_complexity_reduction.py @@ -660,6 +660,7 @@ def get_most_critical_time_steps( num_steps_voltage=None, percentage: float = 1.0, use_troubleshooting_mode=True, + run_initial_analyze=True, ) -> pd.DatetimeIndex: """ Get the time steps with the most critical overloading and voltage issues. @@ -700,6 +701,10 @@ def get_most_critical_time_steps( are then determined based on the power flow results with the reduced load and feed-in. If False, an error will be raised in case time steps do not converge. Default: True. + run_initial_analyze : bool + This parameter can be used to specify whether to run an initial analyze to + determine most critical time steps or to use existing results. If set to False, + `use_troubleshooting_mode` is ignored. Default: True. Returns -------- @@ -709,16 +714,19 @@ def get_most_critical_time_steps( """ # Run power flow - if use_troubleshooting_mode: - edisgo_obj = _troubleshooting_mode(edisgo_obj, timesteps=timesteps) - else: - logger.debug("Running initial power flow for temporal complexity reduction.") - edisgo_obj.analyze( - mode=mode, - timesteps=timesteps, - lv_grid_id=lv_grid_id, - scale_timeseries=scale_timeseries, - ) + if run_initial_analyze: + if use_troubleshooting_mode: + edisgo_obj = _troubleshooting_mode(edisgo_obj, timesteps=timesteps) + else: + logger.debug( + "Running initial power flow for temporal complexity reduction." + ) + edisgo_obj.analyze( + mode=mode, + timesteps=timesteps, + lv_grid_id=lv_grid_id, + scale_timeseries=scale_timeseries, + ) # Select most critical steps based on current violations loading_scores = _scored_most_critical_loading(edisgo_obj)