Demonstrate energy ratio options#

The purpose of this notebook is to show some options in calculation of energy ratio

from pathlib import Path

import floris.layout_visualization as layoutviz
import matplotlib.pyplot as plt
import numpy as np
from floris import FlorisModel, TimeSeries

from flasc import FlascDataFrame
from flasc.analysis import energy_ratio as erp
from flasc.analysis.analysis_input import AnalysisInput
from flasc.data_processing import dataframe_manipulations as dfm

Generate dataset with FLORIS#

Use FLORIS to make a simple data set consisting of 4 turbines in a box, winds from the west, turbine 0/1 upstream, turbine 2/3 downstream

file_path = Path.cwd()
fm_path = file_path / "../floris_input_artificial/gch.yaml"
fm = FlorisModel(fm_path)
fm.set(layout_x=[0, 0, 5 * 126, 6 * 126], layout_y=[0, 5 * 126, 0, 5 * 126])

# # Show the wind farm
ax = layoutviz.plot_turbine_points(fm)
layoutviz.plot_turbine_labels(fm, ax=ax)
layoutviz.plot_waking_directions(fm, ax=ax)
ax.grid()
ax.set_xlabel("x coordinate [m]")
ax.set_ylabel("y coordinate [m]")
Text(0, 0.5, 'y coordinate [m]')
../../_images/0c80ac32135a7b5744d9dc6d956340a1df2abe4092c10e6e1ae725d2eff748a6.png
# Create a time history of points where the wind
# speed and wind direction step different combinations
ws_points = np.arange(5.0, 10.0, 1.0)
wd_points = np.arange(
    250.0,
    290.0,
    2,
)
num_points_per_combination = 5  # How many "seconds" per combination

# I know this is dumb but will come back, can't quite work out the numpy version
ws_array = []
wd_array = []
for ws in ws_points:
    for wd in wd_points:
        for i in range(num_points_per_combination):
            ws_array.append(ws)
            wd_array.append(wd)
t = np.arange(len(ws_array))
wd_array = np.array(wd_array)
ws_array = np.array(ws_array)

print(f"Num Points {len(t)}")

fig, axarr = plt.subplots(2, 1, sharex=True)
axarr[0].plot(t, ws_array, label="Wind Speed")
axarr[0].set_ylabel("m/s")
axarr[0].legend()
axarr[0].grid(True)
axarr[1].plot(t, wd_array, label="Wind Direction")
axarr[1].set_ylabel("deg")
axarr[1].legend()
axarr[1].grid(True)
Num Points 500
../../_images/4dadec2dacebd5080bd3133eaa9ecd660b2482b238af8f952189f6b5018117b0.png
# Compute the power of the second turbine for two cases
# Baseline: The front turbine is aligned to the wind
# WakeSteering: The front turbine is yawed 25 deg
fm.set(
    wind_data=TimeSeries(
        wind_directions=wd_array, wind_speeds=ws_array, turbulence_intensities=0.06
    )
)
fm.run()

# Collect the turbine powers
power_0 = fm.get_turbine_powers()[:, 0].flatten() / 1000.0
power_1 = fm.get_turbine_powers()[:, 1].flatten() / 1000.0
power_2 = fm.get_turbine_powers()[:, 2].flatten() / 1000.0
power_3 = fm.get_turbine_powers()[:, 3].flatten() / 1000.0

# Assume all turbine measure wind direction with some noise
wd_0 = wd_array + np.random.randn(len(wd_array)) * 2
wd_1 = wd_array + np.random.randn(len(wd_array)) * 2
wd_2 = wd_array + np.random.randn(len(wd_array)) * 2
wd_3 = wd_array + np.random.randn(len(wd_array)) * 2

# Only collect the wind speeds of the upstream turbines
ws_0 = ws_array + np.random.randn(len(wd_array)) * 1
ws_1 = ws_array + np.random.randn(len(wd_array)) * 1
# Now build the dataframe
df = FlascDataFrame(
    {
        "pow_000": power_0,
        "pow_001": power_1,
        "pow_002": power_2,
        "pow_003": power_3,
        "ws_000": ws_0,
        "ws_001": ws_1,
        "wd_000": wd_0,
        "wd_001": wd_1,
        "wd_002": wd_2,
        "wd_003": wd_3,
    }
)
# Build the energy ratio input
a_in = AnalysisInput([df], ["baseline"], num_blocks=10)
# Calculate and plot the energy ratio of turbine 2 with respect to
# turbine 0, using turbine 0's measurements of wind speed and wind direction
er_out = erp.compute_energy_ratio(
    a_in, test_turbines=[2], ref_turbines=[0], ws_turbines=[0], wd_turbines=[0], N=50
)
er_out.plot_energy_ratios()
array([<Axes: title={'center': 'Energy Ratio'}, ylabel='Energy Ratio'>,
       <Axes: title={'center': 'Number of Points per Bin'}, ylabel='Number of Points'>,
       <Axes: title={'center': 'Minimum Number of Points per Bin'}, xlabel='Wind Direction (deg)', ylabel='Wind Speed (m/s)'>],
      dtype=object)
