示例#1
0
    def fit(self,keyData,keyTheory,amplitudeRange=np.arange(0.1,2.0,0.01),debug=False,numbins=-1):
        # evaluate likelihood on a 1d grid and fit to a gaussian
        # store fit as new theory curve

        width = amplitudeRange[1]-amplitudeRange[0]
        Likelihood = lambda x: np.exp(-0.5*self.chisq(keyData,keyTheory,amp=x,numbins=numbins))
        Likes = np.array([Likelihood(x) for x in amplitudeRange])
        Likes = Likes / (Likes.sum()*width) #normalize

        ampBest,ampErr = cfit(norm.pdf,amplitudeRange,Likes,p0=[1.0,0.5])[0]

        
        
        if debug:
            fitVals = np.array([norm.pdf(x,ampBest,ampErr) for x in amplitudeRange])
            pl = Plotter()
            pl.add(amplitudeRange,Likes,label="likes")
            pl.add(amplitudeRange,fitVals,label="fit")
            pl.legendOn()
            pl.done("output/debug_coreFit.png")

        fitKey = keyData+"_fitTo_"+keyTheory
        self.datas[fitKey] = {}
        self.datas[fitKey]['covmat'] = None
        self.datas[fitKey]['binned'] = self.datas[keyTheory]['binned']*ampBest
        #self.datas[fitKey]['unbinned'] = self.datas[keyTheory]['unbinned']*ampBest
        self.datas[fitKey]['label'] = keyData+" fit to "+keyTheory+" with amp "+'{0:.2f}'.format(ampBest)+"+-"+'{0:.2f}'.format(ampErr)
        self.datas[fitKey]['amp']=(ampBest,ampErr)
        self.datas[fitKey]['isFit'] = True

        return fitKey
示例#2
0
    def plotCls(self,saveFile,keys=None,xlimits=None,ylimits=None,transform=True,showBinnedTheory=False,scaleX='linear',scaleY='linear'):

        nsigma = 2.
        
        binCenters = self.binner.getBinCenters()

        if transform:
            ylab = "$\ell C_{\ell}$"
            mult = binCenters
            multTh = 1.#binCenters*0.+1.
        else:
            ylab = "$C_{\ell}$"
            mult = binCenters*0.+1.
            multTh = 0.#binCenters*0.
            
        pl = Plotter(labelX="$\ell$",labelY=ylab,scaleX=scaleX,scaleY=scaleY)


        
        if keys is None: keys = list(self.datas.keys())
        for key in keys:

            dat = self.datas[key]

            if dat['covmat'] is None:
                #This is a theory curve
                ells = np.array(list(range(len(dat['unbinned']))))
                if dat['isFit']:
                    ls="--"
                    lw=1
                else:
                    ls="-"
                    lw=2
                    
                base_line, = pl.add(ells,(multTh*(ells-1)+1.)*dat['unbinned'],label=dat['label'],lw=lw,ls=ls)
                if dat['isFit']:
                    pl._ax.fill_between(ells,(multTh*(ells-1)+1.)*dat['unbinned']*(1.-nsigma*dat['amp'][1]/dat['amp'][0]),(multTh*(ells-1)+1.)*dat['unbinned']*(1.+nsigma*dat['amp'][1]/dat['amp'][0]),alpha=0.3, facecolor=base_line.get_color())
                    
                if showBinnedTheory:
                    pl.add(binCenters[:len(dat['binned'])],mult[:len(dat['binned'])]*dat['binned'],
                           ls='none',marker='x',mew=2,markersize=10,label=dat['label']+' binned')
                  
            else:
                errs = np.sqrt(np.diagonal(dat['covmat']))
                print((dat['label']))
                pl.addErr(binCenters[:len(dat['binned'])],mult[:len(dat['binned'])]*dat['binned'],mult[:len(dat['binned'])]*errs,label=dat['label'],marker='o',elinewidth=2,markersize=10,mew=2,)


        [i.set_linewidth(2.0) for i in list(pl._ax.spines.values())]
        pl._ax.tick_params(which='major',width=2)
        pl._ax.tick_params(which='minor',width=2)
        pl._ax.axhline(y=0.,ls='--')
    
        if not(xlimits is None):
            pl._ax.set_xlim(*xlimits)
        else:
            pl._ax.set_xlim(self.binner.bin_edges[0],self.binner.bin_edges[-1])    
        if not(ylimits is None): pl._ax.set_ylim(*ylimits)
        pl.legendOn(loc='lower left',labsize=10)
        pl.done(saveFile)
示例#3
0
def makeTemplate(l, Fl, mod, Nx, Ny, debug=False):
    """
    Given 1d function Fl of l, creates the 2d version
    of Fl on 2d k-space defined by mod
    """

    FlSpline = splrep(l, Fl, k=3)
    ll = np.ravel(mod)
    kk = (splev(ll, FlSpline))

    template = np.reshape(kk, [Ny, Nx])

    if debug:
        print(kk)
        myFig = Plotter("$l$", "$F_l$", scaleX="log", scaleY="log")
        #myFig.add(l,Fl)
        myFig.add(ll, kk)
        myFig.done(fileName="output/interp.png")
        plotme([mod], saveFile="output/mod.png", axoff=True, clbar=False)
        plotme([template], saveFile="output/temp.png", axoff=True, clbar=False)
        plotme([np.log(template)],
               saveFile="output/logtemp.png",
               axoff=True,
               clbar=False)
        sys.exit()

    return template
