예제 #1
0
    def __init__(self,iniFile,expName,gridName,version,ClusterCosmology):
        Config = SafeConfigParser()
        Config.optionxform=str
        Config.read(iniFile)

        self.cc = ClusterCosmology

        bigDataDir = Config.get('general','bigDataDirectory')
        self.clttfile = Config.get('general','clttfile')
        self.constDict = dict_from_section(Config,'constants')
        self.clusterDict = dict_from_section(Config,'cluster_params')
        #version = Config.get('general','version')
        beam = list_from_config(Config,expName,'beams')
        noise = list_from_config(Config,expName,'noises')
        freq = list_from_config(Config,expName,'freqs')
        lknee = list_from_config(Config,expName,'lknee')[0]
        alpha = list_from_config(Config,expName,'alpha')[0]
        self.fsky = Config.getfloat(expName,'fsky')

        self.mgrid,self.zgrid,siggrid = pickle.load(open(bigDataDir+"szgrid_"+expName+"_"+gridName+ "_v" + version+".pkl",'rb'))

        #self.cc = ClusterCosmology(self.fparams,self.constDict,clTTFixFile=self.clttfile)
        self.SZProp = SZ_Cluster_Model(self.cc,self.clusterDict,rms_noises = noise,fwhms=beam,freqs=freq,lknee=lknee,alpha=alpha)
        self.HMF = Halo_MF(self.cc,self.mgrid,self.zgrid)
        self.HMF.sigN = siggrid.copy()
예제 #2
0
    def lnlike(self,theta,parlist):

        param_vals = alter_fparams(self.fparams,parlist,theta)
        for key in self.fix_params:
            if key not in list(param_vals.keys()): param_vals[key] = self.fix_params[key]

        int_cc = ClusterCosmology(param_vals,self.constDict,clTTFixFile=self.clttfile) # internal HMF call
        int_HMF = Halo_MF(int_cc,self.mgrid,self.zgrid) # internal HMF call
        self.s8 = int_HMF.cc.s8
        if np.nan_to_num(self.s8)<0.1 or np.nan_to_num(self.s8)>10. or not(np.isfinite(self.s8)):
            self.s8 = 0.

        #dndm_int = int_HMF.inter_dndmLogm(200.) # delta = 200
        dndm_int = int_HMF.inter_mf_logM(200.) # delta = 200
        cluster_prop = np.array([self.clst_z,self.clst_zerr,10**self.clst_m,self.clst_merr])

        Ntot = self.Ntot_survey(int_HMF,self.fsky)
        print("Ntot comparion, and catalog")
        print(self.Ntot_survey_TEST(int_HMF,self.fsky), Ntot, len(self.clst_z))

        Nind = 0
        for i in range(len(self.clst_z)):
            N_per = self.Prob_per_cluster(int_HMF,cluster_prop[:,i],dndm_int)
            Nind = Nind + np.log(N_per)

        print("-NTOT, Nind, Total, As")
        print(-Ntot, Nind, -Ntot + Nind, theta)
        return -Ntot + Nind
예제 #3
0
def counts_from_config(Config,bigDataDir,version,expName,gridName,mexp_edges,z_edges,lkneeTOverride=None,alphaTOverride=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'))
    #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")
    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()
    Ns = np.multiply(hmf.N_of_z_SZ(fsky,SZProf),np.diff(z_edges).reshape(1,z_edges.size-1))
    return Ns.ravel().sum()
예제 #4
0
    def lnlike(self, theta, parlist):

        param_vals = alter_fparams(self.fparams, parlist, theta)
        for key in self.fix_params:
            if key not in list(param_vals.keys()):
                param_vals[key] = self.fix_params[key]

        print(param_vals)
        int_cc = ClusterCosmology(
            param_vals, self.constDict,
            clTTFixFile=self.clttfile)  # internal HMF call
        int_HMF = Halo_MF(int_cc, self.mgrid, self.zgrid)  # internal HMF call
        self.s8 = int_HMF.cc.s8

        if np.nan_to_num(self.s8) < 0.1 or np.nan_to_num(
                self.s8) > 10. or not (np.isfinite(self.s8)):
            self.s8 = 0.
        #     return -np.inf

        #dndm_int = int_HMF.inter_dndm(200.) # delta = 200
        dndm_int = int_HMF.inter_dndmLogm(200.)  # delta = 200
        cluster_prop = np.array([
            self.clst_z, self.clst_zerr, self.clst_y0 * 1e-4,
            self.clst_y0err * 1e-4
        ])

        if self.test:
            Ntot = 60.
        else:
            Ntot = 0.
            for i in range(len(self.frac_of_survey)):
                Ntot += self.Ntot_survey(
                    int_HMF, self.area_rads * self.frac_of_survey[i],
                    self.thresh_bin[i], param_vals)
        #print 'NTOT', Ntot
        Nind = 0
        #Nind2 = 1.
        for i in range(len(self.clst_z)):

            N_per = self.Prob_per_cluster(int_HMF, cluster_prop[:, i],
                                          dndm_int, param_vals)
            #if (i < 3):
            #print np.log(N_per)
            Nind = Nind + np.log(N_per)
            #Nind2 *= N_per
            #print N_per
        print(-Ntot, Nind, -Ntot + Nind, theta)  #, np.log(np.exp(-Ntot)*Nind2)
        return -Ntot + Nind
예제 #5
0
    def __init__(self,iniFile,test_cat_file,fix_params,mmin=14.3):

        self.fix_params = fix_params
        Config = SafeConfigParser()
        Config.optionxform=str
        Config.read(iniFile)

        self.fparams = {}
        for (key, val) in Config.items('params'):
            if ',' in val:
                param, step = val.split(',')
                self.fparams[key] = float(param)
            else:
                self.fparams[key] = float(val)

        bigDataDir = Config.get('general','bigDataDirectory')
        self.clttfile = Config.get('general','clttfile')
        self.constDict = dict_from_section(Config,'constants')

        logm_min = 14.0
        logm_max = 15.702
        logm_spacing = 0.01
        self.mgrid = np.arange(logm_min,logm_max,logm_spacing)
        self.zgrid = np.arange(0.1,2.001,0.05)

        self.cc = ClusterCosmology(self.fparams,self.constDict,clTTFixFile=self.clttfile)
        self.HMF = Halo_MF(self.cc,self.mgrid,self.zgrid)

        self.fsky = old_div(987.5,41252.9612)
        self.mmin = mmin
        clust_cat = test_cat_file + '.fits' 
        self.clst_z,self.clst_zerr,self.clst_m,self.clst_merr = read_test_mock_cat(clust_cat,self.mmin)
예제 #6
0
파일: velocities.py 프로젝트: mntw/szar
    def __init__(self, iniFile, kmin=1e-4, kmax=5., knum=200):

        Config = SafeConfigParser()
        Config.optionxform = str
        Config.read(iniFile)

        self.fparams = {}
        for (key, val) in Config.items('params'):
            if ',' in val:
                param, step = val.split(',')
                self.fparams[key] = float(param)
            else:
                self.fparams[key] = float(val)

        bigDataDir = Config.get('general', 'bigDataDirectory')
        self.clttfile = Config.get('general', 'clttfile')
        self.constDict = dict_from_section(Config, 'constants')
        self.clusterDict = dictFromSection(Config, 'cluster_params')
        version = Config.get('general', 'version')
        beam = listFromConfig(Config, expName, 'beams')
        noise = listFromConfig(Config, expName, 'noises')
        freq = listFromConfig(Config, expName, 'freqs')
        lknee = listFromConfig(Config, expName, 'lknee')[0]
        alpha = listFromConfig(Config, expName, 'alpha')[0]

        self.mgrid, self.zgrid, siggrid = pickle.load(
            open(
                bigDataDir + "szgrid_" + expName + "_" + gridName + "_v" +
                version + ".pkl", 'rb'))

        self.cc = ClusterCosmology(self.fparams,
                                   self.constDict,
                                   clTTFixFile=self.clttfile)
        self.HMF = Halo_MF(self.cc, self.mgrid, self.zgrid)

        if powerZK is None:
            self.kh, self.pk = self._pk_lin(self.HMF.zarr, kmin, kmax, knum)
        else:
            assert kh is not None
            self.kh = kh
            self.pk = powerZK
예제 #7
0
    if (cal == 'owl2'):
        massGridName = bigDataDir + "lensgrid_grid-" + cal + "_" + cal + ".pkl"
    else:
        massGridName = bigDataDir + "lensgrid_" + expName + "_" + gridName + "_" + cal + "_v" + version + ".pkl"

    mexp_edges, z_edges, lndM = pickle.load(open(massGridName, "rb"))

    zrange = (z_edges[1:] + z_edges[:-1]) / 2.

    beam = list_from_config(Config, expName, 'beams')
    noise = list_from_config(Config, expName, 'noises')
    freq = list_from_config(Config, expName, 'freqs')
    lknee = list_from_config(Config, expName, 'lknee')[0]
    alpha = list_from_config(Config, expName, 'alpha')[0]
    fsky = Config.getfloat(expName, 'fsky')
    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)
    Nofzs = np.multiply(HMF.N_of_z_SZ(fsky, SZProf),
                        np.diff(z_edges).reshape(1, z_edges.size - 1)).ravel()
    print(Nofzs.sum())
    #sys.exit()

    saveId = expName + "_" + gridName + "_" + cal + "_v" + ver
