|
28 | 28 | "source": [ |
29 | 29 | "### Imports and initialization of wind turbines\n", |
30 | 30 | "\n", |
31 | | - "The import of weather data and the initialization of wind turbines is done as in the ``modelchain_example``. Be aware that currently for wind farm and wind cluster calculations wind turbines need to have a power curve as some calculations do not work with the power coefficient curve." |
| 31 | + "The import of weather data and the initialization of wind turbines are taken from the ``modelchain_example``. See there for more information.\n", |
| 32 | + "\n", |
| 33 | + "Also, be aware that currently for wind farm and wind cluster calculations wind turbines need to have a power curve as some calculations do not work with the power coefficient curve." |
32 | 34 | ] |
33 | 35 | }, |
34 | 36 | { |
|
37 | 39 | "metadata": {}, |
38 | 40 | "outputs": [], |
39 | 41 | "source": [ |
| 42 | + "import os\n", |
40 | 43 | "import pandas as pd\n", |
41 | 44 | "\n", |
42 | | - "import modelchain_example as mc_e\n", |
43 | | - "from windpowerlib import TurbineClusterModelChain, WindTurbineCluster, WindFarm\n", |
| 45 | + "from windpowerlib import create_power_curve, TurbineClusterModelChain, WindFarm, WindTurbine, WindTurbineCluster\n", |
44 | 46 | "\n", |
45 | 47 | "import logging\n", |
46 | 48 | "logging.getLogger().setLevel(logging.DEBUG)" |
|
59 | 61 | "height 10 80 2 10 0\n", |
60 | 62 | "2010-01-01 00:00:00+01:00 5.32697 7.80697 267.60 267.57 98405.7\n", |
61 | 63 | "2010-01-01 01:00:00+01:00 5.46199 7.86199 267.60 267.55 98382.7\n", |
62 | | - "2010-01-01 02:00:00+01:00 5.67899 8.59899 267.61 267.54 98362.9\n", |
63 | | - "\n", |
64 | | - "nominal power of my_turbine: 3000000.0\n" |
| 64 | + "2010-01-01 02:00:00+01:00 5.67899 8.59899 267.61 267.54 98362.9\n" |
| 65 | + ] |
| 66 | + } |
| 67 | + ], |
| 68 | + "source": [ |
| 69 | + "def get_weather_data(filename='weather.csv', **kwargs):\n", |
| 70 | + " r\"\"\"\n", |
| 71 | + " Imports weather data from a file.\n", |
| 72 | + "\n", |
| 73 | + " \"\"\"\n", |
| 74 | + "\n", |
| 75 | + " if 'datapath' not in kwargs:\n", |
| 76 | + " kwargs['datapath'] = os.path.dirname(__file__)\n", |
| 77 | + " \n", |
| 78 | + " file = os.path.join(kwargs['datapath'], filename)\n", |
| 79 | + " \n", |
| 80 | + " # download example weather data file in case it does not yet exist\n", |
| 81 | + " if not os.path.isfile(file):\n", |
| 82 | + " logging.debug(\"Download weather data for example.\")\n", |
| 83 | + " req = requests.get(\"https://osf.io/59bqn/download\")\n", |
| 84 | + " with open(file, \"wb\") as fout:\n", |
| 85 | + " fout.write(req.content)\n", |
| 86 | + " \n", |
| 87 | + " # read csv file \n", |
| 88 | + " weather_df = pd.read_csv(\n", |
| 89 | + " file,\n", |
| 90 | + " index_col=0,\n", |
| 91 | + " header=[0, 1],\n", |
| 92 | + " )\n", |
| 93 | + " weather_df.index = pd.to_datetime(weather_df.index, utc=True)\n", |
| 94 | + " \n", |
| 95 | + " # change time zone\n", |
| 96 | + " weather_df.index = weather_df.index.tz_convert(\n", |
| 97 | + " 'Europe/Berlin')\n", |
| 98 | + " \n", |
| 99 | + " return weather_df\n", |
| 100 | + "\n", |
| 101 | + "# Read weather data from csv\n", |
| 102 | + "weather = get_weather_data(filename='weather.csv', datapath='')\n", |
| 103 | + "print(weather[['wind_speed', 'temperature', 'pressure']][0:3])" |
| 104 | + ] |
| 105 | + }, |
| 106 | + { |
| 107 | + "cell_type": "code", |
| 108 | + "execution_count": 3, |
| 109 | + "metadata": {}, |
| 110 | + "outputs": [ |
| 111 | + { |
| 112 | + "name": "stdout", |
| 113 | + "output_type": "stream", |
| 114 | + "text": [ |
| 115 | + "Nominal power of my_turbine: 3000000.0\n" |
65 | 116 | ] |
66 | 117 | } |
67 | 118 | ], |
68 | 119 | "source": [ |
69 | | - "# Get weather data\n", |
70 | | - "weather = mc_e.get_weather_data('weather.csv')\n", |
71 | | - "print(weather[['wind_speed', 'temperature', 'pressure']][0:3])\n", |
| 120 | + "def initialize_wind_turbines():\n", |
| 121 | + " r\"\"\"\n", |
| 122 | + " Initializes three WindTurbine objects.\n", |
| 123 | + "\n", |
| 124 | + " \"\"\"\n", |
| 125 | + " enercon_e126 = {\n", |
| 126 | + " \"turbine_type\": \"E-126/4200\", # turbine type as in register\n", |
| 127 | + " \"hub_height\": 135, # in m\n", |
| 128 | + " }\n", |
| 129 | + " e126 = WindTurbine(**enercon_e126)\n", |
| 130 | + "\n", |
| 131 | + " my_turbine = {\n", |
| 132 | + " \"nominal_power\": 3e6, # in W\n", |
| 133 | + " \"hub_height\": 105, # in m\n", |
| 134 | + " \"power_curve\": pd.DataFrame(\n", |
| 135 | + " data={\n", |
| 136 | + " \"value\": [\n", |
| 137 | + " p * 1000\n", |
| 138 | + " for p in [0.0, 26.0, 180.0, 1500.0, 3000.0, 3000.0]\n", |
| 139 | + " ], # in W\n", |
| 140 | + " \"wind_speed\": [0.0, 3.0, 5.0, 10.0, 15.0, 25.0],\n", |
| 141 | + " }\n", |
| 142 | + " ), # in m/s\n", |
| 143 | + " }\n", |
| 144 | + " my_turbine = WindTurbine(**my_turbine)\n", |
| 145 | + "\n", |
| 146 | + " my_power = pd.Series(\n", |
| 147 | + " [0.0, 39000.0, 270000.0, 2250000.0, 4500000.0, 4500000.0]\n", |
| 148 | + " )\n", |
| 149 | + " my_wind_speed = (0.0, 3.0, 5.0, 10.0, 15.0, 25.0)\n", |
| 150 | + "\n", |
| 151 | + " my_turbine2 = {\n", |
| 152 | + " \"nominal_power\": 6e6, # in W\n", |
| 153 | + " \"hub_height\": 115, # in m\n", |
| 154 | + " \"power_curve\": create_power_curve(\n", |
| 155 | + " wind_speed=my_wind_speed, power=my_power\n", |
| 156 | + " ),\n", |
| 157 | + " }\n", |
| 158 | + " my_turbine2 = WindTurbine(**my_turbine2)\n", |
| 159 | + "\n", |
| 160 | + " return my_turbine, e126, my_turbine2\n", |
72 | 161 | "\n", |
73 | | - "# Initialize wind turbines\n", |
74 | | - "my_turbine, e126, my_turbine2 = mc_e.initialize_wind_turbines()\n", |
75 | | - "print()\n", |
76 | | - "print('nominal power of my_turbine: {}'.format(my_turbine.nominal_power))" |
| 162 | + "my_turbine, e126, my_turbine2 = initialize_wind_turbines()\n", |
| 163 | + "print('Nominal power of my_turbine: {}'.format(my_turbine.nominal_power))" |
77 | 164 | ] |
78 | 165 | }, |
79 | 166 | { |
|
0 commit comments