示例#4
0
def stat_analysis(cutouts, binsize, arcmax, cents, modRMaps):
    profiles = []
    for i in range(0, len(cutouts)):
        thetaRange = np.arange(0., arcmax, binsize)
        breali = bin2D(modRMaps[i] * 180. * 60. / np.pi, thetaRange)
        a = breali.bin(cutouts[i])[1]
        profiles.append(a)
    statistics = stats.getStats(profiles)
    mean = statistics['mean']
    error = statistics['errmean']
    covmat = statistics['cov']
    corrcoef = stats.cov2corr(covmat)
    io.quickPlot2d(corrcoef, 'corrcoef.png')
    pl = Plotter(labelX='Distance from Center (arcminutes)',
                 labelY='Temperature Fluctuation ($\mu K$)',
                 ftsize=10)
    pl.add(cents, mean)
    pl.addErr(cents, mean, yerr=error)
    pl._ax.axhline(y=0., ls="--", alpha=0.5)
    pl.done(out_dir + "error.png")
示例#5
0
R500 = cc.rdel_c(M500, z, delta)
# R500_alt = cc.rdel_c_alt(M500,c500,delta)
# print R500, R500_alt
# sys.exit()
# R500 = R500_alt

Rrange = npspace(0.1, 10. * R500, 100, "log")

rhofunc = halos.rho_nfw(M500, c500, R500)
rhos = rhofunc(Rrange)

pl = Plotter(scaleY='log',
             scaleX='log',
             labelX="$R$ (Mpc/h)",
             labelY="$\\rho (h^2 M_{\\odot}/{\\mathrm{Mpc}^3})$")
pl.add(Rrange, rhos)
pl.done("output/rhos.png")

comL = cc.results.comoving_radial_distance(z) * cc.h
thetaS = R500 / c500 / comL
arcmin = 0.1
arcmax = 50.
thetas = npspace(arcmin * np.pi / 180. / 60., arcmax * np.pi / 180. / 60., 100,
                 'log')
gs = halos.projected_rho(thetas, comL, rhofunc)

gsalt = halos.proj_rho_nfw(thetas, comL, M500, c500, R500)

pl = Plotter(scaleY='log',
             scaleX='log',
             labelX="$\\theta$ (arcmin)",
示例#6
0
            nTX,nPX,nTY,nPY = myNls.updateNoise(beamX,noiseTX,noisePX,tellminX,tellmaxX, \
                              pellminX,pellmaxX,beamY=beamY,noiseTY=noiseTY, \
                              noisePY=noisePY,tellminY=tellminY,tellmaxY=tellmaxY, \
                              pellminY=pellminY,pellmaxY=pellmaxY,lkneesX=(lkneeTX,lkneePX), \
                              alphasX=(alphaTX,alphaPX), \
                              lkneesY=(lkneeTY,lkneePY),alphasY=(alphaTY,alphaPY))

            if polComb == 'EB' and delens:
                ls, Nls, efficiency = myNls.iterativeDelens(
                    polComb, delensTolerance, halo)
                print "percentage efficiency ", efficiency, " %"
            else:
                ls, Nls = myNls.getNl(polComb=polComb, halo=halo)

            pl.add(ls, Nls, label=str(beamX))
            #pl.add(myNls.N.cents,myNls.N.wxy,label=str(beamX))

            LF = LensForecast()
            LF.loadKK(frange, Clkk, ls, Nls)
            sn, errs = LF.sn(snrange, fsky, "kk")
            sns.append(sn)

        pl.add(frange, Clkk, color="black")

        #pl.legendOn(loc='lower left',labsize = 8)
        pl._ax.set_xlim(0, 3000)
        pl._ax.set_ylim(1.e-9, 1.e-6)
        pl.done("beamVary_" + polComb + "_delens_" + str(delens) +
                "_noiseVary.pdf")
示例#7
0
文件: testRefactor.py 项目: mntw/szar
#hmf.sigN = np.loadtxt("temp.txt")

try:
    hmf.sigN = np.loadtxt("tempSigN.txt")
    N2 = hmf.N_of_z_SZ(SZProf) * fsky
except:
    N2 = hmf.N_of_z_SZ(SZProf) * fsky
    np.savetxt("tempSigN.txt", hmf.sigN)

pl = Plotter()
pl.plot2d(hmf.sigN)
pl.done(outDir + "signRefactor.png")

pl = Plotter(scaleY='log')
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)
示例#8
0
fileList = glob.glob("data/CMBdustsynch_*")

cambRoot = "data/ell28k_highacc"
theory = loadTheorySpectraFromCAMB(cambRoot,
                                   unlensedEqualsLensed=False,
                                   useTotal=False,
                                   lpad=9000)
pl = Plotter(scaleY='log')

for i, filen in enumerate(fileList):

    ells, d1, Nls, d2 = np.loadtxt(filen, unpack=True)
    Nls = Nls / TCMB**2.

    if i == 0:
        pl.add(ells, theory.lCl('EE', ells), lw=2)

    lab = ""
    if "5m" in filen:
        lab = "5m"
        ls = "-"
    else:
        lab = "6m"
        ls = "--"

    if "synchGal" in filen:
        lab += "_dust_synch"
    elif "dustGal" in filen:
        lab += "_dust"
    pl.add(ells, Nls, label=lab, ls=ls)