예제 #8
0
파일: testV3.py 프로젝트: mntw/szar
print(("thetc = ", thetc))



# HMF

zbin = np.arange(0.,3.0,0.1)
#zbin = np.insert(zbin_temp,0,0.0)
#print zbin

Mexp = np.arange(13.5,15.71,0.01)

start3 = time.time()
SZProf = SZ_Cluster_Model(cc,clusterDict,rms_noises = noise,fwhms=beam,freqs=freq,lknee=lknee,alpha=alpha)

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:]]))
예제 #9
0

# If boss, do the fiducial. If odd rank, the minion is doing an "up" job, else doing a "down" job
if rank==0:
    pass
elif rank%2==1:
    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):
예제 #10
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()
예제 #11
0
fsky = Config.getfloat(expName, 'fsky')
try:
    v3mode = Config.getint(expName, 'V3mode')
except:
    v3mode = -1

fparams = {}
for (key, val) in Config.items('params'):
    if ',' in val:
        param, step = val.split(',')
        fparams[key] = float(param)
    else:
        fparams[key] = float(val)

cc = ClusterCosmology(fparams, constDict, clTTFixFile=clttfile)
HMF = Halo_MF(cc, mexp_edges, z_edges)
SZCluster = SZ_Cluster_Model(cc,
                             clusterDict,
                             rms_noises=noise,
                             fwhms=beam,
                             freqs=freq,
                             lknee=lknee,
                             alpha=alpha,
                             v3mode=v3mode,
                             fsky=fsky)

HMF.updateSigN(SZCluster)
HMF.updatePfunc(SZCluster)

np.save(bigDataDir + "Sel_func" + saveId, HMF.Pfunc)
예제 #12
0
        ls = None
        Nls = None
        #beamY = None
        #miscentering = None
        #doRayDeriv = False
        rayFid = None
        rayStep = None

    clttfile = Config.get('general', 'clttfile')

    if doSZ:
        clusterDict = dict_from_section(Config, 'cluster_params')

        cc = ClusterCosmology(fparams, constDict, clTTFixFile=clttfile)
        if doSZ:
            HMF = Halo_MF(cc, mgrid, zgrid)
            kh = HMF.kh
            pk = HMF.pk

    else:
        clusterDict = None
        kh = None
        pk = None
        doFg = None

else:
    #doRayDeriv = None
    pzcut = None
    rayFid = None
    rayStep = None
    doLens = None
예제 #13
0
    def __init__(self,iniFile,parDict,nemoOutputDir,noiseFile,fix_params,fitsfile,test=False,simtest=False,simpars=False):
        self.fix_params = fix_params
        self.test = test
        self.simtest = simtest
        self.simpars = simpars
        Config = SafeConfigParser()
        Config.optionxform=str
        Config.read(iniFile)

        self.fparams = {}
        for (key, val) in Config.items('params'):
            if ',' in val:
                param, step = val.split(',')
                self.fparams[key] = float(param)
            else:
                self.fparams[key] = float(val)

        bigDataDir = Config.get('general','bigDataDirectory')
        self.clttfile = Config.get('general','clttfile')
        self.constDict = dict_from_section(Config,'constants')
        #version = Config.get('general','version')
        
        #self.mgrid,self.zgrid,siggrid = pickle.load(open(bigDataDir+"szgrid_"+expName+"_"+gridName+ "_v" + version+".pkl",'rb'))
        logm_min = 13.7
        logm_max = 15.72
        logm_spacing = 0.02
        self.mgrid = np.arange(logm_min,logm_max,logm_spacing)
        self.zgrid = np.arange(0.1,2.01,0.1)        
        #print self.mgrid
        #print self.zgrid
        self.qmin = 5.6
        
        self.cc = ClusterCosmology(self.fparams,self.constDict,clTTFixFile=self.clttfile)
        self.HMF = Halo_MF(self.cc,self.mgrid,self.zgrid)

        self.diagnosticsDir=nemoOutputDir+"diagnostics" 
        self.filteredMapsDir=nemoOutputDir+"filteredMaps"
        self.tckQFit=simsTools.fitQ(parDict, self.diagnosticsDir, self.filteredMapsDir)
        FilterNoiseMapFile = nemoOutputDir + noiseFile
        MaskMapFile = self.diagnosticsDir + '/areaMask.fits'
        
        #if self.simtest or self.simpars:
        #    print "mock catalog"
            #clust_cat = nemoOutputDir + 'mockCatalog_equD56.fits' #'ACTPol_mjh_cluster_cat.fits'
        #    clust_cat = nemoOutputDir + 'mockCat_D56equ_v22.fits' #'ACTPol_mjh_cluster_cat.fits'
        #    self.clst_z,self.clst_zerr,self.clst_y0,self.clst_y0err = read_mock_cat(clust_cat,self.qmin)
        #else:
        #    print "real catalog"
        #    clust_cat = nemoOutputDir + 'E-D56Clusters.fits' #'ACTPol_mjh_cluster_cat.fits'
        #    self.clst_z,self.clst_zerr,self.clst_y0,self.clst_y0err = read_clust_cat(clust_cat,self.qmin)

        clust_cat = nemoOutputDir + fitsfile 
        if self.simtest or self.simpars:
            print("mock catalog")
            self.clst_z,self.clst_zerr,self.clst_y0,self.clst_y0err = read_mock_cat(clust_cat,self.qmin)
        else:
            print("real catalog")
            self.clst_z,self.clst_zerr,self.clst_y0,self.clst_y0err = read_clust_cat(clust_cat,self.qmin)

        self.rms_noise_map  = read_MJH_noisemap(FilterNoiseMapFile,MaskMapFile)
        print ('Number of clusters',len(self.clst_zerr))
        #self.wcs=astWCS.WCS(FilterNoiseMapFile) 
        #self.clst_RA,self.clst_DEC,
        #self.clst_xmapInd,self.clst_ymapInd = self.Find_nearest_pixel_ind(self.clst_RA,self.clst_DEC)

        self.num_noise_bins = 10
        self.area_rads = old_div(987.5,41252.9612) # fraction of sky - ACTPol D56-equ specific
        self.LgY = np.arange(-6,-3,0.01)

        count_temp,bin_edge =np.histogram(np.log10(self.rms_noise_map[self.rms_noise_map>0]),bins=self.num_noise_bins)
        self.frac_of_survey = count_temp*1.0 / np.sum(count_temp)
        self.thresh_bin = 10**(old_div((bin_edge[:-1] + bin_edge[1:]),2.))
