Ejemplo n.º 1
0
    def read_from(self, fname):
        """
        Reads the contents of an NmtCovarianceWorkspaceFlat object from a file (encoded using an internal binary format).

        :param str fname: input file name
        """
        if self.wsp is not None:
            lib.covar_workspace_flat_free(self.wsp)
            self.wsp = None
        self.wsp = lib.read_covar_workspace_flat(fname)
Ejemplo n.º 2
0
    def read_from(self, fname):
        """
        Reads the contents of an NmtCovarianceWorkspaceFlat object from a \
        FITS file.

        :param str fname: input file name
        """
        if self.wsp is not None:
            lib.covar_workspace_flat_free(self.wsp)
            self.wsp = None
        self.wsp = lib.read_covar_workspace_flat(fname)
Ejemplo n.º 3
0
    def compute_coupling_coefficients(self, wa, wb):
        """
        Computes coupling coefficients of the Gaussian covariance between the power spectra computed using wa and wb (two NmtWorkspaceFlat objects).

        :param NmtWorkspaceFlat wa,wb: workspaces used to compute the two power spectra whose covariance matrix you want to compute.
        """
        if (wa.wsp.fs.nx != wb.wsp.fs.nx) or (wa.wsp.fs.ny != wb.wsp.fs.ny):
            raise ValueError("Everything should have the same resolution!")
        if (wa.wsp.ncls != 1) or (wb.wsp.ncls != 1):
            raise ValueError("Gaussian covariances only supported for spin-0 fields")
        if self.wsp is not None:
            lib.covar_workspace_flat_free(self.wsp)
            self.wsp = None
        self.wsp = lib.covar_workspace_flat_init_py(wa.wsp, wb.wsp)
Ejemplo n.º 4
0
    def compute_coupling_coefficients(self,
                                      fla1,
                                      fla2,
                                      bin_a,
                                      flb1=None,
                                      flb2=None,
                                      bin_b=None):
        """
        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 scheme used are also the same.

        :param NmtFieldFlat fla1,fla2: fields contributing to the first \
            power spectrum whose covariance you want to compute.
        :param NmtBinFlat bin_a: binning scheme for the first power \
            spectrum.
        :param NmtFieldFlat flb1,flb2: fields contributing to the second \
            power spectrum whose covariance you want to compute. If None, \
            fla1,fla2 will be used.
        :param NmtBinFlat bin_b: binning scheme for the second power \
            spectrum. If none, bin_a will be used.
        """
        if flb1 is None:
            flb1 = fla1
        if flb2 is None:
            flb2 = fla2
        if bin_b is None:
            bin_b = bin_a

        if (fla1.fl.fs.nx != fla2.fl.fs.nx) or \
           (fla1.fl.fs.ny != fla2.fl.fs.ny) or \
           (fla1.fl.fs.nx != flb1.fl.fs.nx) or \
           (fla1.fl.fs.ny != flb1.fl.fs.ny) or \
           (fla1.fl.fs.nx != flb2.fl.fs.nx) or \
           (fla1.fl.fs.ny != flb2.fl.fs.ny):
            raise ValueError("Everything should have the same resolution!")

        if self.wsp is not None:
            lib.covar_workspace_flat_free(self.wsp)
            self.wsp = None
        self.wsp = lib.covar_workspace_flat_init_py(fla1.fl, fla2.fl,
                                                    bin_a.bin, flb1.fl,
                                                    flb2.fl, bin_b.bin)
Ejemplo n.º 5
0
 def __del__(self):
     if self.wsp is not None:
         lib.covar_workspace_flat_free(self.wsp)
         self.wsp = None