Skip to content

Commit

Permalink
refactor: log the curve shift value sign in the warning message
Browse files Browse the repository at this point in the history
Display the sign (+/-) of the curve shift value in the log warning
message for clarity of the actual shift rather than just displaying the
abs() value that is used when determining whether to raise a log warning
  • Loading branch information
samuelwnaylor committed Nov 19, 2024
1 parent 699be85 commit a56d21c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
1 change: 1 addition & 0 deletions tests/test_ops_curve_shift.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ def test_calculate_power_curve_shift(

if abs(expected) > CURVE_CONSTANTS[CurveTypes.POWER_CURVE.value]["warning_threshold"]:
assert "Ops Curve Shift warning" in caplog.text
assert f": {actual:.3f}" in caplog.text # check the actual value (including its +/- sign) is in the log message

np.testing.assert_almost_equal(actual=actual, desired=expected)

Expand Down
6 changes: 2 additions & 4 deletions wind_up/ops_curve_shift.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def _calculate_curve_shift(curve_shift_input: CurveShiftInput) -> float:
post_df = curve_shift_input.post_df
wtg_name = curve_shift_input.turbine_name

bins = np.arange(0, pre_df[conf.x_col].max() + conf.x_bin_width, conf.x_bin_width) if conf.x_bin_width > 0 else 10 # type: ignore[operator]
bins = np.arange(0, pre_df[conf.x_col].max() + conf.x_bin_width, conf.x_bin_width) if conf.x_bin_width > 0 else 10 # type: ignore[operator,var-annotated]

mean_curve = pre_df.groupby(pd.cut(pre_df[conf.x_col], bins=bins, retbins=False), observed=True).agg(
x_mean=pd.NamedAgg(column=conf.x_col, aggfunc="mean"),
Expand All @@ -224,9 +224,7 @@ def _calculate_curve_shift(curve_shift_input: CurveShiftInput) -> float:

# log warning
if abs(result) > conf.warning_threshold:
warning_msg = (
f"{wtg_name} Ops Curve Shift warning: abs({conf.name}) > {conf.warning_threshold}: {abs(result):.3f}"
)
warning_msg = f"{wtg_name} Ops Curve Shift warning: abs({conf.name}) > {conf.warning_threshold}: {result:.3f}"
result_manager.warning(warning_msg)

return result

0 comments on commit a56d21c

Please sign in to comment.