Skip to content

Commit

Permalink
Allow not running an inital analyze when using reduced analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
birgits committed Oct 22, 2023
1 parent b17d714 commit b54ebc9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
5 changes: 5 additions & 0 deletions edisgo/edisgo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------
Expand Down
8 changes: 8 additions & 0 deletions edisgo/flex_opt/reinforce_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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.")
Expand Down
28 changes: 18 additions & 10 deletions edisgo/tools/temporal_complexity_reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
--------
Expand All @@ -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)
Expand Down

0 comments on commit b54ebc9

Please sign in to comment.