예제 #14
0
noise = listFromConfig(Config, experimentName, 'noises')
freq = listFromConfig(Config, experimentName, 'freqs')
lmax = int(Config.getfloat(experimentName, 'lmax'))
lknee = Config.getfloat(experimentName, 'lknee')
alpha = Config.getfloat(experimentName, 'alpha')
fsky = Config.getfloat(experimentName, 'fsky')

cosmoDict = dictFromSection(Config, cosmologyName)
constDict = dictFromSection(Config, 'constants')
clusterDict = dictFromSection(Config, clusterParams)
cc = ClusterCosmology(cosmoDict, constDict, lmax)

mass_err_file = Config.get(experimentName, 'mass_err')
mass_err = np.loadtxt(mass_err_file)

zbin_temp = np.arange(0.1, 2.01, 0.05)
zbin = np.insert(zbin_temp, 0, 0.0)

HMF = Halo_MF(clusterCosmology=cc)

errs, Ntot = HMF.Mass_err(mass_err, zbin, beam, noise, freq, clusterDict,
                          lknee, alpha, fileFunc)

print((np.sqrt(errs)))
print(Ntot)

#HSC_mass = np.loadtxt('input/HSC_DeltalnM_z0_z1.txt',unpack=True)
#HSC_mass = np.transpose(HSC_mass)

#print np.shape(HSC_mass), np.shape(dndzdm)
예제 #15
0
from orphics.tools.io import Plotter
from scipy.interpolate import interp1d

clusterParams = 'LACluster'  # from ini file
cosmologyName = 'LACosmology'  # from ini file
iniFile = "input/params.ini"
Config = SafeConfigParser()
Config.optionxform = str
Config.read(iniFile)

lmax = 3000
cosmoDict = dictFromSection(Config, cosmologyName)
constDict = dictFromSection(Config, 'constants')
clusterDict = dictFromSection(Config, clusterParams)
cc = ClusterCosmology(cosmoDict, constDict, lmax, pickling=True)
HMF = Halo_MF(cc)

cambOutFile = lambda i: "/home/msyriac/software/CAMB_wa/testWaFid_matterpower_" + str(
    i) + ".dat"

zrange = np.arange(0., 3.05, 0.05)

kh, z, pk, s8 = HMF.pk(zrange)

#pl = Plotter(scaleY='log',scaleX='log')
pl = Plotter()

Nzs = pk.shape[0]

for i, z in enumerate(zrange[::-1]):
예제 #16
0
        9.36305025e-01, 2.53310030e-01, 1.93661978e-01, 1.74839544e-01
    ]
    #parvals2 = [1.194e-01,2.34697120e-02,6.50170056e+01,1.33398673e-09,9.36305025e-01,2.53310030e-01,1.93661978e-01,1.74839544e-01]

    param_vals = lk.alter_fparams(fparams, parlist, parvals)
    cluster_props = np.array(
        [CL.clst_z, CL.clst_zerr, CL.clst_y0 * 1e-4, CL.clst_y0err * 1e-4])

    start = time.time()
    int_cc = ClusterCosmology(param_vals,
                              CL.constDict,
                              clTTFixFile=CL.clttfile)

    print('CC', time.time() - start)
    start = time.time()
    int_HMF = Halo_MF(int_cc, CL.mgrid, CL.zgrid)

    print('HMF', time.time() - start)
    dn_dzdm_int = int_HMF.inter_dndmLogm(200.)

    zbins = 10
    LgYa = np.outer(np.ones(len(int_HMF.M.copy())), CL.LgY)
    Y = 10**LgYa
    Ma = np.outer(int_HMF.M.copy(), np.ones(len(LgYa[0, :])))
    clustind = 1

    print(cluster_props[:, clustind])
    print(parlist)
    print(parvals)
    print(
        "ln prob",
예제 #17
0
ccDn = ClusterCosmology(dnDict,constDict,clTTFixFile=clttfile)

#mbin = np.arange(12.5,15.5,0.05)+0.05
#zbin_temp = np.arange(0.05,2.05,0.05)

zbin_temp = np.arange(0.05,2.0,0.05)
zbin = np.insert(zbin_temp,0,0.0)
qbin = np.arange(np.log(6),np.log(500),0.08)
mbin = np.arange(13.5, 15.71, 0.1)

start3 = time.time()

mgrid,zgrid,siggrid = pickle.load(open(bigDataDir+"szgrid_"+expName+"_"+gridName+ "_v" + version+".pkl",'rb'))

#cc = ClusterCosmology(passParams,constDict,clTTFixFile=clttfile)
HMFup = Halo_MF(ccUp,mgrid,zgrid)
SZProf = SZ_Cluster_Model(ccUp,clusterDict,rms_noises = noise,fwhms=beam,freqs=freq,lknee=lknee,alpha=alpha)
dN_dmqz = HMFup.N_of_mqz_SZ_corr(lndM*massMultiplier,qbin_edges,SZProf)
print((dN_dmqz.sum()))

#dN_dmqz_up = HMFup.N_of_mqz_SZ(mass_err,zbin,mbin,np.exp(qbin),beam,noise,freq,clusterDict,lknee,alpha)
#print((dN_dmqz_up.sum()))
#HMFdn = Halo_MF(ccDn,mexp_edges,z_edges)
#dN_dmqz_dn = HMFdn.N_of_mqz_SZ(mass_err,zbin,mbin,np.exp(qbin),beam,noise,freq,clusterDict,lknee,alpha)

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

#np.save("data/dN_dzmq"+saveId+"_"+key+"_up",dN_dmqz_up)
#np.save("data/dN_dzmq"+saveId+"_"+key+"_dn",dN_dmqz_dn)

               
예제 #18
0
	    massGridName = bigDataDir+"lensgrid_grid-"+cal+"_"+cal+".pkl"
    else:
	    massGridName = bigDataDir+"lensgrid_"+expName+"_"+gridName+"_"+cal+ "_v" + version+".pkl"
	    

    mexp_edges, z_edges, lndM = pickle.load(open(massGridName,"rb"),encoding='latin1')

    zrange = (z_edges[1:]+z_edges[:-1])/2.

    beam = list_from_config(Config,expName,'beams')
    noise = list_from_config(Config,expName,'noises')
    freq = list_from_config(Config,expName,'freqs')
    lknee = list_from_config(Config,expName,'lknee')[0]
    alpha = list_from_config(Config,expName,'alpha')[0]
    fsky = Config.getfloat(expName,'fsky')
    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)
    Nofzs = np.multiply(HMF.N_of_z_SZ(fsky,SZProf),np.diff(z_edges).reshape(1,z_edges.size-1)).ravel()
    print(Nofzs.sum())
    print(Nofzs,zrange)
    #sys.exit()

    saveId = expName + "_" + gridName + "_" + cal + "_v" + ver
    Nmzq = np.load(bigDataDir+"N_mzq_"+saveId+"_fid.npy")*fsky
    Nmz = Nmzq.sum(axis=-1)
    Nz = Nmzq.sum(axis=0).sum(axis=-1)
    print(Nz.shape)
    print(Nz[10:],zrange[10:],np.sum(Nz[10:]))
예제 #19
0
pl.done(os.environ['WWW']+"dps.png")




