Skip to content

Commit

Permalink
remove benchmarking call and run linting
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielecalvo committed Jan 13, 2025
1 parent 404f2ee commit 1ab60fd
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 33 deletions.
2 changes: 1 addition & 1 deletion examples/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def download_zenodo_data(
if len(files_to_download) != len(filenames):
msg = (
f"Could not find all files in the Zenodo record. "
f"Missing files: {set(filenames) - {i['key'] for i in files_to_download} }"
f"Missing files: {set(filenames) - {i['key'] for i in files_to_download}}"
)
raise ValueError(msg)

Expand Down
5 changes: 2 additions & 3 deletions tests/test_windspeed_drift.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,15 @@ def test_check_windspeed_drift(test_lsa_t13_config: WindUpConfig) -> None:
assert test_max_ws_drift_pp_period == pytest.approx(0.42913942378401204)


def test_calc_rolling_windspeed_diff(benchmark) -> None:
def test_calc_rolling_windspeed_diff() -> None:
n_values = 50
timestep = pd.Timedelta("6h")
ts_index = pd.date_range("2020-01-01", periods=n_values, freq=timestep)
ws_col_vals = np.linspace(5, 15, n_values)
test_df = pd.DataFrame({"ws_col": ws_col_vals, "reanalysis_ws_col": ws_col_vals[::-1]}, index=ts_index)

original = test_df.copy()
actual = benchmark(
_calculate_rolling_windspeed_diff,
actual = _calculate_rolling_windspeed_diff(
wtg_df=test_df,
ws_col="ws_col",
reanalysis_ws_col="reanalysis_ws_col",
Expand Down
2 changes: 1 addition & 1 deletion wind_up/detrend.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def check_applied_detrend(
)
else:
result_manager.warning(
f"post_r2_after_detrend < post_r2_before_detrend," f" {post_r2_after_detrend} < {post_r2_before_detrend}"
f"post_r2_after_detrend < post_r2_before_detrend, {post_r2_after_detrend} < {post_r2_before_detrend}"
)

if plot_cfg is not None:
Expand Down
2 changes: 1 addition & 1 deletion wind_up/long_term.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def calc_lt_df(
raise RuntimeError(msg)

logger.info(f"long term distribution uses data from {df_for_lt.index.min()} to {df_for_lt.index.max()}")
logger.info(f"long term distribution data coverage: {data_coverage*100:.1f}%")
logger.info(f"long term distribution data coverage: {data_coverage * 100:.1f}%")

return lt_df

Expand Down
6 changes: 3 additions & 3 deletions wind_up/main_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def yaw_offset_results(
result_name = "mean_test_yaw_offset_command_pre"
results[result_name] = pre_df.dropna(subset=required_pp_cols)["test_yaw_offset_command"].mean()
if results[result_name] > yaw_offset_ul:
result_manager.warning(f"{result_name} > 0: " f"({results[result_name]})")
result_manager.warning(f"{result_name} > 0: ({results[result_name]})")

results["mean_test_yaw_offset_command_post"] = post_df.dropna(subset=required_pp_cols)[
"test_yaw_offset_command"
Expand All @@ -356,12 +356,12 @@ def yaw_offset_results(
result_name = "mean_ref_yaw_offset_command_pre"
results[result_name] = pre_df.dropna(subset=required_pp_cols)["ref_yaw_offset_command"].mean()
if results[result_name] > yaw_offset_ul:
result_manager.warning(f"{result_name} > 0 for: " f"({results[result_name]})")
result_manager.warning(f"{result_name} > 0 for: ({results[result_name]})")

result_name = "mean_ref_yaw_offset_command_pre"
results[result_name] = post_df.dropna(subset=required_pp_cols)["ref_yaw_offset_command"].mean()
if results[result_name] > yaw_offset_ul:
result_manager.warning(f"{result_name} > 0 for: " f"({results[result_name]})")
result_manager.warning(f"{result_name} > 0 for: ({results[result_name]})")
return results


Expand Down
4 changes: 2 additions & 2 deletions wind_up/plots/combine_results_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def plot_combine_results(trdf: pd.DataFrame, tdf: pd.DataFrame, plot_cfg: PlotCo
plt.bar(labels, values, yerr=yerrs, capsize=3)
plt.xlabel("turbine")
plt.ylabel("uplift [%]")
plot_title = f"uplift and {confidence*100:.0f}% CI by test-ref pair"
plot_title = f"uplift and {confidence * 100:.0f}% CI by test-ref pair"
plt.title("uplift by test-ref pair")
plt.grid(axis="y")
plt.xticks(rotation=90, ha="right")
Expand All @@ -41,7 +41,7 @@ def plot_combine_results(trdf: pd.DataFrame, tdf: pd.DataFrame, plot_cfg: PlotCo
plt.bar(labels, values, yerr=yerrs, capsize=3)
plt.xlabel("turbine")
plt.ylabel("uplift [%]")
plot_title = f"combined uplift and {confidence*100:.0f}% CI"
plot_title = f"combined uplift and {confidence * 100:.0f}% CI"
plt.title(plot_title)
plt.grid(axis="y")
plt.xticks(rotation=90, ha="right")
Expand Down
12 changes: 6 additions & 6 deletions wind_up/plots/pp_analysis_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,10 +447,10 @@ def plot_pre_post_pp_analysis(

plt.figure()
plt.plot(pp_df["bin_mid"], pp_df["uplift_kw"], color="b", marker="s")
plt.plot(pp_df["bin_mid"], pp_df[f"uplift_p{p_low*100:.0f}_kw"], color="r", ls="--")
plt.plot(pp_df["bin_mid"], pp_df[f"uplift_p{p_high*100:.0f}_kw"], color="r", ls="--")
plt.plot(pp_df["bin_mid"], pp_df[f"uplift_p{p_low * 100:.0f}_kw"], color="r", ls="--")
plt.plot(pp_df["bin_mid"], pp_df[f"uplift_p{p_high * 100:.0f}_kw"], color="r", ls="--")
plt.grid()
plot_title = f"test={test_name} ref={ref_name} uplift [kW] and {confidence_level*100:.0f}% CI"
plot_title = f"test={test_name} ref={ref_name} uplift [kW] and {confidence_level * 100:.0f}% CI"
plt.title(plot_title)
plt.ylabel("uplift [kW]")
plt.xlabel("bin centre [m/s]")
Expand Down Expand Up @@ -478,18 +478,18 @@ def plot_pre_post_pp_analysis(
)
plt.plot(
pp_df["bin_mid"],
pp_df[f"uplift_p{p_low*100:.0f}_kw"] * pp_df["hours_for_mwh_calc"].sum() * pp_df["f"] / 1000,
pp_df[f"uplift_p{p_low * 100:.0f}_kw"] * pp_df["hours_for_mwh_calc"].sum() * pp_df["f"] / 1000,
color="r",
ls="--",
)
plt.plot(
pp_df["bin_mid"],
pp_df[f"uplift_p{p_high*100:.0f}_kw"] * pp_df["hours_for_mwh_calc"].sum() * pp_df["f"] / 1000,
pp_df[f"uplift_p{p_high * 100:.0f}_kw"] * pp_df["hours_for_mwh_calc"].sum() * pp_df["f"] / 1000,
color="r",
ls="--",
)
plt.grid()
plot_title = f"test={test_name} ref={ref_name} uplift [MWh] and {confidence_level*100:.0f}% CI"
plot_title = f"test={test_name} ref={ref_name} uplift [MWh] and {confidence_level * 100:.0f}% CI"
plt.title(plot_title)
plt.ylabel("uplift [MWh]")
plt.xlabel("bin centre [m/s]")
Expand Down
2 changes: 1 addition & 1 deletion wind_up/plots/scada_funcs_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def print_and_plot_capacity_factor(scada_df: pd.DataFrame, cfg: WindUpConfig, pl
show_plot=plots_cfg.show_plots,
)

logger.info(f'average capacity factor: {cf_df["CF"].mean() * 100:.1f}%')
logger.info(f"average capacity factor: {cf_df['CF'].mean() * 100:.1f}%")
_table = tabulate(
(cf_df.sort_values(by="CF", ascending=False)["CF"][0:3] * 100).to_frame(),
tablefmt="outline",
Expand Down
4 changes: 2 additions & 2 deletions wind_up/plots/windspeed_drift_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@

def plot_rolling_windspeed_diff_one_wtg(
*,
wtg_df: pd.DataFrame,
ser: pd.DataFrame,
wtg_name: str,
ws_col: str,
plot_cfg: PlotConfig,
sub_dir: str | None,
) -> None:
plt.figure()
plt.plot(wtg_df["rolling_windspeed_diff"])
plt.plot(ser["rolling_windspeed_diff"])
plot_title = f"{wtg_name} rolling {ws_col} diff to reanalysis"
plt.title(plot_title)
plt.xlabel("datetime")
Expand Down
8 changes: 4 additions & 4 deletions wind_up/plots/yaw_direction_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ def plot_yaw_direction_pre_post_per_signal(
label=post_label,
)
plt.xlabel(f"{ref_wd_col} [deg]")
plt.ylabel(f'{signal_name.replace("_", " ")} [deg]')
plt.ylabel(f"{signal_name.replace('_', ' ')} [deg]")
plt.grid()

plot_title = (
f"{test_name} ref {ref_name} yaw direction scatter"
if signal_name == "yaw_offset"
else f'{test_name} ref {ref_name} {signal_name.replace("_", " ")} scatter'
else f"{test_name} ref {ref_name} {signal_name.replace('_', ' ')} scatter"
)
plt.suptitle(plot_title)
if plot_cfg.show_plots:
Expand Down Expand Up @@ -144,7 +144,7 @@ def _get_mid(x: float | pd.Interval) -> float:
linewidths=0.5,
vmin=0,
vmax=20,
cbar_kws={"label": f"{signal_name.replace('_',' ')} [deg]"},
cbar_kws={"label": f"{signal_name.replace('_', ' ')} [deg]"},
)

plt.xlabel("wind direction bin centre [deg]")
Expand All @@ -153,7 +153,7 @@ def _get_mid(x: float | pd.Interval) -> float:
signal_descr = (
f"{ref_name} minus {test_name} yaw direction"
if signal_name == "yaw_offset"
else f'{test_name} ref {ref_name} {signal_name.replace("_", " ")}'
else f"{test_name} ref {ref_name} {signal_name.replace('_', ' ')}"
)
plot_title = f"{signal_descr} vs ws and wd {label}"
plt.suptitle(plot_title)
Expand Down
18 changes: 9 additions & 9 deletions wind_up/pp_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ def pre_post_pp_analysis_with_reversal(
logger.info(f"\nresults for test={test_wtg.name} ref={ref_name}:\n")
logger.info(f"hours pre = {pp_results['pp_valid_hours_pre']:.1f}")
logger.info(f"hours post = {pp_results['pp_valid_hours_post']:.1f}")
logger.info(f"\nuplift estimate before adjustments = {100*pp_results['uplift_frc']:.1f} %")
logger.info(f"\nuplift estimate before adjustments = {100 * pp_results['uplift_frc']:.1f} %")

logger.info(f"\npower only uplift estimate = {100 * poweronly_uplift_frc:.1f} %")
logger.info(f"reversed (power only) uplift estimate = {100 * reversed_uplift_frc:.1f} %\n")
Expand Down Expand Up @@ -545,11 +545,11 @@ def pre_post_pp_analysis_with_reversal_and_bootstrapping(

if plot_cfg is not None:
msg = (
f"block bootstrapping uncertainty analysis results (conf={100*confidence_level:.0f}%):"
f"\n median = {100*median:.1f} %"
f"\n lower = {100*lower:.1f} %"
f"\n upper = {100*upper:.1f} %"
f"\n unc_one_sigma = {100*unc_one_sigma:.1f} %"
f"block bootstrapping uncertainty analysis results (conf={100 * confidence_level:.0f}%):"
f"\n median = {100 * median:.1f} %"
f"\n lower = {100 * lower:.1f} %"
f"\n upper = {100 * upper:.1f} %"
f"\n unc_one_sigma = {100 * unc_one_sigma:.1f} %"
)
logger.info(msg)

Expand Down Expand Up @@ -578,8 +578,8 @@ def pre_post_pp_analysis_with_reversal_and_bootstrapping(
logger.info(f"missing bins scale factor = {pp_results['missing_bins_unc_scale_factor']:.3f}")
logger.info(f"final 1 sigma unc = {100 * pp_results['unc_one_sigma_frc']:.1f} %\n")

logger.info(f"final uplift estimate = {100*pp_results['uplift_frc']:.1f} %")
logger.info(f"final P95 uplift estimate = {100*pp_results[f'uplift_p{p_high * 100:.0f}_frc']:.1f} %")
logger.info(f"final P5 uplift estimate = {100*pp_results[f'uplift_p{p_low * 100:.0f}_frc']:.1f} %")
logger.info(f"final uplift estimate = {100 * pp_results['uplift_frc']:.1f} %")
logger.info(f"final P95 uplift estimate = {100 * pp_results[f'uplift_p{p_high * 100:.0f}_frc']:.1f} %")
logger.info(f"final P5 uplift estimate = {100 * pp_results[f'uplift_p{p_low * 100:.0f}_frc']:.1f} %")

return pp_results, pp_df

0 comments on commit 1ab60fd

Please sign in to comment.