../../_images/1796f4a425789ce610cbdc57a03b73f8dff924ecad7d2a8f118be525665b5d1e.png
# Reverse the above calculation showing the energy ratio of T0 / T2,
# letting T1 supply wind speed and direction
er_out = erp.compute_energy_ratio(
    a_in, test_turbines=[0], ref_turbines=[2], ws_turbines=[1], wd_turbines=[1], N=50
)
er_out.plot_energy_ratios()
array([<Axes: title={'center': 'Energy Ratio'}, ylabel='Energy Ratio'>,
       <Axes: title={'center': 'Number of Points per Bin'}, ylabel='Number of Points'>,
       <Axes: title={'center': 'Minimum Number of Points per Bin'}, xlabel='Wind Direction (deg)', ylabel='Wind Speed (m/s)'>],
      dtype=object)
../../_images/0e634a523897517d55c13ca5e3f9405b577a4ad2785cc46b243ae775d00fc29c.png
# Overplot the energy ratios of turbine 2 and 3, with respect to the averages of turbines 0 and 1
er_out_2 = erp.compute_energy_ratio(
    a_in, test_turbines=[2], ref_turbines=[0, 1], ws_turbines=[0, 1], wd_turbines=[0, 1], N=50
)

er_out_3 = erp.compute_energy_ratio(
    a_in, test_turbines=[3], ref_turbines=[0, 1], ws_turbines=[0, 1], wd_turbines=[0, 1], N=50
)

fig, axarr = plt.subplots(3, 1, sharex=True, figsize=(8, 11))

er_out_2.plot_energy_ratios(axarr=axarr, labels="T2")
er_out_3.plot_energy_ratios(
    axarr=axarr[0],
    show_wind_direction_distribution=False,
    show_wind_speed_distribution=False,
    labels="T3",
    color_dict={"T3": "r"},
)
<Axes: title={'center': 'Energy Ratio'}, xlabel='Wind Direction (deg)', ylabel='Energy Ratio'>
../../_images/3cf6ece58fbbd650e9bc50d257ffd5f7a6ed04fb39941989c12991213e370d5c.png

Illustrating pre-computing reference wind speed, direction and power#

# Use the FLASC function for defining wind speed and direction via upstream turbines

df = dfm.set_wd_by_all_turbines(df)
df = dfm.set_ws_by_turbines(df, [0.1])
df = dfm.set_pow_ref_by_turbines(df, [0.1])

df.head()
FlascDataFrame in user (wide) format
pow_000 pow_001 pow_002 pow_003 ws_000 ws_001 wd_000 wd_001 wd_002 wd_003 wd ws pow_ref
0 400.180232 400.180232 400.053966 400.171201 6.497291 5.261107 251.827514 249.201198 249.206996 246.489167 249.181231 6.497291 400.180232
1 400.180232 400.180232 400.053966 400.171201 3.994702 6.198364 249.290248 250.283107 252.071382 249.372538 250.254263 3.994702 400.180232
2 400.180232 400.180232 400.053966 400.171201 4.901322 5.517740 249.991292 246.153093 252.035584 250.390627 249.643009 4.901322 400.180232
3 400.180232 400.180232 400.053966 400.171201 5.171706 5.909239 253.289372 250.332129 247.841504 253.015991 251.119986 5.171706 400.180232
4 400.180232 400.180232 400.053966 400.171201 4.244166 5.336327 251.073826 248.876213 249.973891 249.778346 249.925565 4.244166 400.180232
# Now use the predefined values in the calculation of the average of turbines 2 and 3

a_in = AnalysisInput([df], ["baseline"], num_blocks=10)

er_out = erp.compute_energy_ratio(
    a_in,
    test_turbines=[2, 3],
    use_predefined_ref=True,
    use_predefined_wd=True,
    use_predefined_ws=True,
    N=50,
)
er_out.plot_energy_ratios()
array([<Axes: title={'center': 'Energy Ratio'}, ylabel='Energy Ratio'>,
       <Axes: title={'center': 'Number of Points per Bin'}, ylabel='Number of Points'>,
       <Axes: title={'center': 'Minimum Number of Points per Bin'}, xlabel='Wind Direction (deg)', ylabel='Wind Speed (m/s)'>],
      dtype=object)
../../_images/d1a4d7786eba26e855e9f9c99395e83ccb2de3c845d310fcb82a711342123b73.png