示例#9
0
# pl = Plotter()
# pl.plot2d(filtInput)
# pl.done(outDir+"filtsim.png")

dt = 0.2
thetaRange = np.arange(0., arcmax, dt)
breal = bin2D(thetaMapDown * 180. * 60. / np.pi, thetaRange)
#cents,inps = breal.bin(trueKappaStack)
cents, inpsFilt = breal.bin(filtInput)
cents, recons = breal.bin(kappaStack)
# cents,reconsfix = breal.bin(kappaFix)
# cents,simFilt = breal.bin(filtSim)

pl = Plotter()
#pl.add(cents,inps,ls="--")
pl.add(cents, inpsFilt)
# pl.add(cents,simFilt,ls="-.")
pl.add(cents, recons)
# pl.add(cents,reconsfix,ls="-.")
pl._ax.axhline(y=0., ls="--", alpha=0.5)
pl.done(outDir + "profiles.png")

pl = Plotter()
#pl.add(cents,inps,ls="--")
#pl.add(cents,inpsFilt)
# pl.add(cents,simFilt,ls="-.")
pl.add(cents, (recons - inpsFilt) * 100. / inpsFilt.max())
#pl.add(cents,reconsfix,ls="-.")
pl._ax.axhline(y=0., ls="--", alpha=0.5)
pl.done(outDir + "percent.png")
示例#10
0
def stack_on_map(lite_map,
                 width_stamp_arcminute,
                 pix_scale,
                 ra_range,
                 dec_range,
                 catalog=None,
                 n_random_points=None):
    width_stamp_degrees = width_stamp_arcminute / 60.
    Np = np.int(width_stamp_arcminute / pix_scale + 0.5)
    pad = np.int(Np / 2 + 0.5)
    print("Expected width in pixels = ", Np)

    lmap = lite_map
    stack = 0
    N = 0

    if catalog is not None:
        looprange = range(0, len(catalog))
        assert n_random_points is None
        random = False
    else:
        assert n_random_points is not None
        assert len(ra_range) == 2
        assert len(dec_range) == 2
        looprange = range(0, n_random_points)
        random = True

    for i in looprange:
        if random:
            ra = np.random.uniform(*ra_range)
            dec = np.random.uniform(*dec_range)
        else:
            ra = catalog[i][1]
            dec = catalog[i][2]
        ix, iy = lmap.skyToPix(ra, dec)
        if ix >= pad and ix < lmap.Nx - pad and iy >= pad and iy < lmap.Ny - pad:
            print(i)
            #print(ra,dec)
            smap = lmap.selectSubMap(ra - width_stamp_degrees / 2.,
                                     ra + width_stamp_degrees / 2.,
                                     dec - width_stamp_degrees / 2.,
                                     dec + width_stamp_degrees / 2.)
            #print (smap.data.shape)
            #cutout = zoom(smap.data.copy(),zoom=(float(Np)/smap.data.shape[0],float(Np)/smap.data.shape[1]))
            cutout = resize(smap.data.copy(), output_shape=(Np, Np))
            #print (cutout.shape)
            stack = stack + cutout
            xMap, yMap, modRMap, xx, yy = fmaps.getRealAttributes(smap)
            N = N + 1.
        else:
            print("skip")
    stack = stack / N
    #print(stack.shape())
    #print(smap.data.shape)
    print(stack)
    print(N)
    io.quickPlot2d(stack, out_dir + "stackrandom.png")

    dt = pix_scale
    arcmax = 20.
    thetaRange = np.arange(0., arcmax, dt)
    breal = bin2D(modRMap * 180. * 60. / np.pi, thetaRange)
    cents, recons = breal.bin(stack)
    pl = Plotter(labelX='Distance from Center (arcminutes)',
                 labelY='Temperature Fluctuation ($\mu K$)',
                 ftsize=10)
    pl.add(cents, recons)
    pl._ax.axhline(y=0., ls="--", alpha=0.5)
    pl.done(out_dir + "randomprofiles.png")
    return stack, cents, recons
示例#11
0
import numpy as np

saveRoot = "data/ell28"

gradCut = 2000
polComb = 'TT'
beamY = 1.5
noiseY = 3.0
tellminY = 200
pellminY = 50
kmin = 40
deg = 10.
px = 0.2
delensTolerance = 1.0

pl = Plotter()

for lab in ['planckGrad', 'sameGrad']:
    fileName = saveRoot + getFileNameString([
        'gradCut', 'polComb', 'beamY', 'noiseY', 'grad', 'tellminY',
        'pellminY', 'kmin', 'deg', 'px', 'delens'
    ], [
        gradCut, polComb, beamY, noiseY, lab, tellminY, pellminY, kmin, deg,
        px, delensTolerance
    ]) + ".txt"

    ells, Nls = np.loadtxt(fileName, unpack=True)

    pl.add(ells, Nls, label=lab)
