Exemplo n.º 1
0
    def compute_coupling_coefficients(self,
                                      fla1,
                                      fla2,
                                      flb1=None,
                                      flb2=None,
                                      lmax=None,
                                      n_iter=3,
                                      l_toeplitz=-1,
                                      l_exact=-1,
                                      dl_band=-1):
        """
        Computes coupling coefficients of the Gaussian covariance \
        between the power spectra of two pairs of NmtField objects \
        (fla1, fla2, flb1 and flb2). Note that you can reuse this \
        workspace for the covariance of power spectra between any \
        pairs of fields as long as the fields have the same masks \
        as those passed to this function, and as long as the binning \
        scheme used are also the same.

        :param NmtField fla1,fla2: fields contributing to the first \
            power spectrum whose covariance you want to compute.
        :param NmtField flb1,flb2: fields contributing to the second \
            power spectrum whose covariance you want to compute. If \
            None, fla1,fla2 will be used.
        :param n_iter: number of iterations when computing a_lms.
        :param l_toeplitz: if a positive number, the Toeplitz approximation \
            described in Louis et al. 2020 (arXiv:2010.14344) will be used. \
            In that case, this quantity corresponds to ell_toeplitz in Fig. \
            3 of that paper.
        :param l_exact: if `l_toeplitz>0`, this quantity corresponds to \
            ell_exact in Fig. 3 of Louis et al. 2020.  Ignored if \
            `l_toeplitz<=0`.
        :param dl_band: if `l_toeplitz>0`, this quantity corresponds to \
            Delta ell_band in Fig. 3 of Louis et al. 2020.  Ignored if \
            `l_toeplitz<=0`.
        """
        if flb1 is None:
            flb1 = fla1
        if flb2 is None:
            flb2 = fla2

        if self.wsp is not None:
            lib.covar_workspace_free(self.wsp)
            self.wsp = None

        ns = fla1.fl.cs.n_eq
        if (fla2.fl.cs.n_eq != ns) or (flb1.fl.cs.n_eq != ns) or \
           (flb2.fl.cs.n_eq != ns):
            raise ValueError("Everything should have the same resolution!")

        if lmax is None:
            lmax = lib.get_lmax_from_cs_py(fla1.fl.cs)

        _toeplitz_sanity(l_toeplitz, l_exact, dl_band, lmax, fla1, flb1)
        self.wsp = lib.covar_workspace_init_py(fla1.fl, fla2.fl, flb1.fl,
                                               flb2.fl, lmax, n_iter,
                                               l_toeplitz, l_exact, dl_band)
Exemplo n.º 2
0
    def compute_coupling_matrix(self,
                                fl1,
                                fl2,
                                bins,
                                is_teb=False,
                                n_iter=3,
                                lmax_mask=-1,
                                l_toeplitz=-1,
                                l_exact=-1,
                                dl_band=-1):
        """
        Computes coupling matrix associated with the cross-power spectrum \
        of two NmtFields and an NmtBin binning scheme. Note that the mode \
        coupling matrix will only contain ells up to the maximum multipole \
        included in the NmtBin bandpowers.

        :param NmtField fl1,fl2: fields to correlate
        :param NmtBin bin: binning scheme
        :param boolean is_teb: if true, all mode-coupling matrices \
            (0-0,0-2,2-2) will be computed at the same time. In this case, \
            fl1 must be a spin-0 field and fl1 must be spin-2.
        :param n_iter: number of iterations when computing a_lms.
        :param lmax_mask: maximum multipole for masks. If smaller than the \
            maximum multipoles of the fields, it will be set to that.
        :param l_toeplitz: if a positive number, the Toeplitz approximation \
            described in Louis et al. 2020 (arXiv:2010.14344) will be used. \
            In that case, this quantity corresponds to ell_toeplitz in Fig. \
            3 of that paper.
        :param l_exact: if `l_toeplitz>0`, this quantity corresponds to \
            ell_exact in Fig. 3 of Louis et al. 2020.  Ignored if \
            `l_toeplitz<=0`.
        :param dl_band: if `l_toeplitz>0`, this quantity corresponds to \
            Delta ell_band in Fig. 3 of Louis et al. 2020.  Ignored if \
            `l_toeplitz<=0`.
        """
        if self.wsp is not None:
            lib.workspace_free(self.wsp)
            self.wsp = None

        _toeplitz_sanity(l_toeplitz, l_exact, dl_band, bins.bin.ell_max, fl1,
                         fl2)
        self.wsp = lib.comp_coupling_matrix(fl1.fl, fl2.fl, bins.bin,
                                            int(is_teb), int(n_iter),
                                            lmax_mask, l_toeplitz, l_exact,
                                            dl_band)