fparams = {}   # the 
for (key, val) in Config.items('params'):
    if ',' in val:
        param, step = val.split(',')
        fparams[key] = float(param)
    else:
        fparams[key] = float(val)
passParams = fparams
from szar.counts import ClusterCosmology,Halo_MF
cc = ClusterCosmology(passParams,constDict,clTTFixFile=clttfile)
HMF = Halo_MF(cc,Mexp_edges,z_edges)
kh = HMF.kh
pk = HMF.pk

pl = Plotter(scaleX='log')#,scaleY='log')
from scipy.interpolate import interp1d

for i,z in enumerate(zrange[:]):

    khfid,pkfid = np.loadtxt(cambRoot+"forDerivsFid_matterpower_"+str(z)+".dat",unpack=True)

    
    # pl.add(khfid,pkfid,alpha=1.-z/3.0,color="C0")
    # pl.add(kh,pk[i],alpha=1.-z/3.0,color="C1")

    pkfidI = interp1d(khfid,pkfid,bounds_error=False,fill_value=np.nan)(kh)
예제 #20
0
        fparams[key] = float(val)

constDict = dict_from_section(Config,'constants')
clusterDict = dict_from_section(Config,'cluster_params')
cc = ClusterCosmology(fparams,constDict,skipCls=True)

fsky = Config.getfloat(expName,'fsky')

saveId = expName + "_" + gridName + "_v" + version

ms = list_from_config(Config,gridName,'mexprange')
mrange = np.arange(ms[0],ms[1]+ms[2],ms[2])
zs = list_from_config(Config,gridName,'zrange')
zrange = np.arange(zs[0],zs[1]+zs[2],zs[2])


hmf = Halo_MF(cc,mrange,zrange)
zcents, hb = haloBias(mrange,zrange,cc.rhoc0om,hmf.kh,hmf.pk)
powers = sampleVarianceOverNsquareOverBsquare(cc,hmf.kh,hmf.pk,zrange,fsky,lmax=lmax)

sovernsquarebsquare = np.outer(powers,np.ones([len(mrange)-1])).transpose()

sovernsquare = hb*hb*sovernsquarebsquare


np.savetxt(bigDataDir+"sampleVarGrid_"+saveId+".txt",sovernsquare)