pl.done("output/grad.png")
示例#12
0
def stack_on_map(lite_map,
                 width_stamp_arcminute,
                 pix_scale,
                 ra_range,
                 dec_range,
                 catalog=None,
                 n_random_points=None):
    width_stamp_degrees = width_stamp_arcminute / 60.
    Np = np.int(width_stamp_arcminute / pix_scale + 0.5)
    pad = np.int(Np / 2 + 0.5)
    print("Expected width in pixels = ", Np)
    lmap = lite_map
    stack = 0
    N = 0

    if catalog is not None:
        looprange = range(0, len(catalog))
        assert n_random_points is None
        random = False
    else:
        assert n_random_points is not None
        assert len(ra_range) == 2
        assert len(dec_range) == 2
        looprange = range(0, n_random_points)
        random = True
    print(looprange)
    for i in looprange:
        banana = True
        mass = catalog[i][10]
        if random:
            ra = np.random.uniform(*ra_range)
            dec = np.random.uniform(*dec_range)
        if random == False:
            ra = catalog[i][1]  #1 for ACT catalog 2 for SDSS
            dec = catalog[i][2]  #2 for ACT catalog 3 for SDSS
        for j in range(0, 2130):
            distance = np.sqrt((ra - RAps[j])**2 + (dec - DECps[j])**2)
            crit = 0.25
            if distance < crit:
                banana = False
                print('too close')
        ix, iy = lmap.skyToPix(ra, dec)
        if ix >= pad and ix < lmap.Nx - pad and iy >= pad and iy < lmap.Ny - pad and banana == True and mass > 8:
            print(i)
            #print(ra,dec)
            smap = lmap.selectSubMap(ra - width_stamp_degrees / 2.,
                                     ra + width_stamp_degrees / 2.,
                                     dec - width_stamp_degrees / 2.,
                                     dec + width_stamp_degrees / 2.)
            #print (smap.data.shape)
            #cutout = zoom(smap.data.copy(),zoom=(float(Np)/smap.data.shape[0],float(Np)/smap.data.shape[1])
            cutout = resize(smap.data.copy(),
                            output_shape=(Np, Np)) - randomstack
            xMap, yMap, modRMap, xx, yy = fmaps.getRealAttributes(smap)
            dt = pix_scale
            arcmax = 20.
            thetaRange = np.arange(0., arcmax, dt)
            breali = bin2D(modRMap * 180. * 60. / np.pi, thetaRange)
            a = breali.bin(cutout)[1]
            profiles.append(a)
            io.quickPlot2d(cutout, str(i) + "cutout.png")
            #print (cutout.shape)
            stack = stack + cutout
            N = N + 1
        else:
            print("skip")
    stack = stack / N  #-randomstack
    #print(stack.shape())
    #print(smap.data.shape)
    # print(stack)
    print(N)
    statistics = stats.getStats(profiles)
    mean = statistics['mean']
    error = statistics['errmean']
    corrcoef = statistics['corr']
    covmat = statistics['covmat']
    print(mean / error)
    np.save('statistics', statistics)
    #np.save('newrandomstamp',stack)
    # io.quickPlot2d(stack,out_dir+"newACTstack.png")
    dt = pix_scale
    arcmax = 20.
    thetaRange = np.arange(0., arcmax, dt)
    breal = bin2D(modRMap * 180. * 60. / np.pi, thetaRange)
    cents, recons = breal.bin(stack)
    pl = Plotter(labelX='Distance from Center (arcminutes)',
                 labelY='Temperature Fluctuation ($\mu K$)',
                 ftsize=10)
    pl.add(cents, mean)
    pl.addErr(cents, mean, yerr=error)
    pl._ax.axhline(y=0., ls="--", alpha=0.5)
    pl.done(out_dir + "error.png")
    print(covmat)
    io.quickPlot2d(covmat, 'covmat.png')
    return (stack, cents, recons)
示例#13
0
import matplotlib
matplotlib.use('Agg')
import numpy as np
from orphics.tools.io import Plotter

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

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

for stepSize, ls in zip([0.2, 0.1, 0.05], ['-', '--', '-.']):
    cambOutUpFile = lambda z: "/home/msyriac/software/CAMB_wa/forDerivsStep" + str(
        stepSize) + "Up_matterpower_" + str(z) + ".dat"
    cambOutDnFile = lambda z: "/home/msyriac/software/CAMB_wa/forDerivsStep" + str(
        stepSize) + "Dn_matterpower_" + str(z) + ".dat"

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

        kh_camb_up, P_camb_up = np.loadtxt(cambOutUpFile(z), unpack=True)
        kh_camb_dn, P_camb_dn = np.loadtxt(cambOutDnFile(z), unpack=True)

        assert np.all(kh_camb_dn == kh_camb_up)

        Pderiv = old_div(np.abs(P_camb_up - P_camb_dn), stepSize)

        if i % 5 == 0:
            pl.add(kh_camb_up, Pderiv, ls=ls)
            #pl.add(kh_camb,P_camb)
            #pl.add(kh,pk[Nzs-i-1,:],ls="--")

pl.done("output/testwa.png")
示例#14
0
# Read config
iniFile = "input/params.ini"
Config = SafeConfigParser()
Config.optionxform = str
Config.read(iniFile)

px = 180 * 60 / 60000.
gradCut = 60000.

expName = "DM-18arcsec"
lensName = "lensing"
ls, Nls, ellbb, dlbb, efficiency = lensNoise(Config,
                                             expName,
                                             lensName,
                                             px=px,
                                             gradCut=gradCut,
                                             bigell=gradCut,
                                             plot=True)

print efficiency
print ls
print Nls

from orphics.tools.io import Plotter

pl = Plotter(scaleY='log')
pl.add(ls, Nls)
pl._ax.set_ylim(1e-12, 1e-6)
#pl._ax.set_xlim(2,4000)
pl.done("nls.png")
示例#15
0
                  noisePX,
                  tellmin,
                  tellmax,
                  pellmin,
                  pellmax,
                  beamY=beamY,
                  noiseTY=noiseTY,
                  noisePY=noisePY)
