コード例 #1
0
ファイル: test_utils.py プロジェクト: Swarm-DISC/SwarmPyFAC
def test_delta_examples():
    result = utils.delta(np.arange(5))
    expected = np.array([1, 1, 1, 1])
    assert (result == expected).all()
    result2 = utils.delta(np.array([4, 3, 7, 4, 2, 92]))
    expected2 = np.array([-1, 4, -3, -2, 90])
    assert (result2 == expected2).all()
    result3 = utils.delta(np.array([[1, 0, 0], [0, 1, 3], [7, -13, 4]]))
    expected3 = np.array([[-1, 1, 3], [7, -14, 1]])
    assert (result3 == expected3).all()
コード例 #2
0
 def test_delta_means_together(self, vectors):
     for vector in vectors:
         vec_delta = sw.delta(vector)
         vec_mean = sw.means(vector)
         self.assertEqual(len(vec_delta), len(vec_mean))
         is_ascending = np.logical_and(vector[:-1] <= vec_mean,
                                       vec_mean <= vector[1:])
         is_decending = np.logical_and(vector[:-1] >= vec_mean,
                                       vec_mean >= vector[1:])
         _assert_array_equal(self, is_ascending, vec_delta >= 0)
         _assert_array_equal(self, is_decending, vec_delta <= 0)
         _assert_array_close(self,
                             sw.means(vec_delta),
                             sw.delta(vec_mean),
                             find_other=lambda i, j: vector[i + 1, j])
コード例 #3
0
 def test_diff_transform_invariance(self, vectors):
     velocities, Bs = vectors
     transform = sw.NEC_to_VSC(velocities[:-1])
     # conversion = lambda xss: np.array([[decimal.Decimal(x) for x in xs] for xs in xss])
     # # velocities = conversion(velocities)
     # Bs = conversion(Bs)
     # angles = -np.arctan2(velocities[:-1, 0] - velocities[:-1, 1],
     # velocities[:-1, 0] + velocities[:-1, 1])
     # sines = np.array(list(map(decimal.Decimal,np.sin(angles))))
     # cosines = np.array(list(map(decimal.Decimal,np.cos(angles))))
     # transform = lambda xs: sw.pack_3d(
     # cosines * xs[:,0] + sines * xs[:,1],
     # - sines * xs[:,0] + cosines * xs[:,1],
     # xs[:,2])
     B1 = transform(Bs[:-1])
     B2 = transform(Bs[1:])
     # find = lambda i,j,left,right:max(np.max(abs(left[i,:])),np.max(abs(right[i,:])))
     find = lambda i, j, left, right: max(*map(lambda x: np.max(abs(
         x)), [left[i, :], right[i, :], Bs[i, :]]))
     # left = B2-B1
     # right = transform(sw.delta(Bs))
     # if not _all_close(left,right):
     # print('Failure on:')
     # print('velocities',velocities)
     # print('Bs',Bs)
     # print('left: ', left)
     # print('right: ', right)
     # print('diff: ', left-right)
     # print('is close', np.array([[_close(one,two) for one,two in zip(oneA,twoA)] for oneA,twoA in zip(left,right)]))
     # _assert_array_close(self,left,right)
     # print(Bs,sw.delta(Bs))
     _assert_array_close(self,
                         B2 - B1,
                         transform(sw.delta(Bs)),
                         find_other=find)
コード例 #4
0
 def test_delta_properties(self, vectors):
     for vector in vectors:
         highest = np.max(abs(vector))
         vector_mod = sw.delta(vector)
         self.assertEqual(len(vector_mod), len(vector) - 1)
         effective_sum = np.array(
             [math.fsum(vector_mod[:, i]) for i in range(vector.shape[1])])
         _assert_array_close(self,
                             effective_sum,
                             vector[-1] - vector[0],
                             other_value=highest)
コード例 #5
0
ファイル: test_utils.py プロジェクト: Swarm-DISC/SwarmPyFAC
def test_curl_examples():
    vecs = utils.delta(np.arange(15).reshape(5, 3))
    assert (utils.curl(vecs, vecs) == np.array([0., 0., 0., 0.])).all()
    assert (utils.curl(
        utils.pack_3d(np.ones((4, )), -1.5 * np.ones((4, )), np.zeros((4, ))),
        vecs) == np.array([5., 5., 5., 5.])).all()