def get_sim_stats_qcl(self, k1, mc_sims, k2=None, recache=False, lmax=None): """Returns the sim-average of the input *plancklens.qecl* list QE power spectra average Args: k1: QE anisotropy key 1 mc_sims: the simulation indices to average the spectra over k2: QE anisotropy key 2 (defaults to k1) Returns: *plancklens.utils.stats* instance """ if k2 is None: k2 = k1 if lmax is None: lmax = self.get_lmaxqcl(k1, k2) tfname = os.path.join( self.lib_dir, 'sim_qcl_stats_%s_%s_%s_%s.pk' % (k1, k2, lmax, utils.mchash(mc_sims))) if not os.path.exists(tfname) or recache: stats_qcl = utils.stats(lmax + 1, docov=False) for i, idx in utils.enumerate_progress( mc_sims, label='building sim_stats qcl (k1,k2)=' + str((k1, k2))): stats_qcl.add(self.get_sim_qcl(k1, idx, k2=k2, lmax=lmax)) pk.dump(stats_qcl, open(tfname, 'wb'), protocol=2) return pk.load(open(tfname, 'rb'))
def get_bamc(self): """Binned additive MC correction, with crude error bars. This compares the reconstruction on the simulations to the FFP10 input lensing spectrum. Note: the approximate error corrections to the additive MC correction variance follows Appendix C of https://arxiv.org/abs/1807.06210, check this for more details on its validity. """ assert self.k1[0] == 'p' and self.k2[ 0] == 'p' and self.ksource == 'p', (self.k1, self.k2, self.ksource) ss2 = 2 * self.parfile.qcls_ss.get_sim_stats_qcl( self.k1, self.parfile.mc_sims_var, k2=self.k2).mean() cl_pred = utils.camb_clfile( os.path.join( self.cls_path, 'FFP10_wdipole_lenspotentialCls.dat'))['pp'][:len(ss2)] qc_norm = utils.cli( self.parfile.qresp_dd.get_response(self.k1, self.ksource) * self.parfile.qresp_dd.get_response(self.k2, self.ksource)) bp_stats = utils.stats(self.nbins) bp_n1 = self.get_n1() for i, idx in utils.enumerate_progress(self.parfile.mc_sims_var, label='collecting BP stats'): dd = self.parfile.qcls_dd.get_sim_qcl(self.k1, idx, k2=self.k2) bp_stats.add( self._get_binnedcl(qc_norm * (dd - ss2) - cl_pred) - bp_n1) NMF = len(self.parfile.qcls_dd.mc_sims_mf) NB = len(self.parfile.mc_sims_var) return bp_stats.mean(), bp_stats.sigmas_on_mean() * np.sqrt( (1. + 1. + 2. / NMF + 2 * NB / (float(NMF * NMF))))
def get_mcn0_cov(self, mc_sims_dd=None): """Covariance matrix obtained from the realization-independent debiaser. """ if mc_sims_dd is None: mc_sims_dd = self.parfile.mc_sims_var mcn0_cov = utils.stats(self.nbins) qc_norm = utils.cli( self.parfile.qresp_dd.get_response(self.k1, self.ksource) * self.parfile.qresp_dd.get_response(self.k2, self.ksource)) for i, idx in utils.enumerate_progress(mc_sims_dd): dd = self.parfile.qcls_dd.get_sim_qcl(self.k1, idx, k2=self.k2) mcn0_cov.add(self._get_binnedcl(qc_norm * dd)) return mcn0_cov.cov()
def get_nhl_cov(self, mc_sims_dd=None): """Covariance matrix obtained from the semi-analytical N0 debiaser. """ if mc_sims_dd is None: mc_sims_dd = self.parfile.mc_sims_var nhl_cov = utils.stats(self.nbins) qc_norm = utils.cli( self.parfile.qresp_dd.get_response(self.k1, self.ksource) * self.parfile.qresp_dd.get_response(self.k2, self.ksource)) for i, idx in utils.enumerate_progress(mc_sims_dd): dd = self.parfile.qcls_dd.get_sim_qcl(self.k1, idx, k2=self.k2) nhl_cov.add( self._get_binnedcl(qc_norm * (dd - self.parfile.nhl_dd.get_sim_nhl( int(idx), self.k1, self.k2)))) return nhl_cov.cov()
def get_ampl_x_input(self, mc_sims=None): """Returns cross-correlation of phi-maps to input lensing maps. Uses qlms_x_i library of parfile """ qlmi = self.parfile.qlms_x_in if mc_sims is None: mc_sims = np.unique( np.concatenate( [self.parfile.mc_sims_var, self.parfile.mc_sims_bias])) xin = utils.stats(self.nbins) qnorm = utils.cli( self.parfile.qresp_dd.get_response(self.k1, self.ksource)) for i, idx in utils.enumerate_progress(mc_sims): qi = qlmi.get_sim_qcl(self.k1, idx) xin.add(self._get_binnedcl(qnorm * qi) / self.fid_bandpowers) return xin