示例#1
0
 def __init__(self,cl,res,lsides):
     assert(len(res) == len(lsides) == 2)
     self.cl = cl
     self.lib_cub = library_datacube(res, lsides)
     self.lsides = lsides
     self.shape = (2**res[0],2**res[1])
     self.N_2p1 = 2 ** (res[1] - 1) + 1
     self.inv_pc_mat = self._mk_pcinv()
     self.lnZ = 0.5*np.log(2.*np.pi)*np.prod(self.shape) + 0.5*np.sum(np.log(self.inv_pc_mat))
     assert(np.all(self.inv_pc_mat > 0.)),"setup failed, please make sure the k-range is big enough"
示例#2
0
    def __init__(self, lib_dir,cl_unl, cl_len, LD_res, HD_res,f, f_inv,sN_uKamin,beam_FWHM_amin,lside = np.sqrt(4 * np.pi),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 = ut.library_datacube(np.ones(2, dtype=int) * LD_res, np.ones(2) * lside, verbose=verbose)
        self.HD_cub = ut.library_datacube(np.ones(2, dtype=int) * HD_res, np.ones(2) * lside, verbose=verbose)
        self.LD_shape = tuple(self.LD_cub.shape())
        self.HD_shape = tuple(self.HD_cub.shape())
        self.HD_rshape = (self.HD_shape[0],self.HD_shape[1]/2 + 1)
        self.lsides = (lside,lside)

        self.f_inv = f_inv  # inverse displacement
        self.f = f  # displacement
        ellmax1 = self.ellmax_grid() + 1

        self.cl_unl = np.zeros(ellmax1)
        self.cl_unl[0:min((ellmax1,len(cl_unl)))] = cl_unl[0:min((ellmax1,len(cl_unl)))]
        self.cl_len = np.zeros(ellmax1)
        self.cl_len[0:min((ellmax1,len(cl_len)))] = cl_len[0:min((ellmax1,len(cl_len)))]
        self.cl_noise = get_cl_noise(sN_uKamin,ell_max = ellmax1 - 1) # Flat noise for now. could change that
        self.bl = get_bl(beam_FWHM_amin,ell_max=ellmax1 - 1)

        self.sN_uKamin = sN_uKamin
        self.beam_FWHM_amin = beam_FWHM_amin
        self.verbose = verbose
        self.lib_dir = lib_dir

        if not os.path.exists(self.lib_dir) and pbs.rank == 0 :
            # Build ell matrix and save it for further use.
            try : os.mkdir(self.lib_dir)
            except :
                print '** failed to make directory :',lib_dir

        print "ffs_lencov: caching HD_ellmap"
        ky2 = ut.Freq(np.arange(self.HD_shape[0]), self.HD_shape[0]) ** 2 * np.pi
        ones = np.ones(self.HD_shape[0])
        freq_map = np.sqrt(np.outer(ky2, ones[0:self.HD_shape[1]/2 + 1]) + np.outer(ones, ky2[0:self.HD_shape[1]/2 + 1]))
        freq_map = np.uint16(np.round(freq_map - 0.5))  # map of integer ell. in int16 format.
        np.save(lib_dir + '/HDellmap.npy', freq_map)
        pbs.barrier()
示例#3
0
    def __init__(self, cl_unl, res, lsides, sN_uKamin, Beam_FWHM_amin, verbose=False):
        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.sN_uKamin = sN_uKamin

        self.N_2p1 = 2 ** (res[1] - 1) + 1
示例#4
0
 def __init__(self,cl,res,lsides):
     assert(len(res) == len(lsides) == 2)
     self.cl = cl
     self.lib_cub = library_datacube(res, lsides)
     self.lsides = lsides
     self.shape = (2**res[0],2**res[1])
     self.N_2p1 = 2 ** (res[1] - 1) + 1
     self.rshape = (2**res[0],self.N_2p1)
     # Implementation of \sum_k when using rfft arrays : (for odd number of points set only [:,0]) :
     #self.rfft_sum = lambda arr : 2*np.sum(arr) - np.sum(arr[:,[-1,0]])
     self.rfft_sum = lambda arr : 2. * np.sum(arr[:,slice(1,self.N_2p1 - 1)]) + np.sum(arr[:,[-1,0]])
     # Number of non-zero modes and inverse spectral matrix :
     self.dof, self.lnZ,self.inv_pc_mat = self._mk_pcinv()
示例#5
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"
示例#6
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"
示例#7
0
文件: sims.py 项目: carronj/MLlens
 def _mk_HD_spectral_map_from_cl(self, cl):
     sqd_freq_map = library_datacube(self.HD_res(), self.lsides).sqd_freqmap().flatten()
     return np.interp(sqd_freq_map, np.arange(len(cl)) ** 2, cl / self._vcell_HD()).reshape(self.HD_shape)