Esempio n. 1
0
def sel_counts_from_config(Config,bigDataDir,version,expName,gridName,calName,mexp_edges,z_edges,lkneeTOverride=None,alphaTOverride=None,zmin=-np.inf,zmax=np.inf,mmin=-np.inf,mmax=np.inf,recalculate=False,override_params=None):
    suffix = ""
    if lkneeTOverride is not None:
        suffix += "_"+str(lkneeTOverride)
    if alphaTOverride is not None:
        suffix += "_"+str(alphaTOverride)
    mgrid,zgrid,siggrid = pickle.load(open(bigDataDir+"szgrid_"+expName+"_"+gridName+ "_v" + version+suffix+".pkl",'rb'),encoding='latin1')
    experimentName = expName
    cosmoDict = dict_from_section(Config,"params")
    constDict = dict_from_section(Config,'constants')
    clusterDict = dict_from_section(Config,'cluster_params')
    clttfile = Config.get("general","clttfile")
    if override_params is not None:
        for key in override_params.keys():
            cosmoDict[key] = override_params[key]
    # print(cosmoDict)
    cc = ClusterCosmology(cosmoDict,constDict,clTTFixFile = clttfile)

    beam = list_from_config(Config,experimentName,'beams')
    noise = list_from_config(Config,experimentName,'noises')
    freq = list_from_config(Config,experimentName,'freqs')
    lmax = int(Config.getfloat(experimentName,'lmax'))
    lknee = float(Config.get(experimentName,'lknee').split(',')[0])
    alpha = float(Config.get(experimentName,'alpha').split(',')[0])
    fsky = Config.getfloat(experimentName,'fsky')
    SZProf = SZ_Cluster_Model(cc,clusterDict,rms_noises = noise,fwhms=beam,freqs=freq,lknee=lknee,alpha=alpha)

    hmf = Halo_MF(cc,mexp_edges,z_edges)

    hmf.sigN = siggrid.copy()

    saveId = save_id(expName,gridName,calName,version)
    # Fiducial number counts

    if recalculate:
        from . import counts
        # get s/n q-bins
        qs = list_from_config(Config,'general','qbins')
        qspacing = Config.get('general','qbins_spacing')
        if qspacing=="log":
            qbin_edges = np.logspace(np.log10(qs[0]),np.log10(qs[1]),int(qs[2])+1)
        elif qspacing=="linear":
            qbin_edges = np.linspace(qs[0],qs[1],int(qs[2])+1)
        else:
            raise ValueError
        calFile = mass_grid_name_owl(bigDataDir,calName)        
        mexp_edges, z_edges, lndM = pickle.load(open(calFile,"rb"))
        dN_dmqz = hmf.N_of_mqz_SZ(lndM,qbin_edges,SZProf)
        nmzq = counts.getNmzq(dN_dmqz,mexp_edges,z_edges,qbin_edges)
    else:
        nmzq = np.load(fid_file(bigDataDir,saveId))
    nmzq = nmzq*fsky

    zs = (z_edges[1:]+z_edges[:-1])/2.
    zsel = np.logical_and(zs>zmin,zs<=zmax)

    M_edges = 10**mexp_edges
    M = (M_edges[1:]+M_edges[:-1])/2.
    Mexp = np.log10(M)
    msel = np.logical_and(Mexp>mmin,Mexp<=mmax)
    
    Ns = nmzq.sum(axis=-1)[msel,:][:,zsel]
    return Ns #.ravel().sum()
Esempio n. 2
0
HMF = Halo_MF(cc, mexprange, zrange)

HMF.sigN = siggrid.copy()
SZProf = SZ_Cluster_Model(cc,
                          clusterDict,
                          rms_noises=noise,
                          fwhms=beam,
                          freqs=freq,
                          lknee=lknee,
                          alpha=alpha)

h = 0.05
# s80, As = getA(fparams,constDict,zrange,kmax=11.)
# s8zs = As*s80

dNFid_dmzq = HMF.N_of_mqz_SZ(lndM * massMultiplier, qbins, SZProf)
np.save(bigDataDir + "N_mzq_" + saveId + "_fid_sigma8",
        getNmzq(dNFid_dmzq, mgrid, zrange, qbins))

origPk = HMF.pk.copy()

print("Calculating derivatives for overall power ...")
HMF.pk = origPk.copy()
HMF.pk[:, :] *= (1. + old_div(h, 2.))**2.
dNUp_dmqz = HMF.N_of_mqz_SZ(lndM * massMultiplier, qbins, SZProf)
Nup = getNmzq(dNUp_dmqz, mgrid, zrange, qbins)

HMF.pk = origPk.copy()
HMF.pk[:, :] *= (1. - old_div(h, 2.))**2.
dNDn_dmqz = HMF.N_of_mqz_SZ(lndM * massMultiplier, qbins, SZProf)
Ndn = getNmzq(dNDn_dmqz, mgrid, zrange, qbins)
Esempio n. 3
0
    myParam = inParamList[myParamIndex]
    passParams[myParam] = fparams[myParam] + old_div(stepSizes[myParam],2.)
elif rank%2==0:
    myParam = inParamList[myParamIndex]
    passParams[myParam] = fparams[myParam] - old_div(stepSizes[myParam],2.)


