def gather_patches_plain(self): """Assemble patch statistics relevant to lensing at small scales. Compute the small scale (ell > lmin) temperature power at different patches across the sky as well as the average amplitude of the background temperature gradient (ell < ldT). """ self._edge = 0 # Not throwing away edge pixels m_fft = enmap.fft(self.map_in) hp = np.zeros(self.map_in.shape) hp[np.where((self._lmod > self.lmin) & (self._lmod < self.lmax))] = 1. self._Tss = enmap.ifft(m_fft * hp) self._dTy, self._dTx = gradient_flat(self.map_in, self.ldT) # Scale geometry for lower res map of patches pshp, pwcs = enmap.scale_geometry(self.map_in.shape, self.map_in.wcs, 1. / self._p) if not self.savesteps: del self.map_in, m_fft self._T2patch = enmap.zeros(pshp, pwcs) self._dTxpatch = enmap.zeros(pshp, pwcs) self._dTypatch = enmap.zeros(pshp, pwcs) Trs = self._Tss[:pshp[-2] * self._p, :pshp[-1] * self._p].reshape( [pshp[-2], self._p, pshp[-1], self._p]) dTxrs = self._dTx[:pshp[-2] * self._p, :pshp[-1] * self._p].reshape( [pshp[-2], self._p, pshp[-1], self._p]) dTyrs = self._dTy[:pshp[-2] * self._p, :pshp[-1] * self._p].reshape( [pshp[-2], self._p, pshp[-1], self._p]) self._T2patch[:, :] = np.var(Trs, axis=(1, 3)) self._dTypatch[:, :] = np.mean(dTyrs, axis=(1, 3)) self._dTxpatch[:, :] = np.mean(dTxrs, axis=(1, 3)) self._dT2patch = self._dTxpatch**2 + self._dTypatch**2 if not self.savesteps: del self._dTypatch, self._dTxpatch, self._dTy, self._dTx, self._Tss
def gather_patches_cos(self): """Assemble patch statistics for small scale lensing with cos filter. Compute the small scale (ell > 3000) temperature power at different patches across the sky as well as the average amplitude of the background temperature gradient (ell < 2000). For the small scale statistics, also apply a filter in Fourier space such that: .. math:: f_\\ell = \\cos(\\hat{\\ell}\\cdot\\hat{\\nabla T}) """ self._edge = 5 # Edge pixels to throw away p = self._p m_fft = enmap.fft(self.map_in) hp = np.zeros(self.map_in.shape) hp[np.where((self._lmod > self.lmin) & (self._lmod < self.lmax))] = 1. # Apply pre-whitening or Wiener/inverse variance filters, then top hat if self._aW and self.fid is not None: cs = CubicSpline(self.fid[0], self.fid[1]) # (ell, Cl) m_fft = m_fft / cs(self._lmod) self._Tss = enmap.ifft(m_fft * hp) self._dTy, self._dTx = gradient_flat(self.map_in, self.ldT) # Scale geometry for lower res map of patches pshp, pwcs = enmap.scale_geometry(self.map_in.shape, self.map_in.wcs, 1. / self._p) if not self.savesteps: del self.map_in, m_fft self._T2patch = enmap.zeros(pshp, pwcs) self._dTxpatch = enmap.zeros(pshp, pwcs) self._dTypatch = enmap.zeros(pshp, pwcs) self._T_sub = np.zeros((pshp[-2], pshp[-1], p, p)) for i in range(self._T2patch.shape[-2]): for j in range(self._T2patch.shape[-1]): self._dTypatch[i, j] = np.mean(self._dTy[i * p:(i + 1) * p, j * p:(j + 1) * p]) self._dTxpatch[i, j] = np.mean(self._dTx[i * p:(i + 1) * p, j * p:(j + 1) * p]) Tp = self._Tss[i * p:(i + 1) * p, j * p:(j + 1) * p] lsuby, lsubx = Tp.lmap() lsubmod = Tp.modlmap() lsubmod[0, 0] = 1. fl = 1.j*(lsubx*self._dTxpatch[i,j] + \ lsuby*self._dTypatch[i,j]) / \ (lsubmod * np.sqrt(self._dTxpatch[i,j]**2 + \ self._dTypatch[i,j]**2)) fl[0, 0] = 0. self._T_sub[i, j, :, :] = enmap.ifft(enmap.fft(Tp) * fl).real # Throw away pixels with edge effects self._T2patch[i, j] = np.var(self._T_sub[i, j, 5:-5, 5:-5]) self._dT2patch = self._dTxpatch**2 + self._dTypatch**2 if not self.savesteps: del self._dTypatch, self._dTxpatch, self._dTy, self._dTx, self._Tss del self._T_sub
def test_scale(self): # Test (with a plain geometry) that scale_geometry # will result in geometries with the same bounding box # but different area pixel pres = 0.5 ufact = 2 dfact = 0.5 shape,wcs = enmap.geometry(pos=(0,0),shape=(30,30),res=pres*u.arcmin,proj='plain') ushape,uwcs = enmap.scale_geometry(shape,wcs,ufact) dshape,dwcs = enmap.scale_geometry(shape,wcs,dfact) box = enmap.box(shape,wcs) ubox = enmap.box(ushape,uwcs) dbox = enmap.box(dshape,dwcs) parea = enmap.pixsize(shape,wcs) uparea = enmap.pixsize(ushape,uwcs) dparea = enmap.pixsize(dshape,dwcs) assert np.all(np.isclose(box,ubox)) assert np.all(np.isclose(box,dbox)) assert np.isclose(parea/(ufact**2),uparea) assert np.isclose(parea/(dfact**2),dparea)
def gather_patches_cos2(self): """Assemble patch statistics for small scale lensing with cos^2 filter. Compute the small scale (ell > 3000) temperature power at different patches across the sky as well as the average amplitude of the background temperature gradient (ell < 2000). For the small scale statistics, also apply a filter in Fourier space such that: .. math:: f_\\ell = \\cos^2(\\hat{\\ell}\\cdot\\hat{\\nabla T}) """ self._edge = 3 # Edge pixels to throw away p = self._p m_fft = enmap.fft(self.map_in) hp = np.zeros(self.map_in.shape) hp[np.where((self._lmod > self.lmin) & (self._lmod < self.lmax))] = 1. self._Tss = enmap.ifft(m_fft * hp) self._dTy, self._dTx = gradient_flat(self.map_in, self.ldT) # Scale geometry for lower res map of patches pshp, pwcs = enmap.scale_geometry(self.map_in.shape, self.map_in.wcs, 1. / self._p) if not self.savesteps: del self.map_in, m_fft self._T2patch = enmap.zeros(pshp, pwcs) self._dTxpatch = enmap.zeros(pshp, pwcs) self._dTypatch = enmap.zeros(pshp, pwcs) self._T_sub = np.zeros((pshp[-2], pshp[-1], p, p)) for i in range(self._T2patch.shape[-2]): for j in range(self._T2patch.shape[-1]): self._dTypatch[i, j] = np.mean(self._dTy[i * p:(i + 1) * p, j * p:(j + 1) * p]) self._dTxpatch[i, j] = np.mean(self._dTx[i * p:(i + 1) * p, j * p:(j + 1) * p]) Tp = self._Tss[i * p:(i + 1) * p, j * p:(j + 1) * p] lsuby, lsubx = Tp.lmap() lsubmod = Tp.modlmap() lsubmod[0, 0] = 1. # Avoid divide by 0; set fl here to 0 later fl = (lsubx*self._dTxpatch[i,j] + \ lsuby*self._dTypatch[i,j])**2 / \ (lsubmod * np.sqrt(self._dTxpatch[i,j]**2 + \ self._dTypatch[i,j]**2))**2 fl[0, 0] = 0. self._T_sub[i, j, :, :] = enmap.ifft(enmap.fft(Tp) * fl).real # Throw away pixels with edge effects self._T2patch[i, j] = np.var(self._T_sub[i, j, 3:-3, 3:-3]) self._dT2patch = self._dTxpatch**2 + self._dTypatch**2 if not self.savesteps: del self._dTypatch, self._dTxpatch, self._dTy, self._dTx, self._Tss del self._T_sub