コード例 #1
0
    def test_axis(self):
        x = np.array([[355, 5, 2, 359, 10, 350], [351, 7, 4, 352, 9, 349],
                      [357, 9, 8, 358, 4, 356]])
        M1 = circ_average(x, high=360)
        M2 = circ_average(x.ravel(), high=360)
        np.testing.assert_allclose(M1, M2, rtol=1e-14)

        M1 = circ_average(x, high=360, axis=1)
        M2 = [circ_average(x[i], high=360) for i in range(x.shape[0])]
        np.testing.assert_allclose(M1, M2, rtol=1e-14)

        M1 = circ_average(x, high=360, axis=0)
        M2 = [circ_average(x[:, i], high=360) for i in range(x.shape[1])]
        np.testing.assert_allclose(M1, M2, rtol=1e-14)
コード例 #2
0
 def test_range(self):
     m = circ_average(np.arange(0, 2, 0.1), np.pi, -np.pi)
     assert m < np.pi
     assert m > -np.pi
コード例 #3
0
 def test_scalar(self):
     x = 1.
     M1 = x
     M2 = circ_average(x)
     np.testing.assert_allclose(M2, M1, rtol=1e-5)
コード例 #4
0
 def test_empty(self):
     assert np.isnan(circ_average([]))
コード例 #5
0
 def test_array_like(self):
     x = [355, 5, 2, 359, 10, 350]
     np.testing.assert_allclose(circ_average(x, high=360),
                                0.167690146,
                                rtol=1e-7)
コード例 #6
0
 def test_small(self):
     x = np.array([20, 21, 22, 18, 19, 20.5, 19.2])
     expected = x.mean()
     assert circ_average(x, high=360) == pytest.approx(expected)
コード例 #7
0
 def test_high_360(self):
     x = np.array([355, 5, 2, 359, 10, 350])
     expected = 0.167690146
     assert circ_average(x, high=360) == pytest.approx(expected)
コード例 #8
0
 def test_no_weights(self):
     expected = 3.136593
     assert circ_average([-3.14, 3.13]) == pytest.approx(expected)