pymaster.covariance module

class pymaster.covariance.NmtCovarianceWorkspace(fla1=None, fla2=None, flb1=None, flb2=None, l_toeplitz=-1, l_exact=-1, dl_band=-1, spin0_only=False, fname=None, force_spin0_only=False)[source]

Bases: object

NmtCovarianceWorkspace objects are used to compute and store the coupling coefficients needed to calculate the Gaussian covariance matrix of angular power spectra under the approximations described in in Garcia-Garcia et al. 2019 (see also Efstathiou et al. 2003, and Couchot et al. 2016).

NmtCovarianceWorkspace objects may be constructed from a set of NmtField objects, describing the masks of the fields being correlated, or may be read from a file. We recommend using the class methods from_fields() and from_file() to create new NmtCovarianceWorkspace objects, rather than using the main constructor.

Parameters:
  • fla1 (NmtField) – First field contributing to the first power spectrum whose covariance you want to compute.

  • fla2 (NmtField) – Second field contributing to the first power spectrum whose covariance you want to compute.

  • flb1 (NmtField) – As fla1 for the second power spectrum. If None, it will be set to fla1.

  • flb2 (NmtField) – As fla2 for the second power spectrum. If None, it will be set to fla2.

  • l_toeplitz (int) – If a positive number, the Toeplitz approximation described in Louis et al. 2020 will be used. In that case, this quantity corresponds to \(\ell_{\rm toeplitz}\) in Fig. 3 of that paper.

  • l_exact (int) – If l_toeplitz>0, it corresponds to \(\ell_{\rm exact}\) in Fig. 3 of the paper. Ignored if l_toeplitz<=0.

  • dl_band (int) – If l_toeplitz>0, this quantity corresponds to \(\Delta \ell_{\rm band}\) in Fig. 3 of the paper. Ignored if l_toeplitz<=0.

  • spin0_only (bool) – If True, only spin-0 combinations of the mode-coupling coefficients will be computed and stored.

  • fname (str) – Input file name. If not None, the values of all input fields will be ignored, and all mode-coupling coefficients will be read from file.

  • force_spin_only (bool) – If True, only spin-0 combinations of the mode-coupling coefficients will be read and stored.

classmethod from_fields(fla1, fla2, flb1=None, flb2=None, l_toeplitz=-1, l_exact=-1, dl_band=-1, spin0_only=False)[source]

Creates an NmtCovarianceWorkspace object containing the mode-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 schemes used are also the same.

Parameters:
  • fla1 (NmtField) – First field contributing to the first power spectrum whose covariance you want to compute.

  • fla2 (NmtField) – Second field contributing to the first power spectrum whose covariance you want to compute.

  • flb1 (NmtField) – As fla1 for the second power spectrum. If None, it will be set to fla1.

  • flb2 (NmtField) – As fla2 for the second power spectrum. If None, it will be set to fla2.

  • l_toeplitz (int) –

    If a positive number, the Toeplitz approximation described in Louis et al. 2020 will be used. In that case, this quantity corresponds to \(\ell_{\rm toeplitz}\) in Fig. 3 of that paper.

  • l_exact (int) – If l_toeplitz>0, it corresponds to \(\ell_{\rm exact}\) in Fig. 3 of the paper. Ignored if l_toeplitz<=0.

  • dl_band (int) – If l_toeplitz>0, this quantity corresponds to \(\Delta \ell_{\rm band}\) in Fig. 3 of the paper. Ignored if l_toeplitz<=0.

  • spin0_only (bool) – If True, only spin-0 combinations of the mode-coupling coefficients will be computed and stored.

classmethod from_file(fname, force_spin0_only=False)[source]

Creates an NmtCovarianceWorkspace object from the mode-coupling coefficients stored in a FITS file. See write_to().

Parameters:
  • fname (str) – Input file name.

  • force_spin_only (bool) – If True, only spin-0 combinations of the mode-coupling coefficients will be read and stored.

read_from(fname, force_spin0_only=False)[source]

Reads the contents of an NmtCovarianceWorkspace object from a FITS file.

Parameters:
  • fname (str) – Input file name.

  • force_spin_only (bool) – If True, only spin-0 combinations of the mode-coupling coefficients will be read and stored.

compute_coupling_coefficients(fla1, fla2, flb1=None, flb2=None, *, l_toeplitz=-1, l_exact=-1, dl_band=-1, spin0_only=False)[source]

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 schemes used are also the same.

Parameters:
  • fla1 (NmtField) – First field contributing to the first power spectrum whose covariance you want to compute.

  • fla2 (NmtField) – Second field contributing to the first power spectrum whose covariance you want to compute.

  • flb1 (NmtField) – As fla1 for the second power spectrum. If None, it will be set to fla1.

  • flb2 (NmtField) – As fla2 for the second power spectrum. If None, it will be set to fla2.

  • l_toeplitz (int) –

    If a positive number, the Toeplitz approximation described in Louis et al. 2020 will be used. In that case, this quantity corresponds to \(\ell_{\rm toeplitz}\) in Fig. 3 of that paper.

  • l_exact (int) – If l_toeplitz>0, it corresponds to \(\ell_{\rm exact}\) in Fig. 3 of the paper. Ignored if l_toeplitz<=0.

  • dl_band (int) – If l_toeplitz>0, this quantity corresponds to \(\Delta \ell_{\rm band}\) in Fig. 3 of the paper. Ignored if l_toeplitz<=0.

  • spin0_only (bool) – If True, only spin-0 combinations of the mode-coupling coefficients will be computed and stored.

