diff --git a/floris/wind_data.py b/floris/wind_data.py index b470fe515..dad568650 100644 --- a/floris/wind_data.py +++ b/floris/wind_data.py @@ -174,6 +174,13 @@ def __init__( if not isinstance(wind_speeds, np.ndarray): raise TypeError("wind_speeds must be a NumPy array") + # Confirm that none of wind_directions or wind_speeds contain NaN values + if np.isnan(wind_directions).any(): + raise ValueError("wind_directions contains NaN values") + + if np.isnan(wind_speeds).any(): + raise ValueError("wind_speeds contains NaN values") + # Confirm that both wind_directions and wind_speeds are monitonically # increasing and evenly spaced if len(wind_directions) > 1: @@ -589,15 +596,17 @@ def upsample(self, wd_step=None, ws_step=None, method="linear", inplace=False): # This is the case when wind directions doesn't cover the full range of possible # degrees (0-360) if np.abs((wd_range_min_current % 360.0) - (wd_range_max_current % 360.0)) > 1e-6: - wind_direction_column = np.concatenate(( - np.array([wd_range_min_current]), - wind_direction_column, - np.array([wd_range_max_current]) - )) - ti_matrix = ti_matrix = np.vstack((ti_matrix[0, :], ti_matrix, ti_matrix[-1,:])) - freq_matrix = np.vstack((freq_matrix[0, :], freq_matrix, freq_matrix[-1,:])) + wind_direction_column = np.concatenate( + ( + np.array([wd_range_min_current]), + wind_direction_column, + np.array([wd_range_max_current]), + ) + ) + ti_matrix = ti_matrix = np.vstack((ti_matrix[0, :], ti_matrix, ti_matrix[-1, :])) + freq_matrix = np.vstack((freq_matrix[0, :], freq_matrix, freq_matrix[-1, :])) if self.value_table is not None: - value_matrix = np.vstack((value_matrix[0, :], value_matrix, value_matrix[-1,:])) + value_matrix = np.vstack((value_matrix[0, :], value_matrix, value_matrix[-1, :])) # In the alternative case, where the wind directions cover the full range # ie, 0, 10, 20 30, ...350, then need to place 0 at 360 and 350 at -10 @@ -620,11 +629,7 @@ def upsample(self, wd_step=None, ws_step=None, method="linear", inplace=False): # Pad out the wind speeds wind_speed_column = np.concatenate( - ( - np.array([ws_range_min_current]), - wind_speed_column, - np.array([ws_range_max_current]) - ) + (np.array([ws_range_min_current]), wind_speed_column, np.array([ws_range_max_current])) ) ti_matrix = np.hstack( (ti_matrix[:, 0].reshape((-1, 1)), ti_matrix, ti_matrix[:, -1].reshape((-1, 1))) @@ -637,7 +642,7 @@ def upsample(self, wd_step=None, ws_step=None, method="linear", inplace=False): ( value_matrix[:, 0].reshape((-1, 1)), value_matrix, - value_matrix[:, -1].reshape((-1, 1)) + value_matrix[:, -1].reshape((-1, 1)), ) ) @@ -1121,6 +1126,14 @@ def __init__( if not isinstance(turbulence_intensities, np.ndarray): raise TypeError("turbulence_intensities must be a NumPy array") + # Check that wind_directions, wind_speeds, and turbulence_intensities do not contain NaNs + if np.isnan(wind_directions).any(): + raise ValueError("wind_directions must not contain NaNs") + if np.isnan(wind_speeds).any(): + raise ValueError("wind_speeds must not contain NaNs") + if np.isnan(turbulence_intensities).any(): + raise ValueError("turbulence_intensities must not contain NaNs") + # Confirm that both wind_directions and wind_speeds # and turbulence intensities are monotonically # increasing and evenly spaced @@ -1579,21 +1592,21 @@ def upsample(self, wd_step=None, ws_step=None, ti_step=None, method="linear", in ( np.array([wd_range_min_current]), wind_direction_column, - np.array([wd_range_max_current]) + np.array([wd_range_max_current]), ) ) freq_matrix = np.concatenate( (freq_matrix[0, :, :][None, :, :], freq_matrix, freq_matrix[-1, :, :][None, :, :]), - axis=0 + axis=0, ) if self.value_table is not None: value_matrix = np.concatenate( ( value_matrix[0, :, :][None, :, :], value_matrix, - value_matrix[-1, :, :][None, :, :] + value_matrix[-1, :, :][None, :, :], ), - axis=0 + axis=0, ) # In the alternative case, where the wind directions cover the full range @@ -1624,24 +1637,20 @@ def upsample(self, wd_step=None, ws_step=None, ti_step=None, method="linear", in # Pad out the wind speeds wind_speed_column = np.concatenate( - ( - np.array([ws_range_min_current]), - wind_speed_column, - np.array([ws_range_max_current]) - ) + (np.array([ws_range_min_current]), wind_speed_column, np.array([ws_range_max_current])) ) freq_matrix = np.concatenate( (freq_matrix[:, 0, :][:, None, :], freq_matrix, freq_matrix[:, -1, :][:, None, :]), - axis=1 + axis=1, ) if self.value_table is not None: value_matrix = np.concatenate( ( value_matrix[:, 0, :][:, None, :], value_matrix, - value_matrix[:, -1, :][:, None, :] + value_matrix[:, -1, :][:, None, :], ), - axis=1 + axis=1, ) # Pad out the turbulence intensities @@ -1649,21 +1658,21 @@ def upsample(self, wd_step=None, ws_step=None, ti_step=None, method="linear", in ( np.array([ti_range_min_current]), turbulence_intensity_column, - np.array([ti_range_max_current]) + np.array([ti_range_max_current]), ) ) freq_matrix = np.concatenate( (freq_matrix[:, :, 0][:, :, None], freq_matrix, freq_matrix[:, :, -1][:, :, None]), - axis=2 + axis=2, ) if self.value_table is not None: value_matrix = np.concatenate( ( value_matrix[:, :, 0][:, :, None], value_matrix, - value_matrix[:, :, -1][:, :, None] + value_matrix[:, :, -1][:, :, None], ), - axis=2 + axis=2, ) # Grid wind directions, wind speeds and turbulence intensities to match the @@ -2178,6 +2187,17 @@ def __init__( if len(wind_directions) != len(values): raise ValueError("wind_directions and values must be the same length") + # Confirm that none of wind_directions, wind_speeds, turbulence_intensitiess and + # values contain NaNs + if np.isnan(wind_directions).any(): + raise ValueError("wind_directions must not contain NaNs") + if np.isnan(wind_speeds).any(): + raise ValueError("wind_speeds must not contain NaNs") + if np.isnan(turbulence_intensities).any(): + raise ValueError("turbulence_intensities must not contain NaNs") + if values is not None and np.isnan(values).any(): + raise ValueError("values must not contain NaNs") + self.wind_directions = wind_directions self.wind_speeds = wind_speeds self.turbulence_intensities = turbulence_intensities @@ -2985,7 +3005,7 @@ def _generate_wind_speed_frequencies_from_weibull(self, A, k, wind_speeds=None): wind_speeds = self.wind_speeds ws_steps = np.diff(wind_speeds) if not np.all(np.isclose(ws_steps, ws_steps[0])): - raise ValueError("wind_speeds must be equally spaced.") + raise ValueError("wind_speeds must be equally spaced.") else: ws_step = ws_steps[0]