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:
objectNmtCovarianceWorkspaceobjects 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).NmtCovarianceWorkspaceobjects may be constructed from a set ofNmtFieldobjects, describing the masks of the fields being correlated, or may be read from a file. We recommend using the class methodsfrom_fields()andfrom_file()to create newNmtCovarianceWorkspaceobjects, 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) – Asfla1for the second power spectrum. IfNone, it will be set tofla1.flb2 (
NmtField) – Asfla2for the second power spectrum. IfNone, it will be set tofla2.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) – Ifl_toeplitz>0, it corresponds to \(\ell_{\rm exact}\) in Fig. 3 of the paper. Ignored ifl_toeplitz<=0.dl_band (
int) – Ifl_toeplitz>0, this quantity corresponds to \(\Delta \ell_{\rm band}\) in Fig. 3 of the paper. Ignored ifl_toeplitz<=0.spin0_only (
bool) – IfTrue, 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) – IfTrue, 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
NmtCovarianceWorkspaceobject containing the mode-coupling coefficients of the Gaussian covariance between the power spectra of two pairs ofNmtFieldobjects (fla1,fla2,flb1, andflb2). 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) – Asfla1for the second power spectrum. IfNone, it will be set tofla1.flb2 (
NmtField) – Asfla2for the second power spectrum. IfNone, it will be set tofla2.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) – Ifl_toeplitz>0, it corresponds to \(\ell_{\rm exact}\) in Fig. 3 of the paper. Ignored ifl_toeplitz<=0.dl_band (
int) – Ifl_toeplitz>0, this quantity corresponds to \(\Delta \ell_{\rm band}\) in Fig. 3 of the paper. Ignored ifl_toeplitz<=0.spin0_only (
bool) – IfTrue, 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
NmtCovarianceWorkspaceobject from the mode-coupling coefficients stored in a FITS file. Seewrite_to().
- read_from(fname, force_spin0_only=False)[source]
Reads the contents of an
NmtCovarianceWorkspaceobject from a FITS file.
- 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
NmtFieldobjects (fla1,fla2,flb1, andflb2). 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) – Asfla1for the second power spectrum. IfNone, it will be set tofla1.flb2 (
NmtField) – Asfla2for the second power spectrum. IfNone, it will be set tofla2.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) – Ifl_toeplitz>0, it corresponds to \(\ell_{\rm exact}\) in Fig. 3 of the paper. Ignored ifl_toeplitz<=0.dl_band (
int) – Ifl_toeplitz>0, this quantity corresponds to \(\Delta \ell_{\rm band}\) in Fig. 3 of the paper. Ignored ifl_toeplitz<=0.spin0_only (
bool) – IfTrue, only spin-0 combinations of the mode-coupling coefficients will be computed and stored.
- write_to(fname)[source]
Writes the contents of an
NmtCovarianceWorkspaceobject to a FITS file.- Parameters:
fname (
str) – Output file name.
- class pymaster.covariance.NmtCovarianceWorkspaceFlat[source]
Bases:
objectNmtCovarianceWorkspaceFlatobjects 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
NmtCovarianceWorkspaceFlatobject 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
NmtFieldFlatobjects (fla1,fla2,flb1, andflb2). 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) – Asfla1for the second power spectrum. IfNone, it will be set tofla1.flb2 (
NmtFieldFlat) – Asfla2for the second power spectrum. IfNone, it will be set tofla2.bin_b (
NmtBinFlat) – Binning scheme for the second power spectrum. IfNone,bin_awill be used.
- write_to(fname)[source]
Writes the contents of an
NmtCovarianceWorkspaceFlatobject 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
NmtCovarianceWorkspaceobject).cwshould have been initialized using fourNmtFieldobjects (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 twoNmtWorkspaceobjects,waandwb, which must be passed as arguments of this function (the power spectrum for fields a1 and a2 was computed withwa, and that of b1 and b2 withwb). Using the same notation,clXnYmshould 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) – Aswafor the second power spectrum (that of fields b1 and b2). IfNone,wawill be used instead.coupled (
bool) – IfTrue, 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 withgaussian_covariance()is that all power spectra must have been sampled at the input multipoleslarr.