write_to(fname)[source]

Writes the contents of an NmtCovarianceWorkspace object to a FITS file.

Parameters:

fname (str) – Output file name.

class pymaster.covariance.NmtCovarianceWorkspaceFlat[source]

Bases: object

NmtCovarianceWorkspaceFlat objects are used to compute and store the coupling coefficients needed to calculate the Gaussian covariance matrix of angular power spectra using a flat-sky version of the approximations described in Garcia-Garcia et al. 2019. When initialized, this object is practically empty. The information describing the coupling coefficients must be computed or read from a file afterwards.

read_from(fname)[source]

Reads the contents of an NmtCovarianceWorkspaceFlat object from a FITS file.

Parameters:

fname (str) – Input file name.

compute_coupling_coefficients(fla1, fla2, bin_a, flb1=None, flb2=None, bin_b=None)[source]

Computes coupling coefficients of the Gaussian covariance between the power spectra of two pairs of NmtFieldFlat 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 schemes used are also the same.

Parameters:
  • fla1 (NmtFieldFlat) – First field contributing to the first power spectrum whose covariance you want to compute.

  • fla2 (NmtFieldFlat) – Second field contributing to the first power spectrum whose covariance you want to compute.

  • bin_a (NmtBinFlat) – Binning scheme for the first power spectrum.

  • flb1 (NmtFieldFlat) – As fla1 for the second power spectrum. If None, it will be set to fla1.

  • flb2 (NmtFieldFlat) – As fla2 for the second power spectrum. If None, it will be set to fla2.

  • bin_b (NmtBinFlat) – Binning scheme for the second power spectrum. If None, bin_a will be used.

write_to(fname)[source]

Writes the contents of an NmtCovarianceWorkspaceFlat object to a FITS file.

Parameters:

fname (str) – Output file name.

pymaster.covariance.gaussian_covariance(cw, spin_a1, spin_a2, spin_b1, spin_b2, cla1b1, cla1b2, cla2b1, cla2b2, wa, wb=None, coupled=False)[source]

Computes the Gaussian covariance matrix for power spectra using the information precomputed in cw (a NmtCovarianceWorkspace object). cw should have been initialized using four NmtField objects (let’s call them a1, a2, b1, and b2), corresponding to the two pairs of fields whose power spectra we want the covariance of. These power spectra should have been computed using two NmtWorkspace objects, wa and wb, which must be passed as arguments of this function (the power spectrum for fields a1 and a2 was computed with wa, and that of b1 and b2 with wb). Using the same notation, clXnYm should be a prediction for the power spectrum between fields Xn and Ym. These predicted input power spectra should be defined for all multipoles \(\ell\) up to the \(\ell_{\rm max}\) with which all fields were constructed.

Note

Note that, as suggested in Nicola et al. 2020 (the so-called “improved narrow-kernel approximation”), an optimal choice for the input power spectra would be the mode-coupled version of the true power spectra of the corresponding fields divided by the average of the product of the associated masks across the sky (Eq. 2.36 in the paper). Often, a good substitute for this can be obtained as the pseudo-\(C_\ell\) of the associated maps (e.g. computed via compute_coupled_cell()), divided by the same mean mask product.

Parameters:
  • cw (NmtCovarianceWorkspace) – Workspace containing the precomputed coupling coefficients.

  • spin_a1 (int) – Spin of field a1.

  • spin_a2 (int) – Spin of field a2.

  • spin_b1 (int) – Spin of field b1.

  • spin_b2 (int) – Spin of field b2.

  • cla1b1 (array) – Prediction for the cross-power spectrum between fields a1 and b1.

  • cla1b2 (array) – As cla1b1 for fields a1 and b2.

  • cla2b1 (array) – As cla1b1 for fields a2 and b1.

  • cla2b2 (array) – As cla1b1 for fields a2 and b2.

  • wa (NmtWorkspace) – Workspace containing the mode-coupling matrix for the first power spectrum (that of fields a1 and a2).

  • wb (NmtWorkspace) – As wa for the second power spectrum (that of fields b1 and b2). If None, wa will be used instead.

  • coupled (bool) – If True, the covariance matrix of the mode-coupled pseudo-\(C_\ell\) s will be computed. Otherwise it’ll be the covariance of mode-decoupled bandpowers.

pymaster.covariance.gaussian_covariance_flat(cw, spin_a1, spin_a2, spin_b1, spin_b2, larr, cla1b1, cla1b2, cla2b1, cla2b2, wa, wb=None)[source]

As gaussian_covariance() but for the flat-sky versions of all quantities involved. The only difference with gaussian_covariance() is that all power spectra must have been sampled at the input multipoles larr.