Пример #1
0
def ProcessAndwriteSpectra(cl_vec,
                           filterArray,
                           name,
                           fields,
                           ar1,
                           ar2,
                           spTag,
                           binnedBeamDict=None,
                           iar=None):

    countAll = 0
    count1 = 0
    for l1 in fields:
        count1 += 1
        count2 = 0
        for l2 in fields:
            count2 += 1
            if count2 < count1: continue

            # remove filter
            cl = cl_vec[countAll * Nbin:(countAll + 1) *
                        Nbin] * filterArray[l1 + l2]**2

            # There is an additional correction for the autos as MCM had a transfer
            # function B_l_AR1*B_l_AR_2
            if iar != None:
                cl *= binnedBeamDict[sps[0]][iar -
                                             1] / binnedBeamDict[sps[0]][iar]

            gName = '%s/%s_%s%s_%sx%s_%s.dat' % (specDir, name, l1, l2, ar1,
                                                 ar2, spTag)

            speckMisc.writeBinnedSpectrum(lBin, cl, binCount, gName)

            countAll += 1
Пример #2
0
def ProcessAndwriteSpectra(cl_vec,filterArray,name,fields,ar1,ar2,spTag,binnedBeamDict=None,iar=None):
    
    countAll=0
    count1=0
    for l1 in fields:
        count1+=1
        count2=0
        for l2 in fields:
            count2+=1
            if count2<count1: continue
            
            # remove filter
            cl=cl_vec[countAll*Nbin:(countAll+1)*Nbin]*filterArray[l1+l2]**2
            
            # There is an additional correction for the autos as MCM had a transfer
            # function B_l_AR1*B_l_AR_2
            if iar !=None:
                cl*= binnedBeamDict[sps[0]][iar-1]/binnedBeamDict[sps[0]][iar]
            
            
            gName = '%s/%s_%s%s_%sx%s_%s.dat'%(specDir,name,l1,l2,ar1,ar2,spTag)
            
            speckMisc.writeBinnedSpectrum(lBin,cl,binCount,gName)
            
            countAll+=1
Пример #3
0
def combineAndCalibrate(p):
    """
    @brief combine and calibrate the various auto/cross spectra
    """
    patchDir = "patches"
    labels = p['labels']
    specDir = 'spectra/'

    nPatches = 0
    l = os.listdir(patchDir)
    for il in l:
        if 'patch_%s_00'%labels[0] in il and '_season' in il[-7:]:
            nPatches += 1
    print "Found %d season patch(es) ..."%nPatches

    #Combine Autos
    for label in labels:
        clAuto = []
        for iPatch in xrange(nPatches):
            lbin,clbin,binWeight = numpy.loadtxt("%s/clBinAutoSeason_%sX%s_%03d.dat"\
                                                 %(specDir,label,label,iPatch),unpack=True)
            clAuto += [clbin]
        clAutoMean = numpy.mean(clAuto, axis=0)*p['calibration_%s'%label]**2
        fName = "%s/clBinAutoGlobalMean_%sX%s.dat"%(specDir,label,label)
        speckMisc.writeBinnedSpectrum(lbin,clAutoMean,binWeight,fName)

    clCross = []
    clAuto = [] #Cross- label power
    for iPatch in xrange(nPatches):
        lbin,clbin,binWeight = numpy.loadtxt("%s/clBinCrossSeason_%sX%s_%03d.dat"\
                                             %(specDir,labels[0],labels[1],iPatch),\
                                             unpack=True)
        clCross += [clbin]


    clCrossMean = numpy.mean(clCross,axis=0)*p['calibration_%s'%labels[0]]*p['calibration_%s'%labels[1]]
    fName = "%s/clBinCrossGlobalMean_%sX%s.dat"%(specDir,labels[0],labels[1])
    speckMisc.writeBinnedSpectrum(lbin,clCrossMean,binWeight,fName)
    
    return 0 #sucess
