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
pass if Write2dSpectrum['apply'] == True: try: os.makedirs(spec2dDir) except: pass hpfDict = p['highPassCosSqFilter'] filter_Pol = 1.0 filter_T = 1.0 if hpfDict['apply']: print "Will take off the cos^2 high pass filter" filter_T = speckMisc.getBinnedInvCosSqFilter(hpfDict['lMin'], hpfDict['lMax'], p['binningFile'], trimAtL) filter_Cross = numpy.sqrt(filter_T * filter_Pol) fields = ['T', 'E', 'B'] filterArray = {} filterArray['TT'] = filter_T filterArray['EE'], filterArray['BB'], filterArray['EB'], filterArray[ 'BE'] = filter_Pol, filter_Pol, filter_Pol, filter_Pol filterArray['TE'], filterArray['TB'], filterArray['ET'], filterArray[ 'BT'] = filter_Cross, filter_Cross, filter_Cross, filter_Cross arraysPair = [arrays[0], arrays[-1]] seasonPairs = []
except: pass if Write2dSpectrum['apply']==True: try: os.makedirs(spec2dDir) except: pass hpfDict = p['highPassCosSqFilter'] filter_Pol = 1.0 filter_T= 1.0 if hpfDict['apply']: print "Will take off the cos^2 high pass filter" filter_T = speckMisc.getBinnedInvCosSqFilter(hpfDict['lMin'],hpfDict['lMax'],p['binningFile'],trimAtL) filter_Cross=numpy.sqrt(filter_T*filter_Pol) fields=['T','E','B'] filterArray={} filterArray['TT']=filter_T filterArray['EE'],filterArray['BB'],filterArray['EB'],filterArray['BE']=filter_Pol,filter_Pol,filter_Pol,filter_Pol filterArray['TE'],filterArray['TB'],filterArray['ET'],filterArray['BT']=filter_Cross,filter_Cross,filter_Cross,filter_Cross arraysPair = [arrays[0],arrays[-1]] seasonPairs = [] for i in xrange(len(seasons)): for j in xrange(len(seasons)):