예제 #21
0
class MockCatalog(object):
    def __init__(self,iniFile,parDict,nemoOutputDir,noiseFile,params,parlist,mass_grid_log=None,z_grid=None,randoms=False):

        Config = SafeConfigParser()
        Config.optionxform=str
        Config.read(iniFile)

        if mass_grid_log:
            logm_min,logm_max,logm_spacing = mass_grid_log
        else:
            logm_min = 12.7
            logm_max = 15.72
            logm_spacing = 0.04
        if z_grid:
            zmin,zmax,zdel = z_grid
        else:
            zmin = 0.0
            zmax = 2.01
            zdel = 0.1



        self.fparams = {}
        for (key, val) in Config.items('params'):
            if ',' in val:
                param, step = val.split(',')
                self.fparams[key] = float(param)
            else:
                self.fparams[key] = float(val)

        self.param_vals = alter_fparams(self.fparams,parlist,params)

        bigDataDir = Config.get('general','bigDataDirectory')
        self.clttfile = Config.get('general','clttfile')
        self.constDict = dict_from_section(Config,'constants')

        if mass_grid_log:
            logm_min,logm_max,logm_spacing = mass_grid_log
        else:
            logm_min = 12.7
            logm_max = 15.72
            logm_spacing = 0.04
        if z_grid:
            zmin,zmax,zdel = z_grid
        else:
            zmin = 0.0
            zmax = 2.01
            zdel = 0.1
        
        if randoms:
            self.rand = 1
        else:
            self.rand = 0

        self.mgrid = np.arange(logm_min,logm_max,logm_spacing)
        self.zgrid = np.arange(zmin,zmax,zdel)

        self.Medges = 10.**self.mgrid
        self.Mcents = (self.Medges[1:]+self.Medges[:-1])/2.
        self.Mexpcents = np.log10(self.Mcents)
        self.zcents = (self.zgrid[1:]+self.zgrid[:-1])/2.

        self.cc = ClusterCosmology(self.param_vals,self.constDict,clTTFixFile=self.clttfile)
        self.HMF = Halo_MF(self.cc,self.mgrid,self.zgrid)

        self.diagnosticsDir=nemoOutputDir+"diagnostics"
        self.filteredMapsDir=nemoOutputDir+"filteredMaps"
        self.tckQFit=simsTools.fitQ(parDict, self.diagnosticsDir, self.filteredMapsDir)
        FilterNoiseMapFile = nemoOutputDir + noiseFile
        MaskMapFile = self.diagnosticsDir + '/areaMask.fits'

        self.rms_noise_map = read_MJH_noisemap(FilterNoiseMapFile,MaskMapFile)
        
        self.wcs=astWCS.WCS(FilterNoiseMapFile)

        self.fsky = 987.5/41252.9612 # in rads ACTPol D56-equ specific
        self.scat_val = 0.2
        self.seedval = np.int(np.round(time.time())) #1

    def Total_clusters(self,fsky):
        Nz = self.HMF.N_of_z()
        print (np.trapz(self.HMF.N_of_z_500()*fsky,dx=np.diff(self.HMF.zarr)))
        ans = np.trapz(Nz*fsky,dx=np.diff(self.HMF.zarr))
        return ans

    def Total_clusters_check(self,fsky):
        
        Marr = np.outer(self.Mcents,np.ones(len(self.HMF.zarr)))
        Medgearr = np.outer(self.Medges,np.ones(len(self.HMF.zarr)))
        dn_dzdm = self.HMF.N_of_Mz(Marr,200)
        N_z = np.zeros(self.HMF.zarr.size)
        for i in range(self.HMF.zarr.size):
            N_z[i] = np.dot(dn_dzdm[:,i],np.diff(Medgearr[:,i]))
        
        N_z *= 4.*np.pi
        ans = np.trapz(N_z*fsky,dx=np.diff(self.HMF.zarr))
        #print ('test diff z',np.diff(self.HMF.zarr))
        return ans

    def create_basic_sample(self,fsky):
        '''
        Create simple mock catalog of Mass and Redshift by sampling the mass function
        '''
        #if (self.rand):
        #    Ntot100 = np.int32(np.ceil(self.Total_clusters(fsky))*4.) ## Note for randoms increasing the number density by factor of 100
        #else:
        #    Ntot100 = np.int32(np.ceil(old_div(self.Total_clusters(fsky), 100.))) ## Note the default number of walkers in mcsample_mf is 100 

        #mlim = [np.min(self.mgrid),np.max(self.mgrid)]
        #zlim = [np.min(self.zgrid),np.max(self.zgrid)]

        #old MCMC
        #samples = self.HMF.mcsample_mf(200.,Ntot100,mthresh = mlim,zthresh = zlim)
        #return samples[:,0],samples[:,1]

        Ntot100 = self.Total_clusters(fsky) # np.int32(np.ceil(self.Total_clusters(fsky))) 
        Ntot = np.int32(np.random.poisson(Ntot100))
        print ("Mock cat gen internal counts and Poisson draw",Ntot100,Ntot)

        zsamps, msamps = self.HMF.cpsample_mf(200.,Ntot) 
        #print (zsamps, msamps) 
        return zsamps, msamps

    def create_basic_sample_Mat(self,fsky):
        '''                                                                                                                                                               Create simple mock catalog of Mass and Redshift by sampling the mass function                                                                                     '''
        nmzdensity = HMF.N_of_Mz(self.HMF.M200,200.)
        Ndz = np.multiply(nmzdensity,np.diff(self.zgrid).reshape((1,self.zgrid.size-1)))
        Nmz = np.multiply(Ndz,np.diff(10**self.mgrid).reshape((self.mgrid.size-1,1))) * 4.* np.pi
        Ntot = Nmz.sum() * fsky

        print ("fsky test",Ntot, np.int32(np.ceil(self.Total_clusters(fsky))))

        np.random.seed(self.seedval)
        nclusters = int(np.random.poisson(Ntot)) #if poisson else int(self.ntot)
        mzs = np.zeros((nclusters,2),dtype=np.float32)

        msamps = np.zeros((nclusters),dtype=np.float32)
        zsamps = np.zeros((nclusters),dtype=np.float32)
        print("Generating Nmz catalog...")
        for i in range(nclusters):
            linear_idx = np.random.choice(self.Nmz.size, p=self.Nmz.ravel()/float(self.Nmz.sum()))
            x, y = np.unravel_index(linear_idx, self.Nmz.shape)
            # mzs[i,0] = self.Mexpcents[x]                                                                                         
            # mzs[i,1] = self.zcents[y]                                                                                            
            msamps = np.random.uniform(self.Mexpcents[x].min(),self.Mexpcents[x].max())
            zsamps = np.random.uniform(self.zcents[y].min(),self.zcents[y].max())

        return zsamps, msamps

    def plot_basic_sample(self,fname='default_mockcat.png',):
        fsky = self.fsky
        sampZ,sampM = self.create_basic_sample(fsky)
        plt.figure()
        plt.plot(sampZ,sampM,'x') 
        plt.savefig(fname, bbox_inches='tight',format='png')  
        return sampZ,sampM

    def create_obs_sample(self,fsky):
        
        #include observational effects like scatter and noise into the detection of clusters
        sampZ,sampM = self.create_basic_sample(fsky)
        nsamps = len(sampM)

        Ytilde = sampM * 0.0
        
        Om = old_div((self.param_vals['omch2'] + self.param_vals['ombh2']), (old_div(self.param_vals['H0'],100.))**2)
        OL = 1.-Om 
        print("Omega_M", Om)

        #the function call now includes cosmological dependences
        for i in range(nsamps):
            Ytilde[i], theta0, Qfilt = simsTools.y0FromLogM500(np.log10(self.param_vals['massbias']*10**sampM[i]/(old_div(self.param_vals['H0'],100.))), sampZ[i], self.tckQFit,sigma_int=self.param_vals['scat'],B0=self.param_vals['yslope'], H0 = self.param_vals['H0'], OmegaM0 = Om, OmegaL0 = OL)
        #add scatter of 20% percent
        np.random.seed(self.seedval)
        ymod = np.exp(self.scat_val * np.random.randn(nsamps))
        sampY0 = Ytilde*ymod
        
        #calculate noise for a given object for a random place on the map and save coordinates

        np.random.seed(self.seedval+1)
        nmap = self.rms_noise_map #[::-1,:]
        
        ylims = nmap.shape[0]
        xlims = nmap.shape[1]
        xsave = np.array([])
        ysave = np.array([])
        sampY0err = np.array([])
        count = 0

        while count < nsamps:
            ytemp = np.int32(np.floor(np.random.uniform(0,ylims)))
            xtemp = np.int32(np.floor(np.random.uniform(0,xlims)))
            if nmap[ytemp,xtemp] > 0:
                count += 1
                xsave = np.append(xsave,xtemp)
                ysave = np.append(ysave,ytemp)
                sampY0err = np.append(sampY0err,nmap[ytemp,xtemp])
        return xsave,ysave,sampZ,sampY0,sampY0err,old_div(sampY0,sampY0err),sampM

    def plot_obs_sample(self,filename1='default_mockobscat',filename2='default_obs_mock_footprint'):
        fsky = self.fsky
        xsave,ysave,sampZ,sampY0,sampY0err,SNR,sampM = self.create_obs_sample(fsky)
        ind = np.where(SNR >= 5.6)[0]
        plt.figure()
        plt.plot(sampZ,sampM,'x')
        plt.plot(sampZ[ind],sampM[ind],'o')
        plt.savefig(filename1+'.png', bbox_inches='tight',format='png')

        nmap = self.rms_noise_map # np.flipud(self.rms_noise_map)#[::-1,:]
        plt.figure(figsize=(40,6))
        plt.imshow(nmap,cmap='Blues')
        plt.plot(xsave[ind],ysave[ind],'ko')
        plt.colorbar()
        plt.savefig(filename2+'.png', bbox_inches='tight',format='png')

        return xsave,ysave,sampZ,sampY0,sampY0err,SNR,sampM

    def write_test_cat_toFits(self, filedir,filename):
        '''
        Write out the catalog
        '''
        f1 = filedir+filename+'_testsamp_mz'
        sampZ,sampM = self.plot_basic_sample(f1)
        sampZerr = sampZ * 0.0
        sampMerr = sampM * 0.0

        #ind = np.where(10**sampM >= 2.0*10**(np.min(self.mgrid)))[0]

        clusterID = np.arange(len(sampM)).astype(str)
        hdu = fits.BinTableHDU.from_columns(
            [fits.Column(name='Cluster_ID', format='20A', array=clusterID),
             fits.Column(name='redshift', format='E', array=sampZ),
             fits.Column(name='redshift_err', format='E', array=sampZerr),
             fits.Column(name='Mass', format='E', array=sampM),
             fits.Column(name='Mass_err', format='E', array=sampMerr),])

        hdu.writeto(filedir+filename+'.fits',overwrite=True)

        return 0

    def test_cat_samp(self, filedir,filename, mcut):
        '''
        Write out the catalog
        '''
        f1 = filedir+filename+'_testsamp_mz'
        sampZ,sampM = self.plot_basic_sample(f1)

        print (sampM) 

        return 0

    def test_Mockcat_Nums(self, mmin):
        '''
        Quick write out of the number clusters in the mock catalog, for testing
        '''
        sampZ,sampM = self.create_basic_sample(self.fsky)
        ind = np.where(sampM >= mmin)[0]

        return len(ind)

    def write_obs_cat_toFits(self, filedir,filename):
        '''
        Write out the catalog
        '''
        f1 = filedir+filename+'_mockobscat'
        f2 = filedir+filename+'_obs_mock_footprint'

        xsave,ysave,z,sampY0,sampY0err,SNR,sampM = self.plot_obs_sample(filename1=f1,filename2=f2)

        ind = np.where(SNR >= 4.0)[0]
        ind2 = np.where(SNR >= 5.6)[0]
        print("number of clusters SNR >= 5.6", len(ind2), " SNR >= 4.0",len(ind))

        RAdeg = xsave*0.0
        DECdeg = ysave*0.0
        count = 0
        for xsv, ysv in zip(xsave,ysave):
            ra,dec = self.wcs.pix2wcs(xsv,ysv)
            RAdeg[count] = ra
            DECdeg[count] = dec
            count +=1

        clusterID = ind.astype(str)
        hdu = fits.BinTableHDU.from_columns(
            [fits.Column(name='Cluster_ID', format='20A', array=clusterID),
             fits.Column(name='x_ind', format='E', array=xsave[ind]),
             fits.Column(name='y_ind', format='E', array=ysave[ind]),
             fits.Column(name='RA', format='E', array=RAdeg[ind]),
             fits.Column(name='DEC', format='E', array=DECdeg[ind]),
             fits.Column(name='redshift', format='E', array=z[ind]),
             fits.Column(name='redshiftErr', format='E', array=z[ind]*0.0),
             fits.Column(name='fixed_y_c', format='E', array=sampY0[ind]*1e4),
             fits.Column(name='err_fixed_y_c', format='E', array=sampY0err[ind]*1e4),
             fits.Column(name='fixed_SNR', format='E', array=SNR[ind]),
             fits.Column(name='M500', format='E', array=sampM[ind]),])

        hdu.writeto(filedir+filename+'.fits',overwrite=True)

        return 0

    def Add_completeness(self,filedir,filename,compfile,zcut=False):
        '''
        Add in observing and filter completeness to the selection the mock catalogs
        '''

        fitsfile = filedir+filename+'.fits'
        ID,x,y,ra,dec,z,zerr,Y0,Y0err,SNR,M500 = read_full_mock_cat(fitsfile)
        
        rands = np.random.uniform(0,1,len(z))        
        
        compvals = np.load(compfile)
        inter = interp2d(compvals['log10M500c'],compvals['z'],compvals['M500Completeness'],kind='cubic',fill_value=0)
        use = 0.0*z

        for ii in range(len(z)):
            comp = inter(M500[ii],z[ii])
            if (comp > rands[ii]):
                use[ii] = 1

        if (zcut):
            ind = np.where((z < zcut)*(use > 0))[0]

        print("number of clusters SNR >= 4.0 plus completeness",len(ind))
        fitsout = filedir+filename+'_comp_added.fits'

        hdu = fits.BinTableHDU.from_columns(
            [fits.Column(name='Cluster_ID', format='20A', array=ID[ind]),
             fits.Column(name='x_ind', format='E', array=x[ind]),
             fits.Column(name='y_ind', format='E', array=y[ind]),
             fits.Column(name='RA', format='E', array=ra[ind]),
             fits.Column(name='DEC', format='E', array=dec[ind]),
             fits.Column(name='redshift', format='E', array=z[ind]),
             fits.Column(name='redshiftErr', format='E', array=zerr[ind]),
             fits.Column(name='fixed_y_c', format='E', array=Y0[ind]),
             fits.Column(name='err_fixed_y_c', format='E', array=Y0err[ind]),
             fits.Column(name='fixed_SNR', format='E', array=SNR[ind]),
             fits.Column(name='M500', format='E', array=M500[ind]),])

        hdu.writeto(fitsout,overwrite=True)

        return 0
