Ejemplo n.º 1
0
def test_quats():
    for x, y, z in euler_tuples:
        M1 = ttb.euler2mat(z, y, x)
        quatM = tq.mat2quat(M1)
        quat = ttb.euler2quat(z, y, x)
        assert tq.nearly_equivalent(quatM, quat)
        quatS = sympy_euler2quat(z, y, x)
        assert tq.nearly_equivalent(quat, quatS)
        zp, yp, xp = ttb.quat2euler(quat)
        # The parameters may not be the same as input, but they give the
        # same rotation matrix
        M2 = ttb.euler2mat(zp, yp, xp)
        assert_array_almost_equal(M1, M2)
Ejemplo n.º 2
0
def test_euler_imps():
    for x, y, z in euler_tuples:
        M1 = tg.euler_matrix(z, y, x, 'szyx')[:3, :3]
        M2 = ttb.euler2mat(z, y, x)
        assert_array_almost_equal(M1, M2)
        q1 = tg.quaternion_from_euler(z, y, x, 'szyx')
        q2 = ttb.euler2quat(z, y, x)
        assert tq.nearly_equivalent(q1, q2)
Ejemplo n.º 3
0
def average_anisotropic_tensor(ndat, vq, qframe=(1,0,0,0)):
    """
    The input vector vq has shape (ndat, 3), and we require the np.outer operation.
    This np.outer operation is replaced by an einstein summation shep to speed up calculations.
    """
    # Check if there is no rotation.
    if not qops.nearly_equivalent(qframe,(1,0,0,0)):
        vq = qs.rotate_vector_simd( vq, qframe, axis=-1)
    return np.mean( np.einsum('ij,ik->ijk', vq, vq), axis=0 )
Ejemplo n.º 4
0
def test_axis_angle():
    for M, q in eg_pairs:
        vec, theta = tq.quat2axangle(q)
        q2 = tq.axangle2quat(vec, theta)
        assert tq.nearly_equivalent(q, q2)
        aa_mat = taa.axangle2mat(vec, theta)
        assert_array_almost_equal(aa_mat, M)
        aa_mat2 = sympy_aa2mat(vec, theta)
        assert_array_almost_equal(aa_mat, aa_mat2)
        aa_mat22 = sympy_aa2mat2(vec, theta)
        assert_array_almost_equal(aa_mat, aa_mat22)
Ejemplo n.º 5
0
def average_anisotropic_tensor_old(vq, qframe=(1,0,0,0)):
    ndat=vq.shape[0]
    out=np.zeros((3,3))
    if qops.nearly_equivalent(qframe,(1,0,0,0)):
        for i in range(ndat):
            out+=np.outer(vq[i],vq[i])
    else:
        for i in range(ndat):
            vrot=qops.rotate_vector(vq[i],qframe)
            out+=np.outer(vrot,vrot)
    return out/ndat
Ejemplo n.º 6
0
def average_anisotropic_tensor(vq, qframe=(1,0,0,0)):
    """
    Given the list of N components of q_v in te shape of (N,3)
    Calculates the average tensor < q_i q_j >, i,j={x,y,z}
    """
    ndat=vq.shape[0]
    #print "= = Debug: vq shape", vq.shape
    # Check if there is no rotation.
    if not qops.nearly_equivalent(qframe,(1,0,0,0)):
        vq=qs.rotate_vector_simd(vq, qframe)
    return np.einsum('ij,ik->jk', vq, vq) / ndat
Ejemplo n.º 7
0
def test_axis_angle():
    for M, q in eg_pairs:
        vec, theta = tq.quat2axangle(q)
        q2 = tq.axangle2quat(vec, theta)
        assert tq.nearly_equivalent(q, q2)
        aa_mat = taa.axangle2mat(vec, theta)
        assert_array_almost_equal(aa_mat, M)
        aa_mat2 = sympy_aa2mat(vec, theta)
        assert_array_almost_equal(aa_mat, aa_mat2)
        aa_mat22 = sympy_aa2mat2(vec, theta)
        assert_array_almost_equal(aa_mat, aa_mat22)
Ejemplo n.º 8
0
def test_quaternion_imps():
    for x, y, z in euler_tuples:
        M = ttb.euler2mat(z, y, x)
        quat = tq.mat2quat(M)
        # Against transformations code
        tM = tg.quaternion_matrix(quat)
        assert_array_almost_equal(M, tM[:3, :3])
        M44 = np.eye(4)
        M44[:3, :3] = M
        tQ = tg.quaternion_from_matrix(M44)
        assert tq.nearly_equivalent(quat, tQ)
Ejemplo n.º 9
0
        #chunk_moilist=np.zeros((num_chunk,tot_int,3,3))

    index=0
    for delta in range(min_int,max_int+1,skip_int):
        time_delta=delta*data_delta_t

        #Gather the individual samples of angular displacements.
        num_nd=ndat-delta

        v_dq=obtain_self_dq(data[1:5].T, delta )[...,1:4]
        #v_dq=obtain_v_dqs(num_nd, delta, data[1:5].T)
        #Isotropic diffusion, use theta_q
        iso_sum1=average_LegendreP1quat(num_nd, v_dq)
        #Anisotropic Diffusion. Need tensor of vq
        moi=average_anisotropic_tensor(num_nd, v_dq)
        if not qops.nearly_equivalent(q_frame,(1,0,0,0)):
            moiR1=average_anisotropic_tensor(num_nd, v_dq, q_frame)
        else:
            moiR1=moi
        print( " = = %i of %i intervals summed." % ((delta-min_int)/skip_int+1, tot_int) )

        #Append to overall list in next outer loop.
        out_dtlist[index]=time_delta
        if bDoIso:
           out_isolist[index]=iso_sum1
        if bDoAniso:
            eigval, eigvec = np.linalg.eigh(moi)
            #Numpy returns the axes as column vectors.
            moi_axes=eigvec.T
            if False:
                debug_orthogonality(moi_axes)
Ejemplo n.º 10
0
def test_qexp_qlog():
    # Test round trip
    for unit_quat in unit_quats:
        assert tq.nearly_equivalent(tq.qlog(tq.qexp(unit_quat)), unit_quat)
        assert tq.nearly_equivalent(tq.qexp(tq.qlog(unit_quat)), unit_quat)