33from __future__ import annotations
44
55import os as os
6- from typing import Callable , List , Union
6+ from typing import Callable , Iterable , List , Union
77
88import matplotlib .pyplot as plt
99import numpy as np
@@ -89,7 +89,7 @@ def __init__(
8989
9090 def _load_a_input_for_wd_bias (
9191 self ,
92- wd_bias ,
92+ wd_bias : float ,
9393 ):
9494 """Load AnalysisInput objects with bias.
9595
@@ -158,16 +158,16 @@ def _load_a_input_for_wd_bias(
158158
159159 def _get_energy_ratios_allbins (
160160 self ,
161- wd_bias ,
162- time_mask = None ,
163- ws_mask = (6.0 , 10.0 ),
164- wd_mask = None ,
165- ti_mask = None ,
166- wd_step = 3.0 ,
167- ws_step = 1.0 ,
168- wd_bin_width = 3.0 ,
169- N_btstrp = 1 ,
170- plot_iter_path = None ,
161+ wd_bias : float ,
162+ time_mask : None = None ,
163+ ws_mask : Iterable [ float , float ] = (6.0 , 10.0 ),
164+ wd_mask : Iterable [ float , float ] | None = None ,
165+ ti_mask : None = None ,
166+ wd_step : float = 3.0 ,
167+ ws_step : float = 1.0 ,
168+ wd_bin_width : float = 3.0 ,
169+ N_btstrp : int = 1 ,
170+ plot_iter_path : str | None = None ,
171171 ):
172172 """Calculate the energy ratios.
173173
@@ -177,8 +177,7 @@ def _get_energy_ratios_allbins(
177177 the data based on this variable. Defaults to None.
178178 ws_mask ([iterable], optional): Wind speed mask. Should be an
179179 iterable of length 2, e.g., [6.0, 10.0], defining the lower
180- and upper bound, respectively. If not specified, will not
181- mask the data based on this variable. Defaults to (6, 10).
180+ and upper bound, respectively. Defaults to (6, 10).
182181 wd_mask ([iterable], optional): Wind direction mask. Should
183182 be an iterable of length 2, e.g., [0.0, 180.0], defining
184183 the lower and upper bound, respectively. If not specified,
@@ -233,7 +232,7 @@ def _get_energy_ratios_allbins(
233232
234233 for ii , ti in enumerate (self .test_turbines ):
235234 self .logger .info (
236- " Determining energy ratios for test turbine = %03d." % ( ti )
235+ " Determining energy ratios for test turbine = %03d." % ti
237236 + " WD bias: %.3f deg." % wd_bias
238237 )
239238
@@ -420,9 +419,14 @@ def estimate_wd_bias(
420419 """
421420 self .logger .info ("Estimating the wind direction bias" )
422421
423- def cost_fun (wd_bias ):
422+ def cost_fun (x : np .ndarray ):
423+ """Cost function to minimize.
424+
425+ Args:
426+ x (np.ndarray): Wind direction bias to evaluate. 1D array with 1 element.
427+ """
424428 self ._get_energy_ratios_allbins (
425- wd_bias = wd_bias ,
429+ wd_bias = x [ 0 ], # pass as float
426430 time_mask = time_mask ,
427431 ws_mask = ws_mask ,
428432 wd_mask = wd_mask ,
@@ -467,7 +471,7 @@ def opt_finish(func, x0, args=()):
467471 # workers=opt_workers,
468472 )
469473
470- wd_bias = x_opt
474+ wd_bias = x_opt [ 0 ]
471475 self .opt_wd_bias = wd_bias
472476 self .opt_cost = J_opt
473477 self .opt_wd_grid = x
@@ -476,7 +480,7 @@ def opt_finish(func, x0, args=()):
476480 # End with optimal results and bootstrapping
477481 self .logger .info (" Evaluating optimal solution with bootstrapping" )
478482 self ._get_energy_ratios_allbins (
479- wd_bias = x_opt ,
483+ wd_bias = wd_bias ,
480484 time_mask = time_mask ,
481485 ws_mask = ws_mask ,
482486 wd_mask = wd_mask ,
@@ -530,7 +534,7 @@ def plot_energy_ratios(
530534 er_out_test_turbine_list_scada_copy = self .er_out_test_turbine_list_scada .copy ()
531535 # (Re)compute case with wd_bias=0
532536 self ._get_energy_ratios_allbins (
533- wd_bias = 0 ,
537+ wd_bias = 0.0 ,
534538 time_mask = self ._input_args ["time_mask" ],
535539 ws_mask = self ._input_args ["ws_mask" ],
536540 wd_mask = self ._input_args ["wd_mask" ],
0 commit comments