flasc.utilities.optimization#

Module for optimization functions.

Functions

estimate_ti

Estimate the turbulence intensity for a given turbine.

find_timeshift_between_dfs

Find the optimal time shift between two dataframes.

match_y_curves_by_offset

Match two curves by finding the optimal offset.

flasc.utilities.optimization.find_timeshift_between_dfs(df1, df2, cols_df1, cols_df2, use_circular_statistics=False, t_step=numpy.timedelta64(720, 'h'), correct_y_shift=False, y_shift_range=array([-180., -178., -176., -174., -172., -170., -168., -166., -164., -162., -160., -158., -156., -154., -152., -150., -148., -146., -144., -142., -140., -138., -136., -134., -132., -130., -128., -126., -124., -122., -120., -118., -116., -114., -112., -110., -108., -106., -104., -102., -100., -98., -96., -94., -92., -90., -88., -86., -84., -82., -80., -78., -76., -74., -72., -70., -68., -66., -64., -62., -60., -58., -56., -54., -52., -50., -48., -46., -44., -42., -40., -38., -36., -34., -32., -30., -28., -26., -24., -22., -20., -18., -16., -14., -12., -10., -8., -6., -4., -2., 0., 2., 4., 6., 8., 10., 12., 14., 16., 18., 20., 22., 24., 26., 28., 30., 32., 34., 36., 38., 40., 42., 44., 46., 48., 50., 52., 54., 56., 58., 60., 62., 64., 66., 68., 70., 72., 74., 76., 78., 80., 82., 84., 86., 88., 90., 92., 94., 96., 98., 100., 102., 104., 106., 108., 110., 112., 114., 116., 118., 120., 122., 124., 126., 128., 130., 132., 134., 136., 138., 140., 142., 144., 146., 148., 150., 152., 154., 156., 158., 160., 162., 164., 166., 168., 170., 172., 174., 176., 178.]), opt_bounds=None, opt_Ns=None, verbose=True)[source]#

Find the optimal time shift between two dataframes.

This function is used to find the optimal time shift between two dataframes 'df1' and 'df2'. The function will resample the dataframes to a common time vector and then compare the dataframes in time steps of 't_step'. The function will then find the optimal time shift between the two dataframes by minimizing the Pearson correlation coefficient between the two dataframes. The function can also correct for a bias in the y-values of the dataframes by minimizing the Pearson correlation coefficient between the two dataframes after a bias has been removed.

Parameters:
  • df1 (pd.DataFrame) -- Dataframe 1.

  • df2 (pd.DataFrame) -- Dataframe 2.

  • cols_df1 (list) -- Columns to use in dataframe 1.

  • cols_df2 (list) -- Columns to use in dataframe 2.

  • use_circular_statistics (bool) -- Use circular statistics for averaging. Default is False.

  • t_step (np.timedelta64) -- Time step for comparison. Default is 30 days.

  • correct_y_shift (bool) -- Correct for a bias in the y-values. Default is False.

  • y_shift_range (np.array) -- Range of y-shifts to evaluate. Default is np.arange(-180.0, 180.0, 2.0).

  • opt_bounds (list) -- Bounds for optimization. Default is None.

  • opt_Ns (int) -- Number of steps for optimization. Default is None.

  • verbose (bool) -- Print verbose output. Default is True.

Returns:

List of dictionaries with the following keys:
  • t0: Start time of comparison.

  • t1: End time of comparison.

  • x_opt: Optimal time shift.

  • J_opt: Optimal cost function value.

  • x: Time shifts evaluated.

  • J: Cost function values evaluated.

Return type:

list

flasc.utilities.optimization.match_y_curves_by_offset(yref, ytest, dy_eval=None, angle_wrapping=True)[source]#

Match two curves by finding the optimal offset.

This function is used to match two curves by finding the optimal offset between the two curves. The function will minimize the mean squared error between the two curves for a range of offsets.

Parameters:
  • yref (np.array) -- Reference curve.

  • ytest (np.array) -- Test curve.

  • dy_eval (np.array) -- Range of offsets to evaluate. Default is None.

  • angle_wrapping (bool) -- Use angle wrapping for evaluation. Default is True.

Returns:

dwd_opt: Optimal offset. J_opt: Optimal cost function value.

Return type:

Tuple (float, float) with the following elements

flasc.utilities.optimization.estimate_ti(fm, P_measured, Ns, bounds, turbine_upstream, turbines_downstream, refine_with_fmin=False, verbose=False)[source]#

Estimate the turbulence intensity for a given turbine.

This function is used to estimate the turbulence intensity for a given turbine.

Parameters:
  • fm (FlorisModel) -- FlorisModel object.

  • P_measured (np.array) -- Measured power data.

  • Ns (int) -- Number of steps for optimization.

  • bounds (list) -- Bounds for optimization.

  • turbine_upstream (int) -- Upstream turbine.

  • turbines_downstream (list) -- Downstream turbines.

  • refine_with_fmin (bool) -- Refine with fmin. Default is False.

  • verbose (bool) -- Print verbose output. Default is False.

Returns:

Dictionary with the following

keys: - x_opt: Optimal time shift. - J_opt: Optimal cost function value. - x: Time shifts evaluated. - J: Cost function values evaluated.

Return type:

dict