Example #1
0
    def kappaToAlpha(self, kappaMap, test=False):

        fKappa = fft_gen(kappaMap, axes=[-2, -1])
        fAlpha = self.ftkernels * fKappa
        pixScaleY, pixScaleX = kappaMap.pixshape()
        Ny, Nx = kappaMap.shape

        #retAlpha = (np.fft_gen.ifft_genshift(enmap.ifft_gen(fAlpha,normalize=False).real)+kappaMap*0.)*pixScaleY*pixScaleX/Nx/Ny
        retAlpha = -(np.fft_gen.ifft_genshift(
            ifft_gen(fAlpha, axes=[-2, -1], normalize=False).real[::-1]) +
                     kappaMap * 0.) * pixScaleY * pixScaleX / Nx / Ny

        if test:
            newKap = -np.nan_to_num(0.5 * enmap.div(retAlpha))
            thetaMap = kappaMap.posmap()
            thetaModMap = 60. * 180. * (np.sum(thetaMap**2, 0)**0.5) / np.pi
            print(("newkappaint ", np.nanmean(newKap[thetaModMap < 10.])))

            pl = Plotter()
            pl.plot2d(kappaMap)
            pl.done("output/oldKap.png")
            pl = Plotter()
            pl.plot2d(newKap)
            pl.done("output/newKap.png")
            ratio = np.nan_to_num(newKap / kappaMap)
            print((thetaMap.shape))

            print((ratio[thetaModMap < 5].mean()))
            pl = Plotter()
            pl.plot2d(ratio[200:-200, 200:-200])
            pl.done("output/testratio.png")

        return retAlpha
Example #2
0

    print(("Reconstructing" , i , " ..."))
    qest.updateTEB_X(fot,foe,fob,alreadyFTed=True)
    qest.updateTEB_Y(alreadyFTed=True)

    for j, polComb in enumerate(polCombList):

        kappa = qest.getKappa(polComb)


        reconLm = lensedTLm.copy()
        reconLm.data[:,:] = kappa[:,:].real

        pl = Plotter()
        pl.plot2d(reconLm.data)
        pl.done("/gpfs01/astro/www/msyriac/plots/recon"+str(i)+".png")
        
        print("crossing with input")


        p2d = ft.powerFromLiteMap(kappaLm,reconLm,applySlepianTaper=False)
        # p2d.powerMap = p2d.powerMap/w2
        centers, means = stats.binInAnnuli(p2d.powerMap, p2d.modLMap, bin_edges)
        listCrossPower[polComb].append( means )



        p2d = ft.powerFromLiteMap(reconLm,applySlepianTaper=False)
        # p2d.powerMap = p2d.powerMap/w4
        centers, means = stats.binInAnnuli(p2d.powerMap, p2d.modLMap, bin_edges)
Example #3
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")
Example #4
0
fsky = 0.4

N1 = hmf.N_of_z() * fsky

#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]
Example #5
0
    lensedMapY = fmaps.convolveBeam(lensedMapY, modLMap, beamTemplate)

    if noiseT > 1.e-3:
        lensedMapX = lensedMapX + gGenT.getMap(stepFilterEll=None)
    if noiseT > 1.e-3:
        lensedMapY = lensedMapY + gGenT.getMap(stepFilterEll=None)

    # lensedMapYRot = np.rot90(lensedMapY.copy(),2)

    lensedMapX = lensedMapX * win
    lensedMapY = lensedMapY * win
    # lensedMapYRot = lensedMapYRot*win

    if i == 0:
        pl = Plotter()
        pl.plot2d(lensedMapX)
        pl.done(outDir + "lensed.png")

    fotX = np.nan_to_num(fft(lensedMapX, axes=[-2, -1]) / beamTemplate[:, :])
    fotY = np.nan_to_num(fft(lensedMapY, axes=[-2, -1]) / beamTemplate[:, :])
    # fotYRot = np.nan_to_num(fft(lensedMapYRot,axes=[-2,-1])/ beamTemplate[:,:])

    if i % 1 == 0: print "Reconstructing", i, " ..."
    qest.updateTEB_X(fotX, alreadyFTed=True)
    qest.updateTEB_Y(fotY, alreadyFTed=True)
    kappa = qest.getKappa(polCombList[0]).real / w2

    # qest.updateTEB_Y(-fotYRot,alreadyFTed=True)
    # kappaRot = qest.getKappa(polCombList[0]).real/w2

    kappaStack += kappa
Example #6
0
    inputKappaStack = 0.
    szStack = 0.

    N = numClusters

    for i in range(N):
        print i

        kappa = enmap.read_map(saveName + "_kappa_" + str(i) + "_" +
                               str(snap) + ".hdf")
        inputKappaMap = enmap.read_map(saveName + "_inpkappa_" + str(i) + "_" +
                                       str(snap) + ".hdf")
        szMap = enmap.read_map(saveName + "_sz_" + str(i) + "_" + str(snap) +
                               ".hdf")

        kappaStack += kappa
        inputKappaStack += inputKappaMap
        szStack += szMap

    pl = Plotter()
    pl.plot2d(kappaStack / N)
    pl.done(outDir + "recon_" + str(snap) + ".png")

    pl = Plotter()
    pl.plot2d(inputKappaStack / N)
    pl.done(outDir + "truestack_" + str(snap) + ".png")

    pl = Plotter()
    pl.plot2d(szStack / N)
    pl.done(outDir + "szstack_" + str(snap) + ".png")