예제 #22
0
    yNzs[key] = []
    vals = stepdict[key][:maxSteps]
    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)

예제 #23
0
    def __init__(self,iniFile,parDict,nemoOutputDir,noiseFile,params,parlist,mass_grid_log=None,z_grid=None,randoms=False):

        Config = SafeConfigParser()
        Config.optionxform=str
        Config.read(iniFile)

        if mass_grid_log:
            logm_min,logm_max,logm_spacing = mass_grid_log
        else:
            logm_min = 12.7
            logm_max = 15.72
            logm_spacing = 0.04
        if z_grid:
            zmin,zmax,zdel = z_grid
        else:
            zmin = 0.0
            zmax = 2.01
            zdel = 0.1



        self.fparams = {}
        for (key, val) in Config.items('params'):
            if ',' in val:
                param, step = val.split(',')
                self.fparams[key] = float(param)
            else:
                self.fparams[key] = float(val)

        self.param_vals = alter_fparams(self.fparams,parlist,params)

        bigDataDir = Config.get('general','bigDataDirectory')
        self.clttfile = Config.get('general','clttfile')
        self.constDict = dict_from_section(Config,'constants')

        if mass_grid_log:
            logm_min,logm_max,logm_spacing = mass_grid_log
        else:
            logm_min = 12.7
            logm_max = 15.72
            logm_spacing = 0.04
        if z_grid:
            zmin,zmax,zdel = z_grid
        else:
            zmin = 0.0
            zmax = 2.01
            zdel = 0.1
        
        if randoms:
            self.rand = 1
        else:
            self.rand = 0

        self.mgrid = np.arange(logm_min,logm_max,logm_spacing)
        self.zgrid = np.arange(zmin,zmax,zdel)

        self.Medges = 10.**self.mgrid
        self.Mcents = (self.Medges[1:]+self.Medges[:-1])/2.
        self.Mexpcents = np.log10(self.Mcents)
        self.zcents = (self.zgrid[1:]+self.zgrid[:-1])/2.

        self.cc = ClusterCosmology(self.param_vals,self.constDict,clTTFixFile=self.clttfile)
        self.HMF = Halo_MF(self.cc,self.mgrid,self.zgrid)

        self.diagnosticsDir=nemoOutputDir+"diagnostics"
        self.filteredMapsDir=nemoOutputDir+"filteredMaps"
        self.tckQFit=simsTools.fitQ(parDict, self.diagnosticsDir, self.filteredMapsDir)
        FilterNoiseMapFile = nemoOutputDir + noiseFile
        MaskMapFile = self.diagnosticsDir + '/areaMask.fits'

        self.rms_noise_map = read_MJH_noisemap(FilterNoiseMapFile,MaskMapFile)
        
        self.wcs=astWCS.WCS(FilterNoiseMapFile)

        self.fsky = 987.5/41252.9612 # in rads ACTPol D56-equ specific
        self.scat_val = 0.2
        self.seedval = np.int(np.round(time.time())) #1
예제 #24
0
파일: testRefactor.py 프로젝트: mntw/szar
Mexp_edges = np.arange(13.0, 15.7 + w, w)
M_edges = 10**Mexp_edges
M = old_div((M_edges[1:] + M_edges[:-1]), 2.)
Mexp = np.log10(M)

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

hmf = Halo_MF(cc, Mexp_edges, z_edges)

SZProf = SZ_Cluster_Model(cc,
                          clusterDict,
                          rms_noises=noise,
                          fwhms=beam,
                          freqs=freq,
                          lknee=lknee,
                          alpha=alpha)

fsky = 0.4

N1 = hmf.N_of_z() * fsky

#hmf.sigN = np.loadtxt("temp.txt")
예제 #25
0
cc = ClusterCosmology(cosmoDict,constDict,clTTFixFile = "data/cltt_lensed_Feb18.txt")#,skipCls=True)


if "owl" in calName:
    calFile = bigDataDir+"lensgrid_"+gridName+"_"+cal+".pkl"
    #calFile = bigDataDir+"lensgrid_grid-"+cal+"_"+cal+".pkl"
else:
    calFile = bigDataDir+"lensgrid_"+exp+"_"+gridName+"_"+calName+ "_v" + version+".pkl"


Mexp_edges, z_edges, lndM = pickle.load(open(calFile,"rb"))
mgrid,zgrid,siggrid = pickle.load(open(bigDataDir+"szgrid_"+expName+"_"+gridName+ "_v" + version+".pkl",'rb'))
zs = old_div((z_edges[1:]+z_edges[:-1]),2.)


hmf = Halo_MF(cc,Mexp_edges,z_edges)


SZProf = SZ_Cluster_Model(cc,clusterDict,rms_noises = noise,fwhms=beam,freqs=freq,lknee=lknee,alpha=alpha)


N1 = hmf.N_of_z()*fsky
hmf.sigN = siggrid
N2 = hmf.N_of_z_SZ(SZProf)*fsky

    
pl = Plotter(scaleY='log')
pl.add(zs,N1)
pl.add(zs,N2)

