def readcat(path, subsample=False): # Only used to compute concentration etc from halo mass # thus no need to be accurate. CP = cosmology.Cosmology(Omega0_cdm=0.3, h=0.677, Omega0_b=.05) cat = BigFileCatalog(path, dataset='LL-0.200') if subsample: cat = cat[:subsample] M0 = cat.attrs['M0'] * 1e10 if cat.comm.rank == 0: cat.logger.info("mass of a particle %e" % M0) cat['Mass'] = cat['Length'] * M0 if 'Aemit' in cat.columns: redshift = 1 / cat['Aemit'] - 1 else: redshift = 1 / cat.attrs['Time'] - 1 cat['conc'] = transform.HaloConcentration( cat['Mass'], CP, redshift).compute(scheduler="single-threaded") # proper to comoving cat['rvir'] = transform.HaloRadius(cat['Mass'], CP, redshift).compute() * (1 + redshift) cat['vdisp'] = transform.HaloVelocityDispersion(cat['Mass'], CP, redshift).compute() if 'Aemit' not in cat.columns: cat['Aemit'] = cat.attrs['Time'][0] mean, std = stat(cat['Aemit'].compute(), cat.comm) if cat.comm.rank == 0: cat.logger.info("Aemit mean = %g std = %g" % (mean, std)) mean, std = stat(cat['Mass'].compute(), cat.comm) if cat.comm.rank == 0: cat.logger.info("mass mean, std = %g, %g" % (mean, std)) mean, std = stat(cat['conc'].compute(), cat.comm) if cat.comm.rank == 0: cat.logger.info("conc mean, std = %g, %g" % (mean, std)) mean, std = stat(cat['rvir'].compute(), cat.comm) if cat.comm.rank == 0: cat.logger.info("rvir mean, std = %g, %g" % (mean, std)) mean, std = stat(cat['vdisp'].compute(), cat.comm) if cat.comm.rank == 0: cat.logger.info("vdisp mean, std = %g, %g" % (mean, std)) cat.attrs['BoxSize'] = numpy.ones(3) * cat.attrs['BoxSize'][0] return cat
def __init__(self, h=0.67556, T0_cmb=2.7255, Omega0_b=0.0482754208891869, Omega0_cdm=0.26377065934278865, N_ur=None, m_ncdm=[0.06], P_k_max=10.0, P_z_max=100.0, sigma8=0.8225, gauge='synchronous', n_s=0.9667, nonlinear=False): # input parameters kw_cosmo = locals() kw_cosmo.pop('self') for kw, val in kw_cosmo.items(): print(f'{kw:10s}: {val}') sigma8 = kw_cosmo.pop('sigma8') cosmo = cosmology.Cosmology(**kw_cosmo).match(sigma8=sigma8) # --- cosmology calculators redshift = 0.0 delta_crit = 1.686 # critical overdensity for collapse from Press-Schechter DH = ( cosmo.H0 / cosmo.C ) # in units of h/Mpc, eq. 4 https://arxiv.org/pdf/astro-ph/9905116.pdf Omega0_m = cosmo.Omega0_m k_ = np.logspace(-10, 10, 10000) Plin_ = cosmology.LinearPower(cosmo, redshift, transfer='CLASS') # P(k) in (Mpc/h)^3 self.Plin = IUS(k_, Plin_(k_), ext=1) Tlin_ = cosmology.transfers.CLASS( cosmo, redshift) # T(k), normalized to one at k=0 tk_ = Tlin_(k_) is_good = np.isfinite(tk_) self.Tlin = IUS(k_[is_good], tk_[is_good], ext=1) self.Dlin = cosmo.scale_independent_growth_factor # D(z), normalized to one at z=0 self.f = cosmo.scale_independent_growth_rate # dlnD/dlna self.Dc = cosmo.comoving_distance self.h = cosmo.efunc self.inv_pi = 2.0 / np.pi # alpha_fnl: equation 2 of Mueller et al 2017 self.alpha_fnl = 3.0 * delta_crit * Omega0_m * (DH**2)
def init_plin(self): h = 0.676 Omega_nu = 0.00140971 Omega0_m = 0.31 Omega0_b = 0.022 / h**2 Omega0_cdm = Omega0_m - Omega0_b - Omega_nu n_s = 0.96 sigma8 = 0.824 cosmo = cosmology.Cosmology(h=h, Omega0_b=Omega0_b, Omega0_cdm=Omega0_cdm, n_s=n_s) cosmo.match(sigma8=sigma8) redshift = 0.57 self.Plin = LinearPower(cosmo, redshift, transfer='CLASS')
def generate_data(x): redshift = 0.0 r_vals = np.linspace(50, 140, 10) extra_input = {'redshift': redshift, 'r_vals': r_vals} n_data = x.shape[1] y = np.empty((len(r_vals), n_data)) for i in range(n_data): print(i) om, s8, ob = x[:, i] ocdm = om - ob m_ncdm = [] #no massive neutrinos cosmo = cosmology.Cosmology(Omega0_b=ob, Omega0_cdm=ocdm, m_ncdm=m_ncdm) cosmo = cosmo.match(sigma8=s8) plin = cosmology.LinearPower(cosmo, redshift, transfer='EisensteinHu') cf = cosmology.correlation.CorrelationFunction(plin) y[:, i] = cf(r_vals) return y, extra_input
def bias_model_lrg(z): """ arxiv.org/abs/2001.06018 """ kw_cosmo = dict(h=0.67556, T0_cmb=2.7255, Omega0_b=0.0482754208891869, Omega0_cdm=0.26377065934278865, N_ur=None, m_ncdm=[0.06], P_k_max=10.0, P_z_max=100.0, sigma8=0.8225, gauge='synchronous', n_s=0.9667, nonlinear=False) sigma8 = kw_cosmo.pop('sigma8') cosmo = cosmology.Cosmology(**kw_cosmo).match(sigma8=sigma8) Dlin = cosmo.scale_independent_growth_factor # D(z), normalized to one at z=0 return 1.42 / Dlin(z)
def plot_spectrum_nowiggle_comparison(): from matplotlib import pyplot k,pklin = load_pklin() spectrum_nowiggle = SpectrumNoWiggle(k=k) cosmo_kwargs = dict(Omega_m=0.31,omega_b=0.022,h=0.676,n_s=0.97) spectrum_nowiggle.run_terms(pk=pklin,**cosmo_kwargs) tk = spectrum_nowiggle.transfer() from nbodykit.cosmology.power.transfers import NoWiggleEisensteinHu from nbodykit import cosmology cosmo_kwargs = dict(Omega_m=0.31,omega_b=0.022,h=0.676,sigma8=0.8,n_s=0.97,N_ur=2.0328,m_ncdm=[0.06]) cosmo_kwargs['Omega0_b'] = cosmo_kwargs.pop('omega_b')/cosmo_kwargs['h']**2 Omega0_m = cosmo_kwargs.pop('Omega_m') sigma8 = cosmo_kwargs.pop('sigma8') cosmo = cosmology.Cosmology(**cosmo_kwargs).match(Omega0_m=Omega0_m).match(sigma8=sigma8) eh = NoWiggleEisensteinHu(cosmo,redshift=0.)(k) pyplot.loglog(k,pklin,label='$P_{\\rm lin}$') pyplot.loglog(k,tk,label='$P_{\\rm nowiggle}$') pyplot.loglog(k,eh,label='nbodykit') pyplot.legend() pyplot.show()
grid_mesh = 1024 Boxsize = cata_6411.attrs['BoxSize'] / 1000. print(r"Nmesh = {:.0f}, a_sqrt = {:.0f}, BoxSize = {:.0f}".format( grid_mesh, a_sqrt, Boxsize)) mesh_6411 = cata_6411.to_mesh(Nmesh=grid_mesh, BoxSize=Boxsize, resampler='cic') mesh_6411 = mesh_6411.compute() print(mesh_6411.shape) # xi_6411 = FFTCorr(mesh_6411, mode='1d') redshift = cata_6411.attrs['Redshift'] cosmo = cosmology.Cosmology( h=cata_6411.attrs['HubbleParam'], P_k_max=200).match(Omega0_m=cata_6411.attrs['Omega0']) pk_cosmo = cosmology.LinearPower(cosmo, redshift, transfer='EisensteinHu') def VectorProjection(vector, direction): r""" Vector components of given vectors in a given direction. .. math:: \mathbf{v}_\mathbf{d} &= (\mathbf{v} \cdot \hat{\mathbf{d}}) \hat{\mathbf{d}} \\ \hat{\mathbf{d}} &= \frac{\mathbf{d}}{\|\mathbf{d}\|} Parameters ----------
cata_fa = BigFileCatalog('/home/yuyu22/testfast/B2T10/snapshot/fastpm_1.0000/',dataset='1/',header='Header/') cata_fa.attrs grid_mesh = 1024 print("Nmesh = ", grid_mesh) Boxsize = 500 mesh_fa = cata_fa.to_mesh(Nmesh=grid_mesh, BoxSize=Boxsize, resampler='cic') mesh_fa = mesh_fa.compute() print(mesh_fa.shape) # xi_fa = FFTCorr(mesh_fa, mode='1d') redshift = 0.0; cosmo = cosmology.Cosmology(h=0.6898, P_k_max=200).match(Omega0_m=0.2905) pk_cosmo = cosmology.LinearPower(cosmo, redshift, transfer='EisensteinHu') def VectorProjection(vector, direction): r""" Vector components of given vectors in a given direction. .. math:: \mathbf{v}_\mathbf{d} &= (\mathbf{v} \cdot \hat{\mathbf{d}}) \hat{\mathbf{d}} \\ \hat{\mathbf{d}} &= \frac{\mathbf{d}}{\|\mathbf{d}\|} Parameters ---------- vector : array_like, (..., D) array of vectors to be projected