From 475a2f3cd5b29295121aa3bee6df99b8effc2b6f Mon Sep 17 00:00:00 2001 From: birgits Date: Sun, 22 Oct 2023 14:32:10 +0200 Subject: [PATCH] Change how reduced_analysis is set --- edisgo/edisgo.py | 12 +++++++----- edisgo/flex_opt/reinforce_grid.py | 22 ++++++++++++++-------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/edisgo/edisgo.py b/edisgo/edisgo.py index f0edd32b..28b3d4ba 100755 --- a/edisgo/edisgo.py +++ b/edisgo/edisgo.py @@ -1196,6 +1196,7 @@ def _scale_timeseries(pypsa_network_copy, fraction): def reinforce( self, timesteps_pfa: str | pd.DatetimeIndex | pd.Timestamp | None = None, + reduced_analysis: bool = False, copy_grid: bool = False, max_while_iterations: int = 20, split_voltage_band: bool = True, @@ -1237,14 +1238,15 @@ def reinforce( time steps. If your time series already represents the worst-case, keep the default value of None because finding the worst-case snapshots takes some time. - * 'reduced_analysis' - Reinforcement is conducted for all time steps at which at least one - branch shows its highest overloading or one bus shows its highest voltage - violation. * :pandas:`pandas.DatetimeIndex` or \ :pandas:`pandas.Timestamp` Use this option to explicitly choose which time steps to consider. - + reduced_analysis : bool + If True, reinforcement is conducted for all time steps at which at least + one branch shows its highest overloading or one bus shows its highest + voltage violation. Time steps to consider are specified through parameter + `timesteps_pfa`. If False, all time steps in parameter `timesteps_pfa` + are used. Default: False. copy_grid : bool If True, reinforcement is conducted on a copied grid and discarded. Default: False. diff --git a/edisgo/flex_opt/reinforce_grid.py b/edisgo/flex_opt/reinforce_grid.py index 89a0a651..27fe6ff2 100644 --- a/edisgo/flex_opt/reinforce_grid.py +++ b/edisgo/flex_opt/reinforce_grid.py @@ -25,6 +25,7 @@ def reinforce_grid( edisgo: EDisGo, timesteps_pfa: str | pd.DatetimeIndex | pd.Timestamp | None = None, + reduced_analysis: bool = False, max_while_iterations: int = 20, split_voltage_band: bool = True, mode: str | None = None, @@ -47,6 +48,10 @@ def reinforce_grid( timesteps_pfa specifies for which time steps power flow analysis is conducted. See parameter `timesteps_pfa` in function :attr:`~.EDisGo.reinforce` for more information. + reduced_analysis : bool + Specifies, whether to run reinforcement on a subset of time steps that are most + critical. See parameter `reduced_analysis` in function + :attr:`~.EDisGo.reinforce` for more information. max_while_iterations : int Maximum number of times each while loop is conducted. Default: 20. split_voltage_band : bool @@ -139,14 +144,6 @@ def reinforce_grid( snapshots["min_residual_load"], ] ).dropna() - elif isinstance(timesteps_pfa, str) and timesteps_pfa == "reduced_analysis": - timesteps_pfa = get_most_critical_time_steps( - edisgo, - num_steps_loading=kwargs.get("num_steps_loading", None), - num_steps_voltage=kwargs.get("num_steps_voltage", None), - percentage=kwargs.get("percentage", 1.0), - use_troubleshooting_mode=kwargs.get("use_troubleshooting_mode", True), - ) # if timesteps_pfa is not of type datetime or does not contain # datetimes throw an error elif not isinstance(timesteps_pfa, datetime.datetime): @@ -160,6 +157,15 @@ def reinforce_grid( f"Input {timesteps_pfa} for timesteps_pfa is not valid." ) + if reduced_analysis: + timesteps_pfa = get_most_critical_time_steps( + edisgo, + timesteps=timesteps_pfa, + num_steps_loading=kwargs.get("num_steps_loading", None), + num_steps_voltage=kwargs.get("num_steps_voltage", None), + percentage=kwargs.get("percentage", 1.0), + use_troubleshooting_mode=kwargs.get("use_troubleshooting_mode", True), + ) iteration_step = 1 lv_grid_id = kwargs.get("lv_grid_id", None) scale_timeseries = kwargs.get("scale_timeseries", None)