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
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') plt.title('E') plt.colorbar() plt.savefig('p49_E.png') plt.clf() plt.imshow(B, interpolation='nearest') plt.title('B') plt.colorbar()