|
| 1 | +""" |
| 2 | +The ``further_example`` module shows a further usage of the windpowerlib. |
| 3 | +
|
| 4 | +This example uses functions from the ``basic_example`` module where the |
| 5 | +basic usage of the windpowerlib is shown. |
| 6 | +
|
| 7 | +
|
| 8 | +""" |
| 9 | + |
| 10 | +__copyright__ = "Copyright oemof developer group" |
| 11 | +__license__ = "GPLv3" |
| 12 | + |
| 13 | +try: |
| 14 | + from matplotlib import pyplot as plt |
| 15 | +except ImportError: |
| 16 | + plt = None |
| 17 | + |
| 18 | +import basic_example |
| 19 | +from windpowerlib.turbine_cluster_modelchain import TurbineClusterModelChain |
| 20 | +from windpowerlib.wind_turbine_cluster import WindTurbineCluster |
| 21 | +from windpowerlib.wind_farm import WindFarm |
| 22 | +# TODO: change imports |
| 23 | + |
| 24 | +# You can use the logging package to get logging messages from the windpowerlib |
| 25 | +# Change the logging level if you want more or less messages |
| 26 | +import logging |
| 27 | +logging.getLogger().setLevel(logging.DEBUG) |
| 28 | + |
| 29 | + |
| 30 | +def initialise_wind_farm(my_turbine, e126): |
| 31 | + r""" |
| 32 | + Initialises a :class:`~.wind_farm.WindFarm` object. |
| 33 | +
|
| 34 | + This function shows how to initialise a WindFarm object. You need to |
| 35 | + provide at least a name and a the wind farm's wind turbine fleet as done |
| 36 | + below for 'example_farm'. Optionally you can provide a wind farm efficiency |
| 37 | + (which can be constant or dependent on the wind speed) and coordinates as |
| 38 | + done for 'example_farm_2'. In this example the coordinates are not being |
| 39 | + used as just a single weather data set is provided as example data. |
| 40 | +
|
| 41 | + Parameters |
| 42 | + ---------- |
| 43 | + my_turbine : WindTurbine |
| 44 | + WindTurbine object with self provided power curve. |
| 45 | + e126 : WindTurbine |
| 46 | + WindTurbine object with power curve from data file provided by the |
| 47 | + windpowerlib. |
| 48 | +
|
| 49 | + Returns |
| 50 | + ------- |
| 51 | + Tuple (WindFarm, WindFarm) |
| 52 | +
|
| 53 | + """ |
| 54 | + |
| 55 | + # specification of wind farm data |
| 56 | + example_farm_data = { |
| 57 | + 'name': 'example_farm', |
| 58 | + 'wind_turbine_fleet': [{'wind_turbine': my_turbine, |
| 59 | + 'number_of_turbines': 6}, |
| 60 | + {'wind_turbine': e126, |
| 61 | + 'number_of_turbines': 3} |
| 62 | + ]} |
| 63 | + |
| 64 | + # initialise WindFarm object |
| 65 | + example_farm = WindFarm(**example_farm_data) |
| 66 | + |
| 67 | + # specification of wind farm data (2) containing a wind farm efficiency |
| 68 | + # and coordinates |
| 69 | + example_farm_2_data = { |
| 70 | + 'name': 'example_farm_2', |
| 71 | + 'wind_turbine_fleet': [{'wind_turbine': my_turbine, |
| 72 | + 'number_of_turbines': 6}, |
| 73 | + {'wind_turbine': e126, |
| 74 | + 'number_of_turbines': 3}], |
| 75 | + 'efficiency': 0.9, |
| 76 | + 'coordinates': [52.2, 13.1]} |
| 77 | + |
| 78 | + # initialise WindFarm object |
| 79 | + example_farm_2 = WindFarm(**example_farm_2_data) |
| 80 | + |
| 81 | + return example_farm, example_farm_2 |
| 82 | + |
| 83 | + |
| 84 | +def initialise_wind_turbine_cluster(example_farm, example_farm_2): |
| 85 | + r""" |
| 86 | + Initialises a :class:`~.wind_turbine_cluster.WindTurbineCluster` object. |
| 87 | +
|
| 88 | + Function shows how to initialise a WindTurbineCluster object. In this case |
| 89 | + the cluster only contains two wind farms. |
| 90 | +
|
| 91 | + Parameters |
| 92 | + ---------- |
| 93 | + example_farm : WindFarm |
| 94 | + WindFarm object. |
| 95 | + example_farm_2 : WindFarm |
| 96 | + WindFarm object constant wind farm efficiency and coordinates. |
| 97 | +
|
| 98 | + Returns |
| 99 | + ------- |
| 100 | + WindTurbineCluster |
| 101 | +
|
| 102 | + """ |
| 103 | + |
| 104 | + # specification of cluster data |
| 105 | + example_cluster_data = { |
| 106 | + 'name': 'example_cluster', |
| 107 | + 'wind_farms': [example_farm, example_farm_2]} |
| 108 | + |
| 109 | + # initialise WindTurbineCluster object |
| 110 | + example_cluster = WindTurbineCluster(**example_cluster_data) |
| 111 | + |
| 112 | + return example_cluster |
| 113 | + |
| 114 | + |
| 115 | +def calculate_power_output(weather, example_farm, example_cluster): |
| 116 | + r""" |
| 117 | + Calculates power output of wind farms and clusters using the |
| 118 | + :class:`~.turbine_cluster_modelchain.TurbineClusterModelChain`. |
| 119 | +
|
| 120 | + The :class:`~.turbine_cluster_modelchain.TurbineClusterModelChain` is a |
| 121 | + class that provides all necessary steps to calculate the power output of a |
| 122 | + wind farm or cluster. You can either use the default methods for the |
| 123 | + calculation steps, as done for 'example_farm', or choose different methods, |
| 124 | + as done for 'example_cluster'. |
| 125 | +
|
| 126 | + Parameters |
| 127 | + ---------- |
| 128 | + weather : pd.DataFrame |
| 129 | + Contains weather data time series. |
| 130 | + example_farm : WindFarm |
| 131 | + WindFarm object. |
| 132 | + example_farm_2 : WindFarm |
| 133 | + WindFarm object constant wind farm efficiency and coordinates. |
| 134 | +
|
| 135 | + """ |
| 136 | + |
| 137 | + # set efficiency of example_farm to apply wake losses |
| 138 | + example_farm.efficiency = 0.9 |
| 139 | + # power output calculation for example_farm |
| 140 | + # initialise TurbineClusterModelChain with default parameters and use |
| 141 | + # run_model method to calculate power output |
| 142 | + mc_example_farm = TurbineClusterModelChain(example_farm).run_model(weather) |
| 143 | + # write power output time series to WindFarm object |
| 144 | + example_farm.power_output = mc_example_farm.power_output |
| 145 | + |
| 146 | + # power output calculation for turbine_cluster |
| 147 | + # own specifications for TurbineClusterModelChain setup |
| 148 | + modelchain_data = { |
| 149 | + 'wake_losses_model': 'constant_efficiency', # |
| 150 | + # 'dena_mean' (default), None, |
| 151 | + # 'power_efficiency_curve', |
| 152 | + # 'constant_efficiency' or name of |
| 153 | + # a wind efficiency curve |
| 154 | + # see :py:func:`~.wake_losses.display_wind_efficiency_curves` |
| 155 | + 'smoothing': True, # False (default) or True |
| 156 | + 'block_width': 0.5, # default: 0.5 |
| 157 | + 'standard_deviation_method': 'Staffell_Pfenninger', # |
| 158 | + # 'turbulence_intensity' (default) |
| 159 | + # or 'Staffell_Pfenninger' |
| 160 | + 'smoothing_order': 'wind_farm_power_curves', # |
| 161 | + # 'wind_farm_power_curves' (default) or |
| 162 | + # 'turbine_power_curves' |
| 163 | + 'wind_speed_model': 'logarithmic', # 'logarithmic' (default), |
| 164 | + # 'hellman' or |
| 165 | + # 'interpolation_extrapolation' |
| 166 | + 'density_model': 'ideal_gas', # 'barometric' (default), 'ideal_gas' or |
| 167 | + # 'interpolation_extrapolation' |
| 168 | + 'temperature_model': 'linear_gradient', # 'linear_gradient' (def.) or |
| 169 | + # 'interpolation_extrapolation' |
| 170 | + 'power_output_model': 'power_curve', # 'power_curve' (default) or |
| 171 | + # 'power_coefficient_curve' |
| 172 | + 'density_correction': True, # False (default) or True |
| 173 | + 'obstacle_height': 0, # default: 0 |
| 174 | + 'hellman_exp': None} # None (default) or None |
| 175 | + # initialise TurbineClusterModelChain with own specifications and use |
| 176 | + # run_model method to calculate power output |
| 177 | + mc_example_cluster = TurbineClusterModelChain( |
| 178 | + example_cluster, **modelchain_data).run_model(weather) |
| 179 | + # write power output time series to WindTurbineCluster object |
| 180 | + example_cluster.power_output = mc_example_cluster.power_output |
| 181 | + |
| 182 | + return |
| 183 | + |
| 184 | + |
| 185 | +def plot_or_print(example_farm, example_cluster): |
| 186 | + r""" |
| 187 | + Plots or prints power output and power (coefficient) curves. |
| 188 | +
|
| 189 | + Parameters |
| 190 | + ---------- |
| 191 | + example_farm : WindFarm |
| 192 | + WindFarm object. |
| 193 | + example_farm_2 : WindFarm |
| 194 | + WindFarm object constant wind farm efficiency and coordinates. |
| 195 | +
|
| 196 | + """ |
| 197 | + |
| 198 | + # plot or print power output |
| 199 | + if plt: |
| 200 | + example_cluster.power_output.plot(legend=True, label='example cluster') |
| 201 | + example_farm.power_output.plot(legend=True, label='example farm') |
| 202 | + plt.show() |
| 203 | + else: |
| 204 | + print(example_cluster.power_output) |
| 205 | + print(example_farm.power_output) |
| 206 | + |
| 207 | + |
| 208 | +def run_example(): |
| 209 | + r""" |
| 210 | + Run the example. |
| 211 | +
|
| 212 | + """ |
| 213 | + weather = basic_example.get_weather_data('weather.csv') |
| 214 | + my_turbine, e126 = basic_example.initialise_wind_turbines() |
| 215 | + example_farm, example_farm_2 = initialise_wind_farm(my_turbine, e126) |
| 216 | + example_cluster = initialise_wind_turbine_cluster(example_farm, |
| 217 | + example_farm_2) |
| 218 | + calculate_power_output(weather, example_farm, example_cluster) |
| 219 | + plot_or_print(example_farm, example_cluster) |
| 220 | + |
| 221 | + |
| 222 | +if __name__ == "__main__": |
| 223 | + run_example() |
0 commit comments