def test_Wigner_D_matrices_representation_property(Rs, ell_max): # Test the representation property for special and random angles # Can't try half-integers because Wigner_D_matrices doesn't accept them ell_max = min(8, ell_max) LMpM = sf.LMpM_range(0, ell_max) print("") D1 = np.empty((LMpM.shape[0], ), dtype=complex) D2 = np.empty((LMpM.shape[0], ), dtype=complex) D12 = np.empty((LMpM.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[i:]): # print("\t\t{0} of {1}: R2 = {2}".format(j+1, len(Rs), R2)) R12 = R1 * R2 sf._Wigner_D_matrices(R1.a, R1.b, 0, ell_max, D1) sf._Wigner_D_matrices(R2.a, R2.b, 0, ell_max, D2) sf._Wigner_D_matrices(R12.a, R12.b, 0, ell_max, D12) M12 = np.array([ np.sum([ D1[sf.LMpM_index(ell, mp, mpp, 0)] * D2[sf.LMpM_index(ell, mpp, m, 0)] for mpp in range(-ell, ell + 1) ]) for ell in range(ell_max + 1) for mp in range(-ell, ell + 1) for m in range(-ell, ell + 1) ]) assert np.allclose(M12, D12, atol=ell_max * precision_Wigner_D_element)
def test_rotations_of_each_mode_individually(Rs): ell_min = 0 ell_max = 8 # sf.ell_max is just too much; this test is too slow, and ell=8 should be fine R_basis = Rs Ds = np.empty((len(Rs), sf.LMpM_total_size(ell_min, ell_max)), dtype=complex) for i, R in enumerate(Rs): Ds[i, :] = sf.Wigner_D_matrices(R, ell_min, ell_max) for ell in range(ell_max + 1): first_zeros = np.zeros((len(Rs), sf.LM_total_size(ell_min, ell - 1)), dtype=complex) later_zeros = np.zeros((len(Rs), sf.LM_total_size(ell + 1, ell_max)), dtype=complex) for Mp in range(-ell, ell): W_in = delta_waveform(ell, Mp, begin=-10.0, end=100.0, n_times=len(Rs), ell_min=ell_min, ell_max=ell_max) # Now, the modes are f^{\ell,m[} = \delta^{\ell,mp}_{L,Mp} assert W_in.ensure_validity(alter=False) W_out = scri.WaveformModes(W_in) W_out.rotate_decomposition_basis(Rs) assert W_out.ensure_validity(alter=False) assert np.array_equal(W_out.t, W_in.t) assert np.max(np.abs(W_out.frame - R_basis)) == 0.0 i_D0 = sf.LMpM_index(ell, Mp, -ell, ell_min) assert np.array_equal( W_out.data[:, :sf.LM_total_size(ell_min, ell - 1)], first_zeros) if ell < ell_max: assert np.array_equal( W_out.data[:, sf.LM_total_size(ell_min, ell - 1):-sf. LM_total_size(ell + 1, ell_max)], Ds[:, i_D0:i_D0 + (2 * ell + 1)], ) assert np.array_equal( W_out.data[:, -sf.LM_total_size(ell + 1, ell_max):], later_zeros) else: assert np.array_equal( W_out.data[:, sf.LM_total_size(ell_min, ell - 1):], Ds[:, i_D0:i_D0 + (2 * ell + 1)]) assert W_out.ell_min == W_in.ell_min assert W_out.ell_max == W_in.ell_max assert np.array_equal(W_out.LM, W_in.LM) for h_in, h_out in zip(W_in.history, W_out.history[:-1]): assert h_in == h_out.replace( type(W_out).__name__ + str(W_out.num), type(W_in).__name__ + str(W_in.num)) assert W_out.frameType == W_in.frameType assert W_out.dataType == W_in.dataType assert W_out.r_is_scaled_out == W_in.r_is_scaled_out assert W_out.m_is_scaled_out == W_in.m_is_scaled_out assert W_out.num != W_in.num
def test_LMpM_index(ell_max): for ell_min in range(ell_max + 1): LMpM = sf.LMpM_range(ell_min, ell_max) for ell in range(ell_min, ell_max + 1): for mp in range(-ell, ell + 1): for m in range(-ell, ell + 1): assert np.array_equal( np.array([ell, mp, m]), LMpM[sf.LMpM_index(ell, mp, m, ell_min)])
def test_LMpM_total_size(ell_max): for l_min in range(ell_max + 1): for l_max in range(l_min, ell_max + 1): assert sf.LMpM_index(l_max + 1, -(l_max + 1), -(l_max + 1), l_min) == sf.LMpM_total_size(l_min, l_max)