예제 #1
0
def make_series(mul=1.0,
                x=1.0,
                y=1.0,
                order=1,
                sum=False,
                legendre=False,
                zero=True):
    if zero:
        res = [np.ones_like(x) * mul]
    else:
        res = []

    for i in xrange(1, order + 1):
        maxr = i + 1
        if legendre:
            maxr = order + 1

        for j in xrange(maxr):
            #print i, '-', i - j, j
            if legendre:
                res.append(mul * leg(i)(x) * leg(j)(y))
            else:
                res.append(mul * x**(i - j) * y**j)
    if sum:
        return np.sum(res, axis=0)
    else:
        return res
예제 #2
0
def gauquad(f, a, b, n=50):
    '''
    定义 Gaussian quadrature 积分
    函数 f 的积分区间为 [a,b]
    取 n 个 Legendre 的根
    def Gaussian quadrature integration
    integrate function f from a to b
    take n Legendre roots
    '''
    ft = lambda t: f((b - a) * t / 2 + (a + b) / 2) * (b - a) / 2
    x, w = leg(n)
    I = 0
    for i in range(n):
        I = I + w[i] * ft(x[i])
    err = 0
    return I, err
예제 #3
0
	def gl_eva(self,Lmax): 
	    Gtau=self.gt()
	    tau=self.tau()
	    Ntau=self.Ntau()
	    beta=self.beta()
	    Gl=zeros(Lmax)
	    xtau=[]
	    for t in tau:
	        xtau.append(2.0*t/beta-1.)
	    for i in range(Lmax):
	        y=[]
	        for j in range(Ntau):
	            y.append(leg(i,xtau[j])*Gtau[j])
	        y=array(y)
	        Gl[i]=sqrt(2.*i+1)*integrate.simps(y,tau)
	    return Gl
예제 #4
0
	def Gtau_Gl(self,Gl,Lcut):
	    tau=self.tau()
	    beta=self.beta()
	    Ntau=self.Ntau()
	    Gtau_gl=[]
	    xtau=[]
	    Lmax=len(Gl)
	    if Lmax<Lcut:
	       raise Exception('Lcut used to construct Gtau is greater than Lmax!!!')
	    for t in tau:
	        xtau.append(2.0*t/beta-1.)
	    for i in range(Ntau):
	        sumGtau=0.0
		for j in range(Lcut):
		    sumGtau+=sqrt(2.*j+1)/beta*Gl[j]*leg(j,xtau[i])
		Gtau_gl.append(sumGtau)
	    Gtau_gl=array(Gtau_gl)
	    return Gtau_gl
예제 #5
0
print('Theta values (deg):')
print(th_list)

ll = np.arange(l_start, l_stop + 1)

binsz_x = 360. / N_x  #bin size in degrees
binsz_y = 180. / N_y
NPIX = hp.pixelfunc.nside2npix(NSIDE)  #number of pixel of the conversion map
iii = range(NPIX)
B, L = np.array(hp.pixelfunc.pix2ang(
    NSIDE, iii))  #gives b,l in radians (colatitude and longitude)
#print np.degrees(B),np.degrees(L)

pl_list = []  #Legendre polynomials
for k in range(len(th_list)):
    pl_list.append(leg(ll, np.cos(np.radians(th_list[k]))))


def normalization(moll_array):
    #moll_array[np.isinf(moll_array)] = 0.0
    moll_array = moll_array + np.abs(np.min(moll_array))
    moll_array = moll_array / (np.max(moll_array))
    return moll_array


#coordinates of the cartesian projection
l_interp = np.arange(N_x) * binsz_x
b_interp = np.arange(N_y) * binsz_y

#coordinates conversion
L, B = np.array((np.degrees(L) + 180.) % 360), np.array(180. - np.degrees(B))
예제 #6
0
#!/usr/bin/env python
from scipy import *
from pylab import *
from scipy.special import eval_legendre as leg


def check_norm(poly):
    sump = 0.0
    N = len(poly)
    for i in range(N):
        sump += poly[i]**2
    print sump


if __name__ == "__main__":
    NL = 6  ## number of Legendre polynominals to be plotted
    Lmin = 191
    Lmax = 196
    Nx = 200
    Legp = []
    x = linspace(-1, 1, Nx)
    print "Dx=", x[1] - x[0]
    for n in range(Lmin, Lmax):
        y = leg(n, x)
        Legp.append(y)
        plot(x, y, label='L=' + str(n))
    legend(loc=0)
    ylim([-1.2, 1.2])
    check_norm(Legp[0])
    show()
예제 #7
0
plot_test = False
###############################################################
NPIX = 12 * NSIDE**2
ll = np.arange(l_start, l_stop)
norm = 2. * np.pi / (ll * (ll + 1))

th_list = np.logspace(np.log10(theta_min), np.log10(theta_max), num=10)
print('Theta values (deg):')
print(th_list)
cl_list = [np.insert(ll, 0, range(l_start))]
CCF_list = [th_list]
A = (2. * ll + 1.) / (4. * np.pi)
pl = []
for i in range(len(th_list)):
    pl.append(leg(ll, np.cos(np.radians(th_list[i]))))

print('factor for the correlation function:', fact)

if tag is not '':
    text = '#TAG: ' + tag + '\n' + '#Maps number: ' + str(
        N_start) + ' - ' + str(N_stop) + '\n' + '#N, N1h, N2h, alpha' + '\n'
    text_cl = '#TAG: ' + tag + '\n' + '#Maps number: ' + str(
        N_start) + ' - ' + str(N_stop) + '\n'
    text_CCF = '#TAG: ' + tag + '\n' + '#Maps number: ' + str(
        N_start) + ' - ' + str(N_stop) + '\n'
    tag = tag + '_'
else:
    text = '#Maps number: ' + str(N_start) + ' - ' + str(
        N_stop) + '\n' + '#N, N1h, N2h, alpha' + '\n'
    text_cl = '#Maps number: ' + str(N_start) + ' - ' + str(N_stop) + '\n'
예제 #8
0
def pkd(j, k, x, y):
    return (1 - y) ** j * leg(j, 2 * x / (1 - y) - 1) * jac(k, 2 * j + 1, 0, 2 * y - 1)
예제 #9
0
def che2w(x):
    return np.sqrt(1-x**2)

def jacw(x, a=1, b=1):
    return (1-x)**a*(1+x)**b

def inte(nodes, ws, typ=0):
    funlst = [legw, che1w, che2w, jacw]
    ft = g(nodes)/funlst[typ](nodes)
    return (ws*ft).sum()*(b-a)/2

for n in ns:
    nodeout = 'nodes:   ' + '{:>8.5f} '*n
    wout = 'weights: ' + '{:>8.5f} '*n

    lnds, lws = leg(n)
    intt = inte(lnds, lws, 0)
    print('Legendre')
    print(f'n: {n}, integration: {intt:>8.5f}')
    print(nodeout.format(*lnds))
    print(wout.format(*lws))

    c1nds, c1ws = che1(n)
    intt = inte(c1nds, c1ws, 1)
    print('Chebyshev 1')
    print(f'n: {n}, integration: {intt:>8.5f}')
    print(nodeout.format(*c1nds))
    print(wout.format(*c1ws))

    c2nds, c2ws = che2(n)
    intt = inte(c2nds, c2ws, 2)