|
19 | 19 | try: |
20 | 20 | from matplotlib import pyplot as plt |
21 | 21 | except ImportError: |
22 | | - plt=None |
| 22 | + plt = None |
23 | 23 |
|
24 | 24 | from windpowerlib import ModelChain |
25 | 25 | from windpowerlib import WindTurbine |
@@ -64,24 +64,29 @@ def get_weather_data(filename='weather.csv', **kwargs): |
64 | 64 |
|
65 | 65 | """ |
66 | 66 |
|
67 | | - if 'datapath' not in kwargs: |
68 | | - kwargs['datapath']=os.path.join(os.path.split( |
69 | | - os.path.dirname(__file__))[0], 'example') |
70 | | - file=os.path.join(kwargs['datapath'], filename) |
| 67 | + if "datapath" not in kwargs: |
| 68 | + kwargs["datapath"] = os.path.join( |
| 69 | + os.path.split(os.path.dirname(__file__))[0], "example" |
| 70 | + ) |
| 71 | + file = os.path.join(kwargs["datapath"], filename) |
71 | 72 |
|
72 | 73 | # read csv file |
73 | | - weather_df=pd.read_csv( |
74 | | - file, index_col=0, header=[0, 1], |
75 | | - date_parser=lambda idx: pd.to_datetime(idx, utc=True)) |
| 74 | + weather_df = pd.read_csv( |
| 75 | + file, |
| 76 | + index_col=0, |
| 77 | + header=[0, 1], |
| 78 | + date_parser=lambda idx: pd.to_datetime(idx, utc=True), |
| 79 | + ) |
76 | 80 |
|
77 | 81 | # change type of index to datetime and set time zone |
78 | | - weather_df.index=pd.to_datetime(weather_df.index).tz_convert( |
79 | | - 'Europe/Berlin') |
| 82 | + weather_df.index = pd.to_datetime(weather_df.index).tz_convert( |
| 83 | + "Europe/Berlin" |
| 84 | + ) |
80 | 85 |
|
81 | 86 | # change type of height from str to int by resetting columns |
82 | | - l0=[_[0] for _ in weather_df.columns] |
83 | | - l1=[int(_[1]) for _ in weather_df.columns] |
84 | | - weather_df.columns=[l0, l1] |
| 87 | + l0 = [_[0] for _ in weather_df.columns] |
| 88 | + l1 = [int(_[1]) for _ in weather_df.columns] |
| 89 | + weather_df.columns = [l0, l1] |
85 | 90 |
|
86 | 91 | return weather_df |
87 | 92 |
|
@@ -111,37 +116,42 @@ def initialize_wind_turbines(): |
111 | 116 |
|
112 | 117 | # specification of wind turbine where data is provided in the oedb |
113 | 118 | # turbine library |
114 | | - enercon_e126={ |
115 | | - 'turbine_type': 'E-126/4200', # turbine type as in register |
116 | | - 'hub_height': 135 # in m |
| 119 | + enercon_e126 = { |
| 120 | + "turbine_type": "E-126/4200", # turbine type as in register |
| 121 | + "hub_height": 135, # in m |
117 | 122 | } |
118 | 123 | # initialize WindTurbine object |
119 | | - e126=WindTurbine(**enercon_e126) |
| 124 | + e126 = WindTurbine(**enercon_e126) |
120 | 125 |
|
121 | 126 | # specification of own wind turbine (Note: power values and nominal power |
122 | 127 | # have to be in Watt) |
123 | | - my_turbine={ |
124 | | - 'nominal_power': 3e6, # in W |
125 | | - 'hub_height': 105, # in m |
126 | | - 'power_curve': pd.DataFrame( |
127 | | - data={'value': [p * 1000 for p in [ |
128 | | - 0.0, 26.0, 180.0, 1500.0, 3000.0, 3000.0]], # in W |
129 | | - 'wind_speed': [0.0, 3.0, 5.0, 10.0, 15.0, 25.0]}) # in m/s |
| 128 | + my_turbine = { |
| 129 | + "nominal_power": 3e6, # in W |
| 130 | + "hub_height": 105, # in m |
| 131 | + "power_curve": pd.DataFrame( |
| 132 | + data={ |
| 133 | + "value": [ |
| 134 | + p * 1000 |
| 135 | + for p in [0.0, 26.0, 180.0, 1500.0, 3000.0, 3000.0] |
| 136 | + ], # in W |
| 137 | + "wind_speed": [0.0, 3.0, 5.0, 10.0, 15.0, 25.0], |
| 138 | + } |
| 139 | + ), # in m/s |
130 | 140 | } |
131 | 141 | # initialize WindTurbine object |
132 | | - my_turbine=WindTurbine(**my_turbine) |
| 142 | + my_turbine = WindTurbine(**my_turbine) |
133 | 143 |
|
134 | 144 | # specification of wind turbine where power coefficient curve and nominal |
135 | 145 | # power is provided in an own csv file |
136 | | - csv_path=os.path.join(os.path.dirname(__file__), 'data') |
137 | | - dummy_turbine={ |
138 | | - 'turbine_type': "DUMMY 1", |
139 | | - 'hub_height': 100, # in m |
140 | | - 'rotor_diameter': 70, # in m |
141 | | - 'path': csv_path |
| 146 | + csv_path = os.path.join(os.path.dirname(__file__), "data") |
| 147 | + dummy_turbine = { |
| 148 | + "turbine_type": "DUMMY 1", |
| 149 | + "hub_height": 100, # in m |
| 150 | + "rotor_diameter": 70, # in m |
| 151 | + "path": csv_path, |
142 | 152 | } |
143 | 153 | # initialize WindTurbine object |
144 | | - dummy_turbine=WindTurbine(**dummy_turbine) |
| 154 | + dummy_turbine = WindTurbine(**dummy_turbine) |
145 | 155 |
|
146 | 156 | return my_turbine, e126, dummy_turbine |
147 | 157 |
|
@@ -175,37 +185,38 @@ def calculate_power_output(weather, my_turbine, e126, dummy_turbine): |
175 | 185 | # power output calculation for my_turbine |
176 | 186 | # initialize ModelChain with default parameters and use run_model method |
177 | 187 | # to calculate power output |
178 | | - mc_my_turbine=ModelChain(my_turbine).run_model(weather) |
| 188 | + mc_my_turbine = ModelChain(my_turbine).run_model(weather) |
179 | 189 | # write power output time series to WindTurbine object |
180 | | - my_turbine.power_output=mc_my_turbine.power_output |
| 190 | + my_turbine.power_output = mc_my_turbine.power_output |
181 | 191 |
|
182 | 192 | # power output calculation for e126 |
183 | 193 | # own specifications for ModelChain setup |
184 | | - modelchain_data={ |
185 | | - 'wind_speed_model': 'logarithmic', # 'logarithmic' (default), |
186 | | - # 'hellman' or |
187 | | - # 'interpolation_extrapolation' |
188 | | - 'density_model': 'ideal_gas', # 'barometric' (default), 'ideal_gas' or |
189 | | - # 'interpolation_extrapolation' |
190 | | - 'temperature_model': 'linear_gradient', # 'linear_gradient' (def.) or |
191 | | - # 'interpolation_extrapolation' |
192 | | - 'power_output_model': 'power_curve', # 'power_curve' (default) or |
193 | | - # 'power_coefficient_curve' |
194 | | - 'density_correction': True, # False (default) or True |
195 | | - 'obstacle_height': 0, # default: 0 |
196 | | - 'hellman_exp': None} # None (default) or None |
| 194 | + modelchain_data = { |
| 195 | + "wind_speed_model": "logarithmic", # 'logarithmic' (default), |
| 196 | + # 'hellman' or |
| 197 | + # 'interpolation_extrapolation' |
| 198 | + "density_model": "ideal_gas", # 'barometric' (default), 'ideal_gas' or |
| 199 | + # 'interpolation_extrapolation' |
| 200 | + "temperature_model": "linear_gradient", # 'linear_gradient' (def.) or |
| 201 | + # 'interpolation_extrapolation' |
| 202 | + "power_output_model": "power_curve", # 'power_curve' (default) or |
| 203 | + # 'power_coefficient_curve' |
| 204 | + "density_correction": True, # False (default) or True |
| 205 | + "obstacle_height": 0, # default: 0 |
| 206 | + "hellman_exp": None, |
| 207 | + } # None (default) or None |
197 | 208 | # initialize ModelChain with own specifications and use run_model method |
198 | 209 | # to calculate power output |
199 | | - mc_e126=ModelChain(e126, **modelchain_data).run_model(weather) |
| 210 | + mc_e126 = ModelChain(e126, **modelchain_data).run_model(weather) |
200 | 211 | # write power output time series to WindTurbine object |
201 | | - e126.power_output=mc_e126.power_output |
| 212 | + e126.power_output = mc_e126.power_output |
202 | 213 |
|
203 | 214 | # power output calculation for example_turbine |
204 | 215 | # own specification for 'power_output_model' |
205 | | - mc_example_turbine=ModelChain( |
206 | | - dummy_turbine, |
207 | | - power_output_model='power_coefficient_curve').run_model(weather) |
208 | | - dummy_turbine.power_output=mc_example_turbine.power_output |
| 216 | + mc_example_turbine = ModelChain( |
| 217 | + dummy_turbine, power_output_model="power_coefficient_curve" |
| 218 | + ).run_model(weather) |
| 219 | + dummy_turbine.power_output = mc_example_turbine.power_output |
209 | 220 |
|
210 | 221 | return |
211 | 222 |
|
@@ -272,8 +283,8 @@ def run_example(): |
272 | 283 | Runs the basic example. |
273 | 284 |
|
274 | 285 | """ |
275 | | - weather=get_weather_data('weather.csv') |
276 | | - my_turbine, e126, dummy_turbine=initialize_wind_turbines() |
| 286 | + weather = get_weather_data("weather.csv") |
| 287 | + my_turbine, e126, dummy_turbine = initialize_wind_turbines() |
277 | 288 | calculate_power_output(weather, my_turbine, e126, dummy_turbine) |
278 | 289 | plot_or_print(my_turbine, e126, dummy_turbine) |
279 | 290 |
|
|
0 commit comments