ls, Nls = myNls.getNl(polComb=polComb, halo=halo)

# ls,Nls = np.loadtxt("../SZ_filter/data/LA_pol_Nl.txt",unpack=True,delimiter=',')

ellkk = np.arange(2, 9000, 1)
Clkk = theory.gCl("kk", ellkk)
pl = Plotter(scaleY='log', scaleX='log')
pl.add(ellkk, 4. * Clkk / 2. / np.pi)
pl.add(ls, 4. * Nls / 2. / np.pi)
pl.legendOn(loc='lower left', labsize=10)
pl.done("output/nl.png")

overdensity = 200.
critical = False
atClusterZ = False

# overdensity=180.
# critical=False
# atClusterZ=False
kellmax = 8000

sn, k, std = NFWMatchedFilterSN(cc,
                                Mexp,
示例#16
0
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")


print((HMF.Mass_err(fsky,lndM*24.0,SZProfExample)))

#print "quickvar " , np.sqrt(SZProfExample.quickVar(MM,zz,tmaxN=tmaxN,numts=numts))
#print "filtvar " , np.sqrt(SZProfExample.filter_variance(MM,zz))






#print "y_m",SZProfExample.Y_M(MM,zz)
示例#17
0
        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)
        
        yNzs[key].append((val,Nz,Nm,Nq))
        

        
    pl = Plotter(labelX="$z$",labelY="$dN$")
    xstep = 0.01
    for i,val in enumerate(vals):
        assert yNzs[key][i][0]==val
        pl.add(getCents(z_edges)+((i-old_div(len(vals),2))*xstep),yNzs[key][i][1],label=key+" "+str(val))
    pl.legendOn(labsize=10,loc='upper right')
    pl.done(outDir+key+"_Nz_step.png")
    pl = Plotter(labelX="$M$",labelY="$dN$")
    xstep = 0.01
    for i,val in enumerate(vals):
        assert yNzs[key][i][0]==val
        pl.add(getCents(mexp_edges)+((i-old_div(len(vals),2))*xstep),yNzs[key][i][2],label=key+" "+str(val))
    pl.legendOn(labsize=10,loc='upper right')
    pl.done(outDir+key+"_Nm_step.png")
    pl = Plotter(labelX="$q$",labelY="$dN$",scaleX='log')
    xstep = 0.1
    for i,val in enumerate(vals):
        assert yNzs[key][i][0]==val
        pl.add(getCents(qbin_edges)+((i-old_div(len(vals),2))*xstep),yNzs[key][i][3],label=key+" "+str(val))
    pl.legendOn(labsize=10,loc='upper right')
示例#18
0
Nlmvinv = 0.
pl = Plotter(scaleY='log')
for polComb in ['TT','TE','EE','EB']:
    kmax = getMax(polComb,tellmaxY,pellmaxY)
    bin_edges = np.arange(kmin,kmax,dell)+dell
    lmap = lm.makeEmptyCEATemplate(raSizeDeg=deg, decSizeDeg=deg,pixScaleXarcmin=px,pixScaleYarcmin=px)
    myNls = NlGenerator(lmap,theory,bin_edges,gradCut=gradCut)
    myNls.updateBins(bin_edges)

    nTX,nPX,nTY,nPY = myNls.updateNoise(beamX,noiseTX,noisePX,tellminX,tellmaxX, \
                      pellminX,pellmaxX,beamY=beamY,noiseTY=noiseTY, \
                      noisePY=noisePY,tellminY=tellminY,tellmaxY=tellmaxY, \
                      pellminY=pellminY,pellmaxY=pellmaxY,lkneesX=(lkneeTX,lkneePX),alphasX=(alphaTX,alphaPX), \
                                        lkneesY=(lkneeTY,lkneePY),alphasY=(alphaTY,alphaPY),lxcutTX=lxcutTX, \
                                        lxcutTY=lxcutTY,lycutTX=lycutTX,lycutTY=lycutTY, \
                                        lxcutPX=lxcutPX,lxcutPY=lxcutPY,lycutPX=lycutPX,lycutPY=lycutPY, \
                                        fgFileX=fgFileX,beamFileX=beamFileX,fgFileY=fgFileY,beamFileY=beamFileY )


    cbinner = bin2D(myNls.N.modLMap,cmb_bin_edges)
    ells, Nells = cbinner.bin(nTX)

    pl = Plotter(scaleY='log')
    pl.add(ells,Nells*ells**2.*TCMB**2.)
    pl.add(ells,Nells*ells**2.*TCMB**2.)
    tells,tnlstt = np.loadtxt('data/louisCls.dat',delimiter=',',unpack=True)
    pl.add(tells,tnlstt)
    pl.done("output/compnl.png")
    sys.exit()
           
示例#19
0
print((cbias.shape))
#sys.exit()

pl = Plotter()
pl.plot2d(hb)
pl.done(outDir + "hb.png")

pl = Plotter()
pl.plot2d(cbias)
pl.done(outDir + "cbias.png")

ls = "-"
lab = ""
pl = Plotter(labelX="$z$", labelY="b", ftsize=14)
pl.add(zcents,
       hb[np.where(np.isclose(mrange, 14.0)), :].ravel(),
       ls=ls,
       label=lab + " 10^14 Msol/h")
