Exemplo n.º 1
0
def test_LMpM_range_half_integer(ell_max):
    for twoell_max in range(2 * ell_max + 1):
        assert np.array_equal(
            sf.LMpM_range_half_integer(twoell_max / 2, twoell_max / 2),
            np.array([[twoell_max / 2, twomp / 2, twom / 2]
                      for twomp in range(-twoell_max, twoell_max + 1, 2)
                      for twom in range(-twoell_max, twoell_max + 1, 2)]))
        for twoell_min in range(twoell_max):
            a = sf.LMpM_range_half_integer(twoell_min / 2, twoell_max / 2)
            b = np.array([[twoell / 2, twomp / 2, twom / 2]
                          for twoell in range(twoell_min, twoell_max + 1)
                          for twomp in range(-twoell, twoell + 1, 2)
                          for twom in range(-twoell, twoell + 1, 2)])
            assert np.array_equal(a, b)
Exemplo n.º 2
0
def test_Wigner_D_elements_representation_property(Rs, ell_max):
    # Test the representation property for special and random angles
    # Try half-integers, too
    ell_max = min(8, ell_max)
    twoLMpM = np.round(2 * sf.LMpM_range_half_integer(0, ell_max)).astype(int)
    print("")
    D1 = np.empty((twoLMpM.shape[0], ), dtype=complex)
    D2 = np.empty((twoLMpM.shape[0], ), dtype=complex)
    D12 = np.empty((twoLMpM.shape[0], ), dtype=complex)
    for i, R1 in enumerate(Rs):
        print("\t{0} of {1}: R1 = {2}".format(i + 1, len(Rs), R1))
        for j, R2 in enumerate(Rs):
            # print("\t\t{0} of {1}: R2 = {2}".format(j+1, len(Rs), R2))
            R12 = R1 * R2
            sf._Wigner_D_element(R1.a, R1.b, twoLMpM, D1)
            sf._Wigner_D_element(R2.a, R2.b, twoLMpM, D2)
            sf._Wigner_D_element(R12.a, R12.b, twoLMpM, D12)
            M12 = np.array([
                np.sum([
                    D1[sf._Wigner_index(twoell, twomp, twompp)] *
                    D2[sf._Wigner_index(twoell, twompp, twom)]
                    for twompp in range(-twoell, twoell + 1, 2)
                ]) for twoell in range(2 * ell_max + 1)
                for twomp in range(-twoell, twoell + 1, 2)
                for twom in range(-twoell, twoell + 1, 2)
            ])
            # if not np.allclose(M12, D12, atol=ell_max * precision_Wigner_D_element):
            #     for k in range(min(100, M12.size)):
            #         print(twoLMpM[k], "\t", abs(D12[k]-M12[k]), "\t\t", D12[k], "\t", M12[k])
            #     print(D12.shape, M12.shape)
            assert np.allclose(M12,
                               D12,
                               atol=ell_max * precision_Wigner_D_element)
Exemplo n.º 3
0
def test_Wigner_D_element_values(special_angles, ell_max):
    LMpM = sf.LMpM_range_half_integer(0, ell_max // 2)
    # Compare with more explicit forms given in Euler angles
    print("")
    for alpha in special_angles:
        print("\talpha={0}".format(
            alpha))  # Need to show some progress to Travis
        for beta in special_angles:
            print("\t\tbeta={0}".format(beta))
            for gamma in special_angles:
                a = np.conjugate(
                    np.array([
                        slow_Wigner_D_element(alpha, beta, gamma, ell, mp, m)
                        for ell, mp, m in LMpM
                    ]))
                b = sf.Wigner_D_element(
                    quaternion.from_euler_angles(alpha, beta, gamma), LMpM)
                # if not np.allclose(a, b,
                #     atol=ell_max ** 6 * precision_Wigner_D_element,
                #     rtol=ell_max ** 6 * precision_Wigner_D_element):
                #     for i in range(min(a.shape[0], 100)):
                #         print(LMpM[i], "\t", abs(a[i]-b[i]), "\t\t", a[i], "\t", b[i])
                assert np.allclose(
                    a,
                    b,
                    atol=ell_max**6 * precision_Wigner_D_element,
                    rtol=ell_max**6 * precision_Wigner_D_element)