Ntot0 = np.dot(N1,np.diff(z_edges))
예제 #26
0
class Clustering(object):
    def __init__(self,iniFile,expName,gridName,version,ClusterCosmology):
        Config = SafeConfigParser()
        Config.optionxform=str
        Config.read(iniFile)

        self.cc = ClusterCosmology

        bigDataDir = Config.get('general','bigDataDirectory')
        self.clttfile = Config.get('general','clttfile')
        self.constDict = dict_from_section(Config,'constants')
        self.clusterDict = dict_from_section(Config,'cluster_params')
        #version = Config.get('general','version')
        beam = list_from_config(Config,expName,'beams')
        noise = list_from_config(Config,expName,'noises')
        freq = list_from_config(Config,expName,'freqs')
        lknee = list_from_config(Config,expName,'lknee')[0]
        alpha = list_from_config(Config,expName,'alpha')[0]
        self.fsky = Config.getfloat(expName,'fsky')

        self.mgrid,self.zgrid,siggrid = pickle.load(open(bigDataDir+"szgrid_"+expName+"_"+gridName+ "_v" + version+".pkl",'rb'))

        #self.cc = ClusterCosmology(self.fparams,self.constDict,clTTFixFile=self.clttfile)
        self.SZProp = SZ_Cluster_Model(self.cc,self.clusterDict,rms_noises = noise,fwhms=beam,freqs=freq,lknee=lknee,alpha=alpha)
        self.HMF = Halo_MF(self.cc,self.mgrid,self.zgrid)
        self.HMF.sigN = siggrid.copy()
        #self.dndm_SZ = self.HMF.dn_dmz_SZ(self.SZProp)

    def dVdz_fine(self,zarr):
        DA_z = self.HMF.cc.results.angular_diameter_distance(zarr)
        dV_dz = DA_z**2 * (1.+zarr)**2
        #NOT SURE we need this for loop
        for i in range (zarr.size):
            dV_dz[i] /= (self.HMF.cc.results.h_of_z(zarr[i]))
        dV_dz *= (old_div(self.HMF.cc.H0,100.))**3. # was h0
        return dV_dz

    def ntilde(self):
        dndm_SZ = self.HMF.dn_dmz_SZ(self.SZProp)
        ans = np.trapz(dndm_SZ,dx=np.diff(self.HMF.M200,axis=0),axis=0)
        return ans

    def ntilde_interpol(self,zarr_int):
        ntil = self.ntilde()
        z_arr = self.HMF.zarr

        #n = len(z_arr)
        #k = 4 # 5th degree spline
        #s = 20.*(n - np.sqrt(2*n))* 1.3 # smoothing factor

        #ntilde_spline = UnivariateSpline(z_arr, np.log(ntil), k=k, s=s)
        #ans = np.exp(ntilde_spline(zarr_int))
        f_int = interp1d(z_arr, np.log(ntil),kind='cubic')
        ans = np.exp(f_int(zarr_int))

        return ans

    def b_eff_z(self):
        '''
        effective linear bias wieghted by number density
        '''
        nbar = self.ntilde()

        z_arr = self.HMF.zarr
        dndm_SZ = self.HMF.dn_dmz_SZ(self.SZProp)

        R = tinker.radius_from_mass(self.HMF.M200,self.cc.rhoc0om)
        sig = np.sqrt(tinker.sigma_sq_integral(R, self.HMF.pk, self.HMF.kh))

        blin = tinker.tinker_bias(sig,200.)
        beff = old_div(np.trapz(dndm_SZ*blin,dx=np.diff(self.HMF.M200,axis=0),axis=0), nbar)

        try:
            a_bias = self.cc.paramDict['abias']
        except KeyError:
            print("Using implicit a_bias value")
            a_bias = 1.

        return a_bias * beff

    def non_linear_scale(self,z,M200): #?Who are you?

        zdiff = np.abs(self.HMF.zarr - z)
        use_z = np.where(zdiff == np.min(zdiff))[0]

        R = tinker.radius_from_mass(M200,self.cc.rhoc0om)

        sig = np.sqrt(tinker.sigma_sq_integral(R, self.HMF.pk[use_z,:], self.HMF.kh))

        #print sig[:,0],sig[0,:]
        print(sig.shape)
        print(self.HMF.kh.shape)
        sig1 = sig[0,:]
        print(sig1)
        sigdiff = np.abs(sig1 - 1.)
        use_sig = np.where(sigdiff == np.min(sigdiff))[0]
        print(use_sig)

        return old_div(1.,(R[use_sig])),sig1[use_sig],self.HMF.zarr[use_z]

# norm is off by 4 pi from ps_bar
    def Norm_Sfunc(self):
        #z_arr = self.HMF.zarr
        #Check this
        nbar = self.ntilde()
        ans = self.HMF.dVdz*nbar**2*np.diff(self.HMF.zarr_edges)
        return ans

    def fine_sfunc(self, nsubsamples):
        zs = self.HMF.zarr
        zgridedges = self.HMF.zarr_edges

        fine_zgrid = np.empty((zs.size, nsubsamples))
        for i in range(zs.size):
            fine_zgrid[i,:] = np.linspace(zgridedges[i], zgridedges[i+1], nsubsamples)

        fine_zgrid = fine_zgrid[1:-1]

        ntils = self.ntilde_interpol(fine_zgrid)
        dvdz = np.array([self.dVdz_fine(zs) for zs in fine_zgrid])

        dz = fine_zgrid[0,1] - fine_zgrid[0,0]

        assert np.allclose(dz * np.ones(tuple(np.subtract(fine_zgrid.shape, (0,1)))),  np.diff(fine_zgrid,axis=1), rtol=1e-3)

        integral = np.trapz(dvdz * ntils**2, dx=dz)
        return integral

    def v0(self, nsubsamples):
        zs = self.HMF.zarr
        zgridedges = self.HMF.zarr_edges

        fine_zgrid = np.empty((zs.size, nsubsamples))
        for i in range(zs.size):
            fine_zgrid[i,:] = np.linspace(zgridedges[i], zgridedges[i+1], nsubsamples)

        fine_zgrid = fine_zgrid[1:-1]
        dvdz = np.array([self.dVdz_fine(zs) for zs in fine_zgrid])
        dz = fine_zgrid[0,1] - fine_zgrid[0,0]

        assert np.allclose(dz * np.ones(tuple(np.subtract(fine_zgrid.shape, (0,1)))),  np.diff(fine_zgrid,axis=1), rtol=1e-3)

        integral = np.trapz(dvdz, dx=dz)
        integral *= 4 * np.pi * self.fsky
        return integral

    def w_redshift_err(self, mu):
        ks = self.HMF.kh
        zs = self.HMF.zarr

        kr_sqr = ks[:, None]**2 * (1 - mu[None, :]**2)
        sigma_z = self.cc.paramDict['sigma_z']
        h_z = self.HMF.cc.results.h_of_z(zs)[None, ..., None]
        return np.exp(-0.5*(sigma_z/h_z)**2 * kr_sqr[:, None, :])

    def ps_tilde(self,mu):
        beff_arr = self.b_eff_z()[..., np.newaxis]
        mu_arr = mu[..., np.newaxis]
        logGrowth = self.cc.fgrowth(self.HMF.zarr)

        prefac = (beff_arr.T + logGrowth*mu_arr**2)**2
        prefac = prefac[..., np.newaxis]

        pklin = self.HMF.pk # not actually pklin
        pklin = pklin.T
        pklin = pklin[..., np.newaxis]

        ans = np.multiply(prefac,pklin.T).T
        return ans * self.w_redshift_err(mu)**2

    def ps_tilde_interpol(self, zarr_int, mu):
        ps_tils = self.ps_tilde(mu)
        zs = self.HMF.zarr
        ks = self.HMF.kh

        n = zs.size
        k = 4 # 5th degree spline
        s = 20.*(n - np.sqrt(2*n))* 1.3 # smoothing factor

        ps_interp = interp1d(zs, ps_tils, axis=1, kind='cubic')
        return ps_interp(zarr_int)

    def ps_bar(self,mu):
        z_arr = self.HMF.zarr
        nbar = self.ntilde()
        prefac =  self.HMF.dVdz*nbar**2*np.diff(z_arr)[2]/self.Norm_Sfunc()
        prefac = prefac[..., np.newaxis]
        ans = np.multiply(prefac, self.ps_tilde(mu).T).T
        #for i in range(len(z_arr)):
        #    ans[:,:,i] = self.HMF.dVdz[i]*nbar[i]**2*ps_tilde[:,:,i]*np.diff(z_arr[i])/self.Norm_Sfunc(fsky)[i]
        return ans

    def fine_ps_bar(self,mu, nsubsamples=100):
        zs = self.HMF.zarr
        ks = self.HMF.kh
        zgridedges = self.HMF.zarr_edges

        values = np.empty((ks.size, zs.size, mu.size))

        fine_zgrid = np.empty((zs.size, nsubsamples))
        for i in range(zs.size):
            fine_zgrid[i,:] = np.linspace(zgridedges[i], zgridedges[i+1], nsubsamples)

        fine_zgrid = fine_zgrid[1:-1]
        ntils = self.ntilde_interpol(fine_zgrid)
        dvdz = np.array([self.dVdz_fine(zs) for zs in fine_zgrid])
        prefac = dvdz * ntils**2
        prefac = prefac[..., np.newaxis]
        ps_tils = self.ps_tilde_interpol(fine_zgrid, mu)

        integrand = prefac * ps_tils
        dz = fine_zgrid[0,1] - fine_zgrid[0,0]

        assert np.allclose(dz * np.ones(tuple(np.subtract(fine_zgrid.shape, (0,1)))),  np.diff(fine_zgrid,axis=1), rtol=1e-3)

        integral = np.trapz(integrand, dx=dz, axis=2)
        s_norm = self.fine_sfunc(nsubsamples)[..., np.newaxis]
        values = integral/s_norm
        return values

    def V_eff(self,mu,nsubsamples=100):
        V0 = self.v0( nsubsamples)
        V0 = np.reshape(V0, (V0.size,1))

        nbar = self.ntilde()[1:-1]
        nbar = np.reshape(nbar, (nbar.size,1))

        ps = self.fine_ps_bar(mu, nsubsamples)
        npfact = np.multiply(nbar, ps)
        frac = npfact/(1. + npfact)

        ans = np.multiply(frac**2,V0)
        return ans