pl.add(zcents,
       hb[np.where(np.isclose(mrange, 14.3)), :].ravel(),
       ls=ls,
       label=lab + " 10^14.3 Msol/h")
pl.add(zcents,
       hb[np.where(np.isclose(mrange, 14.5)), :].ravel(),
       ls=ls,
       label=lab + " 10^14.5 Msol/h")
pl.add(zcents,
       hb[np.where(np.isclose(mrange, 14.7)), :].ravel(),
       ls=ls,
       label=lab + " 10^14.7 Msol/h")

ls = "--"
示例#20
0
文件: sn.py 项目: msyriac/alhazen
    # pl.done("output/clbb.png")
    # sys.exit()

    # myNls.updateNoise(beamY,noiseTY,noisePY,tellminY,tellmaxY, \
    #                   pellminY,pellmaxY,beamY=beamX,noiseTY=noiseTX, \
    #                   noisePY=noisePX,tellminY=tellminX,tellmaxY=tellmaxX, \
    #                   pellminY=pellminX,pellmaxY=pellmaxX,lkneesX=lkneeY,alphasX=alphaY, \
    #                   lkneesY=lkneeX,alphasY=alphaX)

    ls, Nls = myNls.getNl(polComb=polComb, halo=halo)
    nlfunc = interp1d(ls, Nls, bounds_error=False, fill_value=np.inf)

    nlnow = nlfunc(kellrange)
    Nlmvinv += (1. / nlnow)

    pl.add(ls, 4. * Nls / 2. / np.pi, label=polComb, ls="--")

    LF = LensForecast()
    LF.loadKK(kfrange, Clkk, ls, Nls)  #kellrange,nlnow)
    sn, errs = LF.sn(kellrange, fsky, "kk")
    print((polComb, sn))

pl.add(kfrange, 4. * Clkk / 2. / np.pi)

Nlmv = 1. / Nlmvinv
pl.add(kellrange, 4. * Nlmv / 2. / np.pi, label="mv", color='black')
pl.legendOn(loc='lower right', labsize=12)
pl._ax.set_xlim(kellrange.min(), kellrange.max())
pl.done("output/projnl.png")

print((ls.shape))
示例#21
0
#    elnc3,nlc3 = ILC3.Noise_ellcmb()
#    elnc4,nlc4 = ILC4.Noise_ellcmb()

if (cf == 1):
    eln, nl = ILC.Noise_ellyy(constraint='cib')
    eln2, nl2 = ILC2.Noise_ellyy(constraint='cib')
    #    eln3,nl3 = ILC3.Noise_ellyy(constraint='cib')
    #    eln4,nl4 = ILC4.Noise_ellyy(constraint='cib')

    elnc, nlc = ILC.Noise_ellcmb(constraint='tsz')
    elnc2, nlc2 = ILC2.Noise_ellcmb(constraint='tsz')
#    elnc3,nlc3 = ILC3.Noise_ellcmb(constraint='tsz')
#    elnc4,nlc4 = ILC4.Noise_ellcmb(constraint='tsz')

pl = Plotter(labelX="$\ell$", labelY="Noise Ratio", ftsize=12, figsize=(8, 6))
pl.add(eln2, old_div(nl2, nl), label="SO/CCATP")
#pl.add(eln3,nl3/nl,label="90 - 270 / Full")
#pl.add(eln4,nl4/nl,label="90 - 220 / Full")
#pl.legend(loc='upper right',labsize=10)
pl.done(outDir + experimentName + "_y_noise_ratio" + constraint_tag[cf] +
        ".png")

pl = Plotter(labelX="$\ell$", labelY="Noise Ratio", ftsize=12, figsize=(8, 6))
pl.add(elnc2, old_div(nlc2, nlc), label="SO/CCATP")
#pl.add(elnc3,nlc3/nlc,label="90 - 270 / Full")
#pl.add(elnc4,nlc4/nlc,label="90 - 220 / Full")
#pl.legend(loc='upper right',labsize=10)
pl.done(outDir + experimentName + "_cmb_noise_ratio" + constraint_tag[cf] +
        ".png")

pl = Plotter(labelX="$\ell$", labelY="Error Ratio", ftsize=12, figsize=(8, 6))
示例#22
0
文件: FigBeam.py 项目: mntw/szar
                                                overdensity=overdensity,
                                                critical=critical,
                                                atClusterZ=atClusterZ,
                                                rayleighSigmaArcmin=ray)

                print((sn * np.sqrt(1000.)))
                sns.append(old_div(1., (sn * np.sqrt(1000.))))

            fgpart = ""
            mispart = ""
            if miscenter:
                mispart = ", miscentered"
                col = "C0"
            else:
                col = "C1"
            if lensName == "CMB_all":
                lenspart = "T+P"
            else:
                lenspart = "P only"
            if not (doFg):
                fgpart = ", no foregrounds"
                col = "black"
                al = 0.5
            else:
                al = 1.0

            lab = lenspart + fgpart + mispart
            pl.add(beamList, sns, label=lab, ls=linestyle, alpha=al, color=col)
