예제 #1
0
파일: ideal.py 프로젝트: carronj/MLlens
 def get_spec_mat(self,ellmat = None):
     """
     Instantiation of spectral matrix.
     Spectral matrix in circulant convention (N/V physical Pk).
     """
     if hasattr(self, '_spec_mat'): return self._spec_mat
     self._spec_mat = spec_mat_from_cl(self.cl, self.res, self.lsides)[:, 0:self.shape[1] / 2 + 1]
     if self.has_pixwin(): self._spec_mat *= ut.square_pixwin_map(self.shape)[:, 0:self.shape[1] / 2 + 1]
     return self._spec_mat
예제 #2
0
파일: sims.py 프로젝트: carronj/MLlens
    def _build_sim(self, idx):
        """
         Returns two independent realisations of a G. field with the given cov.
         Steps are :
         1) Get high resolution cmb sky map (incl lensing or not)
         3) Convolve with beam and pixwin (integral convolution)
         4) Downgrade it
         5) add noise and mask it
        """
        cmb = self.cmb_sims.get_sim(idx)

        Beam_SpecMap = self._mk_HD_spectral_map_from_cl(self.beam_cl()) * square_pixwin_map(self.HD_shape)
        cmb = np.fft.irfft2(np.fft.rfft2(cmb) * Beam_SpecMap[:, 0:self._N_2p1()], self.HD_shape) * self._vcell_HD()
        fac0, fac1 = self._degrade_factors()
        if self.has_mask(): return self.mask * (cmb[::fac0, ::fac1] + self.noise_sims.get_sim(idx))
        return cmb[::fac0, ::fac1] + self.noise_sims.get_sim(idx)
예제 #3
0
    def __init__(self, cl_unl, res, lsides, sN_uKamin, Beam_FWHM_amin, verbose=False):
        """
        Cl is jc_cosmo.Cl instance, #of points on each side 2**res, total lenght on side lsides (rad)
        The matrix stored is the fft of the circulant operator (P*nbar in physical units)
        To convolve with other circulant operators it should be enough to ifft(fft*fft) with these units.
        Meant to be used with radians and uK units.
        """
        assert (len(res) == 2 and len(lsides) == 2)
        self.lib_cub = library_datacube(res, lsides, verbose=verbose)
        self.shape = self.lib_cub.shape()
        self.lsides = self.lib_cub.lside

        self.cl_unl = cl_unl

        self.Beam_FWHM_amin = Beam_FWHM_amin

        self.spec_map = self.__mk_spectral_matrix_from_cl() * square_pixwin_map(self.shape) ** 2
        self.spec_map += self.__nbar() * (sN_uKamin / 60. / 180. * np.pi) ** 2
        # : Spectral matrix in grid units.
        self.N_2p1 = 2 ** (res[1] - 1) + 1
        assert (np.all(self.spec_map > 0.)), "Somethings wrong"
예제 #4
0
    def __init__(self, cl_unl, cl_len, LD_res, HD_res, lside, f, f_inv,sN_uKamin,Beam_FWHM_amin,verbose=False):
        """
        f and finv are displacement field classes. Number of points on each side 2**LD_res,2**HD_res.
        f and f_inv must have a f.lens_map routine that does the lensing of map 2**HD_res by 2**HD_res.
        f_inv must also have a f.det_M routine which returns the determinant of the magnification matrix
        at all points of the map.
        """
        self.LD_cub = library_datacube(np.ones(2, dtype=int) * LD_res, np.ones(2) * lside, verbose=verbose)
        self.HD_cub = library_datacube(np.ones(2, dtype=int) * HD_res, np.ones(2) * lside, verbose=verbose)
        self.LD_shape = self.LD_cub.shape()
        self.HD_shape = self.HD_cub.shape()

        self.f_inv = f_inv  # inverse displacement
        self.f = f  # displacement

        self.cl_unl = cl_unl
        self.cl_len = cl_len

        self.sN_uKamin = sN_uKamin
        self.Beam_FWHM_amin = Beam_FWHM_amin
        self.verbose = verbose

        # FIXME : the value of the variance jumps by a factor 5-6 if the l = 0 is interpolated !
        # There is something fishy with the lowest mode.
        # Again circulant embedding is probably better, but how to get the fake spectra ?

        # Builds useful FFT maps.
        # All spectral maps in grid units ! (nbar * PhysicalSpectrum)
        # TODO Hack
        self.N_2p1 = 2**(HD_res -1) + 1
        kmax_grid = np.sqrt(np.sum(self.HD_cub.kmax()**2))
        self.HD_cl_unl_SpecMap = self._mk_HD_spectral_map_from_cl(cl_unl)[:,0:self.N_2p1]
        self.HD_Beam_SpecMap = self._mk_HD_spectral_map_from_cl(
            gauss_beam(Beam_FWHM_amin * np.pi / 180. / 60., lmax=kmax_grid+1))
        self.HD_Beam_SpecMap *= square_pixwin_map(self.HD_shape)

        assert (np.all(self.HD_cl_unl_SpecMap >= 0.)), "Somethings wrong"
        assert (np.all(self.HD_Beam_SpecMap >= 0.)), "Somethings wrong"
예제 #5
0
 def _beam_spec_map(self):
     beam = gauss_beam(self.Beam_FWHM_amin * np.pi / 180. / 60., lmax=len(self.cl_unl) - 1)
     return self._mk_spectral_matrix_from_cl(beam) * square_pixwin_map(self.shape)