def test_scalar_components(): """Test calculating wind components with scalars""" components = get_wind_components(150, 0) assert_almost_equal(components, (0, -150)) components = get_wind_components(-150, 90) assert_almost_equal(components, (150, 0)) components = get_wind_components(10, 30) assert_almost_equal(components, (-5, -8.660254)) components = get_wind_components(20, 45) assert_almost_equal(components, (-14.1421356, -14.1421356))
def test_wind_components(): """Test wind_components with array inputs.""" speed = np.array([4., 2., 5., 0.]) wdir = np.array([0., 300., 40., 135.]) idx = 2 u, v = get_wind_components(speed, wdir) uu, vv = get_wind_components(speed[idx], wdir[idx]) assert (len(speed) == len(u)) assert (len(speed) == len(v)) assert_array_almost_equal(u[idx], uu, 4) assert_array_almost_equal(v[idx], vv, 4)
def test_wind_component(): """ Test the wind component""" u,v = get_wind_components(100, 0) assert_almost_equal(u, 0) assert_almost_equal(v, -100) speeds = np.array([100, 100, 100, 100]) directions = np.array([0, 90, 180, 275]) u_expected = np.array([-0.000000e+00, -1.000000e+02, -1.224647e-14, 9.961947e+01]) v_expected = np.array([0,0,0,0]) u,v = get_wind_components(speeds, directions) assert_array_almost_equal(u, u_expected)
def test_scalar_wind_components(): """ Tests get_wind_components with scalar inputs. """ speed = 20. wdir = 25. u,v = get_wind_components(speed,wdir) assert_almost_equal(u,-8.45236,4) assert_almost_equal(v,-18.12615,4)
def test_components(): """Test calculating wind components.""" components = get_wind_components(10, 60) expected = [-8.66, -5.00] assert_array_almost_equal(expected, components, 3)
def test_get_wind_components_array(): """Test get_wind_components for array values.""" speed = np.array([4., 2., 0., 0.]) wdir = np.array([0., 2., 4., 0.]) s = get_wind_components(speed, wdir) expected = np.array([[-0., -0.07, -0., -0.], [-4., -1.999, -0., -0.]]) assert_almost_equal(s, expected, 3)
def test_wind_comp_scalar(): speed = 10. wdir = 200. u, v = get_wind_components(speed, wdir) uu = -speed * np.sin(np.radians(wdir)) assert_almost_equal(u, uu, 3)
def test_components_array_like(): """Test calculating wind components with np arrays.""" speed = np.array([4, 8]) wdir = np.array([0, 180]) (x_components, y_components) = get_wind_components(speed, wdir) assert_array_almost_equal([0, 0], x_components, 4) assert_array_almost_equal([-4, 8], y_components, 4)
def test_wind_components_scalar(): """Test calculating wind components using scalar inputs""" s = 8.0 direc = 0 u, v = get_wind_components(s, direc) print(u, v) assert_array_almost_equal(u, -0.0, 3) assert_array_almost_equal(v, -8.0, 3)
def test_array_wind_components(): """ Tests get_wind_components with array inputs. """ speed = np.array([10,17,40,0]) wdir = np.array([3,92,210,297]) true_u = np.array([-0.523359, -16.98964, 20.0, 0.0]) true_v = np.array([-9.986295, 0.593291, 34.641016, 0.0]) u,v = get_wind_components(speed,wdir) assert_array_almost_equal(u,true_u,4) assert_array_almost_equal(v,true_v,4)
def test_wind_components_array(): """Test calculating wind components using array inputs""" s = np.array([10.0, 10.0, 10.0]) direc = np.array([0, 45, 90]) u, v = get_wind_components(s, direc) print(u) true_u = np.array([-0.0, -7.071, -10.0]) true_v = np.array([-10.0, -7.071, 0.0]) assert_array_almost_equal(u, true_u, 3) assert_array_almost_equal(v, true_v, 3)
def test_get_wind_components(): """Test that get_wind_components works with scalar and array inputs""" u, v = get_wind_components(50, 0) assert_almost_equal(u, 0, 3) assert_almost_equal(v, -50, 3) directions = np.array([0, 45, 90, 135, 180, 225, 270, 315, 360]) speeds = np.array([1, 1, 1, 1, 1, 1, 1, 1, 1]) sq2 = np.sqrt(2.0) u, v = get_wind_components(speeds, directions) expected_U = np.array( [0, -1.0 / sq2, -1.0, -1.0 / sq2, 0, 1.0 / sq2, 1.0, 1.0 / sq2, 0]) expected_V = np.array([ -1.0, -1.0 / sq2, 0.0, 1.0 / sq2, 1.0, 1.0 / sq2, 0.0, -1.0 / sq2, -1.0 ]) assert_array_almost_equal(expected_U, u, 4) assert_array_almost_equal(expected_V, v, 4)
def test_get_wind_components_scalar(): """Test calculating wind components.""" true_u = 1.7101007 true_v = 4.698463103929543 dir = 200 speed = 5 u, v = get_wind_components(speed, dir) assert_almost_equal(u, true_u) assert_almost_equal(v, true_v)
def test_wind_comps_basic(): """Test the basic wind component calculation.""" speed = np.array([4, 4, 4, 4, 25, 25, 25, 25, 10.]) dirs = np.array([0, 45, 90, 135, 180, 225, 270, 315, 360]) s2 = np.sqrt(2.) u, v = get_wind_components(speed, dirs) true_u = np.array([0, -4 / s2, -4, -4 / s2, 0, 25 / s2, 25, 25 / s2, 0]) true_v = np.array([-4, -4 / s2, 0, 4 / s2, 25, 25 / s2, 0, -25 / s2, -10]) assert_array_almost_equal(true_u, u, 4) assert_array_almost_equal(true_v, v, 4)
def test_wind_components(): """Test scalar values.""" speed1 = 100 wdir1 = 90 u1, v1 = get_wind_components(speed1, wdir1) np.testing.assert_almost_equal(u1, -100.0) np.testing.assert_almost_equal(v1, -6.123233995736766e-15) # test array values speed2 = np.array([100, 200]) wdir2 = np.array([90, 0]) speed2 = [100, 200] wdir2 = [90, 0] u2, v2 = get_wind_components(speed2, wdir2) np.testing.assert_almost_equal(u2, np.array([-100., -0.])) np.testing.assert_almost_equal( v2, np.array([-6.123234e-15, -2.000000e+02])) # test > 360 directions - catch warning wdir3 = 375 speed3 = 100 with pytest.warns(UserWarning): u2, v2 = get_wind_components(speed3, wdir3)
def test_wind_comps_scalar(): """Test wind components calculation with scalars.""" u, v = get_wind_components(8, 150) assert_almost_equal(u, -4, 3) assert_almost_equal(v, 6.9282, 3)
def test_warning_direction(): "Test the warning." with pytest.warns(UserWarning): get_wind_components(2, 400)
def test_warning_direction(): """Tests that warning is raised when warning direction is > 360.""" with pytest.warns(UserWarning): get_wind_components(3, 361)
def test_warning_direction(): """ Tests the warning is raised when wind direction > 360 """ # Raises UserWarning, since that is the default of warnings.warn # For exceptions: pytest.raise(<Exception Type>) with pytest.warns(UserWarning): get_wind_components(3,480)
def test_warning_direction(): """Test that warning is raised wind direction > 360.""" with pytest.warns(UserWarning): #warnings.warn give UserWarning by default get_wind_components(3, 480)
def test_wind_components_scalar(): """Test wind_components with scalar inputs.""" u, v = get_wind_components(4., 2.) assert_array_almost_equal(u, -0.1395, 4) assert_array_almost_equal(v, -3.9976, 4)
def test_vector_components(): """Test calculating wind components with vectors""" components = get_wind_components(np.array([150, -150, 10, 20]), np.array([0, 90, 30, 45])) results_should_be = [[0, 150, -5, -14.1421356], [-150, 0, -8.660254, -14.1421356]] assert_array_almost_equal(results_should_be, components)
def test_get_wind_components_warn(): """Test get_wind_components warning when out of range.""" with pytest.warns(UserWarning): get_wind_components(3, 480)
def test_warning_for_wind_dir(): """Test warning raised when wdir > 360.""" with pytest.warns(UserWarning): get_wind_components(10, 540)
def test_get_wind_components_scalar(): """Test get_wind_components for scalar values.""" s = get_wind_components(-3., -4.) assert_almost_equal(s, [-0.209, 2.993], 3)
def test_warning_diection(): with pytest.warns(UserWarning): get_wind_components(3, 480)
def test_wind_comps_scalar(): """Test if u and v are scalar""" u, v = get_wind_components(8, 15) assert_almost_equal(u, -2.0705, 3) assert_almost_equal(v, -7.7274066, 4)
def test_warning_error(): """ Test warning error """ with pytest.warns(UserWarning): get_wind_components(100, 400)
def test_warning_direction(): """Test that warning is raised when wind direction > 360.""" with pytest.warns(UserWarning): get_wind_components(3, 460)
def test_warning_direction(): "Test raising when direction greater than 360" with pytest.warns(UserWarning): get_wind_components(3., 400.)