def compute_harmonic_products(self): """ This step may prove to be expensive. If so, insert logic to cache products to and from disk within this function. """ if not self.Q.flags['C_CONTIGUOUS']: self.Q = np.ascontiguousarray(Q) if not self.U.flags['C_CONTIGUOUS']: self.U = np.ascontiguousarray(U) if not self.T.flags['C_CONTIGUOUS']: self.T = np.ascontiguousarray(T) self.N = np.array(self.Q.shape,dtype = np.int32) self.compute_bins() self.Qharm = cmbtools.map2harm(self.Q,self.Delta) self.Uharm = cmbtools.map2harm(self.U,self.Delta) self.Eharm, self.Bharm = cmbtools.QU2EB(self.Qharm,self.Uharm,self.Deltal) self.E = cmbtools.harm2map(self.Eharm,self.Delta) self.B = cmbtools.harm2map(self.Bharm,self.Delta) if self.T is not None: self.Tharm = cmbtools.map2harm(self.T,self.Delta) if self.H is not None: self.Hharm = cmbtools.map2harm(self.H,self.Delta) self.ClEE = cmbtools.harm2cl(self.Eharm,self.Deltal,self.lbins) self.ClBB = cmbtools.harm2cl(self.Bharm,self.Deltal,self.lbins) if self.Hharm is not None: self.ClHH= cmbtools.harm2cl(self.Hharm,self.Deltal,self.lbins) self.ClTT = cmbtools.harm2cl(self.Tharm,self.Deltal,self.lbins) self.ClTE = cmbtools.harm2clcross_samegrid(self.Tharm,self.Eharm,self.Deltal,self.lbins) self.ClTB = cmbtools.harm2clcross_samegrid(self.Tharm,self.Bharm,self.Deltal,self.lbins) self.ClEB = cmbtools.harm2clcross_samegrid(self.Eharm,self.Bharm,self.Deltal,self.lbins)
def QU2EB(rootdir, frame, BoxSize=None): if BoxSize is None: BoxSize = 1 Qlist = glob.glob(rootdir + '/DD%04d_Q[xyz]*.fits' % frame) Ulist = [] for Qfile in Qlist: mo = re.match('(.*/DD[0-9]{4}_)Q([xyz].*)(.fits)', Qfile) Ufile = mo.group(1) + 'U' + mo.group(2) + '.fits' Ulist.append(Ufile) #here we implicity assume Temperature = density. Tfile = mo.group(1) + 'density_' + mo.group(2) + '.fits' QUlist = zip(Qlist, Ulist) for Qfile, Ufile in QUlist: Q = array(pyfits.open(Qfile)[0].data, dtype=double) U = array(pyfits.open(Ufile)[0].data, dtype=double) T = array(pyfits.open(Tfile)[0].data, dtype=double) N = array(shape(Q), dtype=int32) xsize = 5 * pi / 180 size2d = array([xsize, xsize]) Delta = size2d / N Deltal = cmbtools.Delta2l(Delta, N) stuff = EBfromQU(Q, U, T=T, return_quharm=True, BoxSize=BoxSize) lmax = Deltal[0] * N[0] lbins = linspace(0, lmax, 100) lcent = lbins[:-1] + diff(lbins) / 2. ClEE = cmbtools.harm2cl(stuff['Eh'], Deltal, lbins) ClBB = cmbtools.harm2cl(stuff['Bh'], Deltal, lbins) ClTE = cmbtools.harm2clcross_samegrid(stuff['Th'], stuff['Eh'], Deltal, lbins) ClEB = cmbtools.harm2clcross_samegrid(stuff['Eh'], stuff['Bh'], Deltal, lbins) # write the output near the input mo = re.match('(.*/DD[0-9]{4}_)Q([xyz].*)(.fits)', Qfile) outroot = mo.group(1) outsuf = mo.group(2) Efile = outroot + 'E' + outsuf + '.fits' Bfile = outroot + 'B' + outsuf + '.fits' Clfile = outroot + 'Cl' + outsuf + '.dat' print(Efile, Bfile, Clfile) hdu = pyfits.PrimaryHDU(stuff['E']) hdulist = pyfits.HDUList([hdu]) hdulist.writeto(Efile, overwrite=True) hdu = pyfits.PrimaryHDU(stuff['B']) hdulist = pyfits.HDUList([hdu]) hdulist.writeto(Bfile, overwrite=True) savetxt(Clfile, list(zip(lcent, ClEE, ClBB, ClTE, ClEB)))
def QU2EB(rootdir, frame): Qlist = glob.glob(rootdir + '/DD%04d_Q[xyz]*.fits' % frame) Ulist = [] for Qfile in Qlist: mo = re.match('(.*/DD[0-9]{4}_)Q([xyz].*)(.fits)', Qfile) Ufile = mo.group(1) + 'U' + mo.group(2) + '.fits' Ulist.append(Ufile) QUlist = zip(Qlist, Ulist) for Qfile, Ufile in QUlist: Q = array(pyfits.open(Qfile)[0].data, dtype=double) U = array(pyfits.open(Ufile)[0].data, dtype=double) N = array(shape(Q), dtype=int32) xsize = 5 * pi / 180 size2d = array([xsize, xsize]) Delta = size2d / N Deltal = cmbtools.Delta2l(Delta, N) E, B, Eharm, Bharm, Tharm = EBfromQU(Q, U) lmax = Deltal[0] * N[0] lbins = linspace(0, lmax, 100) lcent = lbins[:-1] + diff(lbins) / 2. ClEE = cmbtools.harm2cl(Eharm, Deltal, lbins) ClBB = cmbtools.harm2cl(Bharm, Deltal, lbins) #ClTE = cmbtools.harm2clcross_samegrid(Eharm, Tharm,Deltal,lbins) # write the output near the input mo = re.match('(.*/DD[0-9]{4}_)Q([xyz].*)(.fits)', Qfile) outroot = mo.group(1) outsuf = mo.group(2) Efile = outroot + 'E' + outsuf + '.fits' Bfile = outroot + 'B' + outsuf + '.fits' Clfile = outroot + 'Cl' + outsuf + '.dat' print(Efile, Bfile, Clfile) hdu = pyfits.PrimaryHDU(E) hdulist = pyfits.HDUList([hdu]) hdulist.writeto(Efile, overwrite=True) hdu = pyfits.PrimaryHDU(B) hdulist = pyfits.HDUList([hdu]) hdulist.writeto(Bfile, overwrite=True) savetxt(Clfile, list(zip(lcent, ClEE, ClBB)))
def scatter_clee(self,fname): fig,ax=plt.subplots(1,1,figsize=(12,8)) N = self.Q.shape #build the ell rxa,rya = np.mgrid[ 0:N[0]:1, 0:N[0]//2+1:1] rxa[self.N[1]//2:,:] = rxa[:self.N[1]//2,:]- N[0]/2 #self.lmax #N[0]#*self.Deltal[0]/2 rx=rxa*self.Deltal[0] ry=rya*self.Deltal[0] ell = np.sqrt(rx**2+ry**2) #### #here is code to plot r, and ensure it's right. #fig2,ax2=plt.subplots(1,1,figsize=(8,8)) #the transposei is to make 'x' be the horizontal axis. #ax2.imshow(ell.transpose(),origin='lower',interpolation='nearest') #fig.colorbar(ppp) #fig.savefig(fname) #fig2.savefig('/home/dcollins4096/PigPen/test.png') #compute the spectra. #Take out the normalization spectra = (np.abs(self.Eharm)**2).flatten() this_ClEE = cmbtools.harm2cl(self.Eharm,self.Deltal,self.lbins) this_ClEE *= (2*np.pi)**2*(self.Delta[0])**2/self.Deltal[0]**2 #overplot bins, to see aliasing for l in self.lbins: ax.plot( [l,l], [1e-11,100],c=[0.5]*4) ax.plot( [np.pi]*2, [1e-11,100],c='k') ax.scatter( ell.flatten(), spectra,s=0.1) dt.axbonk(ax,xlabel='ell',ylabel='CEE') ax.set_xscale('symlog',linthreshx=self.Deltal[0]) ax.set_yscale('symlog',linthreshy=1e-9) ax.set_ylim( 0, spectra.max()) ax.set_xlim( ell.min(), ell.max()*1.1) ax.plot( self.lcent, this_ClEE,marker='*') fig.savefig(fname) print(fname) plt.close(fig)
def Make_other(arr, BoxSize=1): N = np.array(arr.shape, dtype=np.int32) arr = np.ascontiguousarray(arr, dtype=np.double) xsize = N.max() #5 * np.pi / 180*BoxSize size2d = np.array([xsize, xsize]) Delta = size2d / N Deltal = cmbtools.Delta2l(Delta, N) harm = cmbtools.map2harm(arr, Delta) lmax = Deltal[0] * N[0] / 2 lbins = np.arange(N[0] // 2 + 1) * Deltal[0] #np.linspace(0,lmax,N//2) lcent = lbins[:-1] + np.diff(lbins) / 2. ClBB = cmbtools.harm2cl(harm, Deltal, lbins) output = { 'Delta': Delta, 'Deltal': Deltal, 'harm': harm, 'lbins': lbins, 'ClBB': ClBB, 'lmax': lmax } return output