pl.legendOn(loc="upper left", labsize=12)
pl.done(out_dir + "FigBeam.pdf")
示例#23
0
文件: FigS8.py 项目: mntw/szar
        s8now = np.mean(s81zs[np.logical_and(zrange >= zleft,
                                             zrange < zright)])
        print((lab, zleft, zright, yerr, s8now, yerr * 100. / s8now, "%"))
        #s8now = np.mean(s81zs[np.logical_and(zrange>=zleft,zrange<zright)])/s81
        #yerrsq = (1./sum([1/x**2. for x in errselect]))
        #yerr = (s8now/s80mean)*np.sqrt(yerrsq/s8now**2. + yerrsq0/s80mean**2.)
        errcents.append(yerr)
        ms8.append(s8now)
        currentAxis.add_patch(
            Rectangle((zcent - xerr + pad, 1. - old_div(yerr, s8now)),
                      2 * xerr - old_div(pad, 2.),
                      2. * yerr / s8now,
                      facecolor=col,
                      alpha=1.0))
    print("=====================")
    pl._ax.fill_between(zrange, 1., 1., label=lab, alpha=0.75, color=col)

#pl.add(zrange,s82zs/s81zs,label="$w=-0.97$",color='red',alpha=0.5)
pl.add(zrange, old_div(s81zs, s81zs), color='white', alpha=0.5,
       ls="--")  #,label="$w=-1$")

# pl.add(zrange,s82zs/s81zs/s82*s81,label="$w=-0.97$",color='red',alpha=0.5)
# pl.add(zrange,s81zs*0.+1.,label="$w=-1$",color='black',alpha=0.5,ls="--")

pl.legendOn(labsize=12, loc="lower left")
pl._ax.set_ylim(0.88, 1.12)  # res
#pl._ax.set_ylim(0.95,1.05) # fsky
#pl._ax.text(0.8,.82,"Madhavacheril et. al. in prep")
pl.done(outDir + "FigS8.pdf")
#pl.done(outDir+"s8SO.png")
示例#24
0
experimentName = "SO-v2-6m"
beams = listFromConfig(Config,experimentName,'beams')
noises = listFromConfig(Config,experimentName,'noises')
freqs = listFromConfig(Config,experimentName,'freqs')
lmax = int(Config.getfloat(experimentName,'lmax'))
lknee = listFromConfig(Config,experimentName,'lknee')[0]
alpha = listFromConfig(Config,experimentName,'alpha')[0]
fsky = Config.getfloat(experimentName,'fsky')

SZProfExample = SZ_Cluster_Model(clusterCosmology=cc,clusterDict=clusterDict,rms_noises = noises,fwhms=beams,freqs=freqs,lmax=lmax,lknee=lknee,alpha=alpha,tsz_cib=True)

#print SZProfExample.nl / SZProfExample.nl_new

pl = Plotter()
pl.add(SZProfExample.evalells,old_div(SZProfExample.nl_old, SZProfExample.nl))
pl.done("tests/new_nl_test.png")

#ILC = ILC_simple(clusterCosmology=cc, rms_noises = noises,fwhms=beams,freqs=freqs,lmax=lmax,lknee=lknee,alpha=alpha)
#ILC2 = ILC_simple(clusterCosmology=cc, rms_noises = noises[3:],fwhms=beams[3:],freqs=freqs[3:],lmax=lmax,lknee=lknee,alpha=alpha)
#ILC3 = ILC_simple(clusterCosmology=cc, rms_noises = noises[3:6],fwhms=beams[3:6],freqs=freqs[3:6],lmax=lmax,lknee=lknee,alpha=alpha)

ILC = ILC_simple(clusterCosmology=cc, rms_noises = noises,fwhms=beams,freqs=freqs,lmax=lmax,lknee=lknee,alpha=alpha)

lsedges = np.arange(300,8001,100)
el_ilc, cls_ilc, err_ilc, s2n = ILC.Forecast_Cellcmb(lsedges,fsky)
el_ilc_c, cls_ilc_c, err_ilc_c, s2n_c = ILC.Forecast_Cellcmb(lsedges,fsky,constraint='tsz')
print((s2n,s2n_c))

ILC = ILC_simple(clusterCosmology=cc, rms_noises = noises,fwhms=beams,freqs=freqs,lmax=7000,lknee=lknee,alpha=alpha)
示例#25
0
                 fmaskX2dTEB=[fMask]*3,
                 fmaskY2dTEB=[fMask]*3,
                 fmaskKappa=fMaskK,
                 doCurl=False,
                 TOnly=len(polCombList)==1,
                 halo=True,
                 gradCut=10000,
                 verbose=True,                 
                 loadPickledNormAndFilters=loadFile,
                 savePickledNormAndFilters=saveFile)


modLMap = qest.N.modLMap
bin_edges = np.arange(2,kellmax,10)
pl = Plotter(scaleY='log',scaleX='log')
pl.add(ellkk,4.*Clkk/2./np.pi)

# CHECK THAT NORM MATCHES HU/OK
for polComb,col in zip(polCombList,colorList):
    data2d = qest.N.Nlkk[polComb]
    centers, Nlbinned = binInAnnuli(data2d, modLMap, bin_edges)

    try:
        huFile = '/astro/u/msyriac/repos/cmb-lensing-projections/data/NoiseCurvesKK/hu_'+polComb.lower()+'.csv'
        huell,hunl = np.loadtxt(huFile,unpack=True,delimiter=',')
    except:
        huFile = '/astro/u/msyriac/repos/cmb-lensing-projections/data/NoiseCurvesKK/hu_'+polComb[::-1].lower()+'.csv'
        huell,hunl = np.loadtxt(huFile,unpack=True,delimiter=',')


    pl.add(centers,4.*Nlbinned/2./np.pi,color=col)
