Exemplo n.º 1
0
def GetBackgroundFuncs(samples):
    ixs = samples.randomSingleSamples_indices()[::40]
    DMs = np.zeros((len(ixs), len(redshifts)))
    Hs = np.zeros(DMs.shape)
    rsDV = np.zeros(DMs.shape)
    camb.set_z_outputs(redshifts)
    for i, ix in enumerate(ixs):
        print(i, ix)
        dic = samples.getParamSampleDict(ix)
        pars = get_camb_params(dic)
        results = camb.get_background(pars)
        bao = results.get_background_outputs()
        rsDV[i, :] = 1 / bao[:, 0]
        DMs[i, :] = bao[:, 2] * (1 + reds)
        Hs[i, :] = bao[:, 1]

    Hmeans = np.zeros(len(redshifts))
    Herrs = np.zeros(len(redshifts))
    DMmeans = np.zeros(len(redshifts))
    DMerrs = np.zeros(len(redshifts))
    for i, z in enumerate(redshifts):
        Hmeans[i] = np.mean(Hs[:, i]) / (1 + z)
        Herrs[i] = np.std(Hs[:, i]) / (1 + z)
        DMmeans[i] = np.mean(DMs[:, i])
        DMerrs[i] = np.std(DMs[:, i])

    Hinterp = UnivariateSpline([0] + redshifts, [samples.mean('H0')] + list(Hmeans), s=0)
    DMinterp = UnivariateSpline([0] + redshifts, [0] + list(DMmeans), s=0)
    Herrinterp = UnivariateSpline([0] + redshifts, [samples.std('H0')] + list(Herrs), s=0)
    DMerrinterp = UnivariateSpline([0] + redshifts, [0] + list(DMerrs), s=0)
    return Hinterp, Herrinterp, DMinterp, DMerrinterp, rsDV
Exemplo n.º 2
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
Exemplo n.º 3
0
def GetBackgroundFuncs(samples):
    ixs = samples.randomSingleSamples_indices()[::40]
    DMs = np.zeros((len(ixs), len(redshifts)))
    Hs = np.zeros(DMs.shape)
    rsDV = np.zeros(DMs.shape)
    camb.set_z_outputs(redshifts)
    for i, ix in enumerate(ixs):
        print(i, ix)
        dic = samples.getParamSampleDict(ix)
        pars = get_camb_params(dic)
        results = camb.get_background(pars)
        bao = results.get_background_outputs()
        rsDV[i, :] = 1 / bao[:, 0]
        DMs[i, :] = bao[:, 2] * (1 + reds)
        Hs[i, :] = bao[:, 1]

    Hmeans = np.zeros(len(redshifts))
    Herrs = np.zeros(len(redshifts))
    DMmeans = np.zeros(len(redshifts))
    DMerrs = np.zeros(len(redshifts))
    for i, z in enumerate(redshifts):
        Hmeans[i] = np.mean(Hs[:, i]) / (1 + z)
        Herrs[i] = np.std(Hs[:, i]) / (1 + z)
        DMmeans[i] = np.mean(DMs[:, i])
        DMerrs[i] = np.std(DMs[:, i])

    Hinterp = UnivariateSpline([0] + redshifts,
                               [samples.mean('H0')] + list(Hmeans),
                               s=0)
    DMinterp = UnivariateSpline([0] + redshifts, [0] + list(DMmeans), s=0)
    Herrinterp = UnivariateSpline([0] + redshifts,
                                  [samples.std('H0')] + list(Herrs),
                                  s=0)
    DMerrinterp = UnivariateSpline([0] + redshifts, [0] + list(DMerrs), s=0)
    return Hinterp, Herrinterp, DMinterp, DMerrinterp, rsDV
Exemplo n.º 4
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
Exemplo n.º 5
0
p = samples.getParams()

reds = np.asarray(redshifts)

ommh2 = samples.mean('omegamh2')
# Need to get f sigma(8) of z using CAMB. This takes at least some minutes, so cache.

cachename = os.path.join(tempfile.gettempdir(), 'planck2018' + str(hash((samples.jobItem.chainRoot, os.path.getmtime(
    samples.jobItem.chainRoot + '_1.txt')) + tuple(redshifts)))
                         + '.fsig_evolve')
if os.path.isfile(cachename):
    with open(cachename, 'rb') as inp:
        ixs, f8s, Hs, DMs, FAPs = pickle.load(inp)
else:
    camb.set_z_outputs(redshifts)
    ixs = samples.randomSingleSamples_indices()[::4]
    DMs = np.zeros((len(ixs), len(redshifts)))
    Hs = np.zeros(DMs.shape)
    FAPs = np.zeros(DMs.shape)
    f8s = np.zeros(DMs.shape)
    for i, ix in enumerate(ixs):
        print(i, ix)
        dic = samples.getParamSampleDict(ix)
        pars = get_camb_params(dic)
        pars.set_matter_power(redshifts, kmax=2)
        results = camb.get_results(pars)
        bao = results.get_background_outputs()
        DMs[i, :] = bao[:, 2] * (1 + reds)
        Hs[i, :] = bao[:, 1]
        FAPs[i, :] = bao[:, 3]
Exemplo n.º 6
0
p = samples.getParams()

reds = np.asarray(redshifts)

ommh2 = samples.mean('omegamh2')
# Need to get f sigma(8) of z using CAMB. This takes at least some minutes, so cache.

cachename = os.path.join(tempfile.gettempdir(), 'planck2018' + str(hash((samples.jobItem.chainRoot, os.path.getmtime(
    samples.jobItem.chainRoot + '_1.txt')) + tuple(redshifts)))
                         + '.fsig_evolve')
if os.path.isfile(cachename):
    with open(cachename, 'rb') as inp:
        ixs, f8s, Hs, DMs, FAPs = pickle.load(inp)
else:
    camb.set_z_outputs(redshifts)
    ixs = samples.randomSingleSamples_indices()[::4]
    DMs = np.zeros((len(ixs), len(redshifts)))
    Hs = np.zeros(DMs.shape)
    FAPs = np.zeros(DMs.shape)
    f8s = np.zeros(DMs.shape)
    for i, ix in enumerate(ixs):
        print(i, ix)
        dic = samples.getParamSampleDict(ix)
        pars = get_camb_params(dic)
        pars.set_matter_power(redshifts, kmax=2)
        results = camb.get_results(pars)
        bao = results.get_background_outputs()
        DMs[i, :] = bao[:, 2] * (1 + reds)
        Hs[i, :] = bao[:, 1]
        FAPs[i, :] = bao[:, 3]