Beispiel #1
0
def A(x, pars, lmax=2000):
    # Gets the spectrum for a set of parameters
    if len(pars) == 5:
        H0, ombh2, omch2, As, ns = pars
        tau = 0.05
    elif len(pars) == 1:
        H0, ombh2, omch2, As, ns = [
            68.4756197, .0224459632, .116026743, 2.05024029e-09, .969172419
        ]
        tau = pars[0]
    else:
        H0, ombh2, omch2, As, ns, tau = pars
    pars = camb.CAMBparams()
    pars.set_cosmology(H0=H0,
                       ombh2=ombh2,
                       omch2=omch2,
                       mnu=0.06,
                       omk=0,
                       tau=tau)
    pars.InitPower.set_params(As=As, ns=ns, r=0)
    pars.set_for_lmax(lmax, lens_potential_accuracy=0)
    results = camb.get_results(pars)
    powers = results.get_cmb_power_spectra(pars, CMB_unit='muK')
    cmb = powers['total']
    tt = cmb[:,
             0]  #you could return the full power spectrum here if you wanted to do say EE
    return tt[x.astype(int)]
Beispiel #2
0
 def __initialize_nonlin_CAMB(self):
     print 'Initializing nonlinear CAMB.'
     parsnl = camb.CAMBparams()
     parsnl.set_cosmology(H0=self.H0,
                          ombh2=self.Ob * self.h**2.,
                          omch2=self.Oc * self.h**2.,
                          omk=0.,
                          mnu=self.Mnu,
                          standard_neutrino_neff=self.Neff,
                          nnu=self.Neff,
                          TCMB=self.TCMB)
     parsnl.InitPower.set_params(ns=self.ns,
                                 As=self.As,
                                 pivot_scalar=self.pivot_scalar)
     #        parsnl.NonLinear = model.NonLinear_both
     parsnl.set_matter_power(redshifts=[0.], kmax=101.)
     self.my_PK_psi = get_matter_power_interpolator(
         parsnl,
         zmin=0.,
         zmax=1100.,
         nz_step=150,
         kmax=101.,
         nonlinear=True,
         hubble_units=True,
         k_hunit=True,
         var1=model.Transfer_Weyl,
         var2=model.Transfer_Weyl).P
Beispiel #3
0
def get_spectrum(p, lmax_acc=2000, lmax_ret=1200):
    """Get power spectrum with CAMB
    Args:
        p: parameters H0, ombh2, omch2, tau, As, ns
        lmax_acc: maximum l index for the accuracy of calculations
        lmax_ret: maximum l index for the returned power spectrum
    Returns:
        tt: TT power spectrum for multipole indices 2 (quadrupole) to lmax_ret
    """
    H0 = p[0]
    ombh2 = p[1]
    omch2 = p[2]
    tau = p[3]
    As = p[4]
    ns = p[5]
    pars = camb.CAMBparams()
    pars.set_cosmology(H0=H0, ombh2=ombh2, omch2=omch2, omk=0.0, mnu=0.06,
                       tau=tau)
    pars.InitPower.set_params(As=As, ns=ns, r=0)
    pars.set_for_lmax(lmax_acc, lens_potential_accuracy=0)
    results = camb.get_results(pars)
    powers = results.get_cmb_power_spectra(pars, CMB_unit='muK', lmax=lmax_ret)
    cmb = powers['total']
    tt = cmb[:, 0][2:]  # don't need first to indices

    return tt
Beispiel #4
0
    def test_cosmo_io_read_write_c_ell(self):

        pars = camb.CAMBparams(**self.cosmo_opts)
        cosmo_new = Cosmology(pars)

        with tempfile.TemporaryDirectory(dir=self.path) as tmpdirname:

            filename = os.path.join(tmpdirname, 'c_ell')
            self.cosmo.write_c_ell(filename)

            cosmo_new.read_c_ell(filename)

            np.testing.assert_almost_equal(
                cosmo_new.c_ell['lensed_scalar']['c_ell'],
                self.cosmo.c_ell['lensed_scalar']['c_ell'])

            np.testing.assert_equal(cosmo_new.c_ell['lensed_scalar']['ells'],
                                    self.cosmo.c_ell['lensed_scalar']['ells'])

            np.testing.assert_almost_equal(
                cosmo_new.c_ell['unlensed_scalar']['c_ell'],
                self.cosmo.c_ell['unlensed_scalar']['c_ell'])

            np.testing.assert_equal(
                cosmo_new.c_ell['unlensed_scalar']['ells'],
                self.cosmo.c_ell['unlensed_scalar']['ells'])