Exemplo n.º 3
0
def compute_full_master(f1,
                        f2,
                        b,
                        cl_noise=None,
                        cl_guess=None,
                        workspace=None,
                        n_iter=3,
                        lmax_mask=-1,
                        l_toeplitz=-1,
                        l_exact=-1,
                        dl_band=-1):
    """
    Computes the full MASTER estimate of the power spectrum of two \
    fields (f1 and f2). This is equivalent to successively calling:

    - :func:`pymaster.NmtWorkspace.compute_coupling_matrix`
    - :func:`pymaster.deprojection_bias`
    - :func:`pymaster.compute_coupled_cell`
    - :func:`pymaster.NmtWorkspace.decouple_cell`

    :param NmtField f1,f2: fields to correlate
    :param NmtBin b: binning scheme defining output bandpower
    :param cl_noise: noise bias (i.e. angular power spectrum of \
        masked noise realizations) (optional).
    :param cl_guess: set of power spectra corresponding to a \
        best-guess of the true power spectra of f1 and f2. Needed \
        only to compute the contaminant cleaning bias (optional).
    :param NmtWorkspace workspace: object containing the mode-coupling \
        matrix associated with an incomplete sky coverage. If \
        provided, the function will skip the computation of the \
        mode-coupling matrix and use the information encoded in this \
        object.
    :param n_iter: number of iterations when computing a_lms.
    :param lmax_mask: maximum multipole for masks. If smaller than the \
        maximum multipoles of the fields, it will be set to that.
    :param l_toeplitz: if a positive number, the Toeplitz approximation \
        described in Louis et al. 2020 (arXiv:2010.14344) will be used. \
        In that case, this quantity corresponds to ell_toeplitz in Fig. \
        3 of that paper.
    :param l_exact: if `l_toeplitz>0`, this quantity corresponds to \
        ell_exact in Fig. 3 of Louis et al. 2020.  Ignored if \
        `l_toeplitz<=0`.
    :param dl_band: if `l_toeplitz>0`, this quantity corresponds to \
        Delta ell_band in Fig. 3 of Louis et al. 2020.  Ignored if \
        `l_toeplitz<=0`.
    :return: set of decoupled bandpowers
    """
    if f1.fl.cs.n_eq != f2.fl.cs.n_eq:
        raise ValueError("Fields must have same resolution")
    if cl_noise is not None:
        if len(cl_noise) != f1.fl.nmaps * f2.fl.nmaps:
            raise ValueError("Wrong length for noise power spectrum")
        cln = cl_noise.copy()
    else:
        cln = np.zeros([f1.fl.nmaps * f2.fl.nmaps, 3 * f1.fl.cs.n_eq])
    if cl_guess is not None:
        if len(cl_guess) != f1.fl.nmaps * f2.fl.nmaps:
            raise ValueError("Wrong length for guess power spectrum")
        clg = cl_guess.copy()
    else:
        clg = np.zeros([f1.fl.nmaps * f2.fl.nmaps, 3 * f1.fl.cs.n_eq])

    _toeplitz_sanity(l_toeplitz, l_exact, dl_band, b.bin.ell_max, f1, f2)

    if workspace is None:
        cl1d = lib.comp_pspec(f1.fl, f2.fl, b.bin, None, cln, clg,
                              len(cln) * b.bin.n_bands, n_iter, lmax_mask,
                              l_toeplitz, l_exact, dl_band)
    else:
        cl1d = lib.comp_pspec(f1.fl, f2.fl, b.bin, workspace.wsp, cln, clg,
                              len(cln) * b.bin.n_bands, n_iter, lmax_mask,
                              l_toeplitz, l_exact, dl_band)

    clout = np.reshape(cl1d, [len(cln), b.bin.n_bands])

    return clout