Esempio n. 1
0
def test_legendre_table_wrapper_logic():
    # tests the SSE 2 logic in the high-level wrapper by using an odd number of thetas
    theta = np.asarray([np.pi/2, np.pi/4, 3 * np.pi / 4])
    m = 3
    lmax = 10
    Plm = normalized_associated_legendre_table(lmax, m, theta)
    assert np.allclose(Plm[1, :], normalized_associated_legendre_table(lmax, m, np.pi/4)[0, :])
    assert np.allclose(Plm[2, :], normalized_associated_legendre_table(lmax, m, 3 * np.pi/4)[0, :])
def test_legendre_table_wrapper_logic():
    # tests the SSE 2 logic in the high-level wrapper by using an odd number of thetas
    theta = np.asarray([np.pi / 2, np.pi / 4, 3 * np.pi / 4])
    m = 3
    lmax = 10
    Plm = normalized_associated_legendre_table(lmax, m, theta)
    assert np.allclose(
        Plm[1, :],
        normalized_associated_legendre_table(lmax, m, np.pi / 4)[0, :])
    assert np.allclose(
        Plm[2, :],
        normalized_associated_legendre_table(lmax, m, 3 * np.pi / 4)[0, :])
Esempio n. 3
0
def arbitrary_beam_by_l(beam_function, params, lmax):
    """
    Find the Legendre coefficients :math:`b_\ell` for an arbitrary (symmetric) 
    real-space beam function, such that 
    :math:`B(\theta) = \sum_\ell (2\ell + 1) b_\ell P_\ell(\cos \theta)`.
    
    Arguments:
      beam_function -- Python function which takes arguments fn(theta, params)
      params -- Tuple containing parameters for the beam function (e.g. FWHM)
      lmax -- Max. l to calculate :math:`b_\ell` up to
    
    Returns:
      b_l -- 1D array of coefficients, for the l-range [0, lmax].
    """
    order = lmax
    l = np.arange(lmax + 1)

    # Get zeros and weights of the Legendre polynomials
    # (Zeros are symmetric about x=0, so only keep the nonzero ones)
    xi, wi = libsharp.legendre_roots(2 * order)
    xi = xi[order:]
    wi = 2. * wi[order:]

    # Get Legendre polynomials and normalise them
    leg = libsharp.normalized_associated_legendre_table(lmax, 0, np.arccos(xi))
    leg *= np.sqrt(4 * np.pi) / np.sqrt(2 * l + 1)

    # Perform Gauss-Legendre sum
    f = np.atleast_2d(wi * beam_function(np.arccos(xi), *params)).T * leg
    return 0.25 * np.sum(f, axis=0)
    def test(theta, m, lmax):
        Plm = normalized_associated_legendre_table(lmax, m, theta)

        Plm_p = sph_harm(m, np.arange(m, lmax + 1), 0, theta)[None, :]
        if not np.allclose(Plm_p, Plm):
            print(Plm_p)
            print(Plm)
        return ok_, np.allclose(Plm_p, Plm)
Esempio n. 5
0
    def test(theta, m, lmax):
        Plm = normalized_associated_legendre_table(lmax, m, theta)

        Plm_p = sph_harm(m, np.arange(m, lmax + 1), 0, theta)[None, :]
        if not np.allclose(Plm_p, Plm):
            print(Plm_p)
            print(Plm)
        return ok_, np.allclose(Plm_p, Plm)