Beispiel #5
0
def matterps2corr2esd(redshift,cosmology):
  z    = redshift
  H_null,Ombh2,Omch2=cosmology
  pars = camb.CAMBparams()
  pars.set_cosmology(H0=H_null,ombh2=Ombh2,omch2=Omch2)
  pars.set_dark_energy()
  pars.InitPower.set_params(ns=nps)
  pars.set_matter_power(redshifts=[0.0,z],kmax=2.0)

  #Linear spectra--------
  pars.NonLinear=model.NonLinear_none
  results       =camb.get_results(pars)
  kh,znon,pk    =results.get_matter_power_spectrum(minkh=1e-4,maxkh=1000.0,npoints=1024)
  xi            =mcfit.P2xi(kh,l=0)
  #Calculate corr from PS------
  nxx   = 50
  Rmin  = -2.0
  Rmax  = 2.0
  rr    = np.logspace(Rmin,Rmax,nxx) 
  rx,corrfunc   =xi(pk,extrap=True)
  corr  = np.interp(rr,rx,corrfunc[0,:])
  #Calculate ESD from corr------
  nxx   = 10
  Rp    = np.linspace(0.03,20.,nxx)   
  ESD   = np.zeros(nxx) 

  for i in range(nxx):
    tmp1     = integrate.quad(simR,Rp[i]+0.001,90.0,args=(rr,corr,Rp[i]),epsabs=1e-4)
    tmp2     = integrate.quad(simLR,0.001,Rp[i],args=(rr,corr,Rp[i]),epsabs=1e-4)
    ESD[i]   = (4.0*tmp2[0]/Rp[i]/Rp[i]-2.0*tmp1[0])*omega_m*h  #Luo et al 2017ApJ 836 38L EQ. 39-40

  return {'Rp':Rp,'ESD':ESD}
Beispiel #6
0
def getPars():
    """
    Purpose:
      quickly get camb parameters object
      follows example code from http://camb.readthedocs.io/en/latest/CAMBdemo.html
        but with slightly different parameters
    Inputs:

    Returns:
      the pars object
  """
    #Set up a new set of parameters for CAMB
    pars = camb.CAMBparams()
    #This function sets up CosmoMC-like settings, with one massive neutrino and helium set using BBN consistency
    #pars.set_cosmology(H0=67.5, ombh2=0.022, omch2=0.122, mnu=0.06, omk=0, tau=0.06) #why 0.122?
    pars.set_cosmology(H0=67.51,
                       ombh2=0.022,
                       omch2=0.119,
                       mnu=0.06,
                       omk=0,
                       tau=0.06)
    pars.set_dark_energy()  #re-set defaults
    pars.InitPower.set_params(ns=0.965, r=0)

    return pars
Beispiel #7
0
def change_neutrino(mnu):
    '''
    mnu : neutrino mass (eV)

    other params set to Planck 2018 results
    '''
    # setup six init params from the paper
    params = camb.CAMBparams()  # the obj stores params
    params.set_cosmology(H0=67.4,
                         ombh2=0.022383,
                         omch2=0.122011,
                         omk=0,
                         tau=0.0543,
                         mnu=mnu,
                         neutrino_hierarchy='degenerate')
    params.InitPower.set_params(As=np.exp(3.0448) * 1e-10, ns=0.96605)

    params.set_for_lmax(2500, lens_potential_accuracy=0)

    # calculate the results of params
    results = camb.get_results(params)

    # get power spec
    power_spec = results.get_cmb_power_spectra(params,
                                               CMB_unit="muK",
                                               lmax=2500)

    return power_spec
Beispiel #8
0
def change_curvature(omk):
    '''
    omk : curvature density

    other params set to Planck 2018 results
    '''
    # setup six init params from the paper
    params = camb.CAMBparams()  # the obj stores params
    params.set_cosmology(H0=67.4,
                         ombh2=0.022383,
                         omch2=0.122011,
                         omk=omk,
                         tau=0.0543)
    params.InitPower.set_params(As=np.exp(3.0448) * 1e-10, ns=0.96605)

    params.set_for_lmax(2500, lens_potential_accuracy=0)

    # calculate the results of params
    results = camb.get_results(params)

    # get power spec
    power_spec = results.get_cmb_power_spectra(params,
                                               CMB_unit="muK",
                                               lmax=2500)

    return power_spec
