Esempio n. 1
0
def wsp_dir2uv(wsp, dir, dir_ref=None):
    """Convert horizontal wind speed and direction to u,v

    Parameters
    ----------
    wsp : array_like
        Horizontal wind speed
    dir : array_like
        Wind direction
    dir_ref : int or float, optional
        Reference direction\n
        If None, default, the mean direction is used as reference

    Returns
    -------
    u : array_like
        u wind component
    v : array_like
        v wind component
    """
    if dir_ref is None:
        dir = dir[:] - mean_deg(dir[:])
    else:
        dir = dir[:] - dir_ref
    u = np.cos(rad(dir)) * wsp[:]
    v = -np.sin(rad(dir)) * wsp[:]
    return np.array([u, v])
Esempio n. 2
0
def test_rotation_matrixes():
    npt.assert_array_almost_equal(rotmat([rad(30), rad(60)], 0), [[[1., 0., 0.],
                                                                   [0., 0.8660254, -0.5],
                                                                   [0., 0.5, 0.8660254]],
                                                                  [[1., 0., 0.],
                                                                   [0., 0.5, -0.8660254, ],
                                                                   [0., +0.8660254, 0.5]]])
Esempio n. 3
0
def test_rotation_matrix():
    npt.assert_array_almost_equal(rotmat(rad(30), x), [[[1., 0., 0.],
                                                        [0., 0.8660254, -0.5],
                                                        [0., 0.5, 0.8660254]]])
    npt.assert_array_almost_equal(rotmat(rad(30), y), [[[0.8660254, 0., 0.5],
                                                        [0., 1., 0],
                                                        [-0.5, 0, 0.8660254]]])
    npt.assert_array_almost_equal(rotmat(rad(30), z), [[[0.8660254, -0.5, 0.],
                                                        [0.5, 0.8660254, 0],
                                                        [0., 0, 1]]])
Esempio n. 4
0
 def test_transformation_matrix(self):
     np.testing.assert_array_almost_equal(
         transformation_matrix(rad(30), x),
         [[[1., 0., 0.], [0., 0.8660254, 0.5], [0., -0.5, 0.8660254]]])
     np.testing.assert_array_almost_equal(
         transformation_matrix(rad(30), y),
         [[[0.8660254, 0., -0.5], [0., 1., 0], [0.5, 0, 0.8660254]]])
     np.testing.assert_array_almost_equal(
         transformation_matrix(rad(30), z),
         [[[0.8660254, 0.5, 0.], [-0.5, 0.8660254, 0], [0., 0, 1]]])
 def test_rad_deg(self):
     for i in [15, 0.5, 355, 400]:
         self.assertEqual(i, deg(rad(i)), i)
 def test_rad(self):
     self.assertEqual(rad(45), np.pi / 4)
     self.assertEqual(rad(135), np.pi * 3 / 4)