예제 #27
0
massMultiplier = Config.getfloat('general', 'mass_calib_factor')

clttfile = Config.get('general', 'clttfile')

# get s/n q-bins
qs = list_from_config(Config, 'general', 'qbins')
qspacing = Config.get('general', 'qbins_spacing')
if qspacing == "log":
    qbins = np.logspace(np.log10(qs[0]), np.log10(qs[1]), int(qs[2]) + 1)
elif qspacing == "linear":
    qbins = np.linspace(qs[0], qs[1], int(qs[2]) + 1)
else:
    raise ValueError

cc = ClusterCosmology(fparams, constDict, clTTFixFile=clttfile)
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)
예제 #28
0
CL = lk.clusterLike(iniFile,pardict,nemoOutputDir,noise_file,fix_params,fitsfile,test=args.test,simtest=simtst,simpars=args.simpars)

if (args.printtest):

    parvals2 = [3.46419819e-01,2.34697120e-02,6.50170056e+01,1.33398673e-09,9.36305025e-01,2.53310030e-01,1.93661978e-01,1.74839544e-01]
#parvals2 = [1.194e-01,2.34697120e-02,6.50170056e+01,1.33398673e-09,9.36305025e-01,2.53310030e-01,1.93661978e-01,1.74839544e-01]

    param_vals= lk.alter_fparams(fparams,parlist,parvals)
    cluster_props = np.array([CL.clst_z,CL.clst_zerr,CL.clst_y0*1e-4,CL.clst_y0err*1e-4])
    
    start = time.time()
    int_cc = ClusterCosmology(param_vals,CL.constDict,clTTFixFile=CL.clttfile) 
    
    print('CC',time.time() - start)
    start = time.time()
    int_HMF = Halo_MF(int_cc,CL.mgrid,CL.zgrid)
    
    print('HMF',time.time() - start)
    dn_dzdm_int = int_HMF.inter_dndmLogm(200.)

    zbins = 10
    LgYa = np.outer(np.ones(len(int_HMF.M.copy())),CL.LgY)
    Y = 10**LgYa
    Ma = np.outer(int_HMF.M.copy(),np.ones(len(LgYa[0,:])))
    clustind = 1


    print(cluster_props[:,clustind])
    print(parlist)
    print(parvals)
    print("ln prob", np.log(CL.Prob_per_cluster(int_HMF,cluster_props[:,clustind],dn_dzdm_int,param_vals)))
예제 #29
0
파일: SO_rezstudy.py 프로젝트: mntw/szar
    mass_err = np.loadtxt(mass_err_file)
# HMF

    #mbin = np.arange(12.5,15.5,0.05)+0.05
    #zbin_temp = np.arange(0.05,2.05,0.05)

    #zbin = np.insert(zbin_temp,0,0.0)
    #qbin = np.arange(np.log(5),np.log(500),0.08)
    zbin_temp = np.arange(0.05,3.0,0.05)
    zbin = np.insert(zbin_temp,0,0.0)
    #qbin = np.arange(np.log(6),np.log(500),0.08)
    qbin = np.arange(np.log(6),np.log(500),0.08)
    mbin = np.arange(13.5, 15.71, .10)
    start3 = time.time()

    HMF = Halo_MF(clusterCosmology=cc)
    dvdz = HMF.dVdz(zbin)
    dndm = HMF.N_of_z_SZ(zbin,beam,noise,freq,clusterDict,lknee,alpha,fileFunc)
    #dndm2 = HMF.N_of_z(zbin)
    #dNdmdz,dm = HMF.N_of_mz_SZ(zbin,beam,noise,freq,clusterDict,lknee,alpha,fileFunc)
    #ans = HMF.N_of_mqz_SZ(mass_err,zbin,mbin,np.exp(qbin),beam,noise,freq,clusterDict,lknee,alpha,fileFunc)

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

    #np.save('output/dN_dzmq'+experimentName[ii]+cosmologyName,ans)
    #print np.max(ans)

    #pl = Plotter()
    #pl.add(zbin[1:], dndm * dvdz[1:])
    #pl.done("output/dndm"+experimentName[ii]+".png")
예제 #30
0
파일: testMassError.py 프로젝트: mntw/szar
# make an SZ profile example


SZProfExample = SZ_Cluster_Model(clusterCosmology=cc,clusterDict=clusterDict,rms_noises = noise,fwhms=beam,freqs=freq,lmax=lmax,lknee=lknee,alpha=alpha,dell=dell,pmaxN=pmaxN,numps=numps,qmin=6)

version = Config.get('general','version')
bigDataDir = Config.get('general','bigDataDirectory')

calFile = bigDataDir+"lensgrid_"+gridName+"_"+calName+".pkl"

mgrid,zgrid,siggrid = pickle.load(open(bigDataDir+"szgrid_"+expName+"_"+gridName+ "_v" + version+".pkl",'rb'))

Mexp_edges, z_edges, lndM = pickle.load(open(calFile,"rb"))

HMF = Halo_MF(cc,Mexp_edges,z_edges)
HMF.sigN = siggrid.copy()
#MM = 10**np.linspace(13.,14.,5)
#print SZProfExample.quickVar(MM,zz,tmaxN=tmaxN,numts=numts)

#sys.exit()

#print z_edges
#print HMF.N_of_z()

Nzs =  HMF.N_of_z_SZ(fsky,SZProfExample)*np.diff(z_edges)
zcents = old_div((z_edges[1:]+z_edges[:-1]),2.)
pl = Plotter()
pl.add(zcents,Nzs)
pl.done("nz.png")