Beispiel #9
0
def rspectrum(nu, r, sig, scaling=1.0):
    """
    Calculates the CMB amplituded given a value of r and requested modes
    """
    import camb
    from camb import model, initialpower
    import healpy as hp
    #Set up a new set of parameters for CAMB
    pars = camb.CAMBparams()
    #This function sets up CosmoMC-like settings, with one massive neutrino and helium set using BBN consistency
    pars.set_cosmology(H0=67.5, ombh2=0.022, omch2=0.122, mnu=0.06, omk=0, tau=0.06)
    pars.InitPower.set_params(As=2e-9, ns=0.965, r=r)
    lmax=6000
    pars.set_for_lmax(lmax,  lens_potential_accuracy=0)
    pars.WantTensors = True
    results = camb.get_results(pars)
    powers = results.get_cmb_power_spectra(params=pars, lmax=lmax, CMB_unit='muK', raw_cl=True,)


    l = np.arange(2,lmax+1)

    if sig == "TT":
        cl = powers['unlensed_scalar']
        signal = 0
    elif sig == "EE":
        cl = powers['unlensed_scalar']
        signal = 1
    elif sig == "BB":
        cl = powers['tensor']
        signal = 2

    bl = hp.gauss_beam(40/(180/np.pi*60), lmax,pol=True)
    A = np.sqrt(sum( 4*np.pi * cl[2:,signal]*bl[2:,signal]**2/(2*l+1) ))
    return cmb(nu, A*scaling)
Beispiel #10
0
def compute_ffp8(ombh2, omch2, omnuh2, H0, tau, As, ns):
    r'''
    Computes a lensed TT `D_\ell` power spectrum given a set of cosmological
    parameters.
    '''
    Neff = 3.046
    params = camb.CAMBparams(
        omnuh2=omnuh2,
        H0=H0,
        ombh2=ombh2,
        omch2=omch2,
        num_nu_massive=1,
        num_nu_massless=Neff - 1,
        nu_mass_degeneracies=[Neff / 3],
        nu_mass_fractions=[1.0],
        nu_mass_numbers=[1],
        tau=tau,
        WantTransfer=True,
        # By default uses PArthENoPE
        bbn_predictor=camb.bbn.BBN_table_interpolator())

    params.InitPower.set_params(As=As, ns=ns)  #, r=0)
    params.Transfer.accurate_massive_neutrinos = True
    params.Transfer.high_precision = True
    params.set_for_lmax(2500, lens_potential_accuracy=1)

    params.Reion.use_optical_depth = True
    params.Reion.optical_depth = tau

    result = camb.get_results(params)
    return result.get_cmb_power_spectra(params, CMB_unit='muK')
Beispiel #11
0
    def __init__(self,omega_m,sigma_8,h,z):
        self.omega_m = omega_m
        self.sigma_8 = sigma_8
        self.h = h
        self.z = z
        self.k_max = 10.0
        self.c = 2.99792e+5
        #=========================
        
        cosmo = camb.CAMBparams()
        cosmo.set_cosmology(H0=100.0*self.h, ombh2=0.048*(self.h**2.0), omch2=(self.omega_m - 0.048)*(self.h**2.0), mnu=0.06, omk=0, tau=0.06)
        cosmo.InitPower.set_params(As=2.0e-9, ns=0.973)
        results = camb.get_results(cosmo)
        cosmo.set_matter_power(redshifts=[0.0], kmax=10.0)
        cambres= camb.get_transfer_functions(cosmo)
        cosmo.NonLinear = model.NonLinear_both
        kh, z, pk = cambres.get_matter_power_spectrum(minkh=1e-3, maxkh=1.0, npoints = 10)
        sigma_8_temp = cambres.get_sigma8()
        As_new  = ((self.sigma_8/sigma_8_temp)**2.0)*(2.0e-9)
        cosmo.InitPower.set_params(As=As_new, ns=0.973)
        cambres = camb.get_results(cosmo)
        backres = camb.get_background(cosmo)

        self.chi = backres.comoving_radial_distance(self.z)
           
        self.PK = camb.get_matter_power_interpolator(cosmo, nonlinear=True, 
                hubble_units=False, k_hunit=False, kmax=self.k_max, zmin = 0.0, zmax=self.z[-1]) 
        
        self.H_z = (backres.hubble_parameter(self.z))/self.c #Hubble parameter in 1/Mpc 
Beispiel #12
0
    def parametrosCAMB():

        #Se preparan los parámetros de CAMB
        pars = camb.CAMBparams()

        #Set cosmology || Se preparan los datos cosmológicos a como se desean.
        pars.set_cosmology(H0=H00,
                           ombh2=omegab * pow(hubble, 2),
                           omch2=omegac * pow(hubble, 2),
                           omk=0,
                           mnu=0)
        pars.set_dark_energy()  #LCDM (default)
        pars.InitPower.set_params(ns=nss, r=0, As=Ass)
        pars.set_for_lmax(2500, lens_potential_accuracy=0)

        #Se calculan resultados para esos parámetros
        results = camb.get_results(pars)

        #Get matter power spectrum at z=0: P(k,z=0)
        pars.set_matter_power(redshifts=[0.], kmax=2.0)

        #Linear spectra
        pars.NonLinear = model.NonLinear_none
        results.calc_power_spectra(pars)
        kh, z, pk = results.get_matter_power_spectrum(minkh=1e-4,
                                                      maxkh=2.0,
                                                      npoints=200)
        return kh, z, pk
