Skip to content
Snippets Groups Projects
Commit 21105c06 authored by Mads M. Pedersen's avatar Mads M. Pedersen
Browse files

Fix failing notebook, combinemodels.ipynb

parent 3df40a91
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id: tags:
# Experiment: Combine Models
In this notebook, you can combine the difference models of PyWake and see the effects in terms of AEP and a flow map.
%% Cell type:markdown id: tags:
**Install PyWake if needed**
%% Cell type:code id: tags:
``` python
# Install PyWake if needed
try:
import py_wake
except ModuleNotFoundError:
!pip install git+https://gitlab.windenergy.dtu.dk/TOPFARM/PyWake.git
```
%% Cell type:markdown id: tags:
**Now we also import all available models**
%% Cell type:code id: tags:
``` python
from py_wake.deficit_models import *
from py_wake.wind_farm_models import *
from py_wake.rotor_avg_models import *
from py_wake.superposition_models import *
from py_wake.deflection_models import *
from py_wake.turbulence_models import *
from py_wake.ground_models import *
from py_wake.deficit_models.utils import *
```
%% Cell type:markdown id: tags:
**Then, we set up the site, wind turbines as well as their initial positions**.
%% Cell type:code id: tags:
``` python
from py_wake.examples.data.iea37._iea37 import IEA37Site, IEA37_WindTurbines
site = IEA37Site(16)
windTurbines = IEA37_WindTurbines()
x,y = site.initial_position.T
```
%% Cell type:code id: tags:
``` python
# prepare for the model combination tool
from py_wake.utils.model_utils import get_models, get_signature
from ipywidgets import interact
from IPython.display import HTML, display, Javascript
import time
import matplotlib.pyplot as plt
# Fix ipywidget label width
display(HTML('''<style>.widget-label { min-width: 20ex !important; }</style>'''))
def print_signature(windFarmModel, **kwargs):
s = """# windFarmModel autogenerated by dropdown boxes
t = time.time()
wfm = %s
sim_res = wfm(x,y)
plt.figure(figsize=(12,8))
sim_res.flow_map(wd=270).plot_wake_map()
print (wfm)
print ("Computation time (AEP + flowmap):", time.time()-t)
plt.title('AEP: %%.2fGWh'%%(sim_res.aep().sum()))"""% get_signature(windFarmModel, kwargs, 1)
# Write windFarmModel code to cell starting "# windFarmModel autogenerated by dropdown boxes"
display(Javascript("""
for (var cell of IPython.notebook.get_cells()) {
if (cell.get_text().startsWith("# windFarmModel autogenerated by dropdown boxes")){
cell.set_text(`%s`);
cell.execute();
}
}"""%s))
# setup list of models
models = {n:[(getattr(m,'__name__',m), m) for m in get_models(cls)]
for n,cls in [('windFarmModel', WindFarmModel),
('wake_deficitModel', WakeDeficitModel),
('rotorAvgModel', RotorAvgModel),
('superpositionModel', SuperpositionModel),
('blockage_deficitModel', BlockageDeficitModel),
('deflectionModel',DeflectionModel),
('turbulenceModel', TurbulenceModel),
('groundModel', GroundModel)
]}
```
%% Output
%% Cell type:markdown id: tags:
### Combine and execute model
Combine your model via the dropdown boxes below.
Choosing a different model updates and executes the the code cell below which runs the wind farm model, prints the AEP and plots a flow map.
%% Cell type:code id: tags:
``` python
_ = interact(print_signature, **models)
```
%% Output
%% Cell type:code id: tags:
``` python
# windFarmModel autogenerated by dropdown boxes
t = time.time()
wfm = PropagateDownwind(
site,
windTurbines,
wake_deficitModel=NOJDeficit(
k=0.1,
rotorAvgModel=AreaOverlapAvgModel(),
groundModel=None),
superpositionModel=LinearSum(),
deflectionModel=None,
turbulenceModel=None,
rotorAvgModel=None)
sim_res = wfm(x,y)
plt.figure(figsize=(12,8))
sim_res.flow_map(wd=270).plot_wake_map()
print (wfm)
print ("Computation time (AEP + flowmap):", time.time()-t)
plt.title('AEP: %.2fGWh'%(sim_res.aep().sum()))
```
%% Output
PropagateDownwind(EngineeringWindFarmModel, NOJDeficit-wake, LinearSum-superposition)
Computation time (AEP + flowmap): 1.170867681503296
Text(0.5, 1.0, 'AEP: 355.83GWh')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment