def accum(self, pmap, coeffs): assert (len(coeffs) == self.nmodes) if len(pmap) == 2: # Q and U maps pmap[1] += read_map(self.map) * coeffs[0] elif len(pmap) == 1: # Assumed U-only pmap[0] += read_map(self.map) * coeffs[0] else: assert 0
def apply(self, pmap, coeffs): assert (len(coeffs) == self.nmodes) if len(pmap) == 2: # Q and U maps pmap[1] *= read_map(self.map) * coeffs[0] pmap[0] *= 0. elif len(pmap) == 1: # Only U pmap[0] *= read_map(self.map) * coeffs[0] else: assert 0
def vmaps2vmap_P(pix_vmaps, weights_e, weights_b, nside): """From individual Q and U freq pixel variance maps and weights create expected pixel variance map Args: pix_vmaps: list of pixel variance maps weights_e: weights for E-mode freq. weighting (as applied onto the noise maps) weights_b: weights for B-mode freq. weighting (as applied onto the noise maps) nside: desired output map resolution Note: the pix_vmaps in pol in this routine are expected to be ~ 1/2 (s2_Q + s2_U) See Planck 2018 gravitational lensing paper Eqs 16-17 """ assert len(pix_vmaps) == len(weights_e), (len(pix_vmaps), len(weights_e)) assert len(pix_vmaps) == len(weights_b), (len(pix_vmaps), len(weights_b)) nf, lmaxp1_e = weights_e.shape nf, lmaxp1_b = weights_b.shape lmax_out = min(2 * max(lmaxp1_e, lmaxp1_b) - 2, 3 * nside - 1) ret_lm = np.zeros(hp.Alm.getsize(lmax_out), dtype=complex) for i, (pix_vmap, wle, wlb) in enumerate_progress( list(zip(pix_vmaps, weights_e, weights_b))): m = read_map(pix_vmap) vpix = hp.nside2pixarea(hp.npix2nside(m.size), degrees=False) this_s2lm = hp.map2alm(m, iter=0, lmax=lmax_out) wl2 = 0.25 * vpix * _w2wsq(wle + wlb, 2, 2, lmax_out) wl2 += 0.25 * vpix * _w2wsq(wle - wlb, 2, -2, lmax_out) hp.almxfl(this_s2lm, wl2, inplace=True) ret_lm += this_s2lm return hp.alm2map(ret_lm, nside, verbose=False)
def vmaps2vmap_I(pix_vmaps, weights, nside): """From individual freq pixel variance maps and weights create expected pixel variance map Args: pix_vmaps: list of pixel variance maps weights: weights for intensity freq. weighting (as applied onto the noise maps) nside: desired output map resolution See Planck 2018 gravitational lensing paper Eqs 16-17 """ assert len(pix_vmaps) == len(weights), (len(pix_vmaps), len(weights)) nf, lmaxp1 = weights.shape lmax_out = min(2 * lmaxp1 - 2, 3 * nside - 1) ret_lm = np.zeros(hp.Alm.getsize(lmax_out), dtype=complex) for i, (pix_vmap, wl) in enumerate_progress(list(zip(pix_vmaps, weights))): m = read_map(pix_vmap) vpix = hp.nside2pixarea(hp.npix2nside(m.size), degrees=False) this_s2lm = hp.map2alm(m, iter=0, lmax=lmax_out) wl2 = _w2wsq(wl, 0, 0, lmax_out) * vpix hp.almxfl(this_s2lm, wl2, inplace=True) ret_lm += this_s2lm return hp.alm2map(ret_lm, nside, verbose=False)
def dot(self, pmap): return [np.sum(read_map(self.map) * pmap[0])] # either Q, U or Q only
def accum(self, pmap, coeffs): assert len(pmap) == 2, len(pmap) assert (len(coeffs) == self.nmodes) pmap[0] += read_map(self.map) * coeffs[0]
def dot(self, pmap): if len(pmap) == 2: # Q and U maps return [np.sum(read_map(self.map) * pmap[1])] elif len(pmap) == 1: # Assumed U-only return [np.sum(read_map(self.map) * pmap[0])] assert 0
def __init__(self, n_inv, b_transf, b_transf_e=None, b_transf_b=None, marge_monopole=False, marge_dipole=False, marge_maps_t=(), marge_maps_p=()): # n_inv = [util.load_map(n[:]) for n in n_inv] self.n_inv = [] for i, tn in enumerate(n_inv): if isinstance(tn, list): n_inv_prod = read_map(tn[0][:]) if len(tn) > 1: for n in tn[1:]: n_inv_prod = n_inv_prod * read_map(n[:]) self.n_inv.append(n_inv_prod) # assert (np.std(self.n_inv[i][np.where(self.n_inv[i][:] != 0.0)]) / np.average( # self.n_inv[i][np.where(self.n_inv[i][:] != 0.0)]) < 1.e-7) else: self.n_inv.append(read_map(n_inv[i])) n_inv = self.n_inv npix = len(n_inv[0]) nside = hp.npix2nside(npix) for n in n_inv[1:]: assert (len(n) == npix) templates_t = [] templates_t_hash = [] for tmap in [read_map(m) for m in marge_maps_t]: assert (npix == len(tmap)) templates_t.append(template_removal.template_map(tmap)) templates_t_hash.append(clhash(tmap)) if marge_monopole: templates_t.append(template_removal.template_monopole()) if marge_dipole: templates_t.append(template_removal.template_dipole()) if len(templates_t) != 0: nmodes = np.sum([t.nmodes for t in templates_t]) modes_idx_t = np.concatenate( ([t.nmodes * [int(im)] for im, t in enumerate(templates_t)])) modes_idx_i = np.concatenate( ([range(0, t.nmodes) for t in templates_t])) Pt_Nn1_P = np.zeros((nmodes, nmodes)) for ir in range(0, nmodes): tmap = np.copy(n_inv[0]) templates_t[modes_idx_t[ir]].apply_mode( tmap, int(modes_idx_i[ir])) ic = 0 for tc in templates_t[0:modes_idx_t[ir] + 1]: Pt_Nn1_P[ir, ic:(ic + tc.nmodes)] = tc.dot(tmap) Pt_Nn1_P[ic:(ic + tc.nmodes), ir] = Pt_Nn1_P[ir, ic:(ic + tc.nmodes)] ic += tc.nmodes self.Pt_Nn1_P_inv = np.linalg.inv(Pt_Nn1_P) self.n_inv = n_inv self.b_transf_t = b_transf self.b_transf_e = b_transf_e if b_transf_e is not None else b_transf self.b_transf_b = b_transf_b if b_transf_b is not None else b_transf assert len(self.b_transf_t) == len(self.b_transf_e) and len( self.b_transf_t) == len(self.b_transf_e) self.b_transf = (self.b_transf_t + self.b_transf_e + self.b_transf_t) / 3. self.marge_monopole = marge_monopole self.marge_dipole = marge_dipole self.templates_t = templates_t self.templates_t_hash = templates_t_hash assert len(marge_maps_p) == 0 self.templates_p = [] self.npix = npix self.nside = nside