Beispiel #13
0
def CL_mat(theta, pts, NL):
    pars = camb.CAMBparams()
    pars.set_cosmology(H0=theta[0],
                       ombh2=theta[1],
                       omch2=theta[2],
                       mnu=mnu,
                       omk=omk,
                       tau=theta[5])
    pars.InitPower.set_params(As=theta[3], ns=theta[4], r=r)
    pars.set_for_lmax(pts, lens_potential_accuracy=0)
    results = camb.get_results(pars)
    powers = results.get_cmb_power_spectra(pars, CMB_unit="muK")
    totCL = powers['total']
    ls = np.arange(totCL.shape[0])
    TT = totCL[:, 0]
    EE = totCL[:, 1]
    TE = totCL[:, 3]
    CL = []
    for element in ls:
        Cmatrix = np.zeros((2, 2))
        Cmatrix[0, 0] = TT[element] + NL[element]
        Cmatrix[1, 1] = EE[element] + NL[element]
        Cmatrix[0, 1], Cmatrix[1, 0] = TE[element], TE[element]
        CL.append(Cmatrix)
    return (np.array(CL)[2:])
Beispiel #14
0
def camb_sigma8(cosmology, camb_params=None):
    """get camb sigma8
        inputs:
            cosmology: can vary H0, Omegabh2,Omegach2,Omegak,mnu,As,ns,OmegaL and w
            camb_params: some parameters controling k
    """
    if camb_params is None:
        raise ValueError('need camb params')
    pars = camb.CAMBparams()
    pars.set_cosmology(H0=cosmology['H0'],
                       ombh2=cosmology['Omegabh2'],
                       omch2=cosmology['Omegach2'],
                       omk=cosmology['Omegak'],
                       mnu=cosmology['mnu'])
    if 'As' in cosmology:
        pars.InitPower.set_params(ns=cosmology['ns'], As=cosmology['As'])
    else:
        warn('cannot compute sigma8 reliably without input As')
        pars.InitPower.set_params(ns=cosmology['ns'])
    pars.set_dark_energy(cosmology['w'])  #re-set defaults
    pars.omegav = cosmology['OmegaL']
    pars.set_matter_power(redshifts=[0.], kmax=camb_params['kmax'])
    results = camb.get_results(pars)
    sigma8 = results.get_sigma8()[0]
    pars.set_dark_energy()  #re-set defaults
    return sigma8
Beispiel #15
0
def change_lambda(omlambda):
    '''
    omlambda : dark energy density

    other params set to Planck 2018 results
    '''
    H0 = 67.4
    h2 = (H0 * 0.01)**2
    omm = 0.321

    omb = 0.02212 / h2 / (omm + omlambda)
    omc = 0.1206 / h2 / (omm + omlambda)

    # calc ombh2 and omch2
    ombh2 = omb * h2
    omch2 = omc * h2

    # setup six init params from the paper
    params = camb.CAMBparams()  # the obj stores params
    params.set_cosmology(H0=H0, ombh2=ombh2, omch2=omch2, omk=0, tau=0.0543)
    params.InitPower.set_params(As=np.exp(3.0448) * 1e-10, ns=0.96605)

    params.set_for_lmax(2500, lens_potential_accuracy=0)

    # calculate the results of params
    results = camb.get_results(params)

    # get power spec
    power_spec = results.get_cmb_power_spectra(params,
                                               CMB_unit="muK",
                                               lmax=2500)

    return power_spec
def Gencl(r=0.05, raw_cl=True, tensorBB_only=False):
    '''
    Generate the theoretical power spectra using camb
    '''

    pars = camb.CAMBparams()
    pars.set_cosmology(H0=67.26,
                       ombh2=0.022,
                       omch2=0.1199,
                       mnu=0.06,
                       omk=0,
                       tau=0.078)
    pars.InitPower.set_params(As=2.19856 * 1e-9, ns=0.9652, r=r)
    pars.set_for_lmax(3000, lens_potential_accuracy=1)
    pars.WantTensors = True

    results = camb.get_results(pars)
    powers = results.get_cmb_power_spectra(pars, CMB_unit='muK', raw_cl=raw_cl)

    if tensorBB_only:
        totCL = powers['tensor']  ## TT EE BB TE

        return totCL.T[2]

    else:

        totCL = powers['total']  ## TT EE BB TE

        return totCL.T
def get_spectrum_fix(pars, lmax=1500):
    """Give the power spectrum of the CMB using the camb package with tau fixed.
    -Arguments: -pars (array): The parmaters for the model that will be updated
                -lmax (array): Number of point at which we evaluate the function
    -Returns:   -tt   (array): The power spectrum evaluated up to around lmax"""
    H0 = pars[0]
    ombh2 = pars[1]
    omch2 = pars[2]
    tau = 0.05
    As = pars[3]
    ns = pars[4]
    pars = camb.CAMBparams()
    pars.set_cosmology(H0=H0,
                       ombh2=ombh2,
                       omch2=omch2,
                       mnu=0.06,
                       omk=0,
                       tau=tau)
    pars.InitPower.set_params(As=As, ns=ns, r=0)
    pars.set_for_lmax(lmax, lens_potential_accuracy=0)
    results = camb.get_results(pars)
    powers = results.get_cmb_power_spectra(pars, CMB_unit='muK')
    cmb = powers['total']
    tt = cmb[:,
             0]  #you could return the full power spectrum here if you wanted to do say EE
    return tt
Beispiel #18
0
def convert_mead_cosmology(cosm, verbose=False):

    # Set up a new default set of parameters for CAMB
    pars = camb.CAMBparams()

    # Get CAMB cosmology from my structure
    wb = cosm.w_b
    wc = cosm.w_c
    h = cosm.h
    As = cosm.As
    ns = cosm.ns
    w = cosm.w
    wa = cosm.wa
    Om_k = cosm.Om_k
    m_nu = cosm.m_nu

    # This function sets standard and helium set using BBN consistency
    pars.set_cosmology(ombh2=wb, omch2=wc, H0=100. * h, mnu=m_nu, omk=Om_k)
    pars.set_dark_energy(w=w, wa=wa, dark_energy_model='ppf')
    pars.InitPower.set_params(As=As, ns=ns, r=0)

    # Print out the full list of cosmological parameters
    if (verbose):
        print(pars)

    return pars
Beispiel #19
0
	def __init__(self, params=None, smica_path=None):
		# Setting cosmo params
		if params is None:
			params = def_cosmo.copy()
		else:
			for key, val in def_cosmo.iteritems():
				params.setdefault(key,val)
		self.params = params.copy()

		#Let's initialize CAMB for distances, growth factor ders, and CMB TT spectrum
		self.pars = camb.CAMBparams()
		self.pars.set_cosmology(H0=self.params['H0'], ombh2=self.params['ombh2'], omch2=self.params['omch2'], mnu=self.params['mnu'], omk=self.params['omk'], tau=self.params['tau'])
		self.pars.InitPower.set_params(As=params['As'], ns=params['ns'], r=0)
		self.pars.set_for_lmax(2500, lens_potential_accuracy=0);
		results = camb.get_results(self.pars)
		self.bkd = camb.get_background(self.pars)
		self.eta_star = self.bkd.conformal_time(1089) # conformal time at recombination

		cmb = results.get_cmb_power_spectra(self.pars,lmax=1000, raw_cl=True)
		self.TCMBmuK = 2.726e6
		self.cltt = np.copy(cmb['lensed_scalar'][:,0])*self.TCMBmuK**2 # muK^2
		
		self.zmin = 0
		self.zmax = 8
		self.nz   = 300
		self.z = np.linspace(self.zmin,self.zmax,self.nz)
		ev = results.get_redshift_evolution(1e-2, self.z, ['growth'])

		self.growth_eta = UnivariateSpline(self.bkd.conformal_time(self.z[::-1]), ev[:, 0][::-1], ext=3)
		self.der_growtg_eta = self.growth_eta.derivative()
	
		if smica_path is None:
			self.smica_path = '/Users/fbianchini/Research/pSZ/data/smica_nside512.fits'
		self.smica_init = False
Beispiel #20
0
def make_cl(r=0,
            return_cl=True,
            Alens=1.,
            lmax=2500,
            tau=0.054,
            As=2.1e-9,
            ombh2=0.02227716,
            omch2=0.1184293):
    pars = camb.CAMBparams()
    pars.WantTensors = True
    pars.set_cosmology(H0=67.86682,
                       ombh2=ombh2,
                       omch2=omch2,
                       mnu=0.06,
                       omk=0,
                       tau=tau)
    pars.InitPower.set_params(ns=0.9682903, r=r, As=As)
    pars.set_for_lmax(lmax - 50, lens_potential_accuracy=0)
    results = camb.get_results(pars)
    powers = results.get_cmb_power_spectra(pars, CMB_unit='muK')
    if Alens == 0:
        totCL = powers['unlensed_total'].T
    else:
        tot_tensor = powers['tensor'].T
        tot_lens = powers['lensed_scalar'].T * Alens
        totCL = tot_tensor + tot_lens
    if return_cl:
        l = np.arange(len(totCL[0]))
        totCL = 2 * np.pi * totCL / l / (l + 1)
        totCL[:, 0] = 0
    return totCL
Beispiel #21
0
    def test_cosmology_init(self):

        pars = camb.CAMBparams(**self.cosmo_opts)

        cosmo = Cosmology(pars)

        self.assertIs(cosmo.camb_params.WantTensors, False)
        self.assertIs(cosmo.camb_params.DoLateRadTruncation, False)
        self.assertIs(cosmo.camb_params.WantCls, True)
        self.assertIs(cosmo.camb_params.WantTransfer, False)
        self.assertIs(cosmo.camb_params.DoLensing, True)
        self.assertEqual(cosmo.camb_params.Accuracy.AccuracyBoost, 2)
        self.assertEqual(cosmo.camb_params.Accuracy.lSampleBoost, 2)
        self.assertEqual(cosmo.camb_params.Accuracy.lAccuracyBoost, 2)
        self.assertIs(cosmo.camb_params.Accuracy.AccurateBB, True)
        self.assertIs(cosmo.camb_params.Accuracy.AccurateReionization, True)
        self.assertEqual(cosmo.camb_params.Accuracy.BessIntBoost, 30)
        self.assertEqual(cosmo.camb_params.Accuracy.KmaxBoost, 3)
        self.assertEqual(cosmo.camb_params.Accuracy.IntTolBoost, 4)
        self.assertEqual(cosmo.camb_params.Accuracy.TimeStepBoost, 4)
        self.assertEqual(cosmo.camb_params.Accuracy.SourcekAccuracyBoost, 5)
        self.assertEqual(cosmo.camb_params.Accuracy.BesselBoost, 5)
        self.assertEqual(cosmo.camb_params.Accuracy.IntkAccuracyBoost, 5)
        self.assertEqual(cosmo.camb_params.Accuracy.lSampleBoost, 2)
        self.assertEqual(cosmo.camb_params.Accuracy.IntkAccuracyBoost, 5)

        self.assertEqual(cosmo.transfer, {})
        self.assertEqual(cosmo.c_ell, {})
        self.assertEqual(cosmo.red_bispectra, [])
Beispiel #22
0
    def __init__(self, pk_zref=None):
        """
            Setup cosmological model. 

            If pk_zref is set, it will compute linear power at z=pk_zref.
        """

        self.pars = camb.CAMBparams()
        ob = 0.02214
        om = 0.1414
        oc = om - ob
        h = 0.719
        self.pars.set_cosmology(H0=100.0 * h, ombh2=ob, omch2=oc)
        self.pars.InitPower.set_params(As=2.2e-9, ns=0.961, r=0)
        self.pk_zref = pk_zref
        if self.pk_zref:
            self.pars.set_matter_power(redshifts=[self.pk_zref], kmax=10.0)
            # compute and store linear power spectrum (at zref)
            self.pars.NonLinear = model.NonLinear_none
            self.results = camb.get_results(self.pars)
        else:
            # compute only background expansion
            self.results = camb.get_results(self.pars)
        # not sure where to put this
        self.c_kms = 2.998e5
        self.lya_A = 1215.67  #Angstrom
Beispiel #23
0
def sigma2_fit(z=0, cosmo='Planck15'):
	if type(cosmo)==str:
		if cosmo.lower() in ['planck15']: cosmo = cosmology.Planck15
		elif cosmo.lower() in ['planck13']: cosmo = cosmology.Planck13
		elif cosmo.lower() in ['wmap9']: cosmo = cosmology.WMAP9
		elif cosmo.lower() in ['wmap7']: cosmo = cosmology.WMAP7
		elif cosmo.lower() in ['wmap5']: cosmo = cosmology.WMAP5
		else:
			print('Setting to Planck15 cosmology.')
			cosmo = cosmology.Planck15
	#Now get matter power spectra and sigma8 at redshift 0 and z
	pars = camb.CAMBparams()
	pars.set_cosmology(H0=cosmo.H0.value, ombh2=cosmo.Ob0*cosmo.h**2, omch2=cosmo.Om0*cosmo.h**2)
	pars.InitPower.set_params(ns=0.96)
	pars.set_matter_power(redshifts=[z], kmax=2.0)
	#Linear spectra
	#pars.NonLinear = model.NonLinear_none
	results = camb.get_results(pars)
	kh, zs, pk = results.get_matter_power_spectrum(minkh=1e-4, maxkh=1, npoints = 200)
	s8 = np.array(results.get_sigma8())

	rho_mean = cosmo.Om(z)*cosmo.critical_density(z)
	Ms   = 10**np.linspace(5,17,100)*units.solMass/cosmo.h
	fM2R = lambda M: np.cbrt(3*M/(4*np.pi*rho_mean)).to('Mpc')
	sigR = np.array([results.get_sigmaR(r.to('Mpc').value, z_indices=None, hubble_units=False, return_R_z=False) for r in tqdm(fM2R(Ms))]).squeeze()

	sigM_tck = splrep(Ms.value, sigR)
	return lambda x: splev(x.to('solMass').value if type(x)==units.quantity.Quantity else x, sigM_tck)