示例#26
0
文件: FigPrior.py 项目: mntw/szar
            errs = np.sqrt(np.diagonal(Finv))
            errDict = {}
            for i, param in enumerate(paramList):
                errDict[param] = errs[i]

            if 'mnu' in fishName:
                constraint = errDict['mnu'] * 1000
            elif 'w0' in fishName:
                constraint = errDict['w0'] * 100
            sigs.append(constraint)
            if (np.abs(preVal - constraint) * 100. / constraint) < pertol:
                print(((constraint - preVal) * 100. / constraint))
                if k > mink: break
            preVal = constraint
            print((prior, val, constraint))
            k += 1

        priorLabel = paramLatexList[paramList.index(prior)]
        if "DESI" in fishSection:
            lab = None
            lss = "--"
        else:
            lab = "$" + priorLabel + "$"
            lss = "-"

        pl.add(xs, sigs, label=lab, ls=lss)
    plt.gca().set_color_cycle(None)

pl.legendOn(loc='upper right', labsize=11)
pl.done(os.environ['WWW'] + "paper/FigPrior_" + fishName + "_tau.pdf")
示例#27
0
if not (saveMf):
    try:
        mf = np.loadtxt("data/meanfield.dat")
        kappaStack -= mf
        print("subtracted meanfield")
    except:
        pass

stepmin = kellmin

kappaStack = fmaps.stepFunctionFilterLiteMap(kappaStack,
                                             modLMap,
                                             kellmax,
                                             ellMin=stepmin)

pl = Plotter()
pl.plot2d(kappaStack)
pl.done(outDir + "recon.png")

dt = pixScale
arcmax = 20.
thetaRange = np.arange(0., arcmax, dt)
breal = bin2D(modRMap * 180. * 60. / np.pi, thetaRange)
cents, recons = breal.bin(kappaStack)

pl = Plotter()
pl.add(cents, recons)
pl._ax.axhline(y=0., ls="--", alpha=0.5)
pl.done(outDir + "profiles.png")
示例#28
0
                            lkneesY=(lkneeTY,lkneePY),alphasY=(alphaTY,alphaPY), noiseFilePX = noiseFile,noiseFilePY=noiseFileY)
                                                
            if polComb=='EB' and delens:
                ls, Nls,efficiency = myNls.iterativeDelens(polComb,delensTolerance,halo,verbose=False)
                #print "percentage efficiency ", efficiency , " %"
            else:
                ls,Nls = myNls.getNl(polComb=polComb,halo=halo)
            
            # if True: #noiseFile is not None:
            #     #ls,Nls = np.loadtxt(noiseFile,unpack=True)
            #     #pl.add(ls,Nls,label=labname,ls=lines,alpha=alpha,lw=lw)
            #     binner = bin2D(myNls.N.modLMap,frangeC)
            #     lcents,Nlbinned = binner.bin(nPX)
            #     pl.add(lcents,Nlbinned,label=labname,ls="--")

            pl.add(ls,Nls,label=labname,ls=lines,alpha=alpha)
                

            

            LF = LensForecast()
            LF.loadKK(frange,Clkk,ls,Nls)
            sn,errs = LF.sn(snrange,fsky,"kk")
            #print errs
            sns.append(sn)
            print((noiseFile, " S/N " , sn))



            
# pl.add(frangeC,theory.lCl('EE',frangeC))
示例#29
0
        for i, polComb in enumerate(polCombList):
            print "Waiting for ", job, " ", polComb, " cross"
            comm.Recv(rcvInputPowerMat, source=job, tag=i)
            listAllCrossPower[polComb] = np.vstack(
                (listAllCrossPower[polComb], rcvInputPowerMat))
            print "Waiting for ", job, " ", polComb, " auto"
            comm.Recv(rcvInputPowerMat, source=job, tag=i + 80)
            listAllReconPower[polComb] = np.vstack(
                (listAllReconPower[polComb], rcvInputPowerMat))

    statsCross = {}
    statsRecon = {}

    pl = Plotter(scaleY='log')
    pl.add(ellkk, Clkk, color='black', lw=2)

    for polComb, col in zip(polCombList, colorList):
        statsCross[polComb] = getStats(listAllCrossPower[polComb])
        pl.addErr(centers,
                  statsCross[polComb]['mean'],
                  yerr=statsCross[polComb]['errmean'],
                  ls="none",
                  marker="o",
                  markersize=8,
                  label="recon x input " + polComb,
                  color=col,
                  mew=2,
                  elinewidth=2)

        statsRecon[polComb] = getStats(listAllReconPower[polComb])
示例#30
0
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]):

    kh_camb, P_camb = np.loadtxt(cambOutFile(i), unpack=True)

    if i == 0:
        kmin = max(kh_camb[0], kh[0])
        kmax = min(kh_camb[-1], kh[-1])
        keval = np.logspace(np.log10(kmin), np.log10(kmax), 20)

    pcambfunc = interp1d(kh_camb, P_camb)
    pfunc = interp1d(kh, pk[Nzs - i - 1, :])

    pcambeval = pcambfunc(keval)
    peval = pfunc(keval)
    pdiff = (pcambeval - peval) * 100. / peval
    print((z, pdiff))

    if i % 1 == 0:
        pl.add(keval, pdiff)
        #pl.add(kh_camb,P_camb)
        #pl.add(kh,pk[Nzs-i-1,:],ls="--")

pl.done("output/testcamb.png")