-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscaledlegs.py
80 lines (62 loc) · 1.67 KB
/
scaledlegs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#! /usr/bin/env python
"""
Name:
scaledlegs
Purpose:
show legendre polynomials * (2l+1) together
Uses:
Inputs:
Outputs:
Modification History:
Written by Z Knight, 2016.09.07
"""
import numpy as np
import matplotlib.pyplot as plt
#import healpy as hp
#import time # for measuring duration
#import get_crosspower as gcp
from numpy.polynomial.legendre import legval # for C_l -> C(theta) conversion
from numpy.polynomial.legendre import legfit # for C(theta) -> C_l conversion
#from ispice import ispice
#from legprodint import getJmn
#from scipy.interpolate import interp1d
def legplot(nterms=6):
"""
Purpose:
calculate (2l+1)/4pi * Pl and plot
Procedure:
Inputs:
nterms: the number of Pl to plot, starting from 0
Returns:
theta values and scaled legendre polynomials
"""
coefs = np.zeros([nterms,nterms])
for coef in range(nterms):
coefs[coef,coef] = ((2*coef)+1)/(4*np.pi)
npoints = 1801
thetavals = np.linspace(0,180,npoints)
xvals = np.cos(thetavals*np.pi/180.)
print 'x vals: ',xvals
Pl = np.empty([nterms,npoints])
for ell in range(nterms):
Pl[ell] = legval(xvals,coefs[ell])
#print 'l = ',ell,', scaled Pl = ',Pl[ell]
plt.plot(thetavals,Pl[ell],label='l = '+str(ell))
plt.xlabel('angle (degrees)')
plt.ylabel('P_l * (2*l+1)/4pi')
plt.title('scaled legendre polynomials')
#plt.legend()
plt.show()
return thetavals,Pl
################################################################################
# testing code
def test(nterms=6):
"""
Purpose:
function for testing legplot
Inputs:
"""
thetavals,Pl = legplot(nterms=nterms)
print 'step 3: profit'
if __name__=='__main__':
test()