def get_camb_params(p,
                    num_massive_neutrinos=1,
                    neutrino_hierarchy='degenerate',
                    inpars=None):
    pars = inpars or camb.CAMBparams()
    if p.get('wa', 0) or p.get(
            'alpha1', 0) or p.get('Alens', 1) != 1 or p.get('Aphiphi', 1) != 1:
        raise Exception(
            'Parameter not currrently supported by Cosmomc-> camb converter')
    pars.set_cosmology(H0=p['H0'],
                       ombh2=p['omegabh2'],
                       omch2=p['omegach2'],
                       mnu=p.get('mnu', 0.06),
                       omk=p.get('omegak', 0),
                       tau=p['tau'],
                       deltazrei=p.get('deltazrei', None),
                       nnu=p.get('nnu', 3.046),
                       YHe=p.get('yheused', None),
                       meffsterile=p.get('meffsterile', 0),
                       num_massive_neutrinos=num_massive_neutrinos,
                       neutrino_hierarchy=neutrino_hierarchy)
    pars.InitPower.set_params(ns=p['ns'],
                              r=p.get('r', 0),
                              As=p['A'] * 1e-9,
                              nrun=p.get('nrun', 0),
                              nrunrun=p.get('nrunrun', 0))
    pars.set_dark_energy(w=p.get('w', -1))
    pars.set_for_lmax(2500, lens_potential_accuracy=1)
    return pars
Beispiel #25
0
 def __initialize_CAMB(self):  #{{{
     # adds linear matter power interpolator
     print 'Initializing CAMB.'
     pars = camb.CAMBparams()
     pars.set_cosmology(H0=self.H0,
                        ombh2=self.Ob * self.h**2.,
                        omch2=self.Oc * self.h**2.,
                        omk=0.,
                        mnu=self.Mnu,
                        standard_neutrino_neff=self.Neff,
                        nnu=self.Neff,
                        TCMB=self.TCMB)
     pars.InitPower.set_params(ns=self.ns,
                               As=self.As,
                               pivot_scalar=self.pivot_scalar)
     pars.NonLinear = model.NonLinear_none
     #        print(pars)
     self.my_PK = get_matter_power_interpolator(pars,
                                                zmin=0.,
                                                zmax=6.,
                                                nz_step=150,
                                                kmax=101.,
                                                nonlinear=False,
                                                hubble_units=True,
                                                k_hunit=True).P
     pars.set_matter_power(redshifts=[0.], kmax=20.)
     results = camb.get_results(pars)
     self.sigma8 = results.get_sigma8()[0]
     print 'sigma8 = ' + str(self.sigma8)
Beispiel #26
0
def getBAOCamb(zrange, params, AccuracyBoost=False):
    '''
    Get BAO's fk=rs/D_V from CAMB. Return 1D array of fk for all redshifts z
    '''
    pars = camb.CAMBparams()
    if AccuracyBoost:
        pars.set_accuracy(AccuracyBoost=2.0,
                          lSampleBoost=2.0,
                          lAccuracyBoost=2.0)
        #pars.set_accuracy(AccuracyBoost=3.0, lSampleBoost=3.0, lAccuracyBoost=3.0)
    pars.set_cosmology(H0=params['H0'],
                       ombh2=params['ombh2'],
                       omch2=params['omch2'],
                       tau=params['tau'],
                       mnu=params['mnu'],
                       nnu=params['nnu'],
                       omk=params['omk'])
    pars.set_dark_energy(w=params['w'])
    pars.InitPower.set_params(As=params['As'], ns=params['ns'], r=params['r'])
    #pars.set_for_lmax(lmax=int(params['lmax']), lens_potential_accuracy=1, max_eta_k=2*params['lmax'])
    camb.set_z_outputs(zrange)
    results = camb.get_results(pars)
    fk = results.get_background_outputs()  #results.get_BAO(zrange,pars)[:,0]
    #print fk
    fk = np.nan_to_num(fk[:, 0])
    return fk
