diff --git a/pyproject.toml b/pyproject.toml index 9cd8d1a..da7252b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "res-wind-up" -version = "0.4.9" +version = "0.4.10" authors = [ { name = "Alex Clerc", email = "alex.clerc@res-group.com" } ] @@ -97,7 +97,7 @@ max-complexity = 12 # try to bring this down to 10 [tool.ruff.lint.pylint] max-branches = 14 # try to bring this down to 12 -max-statements = 68 # try to bring this down to 50 +max-statements = 69 # try to bring this down to 50 max-args = 17 # try to bring this down to 5 [tool.ruff.lint.per-file-ignores] diff --git a/wind_up/main_analysis.py b/wind_up/main_analysis.py index c103788..91ee8af 100644 --- a/wind_up/main_analysis.py +++ b/wind_up/main_analysis.py @@ -585,7 +585,7 @@ def _calc_test_ref_results( pre_df = pre_df.merge(ref_df, how="left", left_index=True, right_index=True) post_df = post_df.merge(ref_df, how="left", left_index=True, right_index=True) - compare_active_and_reactive_power_pre_post( + _reactive_fig = compare_active_and_reactive_power_pre_post( pre_df=pre_df, post_df=post_df, wtg_name=ref_name, @@ -595,6 +595,8 @@ def _calc_test_ref_results( sub_dir=f"{test_name}/{ref_name}", is_toggle_test=cfg.toggle is not None, ) + if _reactive_fig is not None: + plt.close(_reactive_fig) ref_ops_curve_shift_dict = _check_for_ops_curve_shift( pre_df, @@ -881,7 +883,7 @@ def run_wind_up_analysis( test_df, pre_df, post_df = pre_post_splitter.split(test_df, test_wtg_name=test_name) - compare_active_and_reactive_power_pre_post( + _reactive_fig = compare_active_and_reactive_power_pre_post( pre_df=pre_df, post_df=post_df, wtg_name=test_name, @@ -890,6 +892,8 @@ def run_wind_up_analysis( plot_cfg=plot_cfg, is_toggle_test=cfg.toggle is not None, ) + if _reactive_fig is not None: + plt.close(_reactive_fig) test_ops_curve_shift_dict = _check_for_ops_curve_shift( pre_df, diff --git a/wind_up/plots/combine_results_plots.py b/wind_up/plots/combine_results_plots.py index 7e274e5..299774f 100644 --- a/wind_up/plots/combine_results_plots.py +++ b/wind_up/plots/combine_results_plots.py @@ -14,21 +14,23 @@ def plot_combined_results(tdf: pd.DataFrame, *, plot_cfg: PlotConfig, confidence grouped_results = tdf.index.name == "role" plt.figure() - labels = tdf.index.to_list() if grouped_results else tdf["test_wtg"] + labels = ( + [f"{i} ({int(v)} wtgs)" for i, v in zip(tdf.index, tdf["wtg_count"])] if grouped_results else tdf["test_wtg"] + ) values = tdf["p50_uplift"] * 100 yerrs = tdf["sigma"] * 100 * z_score plt.bar(labels, values, yerr=yerrs, capsize=3) plt.xlabel("turbine group" if grouped_results else "turbine") - plt.ylabel("uplift [%]") + plt.ylabel("uplift [%]", fontsize=12) plot_title = f"combined uplift and {confidence * 100:.0f}% CI" plt.title(plot_title) plt.grid(axis="y") - plt.xticks(rotation=90, ha="right") + plt.xticks(fontsize=12) plt.tight_layout() if show_plots: plt.show() if save_plots: - plt.savefig(plot_cfg.plots_dir / f"{plot_title}.png") + plt.savefig(plot_cfg.plots_dir / f"{plot_title.replace('%', 'pct')}.png") plt.close() diff --git a/wind_up/plots/scada_funcs_plots.py b/wind_up/plots/scada_funcs_plots.py index 4a5cbe3..2233415 100644 --- a/wind_up/plots/scada_funcs_plots.py +++ b/wind_up/plots/scada_funcs_plots.py @@ -359,7 +359,7 @@ def plot_toggle_active_vs_reactive_power( t_dir = plot_cfg.plots_dir / wtg_name if sub_dir is None else plot_cfg.plots_dir / sub_dir t_dir.mkdir(exist_ok=True, parents=True) fig.savefig(t_dir / f"{plot_title}.png") - return None + return fig def compare_active_and_reactive_power_pre_post( @@ -372,7 +372,7 @@ def compare_active_and_reactive_power_pre_post( plot_cfg: PlotConfig, is_toggle_test: bool, sub_dir: str | None = None, -) -> None: +) -> plt.Figure | None: """Plot active vs reactive power Distinguishes data pre- and post-upgrade or toggled on/off (depending on `is_toggle_test`). @@ -381,10 +381,10 @@ def compare_active_and_reactive_power_pre_post( result_manager.warning( f"Column '{reactive_power_col}' not found, skipping reactive vs active power plot for {wtg_name}" ) - return + return None if is_toggle_test: - plot_toggle_active_vs_reactive_power( + return plot_toggle_active_vs_reactive_power( input_df=pd.concat([pre_df, post_df]), wtg_name=wtg_name, toggle_name="toggle", @@ -393,12 +393,11 @@ def compare_active_and_reactive_power_pre_post( plot_cfg=plot_cfg, sub_dir=sub_dir, ) - return pre_df_fake_toggle = pre_df.copy() post_df_fake_toggle = post_df.copy() pre_df_fake_toggle["test_toggle_off"] = True post_df_fake_toggle["test_toggle_on"] = True - plot_toggle_active_vs_reactive_power( + return plot_toggle_active_vs_reactive_power( input_df=pd.concat([pre_df_fake_toggle, post_df_fake_toggle]), wtg_name=wtg_name, toggle_name="upgrade", @@ -407,7 +406,6 @@ def compare_active_and_reactive_power_pre_post( plot_cfg=plot_cfg, sub_dir=sub_dir, ) - return def compare_ops_curves_pre_post( diff --git a/wind_up/plots/ws_est_plots.py b/wind_up/plots/ws_est_plots.py index 4ab9d68..6e36ec5 100644 --- a/wind_up/plots/ws_est_plots.py +++ b/wind_up/plots/ws_est_plots.py @@ -35,7 +35,7 @@ def plot_ws_est_gain_xs_one_ttype( plt.close() -def plot_ws_est_one_ttype_or_wtg( # noqa C901 PLR0915 +def plot_ws_est_one_ttype_or_wtg( df: pd.DataFrame, ttype_or_wtg: str, pc_transposed: pd.DataFrame, diff --git a/wind_up/plots/yaw_direction_plots.py b/wind_up/plots/yaw_direction_plots.py index 7c18553..16c0e6b 100644 --- a/wind_up/plots/yaw_direction_plots.py +++ b/wind_up/plots/yaw_direction_plots.py @@ -15,7 +15,7 @@ logger = logging.getLogger(__name__) -def plot_yaw_direction_pre_post_per_signal( # noqa:PLR0915 +def plot_yaw_direction_pre_post_per_signal( signal_name: str, test_wd_col: str, *,