Exemplo n.º 1
0
def plot_sympix_grid_efficiency(nrings_min, grid):
    """
    Debug/diagnositc plot to verify a given grid found.
    """
    from matplotlib.pyplot import clf, gcf, draw
    # Get pure reduced legendre grid
    x0, w0 = legendre_roots(nrings_min)
    thetas0 = np.arccos(x0[::-1])
    lens0 = get_min_ring_length(thetas0, grid.nrings - 1)

    lens = grid.ring_lengths
    lens = np.concatenate([lens, lens[::-1]])
    thetas = np.concatenate([grid.thetas, np.pi - grid.thetas[::-1]])

    clf()
    fig = gcf()
    ax0 = fig.add_subplot(1, 2, 1)
    ax1 = fig.add_subplot(1, 2, 2)

    pix_dists0 = 2 * np.pi * np.sin(thetas0) / lens0
    pix_dists = 2 * np.pi * np.sin(thetas) / lens

    ax0.plot(thetas0, pix_dists0)
    ax0.plot(thetas, pix_dists)

    ax1.plot(thetas0, lens0)
    ax1.plot(thetas, lens)
    draw()
Exemplo n.º 2
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)
Exemplo n.º 3
0
def check_legendre_roots(n):
    xs, ws = ([], []) if n == 0 else p_roots(n) # from SciPy
    xl, wl = libsharp.legendre_roots(n)
    assert_allclose(xs, xl)
    assert_allclose(ws, wl)
Exemplo n.º 4
0
def check_legendre_roots(n):
    xs, ws = ([], []) if n == 0 else p_roots(n) # from SciPy
    xl, wl = libsharp.legendre_roots(n)
    assert_allclose(xs, xl, rtol=1e-14, atol=1e-14)
    assert_allclose(ws, wl, rtol=1e-14, atol=1e-14)
Exemplo n.º 5
0
def _theta_and_weights(nrings):
    x, weights = legendre_roots(nrings)
    thetas = np.arccos(x[::-1][:x.shape[0] // 2])
    weights = weights[:weights.shape[0] // 2]
    return thetas, weights