예제 #1
0
def gen_leg_real(lmax, theta):
    cost = np.cos(theta)
    sint = np.sin(theta)
    maxIndex = int( (lmax+1)*(lmax+2)/2 )
    leg = np.zeros( ( maxIndex, theta.size ) )
    leg_d1 = np.zeros( ( maxIndex, theta.size ) )
    dp_leg = np.zeros( (maxIndex, theta.size) )

    count = 0
    for z in cost:
        leg[:, count], leg_d1[:, count] = pleg.PlmBar_d1(lmax, z, 1, 1)
        count += 1
    dt_leg = leg_d1 * (-sint).reshape(1, sint.shape[0])
    
    ellArr = np.zeros(maxIndex)
    emmArr = np.zeros(maxIndex)
    countm, countl = 0, 0
    for i in range(maxIndex):
        ellArr[i] = countl
        emmArr[i] = countm
        if countm==countl:
            countl += 1
            countm = 0
        else:
            countm += 1
    norm = np.sqrt( ellArr * (ellArr + 1) )
    norm[norm<1] = 1.0
    
    legtemp = leg.copy()
    dp_leg = emmArr.reshape(maxIndex, 1) * legtemp / sint.reshape(1, sint.shape[0])
    dt_leg /= norm.reshape(maxIndex, 1)
    dp_leg /= norm.reshape(maxIndex, 1)
    return leg/sqrt(2)/sqrt(2*pi), dt_leg/sqrt(2)/sqrt(2*pi), dp_leg/sqrt(2)/sqrt(2*pi)
예제 #2
0
def gen_leg(lmax, theta):
    """Generates legendre polynomials and derivatives normalized to 1.0

    Parameters:
    -----------
    lmax - int
        maximum spherical harmonic degree
    theta - np.ndarray(ndim=1, dtype=float)
        array for theta to compute P_l(cos(theta))

    Returns:
    --------
    leg - np.ndarray(ndim=2, dtype=float)
        P_l(cos(theta))
    dt_leg - np.ndarray(ndim=2, dtype=float)
        d/d(theta) P_l(cos(theta)) 
    dp_leg - np.ndarray(ndim=2, dtype=complex)
        im * P_l(cos(theta)) / sin(theta)

    """
    cost = np.cos(theta)
    sint = np.sin(theta)
    maxIndex = int((lmax + 1) * (lmax + 2) / 2)
    leg = np.zeros((maxIndex, theta.size))
    leg_d1 = np.zeros((maxIndex, theta.size))
    dp_leg = np.zeros((maxIndex, theta.size), dtype=complex)

    count = 0
    for z in cost:
        leg[:, count], leg_d1[:, count] = pleg.PlmBar_d1(lmax, z, 1, 1)
        count += 1
    dt_leg = leg_d1 * (-sint).reshape(1, sint.shape[0])

    ellArr = np.zeros(maxIndex)
    emmArr = np.zeros(maxIndex)
    countm, countl = 0, 0
    for i in range(maxIndex):
        ellArr[i] = countl
        emmArr[i] = countm
        if countm == countl:
            countl += 1
            countm = 0
        else:
            countm += 1
    norm = np.sqrt(ellArr * (ellArr + 1))
    norm[norm < 1] = 1.0

    legtemp = leg.copy()
    dp_leg = 1j * emmArr.reshape(maxIndex, 1) \
            * legtemp / sint.reshape(1, sint.shape[0])
    dt_leg /= norm.reshape(maxIndex, 1)
    dp_leg /= norm.reshape(maxIndex, 1)

    return leg/sqrt(2)/sqrt(2*pi), \
            dt_leg/sqrt(2)/sqrt(2*pi), \
            dp_leg/sqrt(2)/sqrt(2*pi)