|
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,29 +64,24 @@ 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( |
69 | | - os.path.split(os.path.dirname(__file__))[0], "example" |
70 | | - ) |
71 | | - file = os.path.join(kwargs["datapath"], filename) |
| 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) |
72 | 71 |
|
73 | 72 | # read csv file |
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 | | - ) |
| 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)) |
80 | 76 |
|
81 | 77 | # change type of index to datetime and set time zone |
82 | | - weather_df.index = pd.to_datetime(weather_df.index).tz_convert( |
83 | | - "Europe/Berlin" |
84 | | - ) |
| 78 | + weather_df.index=pd.to_datetime(weather_df.index).tz_convert( |
| 79 | + 'Europe/Berlin') |
85 | 80 |
|
86 | 81 | # change type of height from str to int by resetting columns |
87 | | - l0 = [_[0] for _ in weather_df.columns] |
88 | | - l1 = [int(_[1]) for _ in weather_df.columns] |
89 | | - weather_df.columns = [l0, l1] |
| 82 | + l0=[_[0] for _ in weather_df.columns] |
| 83 | + l1=[int(_[1]) for _ in weather_df.columns] |
| 84 | + weather_df.columns=[l0, l1] |
90 | 85 |
|
91 | 86 | return weather_df |
92 | 87 |
|
@@ -116,42 +111,37 @@ def initialize_wind_turbines(): |
116 | 111 |
|
117 | 112 | # specification of wind turbine where data is provided in the oedb |
118 | 113 | # turbine library |
119 | | - enercon_e126 = { |
120 | | - "turbine_type": "E-126/4200", # turbine type as in register |
121 | | - "hub_height": 135, # in m |
| 114 | + enercon_e126={ |
| 115 | + 'turbine_type': 'E-126/4200', # turbine type as in register |
| 116 | + 'hub_height': 135 # in m |
122 | 117 | } |
123 | 118 | # initialize WindTurbine object |
124 | | - e126 = WindTurbine(**enercon_e126) |
| 119 | + e126=WindTurbine(**enercon_e126) |
125 | 120 |
|
126 | 121 | # specification of own wind turbine (Note: power values and nominal power |
127 | 122 | # have to be in Watt) |
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 |
| 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 |
140 | 130 | } |
141 | 131 | # initialize WindTurbine object |
142 | | - my_turbine = WindTurbine(**my_turbine) |
| 132 | + my_turbine=WindTurbine(**my_turbine) |
143 | 133 |
|
144 | 134 | # specification of wind turbine where power coefficient curve and nominal |
145 | 135 | # power is provided in an own csv file |
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, |
| 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 |
152 | 142 | } |
153 | 143 | # initialize WindTurbine object |
154 | | - dummy_turbine = WindTurbine(**dummy_turbine) |
| 144 | + dummy_turbine=WindTurbine(**dummy_turbine) |
155 | 145 |
|
156 | 146 | return my_turbine, e126, dummy_turbine |
157 | 147 |
|
@@ -185,38 +175,37 @@ def calculate_power_output(weather, my_turbine, e126, dummy_turbine): |
185 | 175 | # power output calculation for my_turbine |
186 | 176 | # initialize ModelChain with default parameters and use run_model method |
187 | 177 | # to calculate power output |
188 | | - mc_my_turbine = ModelChain(my_turbine).run_model(weather) |
| 178 | + mc_my_turbine=ModelChain(my_turbine).run_model(weather) |
189 | 179 | # write power output time series to WindTurbine object |
190 | | - my_turbine.power_output = mc_my_turbine.power_output |
| 180 | + my_turbine.power_output=mc_my_turbine.power_output |
191 | 181 |
|
192 | 182 | # power output calculation for e126 |
193 | 183 | # own specifications for ModelChain setup |
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 |
| 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 |
208 | 197 | # initialize ModelChain with own specifications and use run_model method |
209 | 198 | # to calculate power output |
210 | | - mc_e126 = ModelChain(e126, **modelchain_data).run_model(weather) |
| 199 | + mc_e126=ModelChain(e126, **modelchain_data).run_model(weather) |
211 | 200 | # write power output time series to WindTurbine object |
212 | | - e126.power_output = mc_e126.power_output |
| 201 | + e126.power_output=mc_e126.power_output |
213 | 202 |
|
214 | 203 | # power output calculation for example_turbine |
215 | 204 | # own specification for 'power_output_model' |
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 |
| 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 |
220 | 209 |
|
221 | 210 | return |
222 | 211 |
|
@@ -283,8 +272,8 @@ def run_example(): |
283 | 272 | Runs the basic example. |
284 | 273 |
|
285 | 274 | """ |
286 | | - weather = get_weather_data("weather.csv") |
287 | | - my_turbine, e126, dummy_turbine = initialize_wind_turbines() |
| 275 | + weather=get_weather_data('weather.csv') |
| 276 | + my_turbine, e126, dummy_turbine=initialize_wind_turbines() |
288 | 277 | calculate_power_output(weather, my_turbine, e126, dummy_turbine) |
289 | 278 | plot_or_print(my_turbine, e126, dummy_turbine) |
290 | 279 |
|
|
0 commit comments