<jupyter_start><jupyter_text>Exercise: Wake deflectionIn this exercise you can investigate the wake-deflection effects of yaw-misalignment<jupyter_code># Install PyWake if needed
try:
    import py_wake
except ModuleNotFoundError:
    !pip install git+https://gitlab.windenergy.dtu.dk/TOPFARM/PyWake.git
# setup site, wind turbines and wind farm model
from py_wake.examples.data.iea37._iea37 import IEA37Site, IEA37_WindTurbines
from py_wake.deficit_models.gaussian import IEA37SimpleBastankhahGaussian
from py_wake.deflection_models.jimenez import JimenezWakeDeflection
import numpy as np
from ipywidgets import interact
from ipywidgets import IntSlider
from py_wake.flow_map import HorizontalGrid
import matplotlib.pyplot as plt
site = IEA37Site(16)
x, y = [0, 600, 1200], [0, 0, 0]  # site.initial_position[:2].T
windTurbines = IEA37_WindTurbines()
wfm = IEA37SimpleBastankhahGaussian(site, windTurbines, deflectionModel=JimenezWakeDeflection())
# define function that plots the flow field and AEP history of 3 wind turbines
def plot_flow_field_and_aep(WT0, WT1):
    
    #_, (ax1, ax2) = plt.subplots(2,1,figsize=(20,6))
    ax1 = plt.figure(figsize=(20,4)).gca()
    ax2 = plt.figure(figsize=(10,3)).gca()
    
    sim_res = wfm(x, y, yaw=np.reshape([WT0,WT1,0],(3,1,1)), wd=270, ws=10)
    sim_res.flow_map(HorizontalGrid(x = np.linspace(0,1400,200), y=np.linspace(-200,200,50))).plot_wake_map(ax=ax1)
    ax1.set_xlim([-200,1400])
    aep.append(sim_res.aep().values[:,0,0])
    aep_arr = np.array(aep)                                     
    for i in range(3):
        ax2.plot(aep_arr[:,i], '.-', label='WT%d, %.2f'%(i,aep_arr[-1,i]))
    ax2.plot(aep_arr.sum(1), '.-', label='Total, %.2f'%aep_arr[-1].sum())
    ax2.axhline(aep_arr[0].sum(),ls='--',c='r')
    ax2.set_ylabel('AEP [GWh]')
    ax2.set_xlabel('Iteration')
    ax2.legend(loc='upper left')
    
    
# Run the plot_flow_field_and_aep function when moving the sliders
aep = []
_ = interact(plot_flow_field_and_aep, 
             WT0=IntSlider(min=-50, max=50, step=1, value=0, continuous_update=False),
             WT1=IntSlider(min=-50, max=50, step=1, value=0, continuous_update=False))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1404468764249886, 'fraction_numerical': 0.051527587779297765, 'mean_word_length': 4.568527918781726, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '156588', 'license': 'MIT', 'n_tokens_mistral': 907, 'n_tokens_neox': 853, 'n_words': 156, 'path': 'docs/notebooks/exercises/WakeDeflection.ipynb', 'repo_name': 'aemoser/PyWake', 'size': '2193'}