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

Add test of exercise notebooks

parent cc0a11f0
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id: tags:
# Exercise: Combine Models
In this exercise you can combine the difference models of py_wake and see the effects in terms of AEP and a flow map
%% 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:code id: tags:
``` python
# Importing all required modules
import time
import inspect
from ipywidgets import interact
from py_wake.examples.data.iea37._iea37 import IEA37Site, IEA37_WindTurbines
from py_wake.wind_farm_models.engineering_models import PropagateDownwind, All2AllIterative
from py_wake import deficit_models
from py_wake.deficit_models import DeficitModel
from py_wake.deficit_models import NOJDeficit, GCLDeficit
from py_wake.deficit_models.fuga import FugaDeficit
from py_wake.deficit_models.selfsimilarity import SelfSimilarityDeficit
from py_wake.rotor_avg_models.rotor_avg_model import RotorCenter,CGIRotorAvg, EqGridRotorAvg
from py_wake import superposition_models
from py_wake.superposition_models import SuperpositionModel
from py_wake import turbulence_models
from py_wake.turbulence_models.turbulence_model import TurbulenceModel
from py_wake.examples.data.iea37._iea37 import IEA37Site, IEA37_WindTurbines
import matplotlib.pyplot as plt
```
%% Cell type:code id: tags:
``` python
# Setup site, wind turbines
site = IEA37Site(16)
wt = IEA37_WindTurbines()
x,y = site.initial_position.T
```
%% Cell type:code id: tags:
``` python
# setup some utility functions
def get_models(module, baseclass, ignore=set()):
ignore.add(baseclass)
return [(v.__name__, v) for v in module.__dict__.values() if inspect.isclass(v) and issubclass(v, baseclass) and v not in ignore]
def run(WindFarmModel, WakeDeficitModel, RotorAvgModel, SuperpositionModel, BlockageDeficitModel, TurbulenceModel):
if inspect.isclass(WakeDeficitModel):
WakeDeficitModel = WakeDeficitModel()
kwargs = {}
if WindFarmModel==All2AllIterative:
kwargs['blockage_deficitModel'] = BlockageDeficitModel
wfm = WindFarmModel(site, wt, wake_deficitModel=WakeDeficitModel, rotorAvgModel=RotorAvgModel, superpositionModel=SuperpositionModel(),
turbulenceModel=TurbulenceModel(),**kwargs)
t = time.time()
sim_res = wfm(x,y)
plt.figure(figsize=(12,8))
sim_res.flow_map(wd=270).WS_eff.plot()
print ("Computation time (AEP + flowmap):", time.time()-t)
plt.title('AEP: %.2fGWh'%(sim_res.aep().sum()))
wt.plot(x,y,wd=270)
```
%% Cell type:code id: tags:
``` python
# setup available models
models = {
'WindFarmModel':[('PropagateDownwind', PropagateDownwind),
('All2AllIterative', All2AllIterative)],
'WakeDeficitModel':get_models(deficit_models, DeficitModel, {SelfSimilarityDeficit}) + [
('NOJDeficit_ws_eff',NOJDeficit(use_effective_ws=True)),
('GCLDeficit_ws_eff',GCLDeficit(use_effective_ws=True)),
],
'RotorAvgModel':[('RotorCenter', RotorCenter()),
('CGIRotorAvg_4', EqGridRotorAvg(4)),
('EqGridRotorAvg_4x4', EqGridRotorAvg(4)),
('EqGridRotorAvg_100x100', EqGridRotorAvg(100))
],
'SuperpositionModel':get_models(superposition_models, SuperpositionModel),
'BlockageDeficitModel':[('None',None),
('SelfSimilarityDeficit',SelfSimilarityDeficit()),
('FugaDeficit', FugaDeficit())],
'TurbulenceModel':get_models(turbulence_models, TurbulenceModel)
}
```
%% Cell type:code id: tags:
``` python
_ = interact(run, **models)
```
%% Output
%% Cell type:markdown id: tags:
Note, the only the All2AllIterative WindFarmModel supports blockage
......
Source diff could not be displayed: it is too large. Options to address this: view the blob.
......@@ -8,8 +8,10 @@ from py_wake.flow_map import Grid
def get_notebooks():
def get(path):
return [Notebook(path + f) for f in [f for f in os.listdir(path) if f.endswith('.ipynb')]]
path = os.path.dirname(py_wake.__file__) + "/../docs/notebooks/"
return [Notebook(path + f) for f in [f for f in os.listdir(path) if f.endswith('.ipynb')]]
return get(path) + get(path + "exercises/")
@pytest.mark.parametrize("notebook", get_notebooks())
......
......@@ -44,6 +44,7 @@ setup(name='py_wake',
'tqdm', # progressbar
'sphinx', # generating documentation
'sphinx_rtd_theme', # docs theme
'ipywidgets', # notebook widgets
],
zip_safe=True)
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