{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Multi-height wind data" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "In this example we explore the calculation of multi-height wind data, as for example obtained from WRF results or downloaded from the [NEWA website](https://map.neweuropeanwindatlas.eu/) at a single point.\n", "\n", "Here we will use the static data file `WRF-Timeseries-3000.nc` that is part of the `foxes` static data.\n", "The time coordinate marks one month in 10 minute steps, and the wind speed (WS), wind direction (WD) and turbulent intensity (TI) are provided at 8 heights between 50 and 500 m. The air density (RHO) does not have height dependency but varies with time. The detailed data structure will be displayed below.\n", "\n", "The basic assumption of this example is that we can calculate our wind farm results based on this data, i.e., that the horizontal variation can be neglected (for completely heterogeneous inflow data, see the corresponding example)." ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "These are the imports for this example:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%matplotlib inline\n", "import matplotlib.pyplot as plt\n", "from xarray import open_dataset\n", "\n", "import foxes\n", "import foxes.variables as FV" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "First, we setup the model book and the wind farm. We choose 5 turbines in a row:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [], "source": [ "# create wind farm, a single row of turbines:\n", "farm = foxes.WindFarm()\n", "foxes.input.farm_layout.add_row(\n", " farm=farm,\n", " xy_base=[0.0, 0.0],\n", " xy_step=[600.0, 0.0],\n", " n_turbines=5,\n", " turbine_models=[\"NREL5MW\"],\n", " H=200.0,\n", " verbosity=0,\n", ")\n", "\n", "ax = foxes.output.FarmLayoutOutput(farm).get_figure(figsize=(5, 3))\n", "plt.show()" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Note that we manually change the hub height from 90 m to 200 m here. Next, we create the states based on the static data file `WRF-Timeseries-3000.nc`:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# This is what the nc file looks like:\n", "fpath = foxes.StaticData().get_file_path(foxes.STATES, \"WRF-Timeseries-3000.nc\")\n", "open_dataset(fpath)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now let's create the corresponding states object:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "states = foxes.input.states.MultiHeightNCTimeseries(\n", " data_source=\"WRF-Timeseries-3000.nc\",\n", " time_coord=\"Time\",\n", " h_coord=\"height\",\n", " output_vars=[FV.WS, FV.WD, FV.TI, FV.RHO],\n", " var2col={FV.WS: \"ws\", FV.WD: \"wd\", FV.TI: \"ti\", FV.RHO: \"rho\"},\n", ")\n", "\n", "o = foxes.output.StatesRosePlotOutput(states, point=[0.0, 0.0, 100.0])\n", "o.get_figure(16, FV.AMB_WS, [0, 3.5, 6, 10, 15, 20], figsize=(6, 6))\n", "plt.show()" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Note how the `var2col` option offers a mapping from the expected to the actual column names, if needed.\n", "\n", "Let's next setup our algorithm. Notice that we include the z-sensitive rotor model `level10`, with 10 points on a vertical line (also the `grid` models would be an option). The partial wakes choice `None` represents default settings for all wake models. It is important that we do not select `rotor_points` together with the `level10` rotor, since averaging over a vertical line of points does not make much sense." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "algo = foxes.algorithms.Downwind(\n", " farm,\n", " states,\n", " rotor_model=\"level10\",\n", " wake_models=[\"Bastankhah2014_linear_ka02\"],\n", " partial_wakes=None,\n", " verbosity=0,\n", ")" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "We now visualize the vertical flow profile. Alternatively to the here shown use of the `states_sel` parameter in the plotting function, we could have reduced the whole `states` object by `states.reset(states_loc=[\"2009-01-06 13:50:00\"])`." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "farm_results = algo.calc_farm()\n", "\n", "o = foxes.output.FlowPlots2D(algo, farm_results)\n", "g = o.gen_states_fig_xz(\n", " FV.AMB_WS,\n", " resolution=10,\n", " x_direction=270,\n", " xmin=0.0,\n", " xmax=1000.0,\n", " zmin=50.0,\n", " zmax=500.0,\n", " figsize=(8, 6),\n", " states_sel=[\"2009-01-06 13:50:00\"],\n", ")\n", "fig = next(g)\n", "plt.show()" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "We can now calculate the full states results:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "farm_results = algo.calc_farm()\n", "\n", "fr = farm_results.to_dataframe()\n", "print(fr[[FV.WD, FV.REWS, FV.P]])\n", "\n", "o = foxes.output.FarmLayoutOutput(farm, farm_results)\n", "o.get_figure(color_by=\"mean_REWS\", title=\"Mean REWS [m/s]\", s=150, annotate=0)\n", "plt.show()\n", "\n", "o = foxes.output.FarmResultsEval(farm_results)\n", "P0 = o.calc_mean_farm_power(ambient=True)\n", "P = o.calc_mean_farm_power()\n", "print(f\"\\nFarm power : {P / 1000:.1f} MW\")\n", "print(f\"Farm ambient power: {P0 / 1000:.1f} MW\")\n", "print(f\"Farm efficiency : {o.calc_farm_efficiency() * 100:.2f} %\")\n", "print(f\"Annual farm yield : {o.calc_farm_yield(algo=algo):.2f} GWh\")" ] } ], "metadata": { "kernelspec": { "display_name": ".venv", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.3" } }, "nbformat": 4, "nbformat_minor": 4 }