@@ -158,65 +158,65 @@ def apply_static_rate_limits(
158158 pd.DataFrame: A yaw offset lookup table with rate limits applied.
159159 """
160160
161- offsets_all = np .vstack (df_opt .yaw_angles_opt .to_numpy ()). transpose ()
161+ offsets_all = np .vstack (df_opt .yaw_angles_opt .to_numpy ())
162162
163163 wd_array = np .unique (df_opt .wind_direction )
164164 ws_array = np .unique (df_opt .wind_speed )
165165 ti_array = np .unique (df_opt .turbulence_intensity )
166166
167167 wd_step = wd_array [1 ] - wd_array [0 ]
168168 ws_step = ws_array [1 ] - ws_array [0 ]
169+ ti_step = ti_array [1 ] - ti_array [0 ] if len (ti_array ) > 1 else 1
169170
170171 # 4D array, with dimensions: (turbine, wd, ws, ti)
171172 # TODO: will this ordering always work? Or not?
172173 offsets_array = offsets_all .reshape (
173- (offsets_all . shape [ 0 ], len (wd_array ), len (ws_array ), len (ti_array ))
174+ (len (wd_array ), len (ws_array ), len (ti_array ), offsets_all . shape [ - 1 ] )
174175 )
175176
176177 # Apply wd rate limits
177178 offsets_limited_lr = offsets_array .copy ()
178179 for i in range (1 , len (wd_array )):
179- delta_yaw = offsets_limited_lr [:, i , :, :] - offsets_limited_lr [:, i - 1 , :, :]
180+ delta_yaw = offsets_limited_lr [i , : , :, :] - offsets_limited_lr [i - 1 , : , :, :]
180181 delta_yaw = np .clip (delta_yaw , - wd_rate_limit * wd_step , wd_rate_limit * wd_step )
181- offsets_limited_lr [:, i , :, :] = offsets_limited_lr [:, i - 1 , :, :] + delta_yaw
182+ offsets_limited_lr [i , : , :, :] = offsets_limited_lr [i - 1 , : , :, :] + delta_yaw
182183 offsets_limited_rl = offsets_array .copy ()
183184 for i in range (len (wd_array )- 2 , - 1 , - 1 ):
184- delta_yaw = offsets_limited_rl [:, i , :, :] - offsets_limited_rl [:, i + 1 , :, :]
185+ delta_yaw = offsets_limited_rl [i , : , :, :] - offsets_limited_rl [i + 1 , : , :, :]
185186 delta_yaw = np .clip (delta_yaw , - wd_rate_limit * wd_step , wd_rate_limit * wd_step )
186- offsets_limited_rl [:, i , :, :] = offsets_limited_rl [:, i + 1 , :, :] + delta_yaw
187+ offsets_limited_rl [i , : , :, :] = offsets_limited_rl [i + 1 , : , :, :] + delta_yaw
187188 offsets_array = (offsets_limited_lr + offsets_limited_rl ) / 2
188189
189190 # Apply ws rate limits
190191 offsets_limited_lr = offsets_array .copy ()
191192 for j in range (1 , len (ws_array )):
192- delta_yaw = offsets_limited_lr [:, :, j , :] - offsets_limited_lr [:, :, j - 1 , :]
193+ delta_yaw = offsets_limited_lr [:, j , : , :] - offsets_limited_lr [:, j - 1 , : , :]
193194 delta_yaw = np .clip (delta_yaw , - ws_rate_limit * ws_step , ws_rate_limit * ws_step )
194- offsets_limited_lr [:, :, j , :] = offsets_limited_lr [:, :, j - 1 , :] + delta_yaw
195+ offsets_limited_lr [:, j , : , :] = offsets_limited_lr [:, j - 1 , : , :] + delta_yaw
195196 offsets_limited_rl = offsets_array .copy ()
196197 for j in range (len (ws_array )- 2 , - 1 , - 1 ):
197- delta_yaw = offsets_limited_rl [:, :, j , :] - offsets_limited_rl [:, :, j + 1 , :]
198+ delta_yaw = offsets_limited_rl [:, j , : , :] - offsets_limited_rl [:, j + 1 , : , :]
198199 delta_yaw = np .clip (delta_yaw , - ws_rate_limit * ws_step , ws_rate_limit * ws_step )
199- offsets_limited_rl [:, :, j , :] = offsets_limited_rl [:, :, j + 1 , :] + delta_yaw
200+ offsets_limited_rl [:, j , : , :] = offsets_limited_rl [:, j + 1 , : , :] + delta_yaw
200201 offsets_array = (offsets_limited_lr + offsets_limited_rl ) / 2
201202
202203 # Apply ti rate limits
203204 offsets_limited_lr = offsets_array .copy ()
204205 for k in range (1 , len (ti_array )):
205- delta_yaw = offsets_limited_lr [:, :, :, k ] - offsets_limited_lr [:, :, :, k - 1 ]
206- delta_yaw = np .clip (delta_yaw , - ti_rate_limit , ti_rate_limit )
207- offsets_limited_lr [:, :, :, k ] = offsets_limited_lr [:, :, :, k - 1 ] + delta_yaw
206+ delta_yaw = offsets_limited_lr [:, :, k , : ] - offsets_limited_lr [:, :, k - 1 , : ]
207+ delta_yaw = np .clip (delta_yaw , - ti_rate_limit * ti_step , ti_rate_limit * ti_step )
208+ offsets_limited_lr [:, :, k , : ] = offsets_limited_lr [:, :, k - 1 , : ] + delta_yaw
208209 offsets_limited_rl = offsets_array .copy ()
209210 for k in range (len (ti_array )- 2 , - 1 , - 1 ):
210- delta_yaw = offsets_limited_rl [:, :, :, k ] - offsets_limited_rl [:, :, :, k + 1 ]
211- delta_yaw = np .clip (delta_yaw , - ti_rate_limit , ti_rate_limit )
212- offsets_limited_rl [:, :, :, k ] = offsets_limited_rl [:, :, :, k + 1 ] + delta_yaw
211+ delta_yaw = offsets_limited_rl [:, :, k , : ] - offsets_limited_rl [:, :, k + 1 , : ]
212+ delta_yaw = np .clip (delta_yaw , - ti_rate_limit * ti_step , ti_rate_limit * ti_step )
213+ offsets_limited_rl [:, :, k , : ] = offsets_limited_rl [:, :, k + 1 , : ] + delta_yaw
213214 offsets_array = (offsets_limited_lr + offsets_limited_rl ) / 2
214215
215216 # Flatten array back into 2D array for dataframe
216- offsets_shape = offsets_array .shape
217217 offsets_all_limited = offsets_array .reshape (
218- (offsets_shape [ 0 ], offsets_shape [ 1 ] * offsets_shape [ 2 ] * offsets_shape [ 3 ])
219- ). transpose ()
218+ (len ( wd_array ) * len ( ws_array ) * len ( ti_array ), offsets_all . shape [ - 1 ])
219+ )
220220 df_opt_rate_limited = df_opt .copy ()
221221 df_opt_rate_limited ["yaw_angles_opt" ] = [* offsets_all_limited ]
222222
0 commit comments