Пример #4
0
def compileSpectra(p):
    """
    @brief compile the various auto/cross spectra
    """
    
    patchDir = "patches"
    labels = p['labels']
    taper = p['taper']
    gaussApod = p['gaussianApodization']
    applyMask = p['applyMask']
    
    nPatches = 0
    l = os.listdir(patchDir)
    for il in l:
        if 'patch_%s_00'%labels[0] in il and '_season' in il[-7:]:
            nPatches += 1
    print "Found %d season patch(es) ..."%nPatches
    
    
    
    
    if taper['apply'] and gaussApod['apply']:
        raise ValueError, "Both taper and Gaussian Apodization cannot be applied."+\
              "Use one or the other"
    
    
    trimAtL = p['trimAtL']
    specDir = 'spectra/'
    
    try:
        os.makedirs(specDir)
    except:
        pass
    
    lU,lL,lCen = fftTools.readBinningFile(p['binningFile'])
    ii = numpy.where(lU<p['trimAtL'])
    
    #beam transfer ()
    binnedBeamWindow = []
    for label in labels:
        Bb = speckMisc.getBinnedBeamTransfer(p['beamFile_%s'%label],p['binningFile'],trimAtL)
        binnedBeamWindow += [Bb]
    
    hpfDict = p['highPassCosSqFilter']
    filter = 1.0
    if hpfDict['apply']:
        print "Will take off the cos^2 high pass filter"
        filter = speckMisc.getBinnedInvCosSqFilter(hpfDict['lMin'],hpfDict['lMax'],p['binningFile'],trimAtL)
        
        
    
    for iPatch in xrange(nPatches):
        
        mbb = pickle.load(open('mcm/'+p['mcmFileRoot']+'_%03d.pkl'%iPatch,mode="r"))
        mbbInv = scipy.linalg.inv(mbb)

        if applyMask:
            mask = liteMap.liteMapFromFits("%s/mask%03d"%(patchDir,iPatch))
        else:
            mask = None
        pixW = None
        if p['applyPixelWeights']:
            pixW = (liteMap.liteMapFromFits("%s/totalWeightMap_%03d"%(patchDir,iPatch)))


        binWeightMap = pickle.load(open('noiseAndWeights/weightMap%03d.pkl'%iPatch,mode="r"))

        # Get the auto spectra first
        ilabel = 0 
        for label in labels:

            print "In patch: %03d, computing %sx%s season spectrum "%(iPatch,label,label)
            m0 = liteMap.liteMapFromFits("%s/patch_%s_%03d_season" %(patchDir,label,iPatch))
            area = m0.Nx*m0.Ny*m0.pixScaleX*m0.pixScaleY
            p2d = get2DSpectrum(m0,m0,taper,gaussApod,mask=mask,pixelWeight=pixW)
            lL,lU,lbin,clbin,binCount = weightedBinInAnnuli(p2d,\
                                                            binWeightMap.powerMap,\
                                                            p['binningFile'],p['trimAtL'],\
                                                            p['powerOfL'])
            
            clbinDecoup = numpy.dot(mbbInv,clbin)*area*filter**2
            # There is an additional correction for the autos as MCM had a transfer
            # function B_l_AR1*B_l_AR_2
            clbinDecoup *= binnedBeamWindow[ilabel-1]/binnedBeamWindow[ilabel]

            inds = numpy.where(clbinDecoup < 0.0)[0]
            clbinDecoup[inds] = 0.0

            fName = "%s/clBinAutoSeason_%sX%s_%03d.dat"%(specDir,label,label,iPatch)
            speckMisc.writeBinnedSpectrum(lbin,clbinDecoup,binCount,fName)

            ilabel += 1


        # Now do the cross- spectra
        m0 = liteMap.liteMapFromFits("%s/patch_%s_%03d_season"\
                                     %(patchDir,labels[0],iPatch))
        area = m0.Nx*m0.Ny*m0.pixScaleX*m0.pixScaleY

        m1 = liteMap.liteMapFromFits("%s/patch_%s_%03d_season"\
                                     %(patchDir,labels[1],iPatch))

        print "In patch: %03d, computing %sx%s season spectrum "%(iPatch,labels[0],labels[-1])



        p2d = get2DSpectrum(m0,m1,taper,gaussApod,mask=mask,pixelWeight=pixW)
        lL,lU,lbin,clbin,binCount = weightedBinInAnnuli(p2d,\
                                                        binWeightMap.powerMap,\
                                                        p['binningFile'],p['trimAtL'],\
                                                        p['powerOfL'])
        clbinDecoup = numpy.dot(mbbInv,clbin)*area*filter**2

        fName = "%s/clBinCrossSeason_%sX%s_%03d.dat"%(specDir,labels[0],labels[-1],iPatch)
        speckMisc.writeBinnedSpectrum(lbin,clbinDecoup,binCount,fName)
        
    return 0 #success
Пример #5
0
    
    for i in xrange(nDivs):
            
        T = liteMap.liteMapFromFits('%s/%s/T_map_%s_%s_%d'%(dir,patchDir,array,season,i))
        Q = liteMap.liteMapFromFits('%s/%s/Q_map_%s_%s_%d'%(dir,patchDir,array,season,i))
        U = liteMap.liteMapFromFits('%s/%s/U_map_%s_%s_%d'%(dir,patchDir,array,season,i))
        
        Q_rot=Q.copy()
        U_rot=U.copy()
        
        Q_rot.data=Q.data*numpy.cos(2*phi)+U.data*numpy.sin(2*phi)
        U_rot.data=-Q.data*numpy.sin(2*phi)+U.data*numpy.cos(2*phi)

        Q_rot.writeFits(patchDir+os.path.sep+'Q_map_%s_%s_%d'%(array,season,i),overWrite=True)
        U_rot.writeFits(patchDir+os.path.sep+'U_map_%s_%s_%d'%(array,season,i),overWrite=True)

    os.system('HQcompileSpectra.py global.dict')
    os.system('HQcomputeAnalyticCovariance.py global.dict')

    print 'only seasonTags[0] arrayTags[0] at the moment'
    l,cl_EB,error_EB=numpy.loadtxt('spectra/spectrum_EB_%sx%s_%sx%s.dat'%(array,array,season,season),unpack=True)


    speckMisc.writeBinnedSpectrum(l,cl_EB,error_EB,'spectrum_EB_%sx%s_%sx%s_%d.dat'%(array,array,season,season,count))
    chi2[count]=numpy.mean(cl_EB**2/error_EB**2)

    print phi,chi2[count]
    count+=1

pylab.plot(ang,chi2)
pylab.show()
Пример #6
0
lmin[0], lmax[0], lcenter[0] = 0.0, 110, 110. / 2

for i in range(99):

    if lmax[i] < 2000:
        lmin[i + 1] = lmax[i] + 1
        lmax[i + 1] = lmax[i] + 50
    if ((lmax[i] >= 2000) & (lmax[i] < 2500)):
        lmin[i + 1] = lmax[i] + 1
        lmax[i + 1] = lmax[i] + 100
    if ((lmax[i] >= 2500) & (lmax[i] < 3000)):
        lmin[i + 1] = lmax[i] + 1
        lmax[i + 1] = lmax[i] + 200
    if ((lmax[i] >= 3000) & (lmax[i] < 6000)):
        lmin[i + 1] = lmax[i] + 1
        lmax[i + 1] = lmax[i] + 400
    if lmax[i] >= 6000:
        lmin[i + 1] = lmax[i] + 1
        lmax[i + 1] = lmax[i] + 800
    lcenter[i + 1] = (lmax[i + 1] + lmin[i + 1]) / 2.

    print lmin[i], lmax[i], lcenter[i]

pylab.plot(lmin)
pylab.plot(lmax)
pylab.plot(lcenter)
pylab.show()

speckMisc.writeBinnedSpectrum(lmin, lmax, lcenter, 'BIN_ACTPOL_50_5')
Пример #7
0
for i in range(99):
    
    
    if lmax[i]<2000:
        lmin[i+1]=lmax[i]+1
        lmax[i+1]=lmax[i]+50
    if ((lmax[i]>=2000) & (lmax[i]<2500)):
        lmin[i+1]=lmax[i]+1
        lmax[i+1]=lmax[i]+100
    if ((lmax[i]>=2500) & (lmax[i]<3000)):
        lmin[i+1]=lmax[i]+1
        lmax[i+1]=lmax[i]+200
    if ((lmax[i]>=3000) & (lmax[i]<6000)):
        lmin[i+1]=lmax[i]+1
        lmax[i+1]=lmax[i]+400
    if lmax[i]>=6000:
        lmin[i+1]=lmax[i]+1
        lmax[i+1]=lmax[i]+800
    lcenter[i+1]=(lmax[i+1]+lmin[i+1])/2.


    print lmin[i],lmax[i],lcenter[i]

pylab.plot(lmin)
pylab.plot(lmax)
pylab.plot(lcenter)
pylab.show()

speckMisc.writeBinnedSpectrum(lmin,lmax,lcenter,'BIN_ACTPOL_50_5')
Пример #8
0
            meanAutoSpec_B[l2+l1,spTag]=meanAutoSpec_B[l1+l2,spTag]
            meanAutoSpec_AB[l2+l1,spTag]=meanAutoSpec_AB[l1+l2,spTag]


            meanNoise_A[l1+l2,spTag]=meanAutoSpec_A[l1+l2,spTag]-meanCrossSpec[l1+l2,spTag]
            meanNoise_A[l2+l1,spTag]=meanNoise_A[l1+l2,spTag]

            meanNoise_B[l1+l2,spTag]=meanAutoSpec_B[l1+l2,spTag]-meanCrossSpec[l1+l2,spTag]
            meanNoise_B[l2+l1,spTag]=meanNoise_B[l1+l2,spTag]

            meanNoise_AB[l1+l2,spTag]=meanAutoSpec_AB[l1+l2,spTag]-meanCrossSpec[l1+l2,spTag]
            meanNoise_AB[l2+l1,spTag]=meanNoise_AB[l1+l2,spTag]


            fName = '%s/noise_%s%s_%sx%s_%sx%s.dat'%(specDir,l1,l2,arrays[0],arrays[0],sps[0],sps[0])
            speckMisc.writeBinnedSpectrum(lbin,meanNoise_A[l1+l2,spTag]/nDivs,binWeight[l1+l2,spTag],fName)

            fName = '%s/noise_%s%s_%sx%s_%sx%s.dat'%(specDir,l1,l2,arrays[-1],arrays[-1],sps[1],sps[1])
            speckMisc.writeBinnedSpectrum(lbin,meanNoise_B[l1+l2,spTag]/nDivs,binWeight[l1+l2,spTag],fName)


            fName = '%s/noise_%s%s_%sx%s_%sx%s.dat'%(specDir,l1,l2,arrays[0],arrays[-1],sps[0],sps[1])
            speckMisc.writeBinnedSpectrum(lbin,meanNoise_AB[l1+l2,spTag]/nDivs,binWeight[l1+l2,spTag],fName)




c=0
count1=0
for l1 in fields:
    count1+=1