def simulate_MultinomialLognormalSky(self, NSIDE, Npts_per_sqdeg): if self.verbose: t0 = time.time() utils.PrtMsg("Generating Lognormal field :", self.verbose) rho = self.simulate_LognormalSky(NSIDE) if self.verbose: t0 = utils.PrtAndRstTime(self.verbose, t0) utils.PrtMsg("Multinomial sampling and returning: ", self.verbose) Ntot = hp.nside2pixarea(NSIDE, degrees=True) * Npts_per_sqdeg * hp.nside2npix(NSIDE) return np.random.multinomial(Ntot, rho / np.sum(rho))
def simulate_PoissonLognormalSky(self, NSIDE, NGal_per_sqdeg): if self.verbose: t0 = time.time() utils.PrtMsg("Generating Lognormal field :", self.verbose) rho = self.simulate_LognormalSky(NSIDE) rate = hp.nside2pixarea(NSIDE, degrees=True) * NGal_per_sqdeg if self.verbose: t0 = utils.PrtAndRstTime(self.verbose, t0) utils.PrtMsg("Poisson sampling and returning : ", self.verbose) return np.random.poisson(rho * rate, size=rho.size)
def simulate_GaussianSky(self, NSIDE, seed=None): """ Returns a healpy sky map from the Cl with synfast """ if self.lmin > 0: if self.verbose: utils.PrtMsg("Filling ell (0 : " + str(self.lmin) + ") with zeros.", self.verbose) Cl = Cl_lmax(self.ell(), self.Cl).Cl # In order to fill in the missing ells else: Cl = self.Cl if seed is not None: np.random.set_state(seed) return hp.synfast(Cl, NSIDE, new=True)
def to_realspace(self, cos_t): """ Performs the Legendre transform to get the real space 2pcf. """ cos_t = np.array(cos_t) if self.lmin > 0: if self.verbose: utils.PrtMsg("Filling ell (0 : " + str(self.lmin) + ") with zeros.", self.verbose) Cl_temp = Cl_lmax(self.ell(), self.Cl) # In order to fill in the missing ells Cl = Cl_temp.Cl ell = Cl_temp.ell() else: Cl = self.Cl ell = self.ell() Clell2_4pi = Cl * (2. * ell + 1.) / (4. * np.pi) return np.polynomial.legendre.legval(cos_t, Clell2_4pi)
def Cl_log(self, NSIDE=2048, lmax=None): """ Returns the spectrum of the log field assuming lognormal statistics : This produces a fake map with map(n) = xi(cost), take the log and get the new alm. Input parameter NSIDE is the healpix res of the fake map. (lmax \sim 3*NSIDE -1) """ if self.verbose and self.lmin > 0: utils.PrtMsg("Filling ell (0 : " + str(self.lmin) + ") with lowest l entry.", self.verbose) Clc = Cl_lmax(self.ell(), self.Cl) Clc.Cl[0:self.lmin] = self.Cl[0] alm = 1j * np.zeros(self.lmax + 1) + Clc.Cl w = np.sqrt((2. * Clc.ell() + 1.) / 4. / np.pi) # weights -> sum_l Cl/w_l Y_l0(cost) = xi(n) # This creates a map xi with xi(hat n) = xi(cos t) print "Generating NSIDE " + str(NSIDE) + " xi map" xi = hp.alm2map(w * alm, NSIDE, lmax=self.lmax, mmax=0, verbose=False) assert (np.all(xi > -1.)), "Procedure ill-defined" alm_log = hp.map2alm(np.log(1. + xi), lmax=lmax, mmax=0) alm_log /= np.sqrt((2. * np.arange(len(alm_log)) + 1.) / 4. / np.pi) if not (np.all(alm_log.real >= 0.)): "Warning , negative values in Plog" return Cl_lminlmax(np.arange(len(alm_log)), alm_log.real, verbose=self.verbose)