diff --git a/docs/notebooks/Site.ipynb b/docs/notebooks/Site.ipynb index 71a28d8140937175682aa5dda22d42a372a5c334..12c1bbb30f3ec0303e0a6b7463960d9d424a5aa2 100644 --- a/docs/notebooks/Site.ipynb +++ b/docs/notebooks/Site.ipynb @@ -18,7 +18,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Predefined example sites\n", + "## Predefined example sites\n", "PyWake contains a few predefined sites of different complexities:\n", "- IEA37Site: `UniformSite` (fix wind speed (9.8m/s), predefined wind sector probability)\n", "- Hornsrev1: `UniformWeibullSite` (weibull distributed wind speed, predefined wind sector propability, uniform wind a over flat wind area)\n", @@ -27,7 +27,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -40,7 +40,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -55,6 +55,93 @@ " \"ParqueFicticio\": ParqueFicticioSite()}" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Define your own site\n", + "You can define your own site using one of the `Site` classes:\n", + "\n", + "- [UniformWeibullSite](#UniformWeibullSite): Site with uniform sector-dependent weibull distributed wind speed\n", + "- [WaspGridSite](#WaspGridSite): Site with gridded non-uniform inflow based on *.grd files exported from WAsP\n", + "- [XRSite](#XRSite): The flexible general base class behind all Sites\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### UniformWeibullSite" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [], + "source": [ + "from py_wake.site import UniformWeibullSite\n", + "site = UniformWeibullSite(p_wd = [.20,.25,.35,.25], # sector frequencies\n", + " a = [9.176929, 9.782334, 9.531809, 9.909545], # Weibull scale parameter\n", + " k = [2.392578, 2.447266, 2.412109, 2.591797], # Weibull shape parameter\n", + " ti = 0.1 # turbulence intensity, optional (not needed in all cases)\n", + " )" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### WaspGridSite" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [], + "source": [ + "from py_wake.site import WaspGridSite\n", + "from py_wake.examples.data.ParqueFicticio import ParqueFicticio_path\n", + "site = WaspGridSite.from_wasp_grd(ParqueFicticio_path)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### XRSite\n", + "\n", + "The `XRSite` is the most general and flexible `Site`. It takes a xarray dataset with some required and optional data variables. Each variable may be constant or depend on any combination of:\n", + "\n", + "- ws: Reference wind speed\n", + "- wd: Refernce wind direction \n", + "- i: Wind turbine position (one position per wind turbine)\n", + "- x,y: Gridded 2d position\n", + "- x,y,h: Gridded 3d position\n", + "- time: Time\n", + "\n", + "\n", + "**Required data variables**:\n", + "- `P`: probability of flow case(s)\n", + "\n", + "or\n", + "\n", + "- `Weibull_A`: Weibull scale parameter(s)\n", + "- `Weibull_k`: Weibull shape parameter(s)\n", + "- `Sector_frequency`: Probability of each wind direction sector\n", + "\n", + "**Optional data variables**\n", + "- `WS`: Wind speed, if not present, the reference wind speed `ws` is used\n", + "- `Speedup`: Factor multiplied to the wind speed\n", + "- `Turning`: Wind direction turning\n", + "- `TI`: Turbulence intensity\n", + "- xxx: Custom variables needed by the wind turbines to compute power, ct or loads\n", + "\n", + "**Examples**\n", + "Examples can be found in the top of https://gitlab.windenergy.dtu.dk/TOPFARM/PyWake/-/blob/master/py_wake/tests/test_sites/test_xrsite.py" + ] + }, { "cell_type": "markdown", "metadata": {}, diff --git a/py_wake/site/xrsite.py b/py_wake/site/xrsite.py index d31cc96c18e637b2f4c939702dc19af1b9717cf0..af53d989cd572d6b65b0ca421af8f426a4018c86 100644 --- a/py_wake/site/xrsite.py +++ b/py_wake/site/xrsite.py @@ -263,11 +263,12 @@ class UniformSite(XRSite): constant wind speed probability of 1. Only for one fixed wind speed """ - def __init__(self, p_wd, ti, ws=12, interp_method='nearest', shear=None, initial_position=None): + def __init__(self, p_wd, ti=None, ws=12, interp_method='nearest', shear=None, initial_position=None): ds = xr.Dataset( - data_vars={'P': ('wd', p_wd), 'TI': ti}, + data_vars={'P': ('wd', p_wd)}, coords={'wd': np.linspace(0, 360, len(p_wd), endpoint=False)}) - + if ti is not None: + ds['TI'] = ti XRSite.__init__(self, ds, interp_method=interp_method, shear=shear, initial_position=initial_position, default_ws=np.atleast_1d(ws)) @@ -277,7 +278,7 @@ class UniformWeibullSite(XRSite): weibull distributed wind speed """ - def __init__(self, p_wd, a, k, ti, interp_method='nearest', shear=None): + def __init__(self, p_wd, a, k, ti=None, interp_method='nearest', shear=None): """Initialize UniformWeibullSite Parameters @@ -288,7 +289,7 @@ class UniformWeibullSite(XRSite): Weilbull scaling parameter of wind direction sectors k : array_like Weibull shape parameter - ti : float or array_like + ti : float or array_like, optional Turbulence intensity interp_method : 'nearest', 'linear' p_wd, a, k, ti and alpha are interpolated to 1 deg sectors using this @@ -303,6 +304,8 @@ class UniformWeibullSite(XRSite): """ ds = xr.Dataset( - data_vars={'Sector_frequency': ('wd', p_wd), 'Weibull_A': ('wd', a), 'Weibull_k': ('wd', k), 'TI': ti}, + data_vars={'Sector_frequency': ('wd', p_wd), 'Weibull_A': ('wd', a), 'Weibull_k': ('wd', k)}, coords={'wd': np.linspace(0, 360, len(p_wd), endpoint=False)}) + if ti is not None: + ds['TI'] = ti XRSite.__init__(self, ds, interp_method=interp_method, shear=shear)