From f47b22d262dc05f88dfbaef385c14e8cc40ad633 Mon Sep 17 00:00:00 2001 From: Paul Date: Mon, 21 Oct 2024 14:31:18 -0600 Subject: [PATCH 1/5] Check for input nans --- floris/wind_data.py | 82 ++++++++++++++++++++++++++++----------------- 1 file changed, 51 insertions(+), 31 deletions(-) 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] From 1330a83d7d004ff7ced0141f9679f5c0e8396188 Mon Sep 17 00:00:00 2001 From: Paul Date: Mon, 21 Oct 2024 14:32:13 -0600 Subject: [PATCH 2/5] Add test of nan checks --- tests/wind_data_integration_test.py | 66 +++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/tests/wind_data_integration_test.py b/tests/wind_data_integration_test.py index 02d2a7ced..77677a6ed 100644 --- a/tests/wind_data_integration_test.py +++ b/tests/wind_data_integration_test.py @@ -1109,3 +1109,69 @@ def test_read_csv_long_ti(): expected_result = np.array([0.06, 0.07]) np.testing.assert_allclose(wind_ti_rose.turbulence_intensities, expected_result) + + +def test_wind_rose_nan_values(): + wind_directions = np.array([0.0, 90.0, 180.0, 270.0]) + wind_speeds = np.array([5.0, 10.0, 15.0]) + + WindRose(wind_directions, wind_speeds, ti_table=0.06) + + # Introduce NaN values + wind_directions[1] = np.nan + with pytest.raises(ValueError): + WindRose(wind_directions, wind_speeds, ti_table=0.06) + + wind_directions[1] = 90 # Reset + wind_speeds[1] = np.nan + with pytest.raises(ValueError): + WindRose(wind_directions, wind_speeds, ti_table=0.06) + + +def test_wind_ti_rose_nan_values(): + wind_directions = np.array([0.0, 90.0, 180.0, 270.0]) + wind_speeds = np.array([5.0, 10.0, 15.0]) + turbulence_intensities = np.array([0.1, 0.2, 0.3]) + + WindTIRose(wind_directions, wind_speeds, turbulence_intensities) + + # Introduce NaN values + wind_directions[1] = np.nan + with pytest.raises(ValueError): + WindTIRose(wind_directions, wind_speeds, turbulence_intensities) + + wind_directions[1] = 90 # Reset + wind_speeds[1] = np.nan + with pytest.raises(ValueError): + WindTIRose(wind_directions, wind_speeds, turbulence_intensities) + + wind_speeds[1] = 10 # Reset + turbulence_intensities[1] = np.nan + with pytest.raises(ValueError): + WindTIRose(wind_directions, wind_speeds, turbulence_intensities) + + +def test_time_series_nan_values(): + wind_directions = np.array([0.0, 90.0, 180.0, 270.0]) + wind_speeds = np.array([5.0, 10.0, 15.0]) + turbulence_intensities = np.array([0.1, 0.2, 0.3, 0.4]) + values = np.array([1.0, 2.0, 3.0, 4.0]) + + # Introduce NaN values + wind_directions[1] = np.nan + with pytest.raises(ValueError): + TimeSeries(wind_directions, wind_speeds, turbulence_intensities, values) + + wind_directions[1] = 90 # Reset + wind_speeds[1] = np.nan + with pytest.raises(ValueError): + TimeSeries(wind_directions, wind_speeds, turbulence_intensities, values) + + wind_speeds[1] = 10 # Reset + turbulence_intensities[1] = np.nan + with pytest.raises(ValueError): + TimeSeries(wind_directions, wind_speeds, turbulence_intensities, values) + + values[1] = np.nan + with pytest.raises(ValueError): + TimeSeries(wind_directions, wind_speeds, turbulence_intensities, values) From 1acda7cd4bf616a2a1ab85ef2ec1f1ac55e9478d Mon Sep 17 00:00:00 2001 From: misi9170 Date: Mon, 3 Mar 2025 15:09:32 -0700 Subject: [PATCH 3/5] Revert autoformatting changes. --- floris/wind_data.py | 69 +++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 37 deletions(-) diff --git a/floris/wind_data.py b/floris/wind_data.py index dad568650..a45af33c0 100644 --- a/floris/wind_data.py +++ b/floris/wind_data.py @@ -181,7 +181,7 @@ def __init__( if np.isnan(wind_speeds).any(): raise ValueError("wind_speeds contains NaN values") - # Confirm that both wind_directions and wind_speeds are monitonically + # Confirm that both wind_directions and wind_speeds are monotonically # increasing and evenly spaced if len(wind_directions) > 1: # Check monotonically increasing @@ -596,17 +596,15 @@ 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 @@ -629,7 +627,11 @@ 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))) @@ -642,7 +644,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)) ) ) @@ -1592,21 +1594,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 @@ -1637,20 +1639,24 @@ 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 @@ -1658,21 +1664,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 @@ -2187,17 +2193,6 @@ 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 @@ -3005,7 +3000,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] From 00507c643ca25c63949df5bf3043c280f4849fba Mon Sep 17 00:00:00 2001 From: misi9170 Date: Mon, 3 Mar 2025 15:30:23 -0700 Subject: [PATCH 4/5] Move NaN error checks to existing instantiation tests. --- tests/wind_data_integration_test.py | 94 +++++++++-------------------- 1 file changed, 28 insertions(+), 66 deletions(-) diff --git a/tests/wind_data_integration_test.py b/tests/wind_data_integration_test.py index c9cf4abf6..621ee54aa 100644 --- a/tests/wind_data_integration_test.py +++ b/tests/wind_data_integration_test.py @@ -37,6 +37,21 @@ def test_time_series_instantiation(): with pytest.raises(TypeError): TimeSeries(wind_directions, wind_speeds) + # Test instantiation with NaN values + with pytest.raises(ValueError, match="contains NaN values"): + TimeSeries(np.array([270, 280, np.nan]), wind_speeds) + with pytest.raises(ValueError, match="contains NaN values"): + TimeSeries(wind_directions, np.array([np.nan, 5, 5,])) + with pytest.raises(ValueError, match="contains NaN values"): + TimeSeries(wind_directions, wind_speeds, np.array([0.06, np.nan, 0.06])) + with pytest.raises(ValueError, match="contains NaN values"): + TimeSeries( + wind_directions, + wind_speeds, + 0.06*np.ones_like(wind_speeds), + np.array([1.0, np.nan, 3.0, 4.0]) + ) + # Test that passing a float TI returns a list of length matched to wind directions time_series = TimeSeries(wind_directions, wind_speeds, turbulence_intensities=0.06) np.testing.assert_allclose(time_series.turbulence_intensities, [0.06, 0.06, 0.06]) @@ -81,6 +96,12 @@ def test_wind_rose_init(): with pytest.raises(ValueError): WindRose(np.array([290, 280, 270]), np.array([6, 7]), 0.06) + # Test that passing in a NaN value raises an error + with pytest.raises(ValueError, match="contains NaN values"): + WindRose(np.array([270, 280, np.nan]), np.array([6, 7]), 0.06) + with pytest.raises(ValueError, match="contains NaN values"): + WindRose(np.array([270, 280, 290]), np.array([np.nan, 7]), 0.06) + wind_directions = np.array([270, 280, 290]) wind_speeds = np.array([6, 7]) @@ -750,6 +771,13 @@ def test_wind_ti_rose_init(): with pytest.raises(ValueError): WindTIRose(wind_directions, wind_speeds, turbulence_intensities, np.ones((3, 3, 3))) + # Test that passing in a NaN value raises an error + with pytest.raises(ValueError, match="contains NaN values"): + WindRose(np.array([270, 280, np.nan, 300]), wind_speeds, turbulence_intensities) + with pytest.raises(ValueError, match="contains NaN values"): + WindRose(wind_directions, np.array([6, np.nan, 8]), turbulence_intensities) + with pytest.raises(ValueError, match="contains NaN values"): # FAILING + WindRose(wind_directions, wind_speeds, np.array([0.05, np.nan])) def test_wind_ti_rose_grid(): wind_directions = np.array([270, 280, 290, 300]) @@ -1110,69 +1138,3 @@ def test_read_csv_long_ti(): expected_result = np.array([0.06, 0.07]) np.testing.assert_allclose(wind_ti_rose.turbulence_intensities, expected_result) - - -def test_wind_rose_nan_values(): - wind_directions = np.array([0.0, 90.0, 180.0, 270.0]) - wind_speeds = np.array([5.0, 10.0, 15.0]) - - WindRose(wind_directions, wind_speeds, ti_table=0.06) - - # Introduce NaN values - wind_directions[1] = np.nan - with pytest.raises(ValueError): - WindRose(wind_directions, wind_speeds, ti_table=0.06) - - wind_directions[1] = 90 # Reset - wind_speeds[1] = np.nan - with pytest.raises(ValueError): - WindRose(wind_directions, wind_speeds, ti_table=0.06) - - -def test_wind_ti_rose_nan_values(): - wind_directions = np.array([0.0, 90.0, 180.0, 270.0]) - wind_speeds = np.array([5.0, 10.0, 15.0]) - turbulence_intensities = np.array([0.1, 0.2, 0.3]) - - WindTIRose(wind_directions, wind_speeds, turbulence_intensities) - - # Introduce NaN values - wind_directions[1] = np.nan - with pytest.raises(ValueError): - WindTIRose(wind_directions, wind_speeds, turbulence_intensities) - - wind_directions[1] = 90 # Reset - wind_speeds[1] = np.nan - with pytest.raises(ValueError): - WindTIRose(wind_directions, wind_speeds, turbulence_intensities) - - wind_speeds[1] = 10 # Reset - turbulence_intensities[1] = np.nan - with pytest.raises(ValueError): - WindTIRose(wind_directions, wind_speeds, turbulence_intensities) - - -def test_time_series_nan_values(): - wind_directions = np.array([0.0, 90.0, 180.0, 270.0]) - wind_speeds = np.array([5.0, 10.0, 15.0]) - turbulence_intensities = np.array([0.1, 0.2, 0.3, 0.4]) - values = np.array([1.0, 2.0, 3.0, 4.0]) - - # Introduce NaN values - wind_directions[1] = np.nan - with pytest.raises(ValueError): - TimeSeries(wind_directions, wind_speeds, turbulence_intensities, values) - - wind_directions[1] = 90 # Reset - wind_speeds[1] = np.nan - with pytest.raises(ValueError): - TimeSeries(wind_directions, wind_speeds, turbulence_intensities, values) - - wind_speeds[1] = 10 # Reset - turbulence_intensities[1] = np.nan - with pytest.raises(ValueError): - TimeSeries(wind_directions, wind_speeds, turbulence_intensities, values) - - values[1] = np.nan - with pytest.raises(ValueError): - TimeSeries(wind_directions, wind_speeds, turbulence_intensities, values) From ba72caf489d4d3d8de524913547c1fc015d32271 Mon Sep 17 00:00:00 2001 From: misi9170 Date: Mon, 3 Mar 2025 15:47:15 -0700 Subject: [PATCH 5/5] Use same form of NaN errors. --- floris/wind_data.py | 4 ++-- tests/wind_data_integration_test.py | 30 ++++++++++++++--------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/floris/wind_data.py b/floris/wind_data.py index cf04894b5..802a0fb4e 100644 --- a/floris/wind_data.py +++ b/floris/wind_data.py @@ -176,10 +176,10 @@ def __init__( # 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") + raise ValueError("wind_directions must not contain NaNs") if np.isnan(wind_speeds).any(): - raise ValueError("wind_speeds contains NaN values") + raise ValueError("wind_speeds must not contain NaNs") # Confirm that both wind_directions and wind_speeds are monotonically # increasing and evenly spaced diff --git a/tests/wind_data_integration_test.py b/tests/wind_data_integration_test.py index 621ee54aa..57288145f 100644 --- a/tests/wind_data_integration_test.py +++ b/tests/wind_data_integration_test.py @@ -38,18 +38,18 @@ def test_time_series_instantiation(): TimeSeries(wind_directions, wind_speeds) # Test instantiation with NaN values - with pytest.raises(ValueError, match="contains NaN values"): - TimeSeries(np.array([270, 280, np.nan]), wind_speeds) - with pytest.raises(ValueError, match="contains NaN values"): - TimeSeries(wind_directions, np.array([np.nan, 5, 5,])) - with pytest.raises(ValueError, match="contains NaN values"): + with pytest.raises(ValueError, match="contain NaNs"): + TimeSeries(np.array([270, 280, np.nan]), wind_speeds, turbulence_intensities=0.06) + with pytest.raises(ValueError, match="contain NaNs"): + TimeSeries(wind_directions, np.array([np.nan, 5, 5,]), turbulence_intensities=0.06) + with pytest.raises(ValueError, match="contain NaNs"): TimeSeries(wind_directions, wind_speeds, np.array([0.06, np.nan, 0.06])) - with pytest.raises(ValueError, match="contains NaN values"): + with pytest.raises(ValueError, match="contain NaNs"): TimeSeries( wind_directions, wind_speeds, 0.06*np.ones_like(wind_speeds), - np.array([1.0, np.nan, 3.0, 4.0]) + np.array([1.0, np.nan, 3.0]) ) # Test that passing a float TI returns a list of length matched to wind directions @@ -97,9 +97,9 @@ def test_wind_rose_init(): WindRose(np.array([290, 280, 270]), np.array([6, 7]), 0.06) # Test that passing in a NaN value raises an error - with pytest.raises(ValueError, match="contains NaN values"): + with pytest.raises(ValueError, match="contain NaNs"): WindRose(np.array([270, 280, np.nan]), np.array([6, 7]), 0.06) - with pytest.raises(ValueError, match="contains NaN values"): + with pytest.raises(ValueError, match="contain NaNs"): WindRose(np.array([270, 280, 290]), np.array([np.nan, 7]), 0.06) wind_directions = np.array([270, 280, 290]) @@ -772,12 +772,12 @@ def test_wind_ti_rose_init(): WindTIRose(wind_directions, wind_speeds, turbulence_intensities, np.ones((3, 3, 3))) # Test that passing in a NaN value raises an error - with pytest.raises(ValueError, match="contains NaN values"): - WindRose(np.array([270, 280, np.nan, 300]), wind_speeds, turbulence_intensities) - with pytest.raises(ValueError, match="contains NaN values"): - WindRose(wind_directions, np.array([6, np.nan, 8]), turbulence_intensities) - with pytest.raises(ValueError, match="contains NaN values"): # FAILING - WindRose(wind_directions, wind_speeds, np.array([0.05, np.nan])) + with pytest.raises(ValueError, match="contain NaNs"): + WindTIRose(np.array([270, 280, np.nan, 300]), wind_speeds, turbulence_intensities) + with pytest.raises(ValueError, match="contain NaNs"): + WindTIRose(wind_directions, np.array([6, np.nan, 8]), turbulence_intensities) + with pytest.raises(ValueError, match="contain NaNs"): + WindTIRose(wind_directions, wind_speeds, np.array([0.05, np.nan])) def test_wind_ti_rose_grid(): wind_directions = np.array([270, 280, 290, 300])