Beispiel #27
0
def matter_power(*,
                 hub=0.7,
                 omega_b=0.049,
                 omega_c=0.25,
                 ns=0.965,
                 As=2.41e-9,
                 zz=3.):
    """Get a matter power spectrum using CAMB's python interface."""
    #Set up a new set of parameters for CAMB
    pars = camb.CAMBparams()
    #This function sets up CosmoMC-like settings, with one massive neutrino and helium set using BBN consistency
    pars.set_cosmology(H0=hub * 100,
                       ombh2=omega_b * hub**2,
                       omch2=omega_c * hub**2,
                       mnu=0.,
                       omk=0,
                       tau=0.06)
    pars.InitPower.set_params(As=As, ns=ns, r=0)
    if len(zz) == 1:
        zz = [
            zz,
        ]
    pars.set_matter_power(redshifts=zz, kmax=10)
    assert pars.validate()
    pars.NonLinear = camb.model.NonLinear_none
    results = camb.get_results(pars)
    kh, _, pk = results.get_matter_power_spectrum(minkh=1e-2,
                                                  maxkh=10,
                                                  npoints=200)
    return kh, pk
Beispiel #28
0
    def testTimeTransfers(self):
        from camb import initialpower
        pars = camb.set_params(H0=69, YHe=0.22, lmax=2000, lens_potential_accuracy=1, ns=0.96, As=2.5e-9)
        results1 = camb.get_results(pars)
        cl1 = results1.get_total_cls()

        pars = camb.set_params(H0=69, YHe=0.22, lmax=2000, lens_potential_accuracy=1)
        results = camb.get_transfer_functions(pars, only_time_sources=True)
        inflation_params = initialpower.InitialPowerLaw()
        inflation_params.set_params(ns=0.96, As=2.5e-9)
        results.power_spectra_from_transfer(inflation_params)
        cl2 = results.get_total_cls()
        np.testing.assert_allclose(cl1, cl2, rtol=1e-4)
        inflation_params.set_params(ns=0.96, As=1.9e-9)
        results.power_spectra_from_transfer(inflation_params)
        inflation_params.set_params(ns=0.96, As=2.5e-9)
        results.power_spectra_from_transfer(inflation_params)
        cl2 = results.get_total_cls()
        np.testing.assert_allclose(cl1, cl2, rtol=1e-4)

        pars = camb.CAMBparams()
        pars.set_cosmology(H0=78, YHe=0.22)
        pars.set_for_lmax(2000, lens_potential_accuracy=1)
        pars.WantTensors = True
        results = camb.get_transfer_functions(pars, only_time_sources=True)
        cls = []
        for r in [0, 0.2, 0.4]:
            inflation_params = initialpower.InitialPowerLaw()
            inflation_params.set_params(ns=0.96, r=r, nt=0)
            results.power_spectra_from_transfer(inflation_params)
            cls += [results.get_total_cls(CMB_unit='muK')]
        self.assertTrue(np.allclose((cls[1] - cls[0])[2:300, 2] * 2, (cls[2] - cls[0])[2:300, 2], rtol=1e-3))
Beispiel #29
0
def get_spectrum(par, lmax):
    #print('pars are ',pars)
    H0 = par[0]
    ombh2 = par[1]
    omch2 = par[2]
    tau = par[3]
    As = par[4]
    ns = par[5]

    pars = camb.CAMBparams()
    pars.set_cosmology(H0=H0,
                       ombh2=ombh2,
                       omch2=omch2,
                       mnu=0.06,
                       omk=0,
                       tau=tau)
    pars.InitPower.set_params(As=As, ns=ns, r=0)
    pars.set_for_lmax(lmax, lens_potential_accuracy=0)
    results = camb.get_results(pars)
    powers = results.get_cmb_power_spectra(pars, CMB_unit='muK')
    cmb = powers['total']
    tt = cmb[:,
             0]  #you could return the full power spectrum here if you wanted to do say EE

    return tt
Beispiel #30
0
def get_spectrum2(par, lmax):
    #print('pars are ',pars)
    #THIS FUNCTION IS ONLY USED TO GET THE COVARIANCE MATRIX FOR ALL 6 PARAMETERS AS MENTIONNNED IN QUESTION 3

    H0 = par[0]
    ombh2 = par[1]
    omch2 = par[2]

    tau = par[3]
    As = par[4]
    ns = par[5]

    pars = camb.CAMBparams()
    pars.set_cosmology(H0=H0,
                       ombh2=ombh2,
                       omch2=omch2,
                       mnu=0.06,
                       omk=0,
                       tau=tau)
    pars.InitPower.set_params(As=As, ns=ns, r=0)
    pars.set_for_lmax(lmax, lens_potential_accuracy=0)
    results = camb.get_results(pars)
    powers = results.get_cmb_power_spectra(pars, CMB_unit='muK')
    cmb = powers['total']
    tt = cmb[:,
             0]  #you could return the full power spectrum here if you wanted to do say EE

    return tt