if rank!=0: print(rank,myParam,fparams[myParam],passParams[myParam])
cc = ClusterCosmology(passParams,constDict,clTTFixFile=clttfile)
HMF = Halo_MF(cc,mexp_edges,z_edges)
HMF.sigN = siggrid.copy()
SZProf = SZ_Cluster_Model(cc,clusterDict,rms_noises = noise,fwhms=beam,freqs=freq,lknee=lknee,alpha=alpha,v3mode=v3mode,fsky=fsky)
if (YWLcorrflag == 1):
    dN_dmqz = HMF.N_of_mqz_SZ_corr(lndM*massMultiplier,qbin_edges,SZProf)
else:
    dN_dmqz = HMF.N_of_mqz_SZ(lndM*massMultiplier,qbin_edges,SZProf)

if rank==0: 
    #np.save(bigDataDir+"N_dzmq_"+saveId+"_fid",dN_dmqz)
    np.save(sfisher.fid_file(bigDataDir,saveId),getNmzq(dN_dmqz,mexp_edges,z_edges,qbin_edges))
    dUps = {}
    dDns = {}

    print("Waiting for ups and downs...")
    for i in range(1,numcores):
        data = np.empty(dN_dmqz.shape, dtype=np.float64)
        comm.Recv(data, source=i, tag=77)
        myParamIndex = old_div((i+1),2)-1
        if i%2==1:
            dUps[inParamList[myParamIndex]] = data.copy()
        elif i%2==0:
Esempio n. 4
0
File: testV3.py Progetto: mntw/szar
HMF = Halo_MF(cc,Mexp,zbin)
dvdz = HMF.dVdz#(zbin)
dndm = HMF.N_of_z_SZ(fsky,SZProf)

sys.exit()
print(("Time for N of z " , time.time() - start3))


# pl = Plotter()
# pl.add(zbin[1:], dndm * dvdz[1:])
# pl.done("output/dndm.png")

print(("Total number of clusters ", np.trapz(dndm ,zbin[:],np.diff(zbin[:]))*fsky))

#np.savetxt('output/dndm_dVdz_1muK_3_0arc.txt',np.transpose([zbin[1:],dndm,dvdz[1:]]))

mfile = "data/S4-7mCMB_all.pkl"
minrange, zinrange, lndM = pickle.load(open(mfile,'rb'))

outmerr = interpolate_grid(lndM,minrange,zinrange,Mexp,zbin,regular=False,kind="cubic",bounds_error=False,fill_value=np.inf)


q_arr = np.logspace(np.log10(6.),np.log10(500.),64)

dnqmz = HMF.N_of_mqz_SZ(outmerr,q_arr,SZProf)

N,Nofz = getTotN(dnqmz,Mexp,zbin,q_arr,returnNz=True)

print((N*fsky))
Esempio n. 5
0
pl.add(zs, N1)
pl.add(zs, N2)

Ntot1 = np.trapz(N2, zs)
print(Ntot1)

sn, ntot = hmf.Mass_err(fsky, outmerr, SZProf)

print(ntot)

#q_arr = np.logspace(np.log10(6.),np.log10(500.),64)
qs = [6., 500., 64]
qbin_edges = np.logspace(np.log10(qs[0]), np.log10(qs[1]), int(qs[2]) + 1)
q_arr = old_div((qbin_edges[1:] + qbin_edges[:-1]), 2.)

dnqmz = hmf.N_of_mqz_SZ(outmerr, qbin_edges, SZProf)

print((qbin_edges.shape))
print((dnqmz.shape))
N, Nofz = getTotN(dnqmz, Mexp_edges, z_edges, qbin_edges, returnNz=True)

print((N * fsky))

pl.add(zs, Nofz * fsky, label="mqz")
pl.legendOn()
pl.done(outDir + "nsRefactor.png")

nnoq = np.trapz(dnqmz, q_arr, axis=2) * fsky
pl = Plotter()
pl.plot2d(nnoq)
pl.done(outDir + "ngridRefactor.png")
Esempio n. 6
0
    vals.sort()
    for val in vals:
        print((key, val))
        
        uppassparams = fparams.copy()
        dnpassparams = fparams.copy()

        uppassparams[key] = fparams[key]+old_div(val,2.)
        dnpassparams[key] = fparams[key]-old_div(val,2.)


        cc = ClusterCosmology(uppassparams,constDict,clTTFixFile=clttfile)
        HMF = Halo_MF(cc,mexp_edges,z_edges)
        HMF.sigN = siggrid.copy()
        SZProf = SZ_Cluster_Model(cc,clusterDict,rms_noises = noise,fwhms=beam,freqs=freq,lknee=lknee,alpha=alpha)
        Nup = HMF.N_of_mqz_SZ(lndM*massMultiplier,qbin_edges,SZProf)


        cc = ClusterCosmology(dnpassparams,constDict,clTTFixFile=clttfile)
        HMF = Halo_MF(cc,mexp_edges,z_edges)
        HMF.sigN = siggrid.copy()
        SZProf = SZ_Cluster_Model(cc,clusterDict,rms_noises = noise,fwhms=beam,freqs=freq,lknee=lknee,alpha=alpha)
        Ndn = HMF.N_of_mqz_SZ(lndM*massMultiplier,qbin_edges,SZProf)
        
    
        dNdp = old_div((getNmzq(Nup,mexp_edges,z_edges,qbin_edges)-getNmzq(Ndn,mexp_edges,z_edges,qbin_edges)),val)


        Nz = dNdp.copy().sum(axis=-1).sum(axis=0)
        Nm = dNdp.copy().sum(axis=-1).sum(axis=-1)
        Nq = dNdp.copy().sum(axis=0).sum(axis=0)