Example #7
0
print(oml)
# cbias = np.zeros((mrange.size,zcents.size))

# for i,z in enumerate(zcents):
#     cbias[:,i] = hbias(10**mrange,zcents,cc.h,cc.om,oml)

Mg, zg = np.meshgrid(10**mrange, zcents)
cbias = hbias(Mg, zg, cc.h, cc.om, oml).T

print(cbias)
print((hb.shape))
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(),
Example #8
0
    def fitAuto(self,keyData,keyTheory,amplitudeRange=np.arange(0.1,2.0,0.01),constRange=np.arange(0.1,2.0,0.01),debug=False,store=False):
        # evaluate likelihood on a 2d grid and fit to a gaussian
        # store fit as new theory curve

        width = amplitudeRange[1]-amplitudeRange[0]
        height = constRange[1]-constRange[0]
        Likelihood = lambda x,y: np.exp(-0.5*self.chisqAuto(keyData,keyTheory,amp=x,const=y))
        #Likelihood = lambda x,y: -0.5*self.chisqAuto(keyData,keyTheory,amp=x,const=y)

        Likes = np.array([[Likelihood(x,y) for x in amplitudeRange] for y in constRange])

        ampLike = np.sum(Likes,axis=0)    
        constLike = np.sum(Likes,axis=1)

        ampLike = ampLike / (ampLike.sum()*width) #normalize
        constLike = constLike / (constLike.sum()*height) #normalize
                

        ampBest,ampErr = cfit(norm.pdf,amplitudeRange,ampLike,p0=[amplitudeRange.mean(),0.1*amplitudeRange.mean()])[0]
        constBest,constErr = cfit(norm.pdf,constRange,constLike,p0=[constRange.mean(),0.1*constRange.mean()])[0]


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

            pl = Plotter()
            fitVals = np.array([norm.pdf(x,constBest,constErr) for x in constRange])
            pl.add(constRange,constLike,label="constlikes")
            pl.add(constRange,fitVals,label="fit")
            pl.legendOn()
            pl.done("output/constlike1d.png")

            #sys.exit()
            
        if not(store):
            return constBest,constErr
        else:
            
            self.datas[keyData]['binned'] -= constBest
            self.datas[keyData]['unbinned'] -= constBest
            
            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]['const']=(constBest,constErr)
            self.datas[fitKey]['isFit'] = True
    
            return fitKey
Example #9
0
File: FigSN.py Project: mntw/szar
# sngrid = 1./jointgrid
# lab = "joint"
# pl.add(outzgrid,sngrid[np.where(np.isclose(outmgrid,14.0)),:].ravel(),ls=ls,label=lab+" 10^14 Msol/h")
# pl.add(outzgrid,sngrid[np.where(np.isclose(outmgrid,14.3)),:].ravel(),ls=ls,label=lab+" 10^14.3 Msol/h")
# pl.add(outzgrid,sngrid[np.where(np.isclose(outmgrid,14.5)),:].ravel(),ls=ls,label=lab+" 10^14.5 Msol/h")
# pl.add(outzgrid,sngrid[np.where(np.isclose(outmgrid,14.7)),:].ravel(),ls=ls,label=lab+" 10^14.7 Msol/h")

pl.legendOn(loc='upper right', labsize=8)
pl.done(outDir + "FigSN.pdf")

from orphics.tools.io import Plotter
pgrid = np.rot90(old_div(1., jointgrid))
pl = Plotter(labelX="$\\mathrm{log}_{10}(M)$", labelY="$z$", ftsize=14)
pl.plot2d(pgrid,
          extent=[mmin, mmax, zmin, zmax],
          levels=[1.0, 3.0, 5.0],
          labsize=14)
pl.done(outDir + "joint.png")

# tmgrid = np.arange(mmin,mmax,0.5)
# tzgrid = np.arange(zmin,zmax,0.5)
# coarsegrid = interpolateGrid(jointgrid,outmgrid,outzgrid,tmgrid,tzgrid,regular=False,kind="cubic",bounds_error=False,fill_value=np.inf)

# from orphics.tools.output import Plotter
# pgrid = np.rot90(1./coarsegrid)
# pl = Plotter(labelX="$\\mathrm{log}_{10}(M)$",labelY="$z$",ftsize=14)
# pl.plot2d(pgrid,extent=[mmin,mmax,zmin,zmax],levels=[1.0,3.0,5.0],labsize=14)
# pl.done(outDir+"coarse.png")

# pickle.dump((tmgrid,tzgrid,coarsegrid),open("data/testGrid.pkl",'wb'))