In [1]:
%matplotlib inline

import matplotlib
import numpy as np
import matplotlib.pyplot as plt

from matplotlib import rc
rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']})
## for Palatino and other serif fonts use:
#rc('font',**{'family':'serif','serif':['Palatino']})
rc('text', usetex=True)

In [2]:
%pwd


Out[2]:
u'/Users/evanbiederstedt'

In [3]:
cd downloads


/Users/evanbiederstedt/Downloads

In [4]:
cd class_public-master


/Users/evanbiederstedt/Downloads/class_public-master

In [5]:
#run CPU.py -h

In [6]:
#run CPU.py output/explanatory200_cl.dat

In [7]:
#run output/explanatory200_cl.py

In [8]:
#run output/cl_test1.py

In [9]:
import classy

In [10]:
from classy import Class

In [11]:
from math import *
import sys

from classy import Class
from numpy.polynomial.legendre import legval
cosmo = Class()
cosmo.set({'output':'lCl, tCl','lensing':'no'})
cosmo.compute()


cls = cosmo.raw_cl()
print 'cls = ', cls
ntot = len(cls)
print 'number of cls = ', ntot


cls =  {'tt': array([  0.00000000e+00,   0.00000000e+00,   1.56538072e-10, ...,
         9.43319972e-18,   9.38755966e-18,   9.34218587e-18]), 'ell': array([   0,    1,    2, ..., 2498, 2499, 2500]), 'pp': array([  0.00000000e+00,   0.00000000e+00,   9.24246249e-09, ...,
         1.09790035e-22,   1.09474821e-22,   1.09160652e-22]), 'tp': array([  0.00000000e+00,   0.00000000e+00,   5.08325759e-10, ...,
         2.55087868e-23,   2.56363260e-23,   2.57653852e-23])}
number of cls =  4

In [12]:
def legpols(n, t):
    pols = np.zeros(n+1)
    pols[0] = 1.0
    pols[1] = t
    for i in range(1,n):
        pols[i+1] = ((i*2.0+1)*t*pols[i] - i*pols[i-1])/(i+1.0)        
    return pols

In [13]:
n = 2000
alphas = np.exp(np.linspace(np.log(pi/18000), np.log(pi), num=n, endpoint=False))
print 'alphas = ', alphas


alphas =  [  1.74532925e-04   1.75390071e-04   1.76251426e-04 ...,   3.09575772e+00
   3.11096124e+00   3.12623943e+00]

In [14]:
val = np.zeros(n)

In [15]:
for i in range(n):
    t = cos(alphas[i])
    pols = legpols(ntot+10, t)
    val[i] = 0
    for j in range(ntot):
        val[i] = val[i] + (2.0*j+1)*cls[j]*pols[j]


---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-15-30b3a37701ef> in <module>()
      4     val[i] = 0
      5     for j in range(ntot):
----> 6         val[i] = val[i] + (2.0*j+1)*cls[j]*pols[j]

KeyError: 0

In [ ]: