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 EBfromQU(Q, U, T=None, H=None, BoxSize=1, return_quharm=False): if not Q.flags['C_CONTIGUOUS']: Q = np.ascontiguousarray(Q) if not U.flags['C_CONTIGUOUS']: U = np.ascontiguousarray(U) if T is not None: if not T.flags['C_CONTIGUOUS']: T = np.ascontiguousarray(T) if H is not None: if not H.flags['C_CONTIGUOUS']: H = np.ascontiguousarray(H) N = array(shape(Q), dtype=int32) xsize = 5 * pi / 180 * BoxSize size2d = array([xsize, xsize]) Delta = size2d / N print("N = ", N) print("Delta = ", Delta) Deltal = cmbtools.Delta2l(Delta, N) Qharm = cmbtools.map2harm(Q, Delta) Uharm = cmbtools.map2harm(U, Delta) Eharm, Bharm = cmbtools.QU2EB(Qharm, Uharm, Deltal) E = cmbtools.harm2map(Eharm, Delta) B = cmbtools.harm2map(Bharm, Delta) if return_quharm: output = { 'E': E, 'B': B, 'Eh': Eharm, 'Bh': Bharm, 'Qh': Qharm, 'Uh': Uharm, 'Deltal': Deltal, 'Delta': Delta } output['N'] = N else: output = E, B, Eharm, Bharm if T is not None: Tharm = cmbtools.map2harm(T, Delta) output['Th'] = Tharm if H is not None: Hharm = cmbtools.map2harm(H, Delta) output['Hh'] = Hharm return output
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
def PlotQUEBharm(self,frame, style=1): self.GetQUEB(frame) if style == 0: for field in 'QUEB': for f in qb.QUEBarr[field]: oot = "%s_%s"%(selfcar.outname,f.split('/')[-1]) plt.clf() #Qharm = cmbtools.map2harm(Q,Delta) #Uharm = cmbtools.map2harm(U,Delta) pdb.set_trace() f = plt.imshow(field_hat,interpolation='nearest',origin='lower') plt.colorbar(f) print("did a color") plt.title(oot) plt.savefig(oot+".png") print(oot) else: for ax in 'xyz': outname = 'P49_QUEB_harm_4p_%s_%s.%s'%(self.car.outname,ax,self.plot_format) hats = {} for field in 'QUEB': arr = self.QUEBarr[field][ax] Delta = np.array([5*np.pi/180.]*2)/np.array(arr.shape) hats[field] = np.abs(cmbtools.map2harm(arr,Delta)) #print(p49_print_tools.nz(hats[field])) #print(p49_print_tools.nonzero(hats['Q'][:10,:10])) #print(p49_print_tools.nonzero(hats['U'][:10,:10])) #print(p49_print_tools.nonzero(hats['E'][:10,:10])) #print(p49_print_tools.nonzero(hats['B'][:10,:10])) plotter(hats['Q'], hats['U'], hats['E'], hats['B'], outname,norm='positive') print("Save %s"%outname)
print("N = ", N) print("Delta = ", Delta) Deltal = cmbtools.Delta2l(Delta, N) print("Deltal = ", Deltal) E = np.zeros(N) #E = array([[cos(3*2*pi*(i+2*j)/N[1]) for i in range(N[1]) ] for j in range(N[0])]) # + sin(2*pi*i/N[1]) B = np.array([[np.cos(3 * 2 * np.pi * (i + j) / N[1]) for i in range(N[1])] for j in range(N[0])]) Eharm = cmbtools.map2harm(E, Delta) Bharm = cmbtools.map2harm(B, Delta) Qharm, Uharm = cmbtools.EB2QU(Eharm, Bharm, Deltal) Q = cmbtools.harm2map(Qharm, Delta) U = cmbtools.harm2map(Uharm, Delta) Eharm2, Bharm2 = cmbtools.QU2EB(Qharm, Uharm, Deltal) E2 = cmbtools.harm2map(Eharm2, Delta) B2 = cmbtools.harm2map(Bharm2, Delta) #figure() plt.clf() plt.imshow(E, interpolation='nearest')