def test_linear(): # initialize the power c = Cosmology().match(sigma8=0.82) P = LinearPower(c, redshift=0, transfer='CLASS') # check velocity dispersion assert_allclose(P.velocity_dispersion(), 5.898, rtol=1e-3) # test sigma8 assert_allclose(P.sigma_r(8.), c.sigma8, rtol=1e-5) # change sigma8 P.sigma8 = 0.80 c = c.match(sigma8=0.80) assert_allclose(P.sigma_r(8.), P.sigma8, rtol=1e-5) # change redshift and test sigma8(z) P.redshift = 0.55 assert_allclose(P.sigma_r(8.), c.sigma8_z(P.redshift), rtol=1e-5) # desired wavenumbers (in h/Mpc) k = numpy.logspace(-3, 2, 500) # initialize EH power P1 = LinearPower(c, redshift=0., transfer="CLASS") P2 = LinearPower(c, redshift=0., transfer='EisensteinHu') P3 = LinearPower(c, redshift=0., transfer='NoWiggleEisensteinHu') # check different transfers (very roughly) Pk1 = P1(k) Pk2 = P2(k) Pk3 = P3(k) assert_allclose(Pk1 / Pk1.max(), Pk2 / Pk2.max(), rtol=0.1) assert_allclose(Pk1 / Pk1.max(), Pk3 / Pk3.max(), rtol=0.1) # also try scalar Pk = P(0.1)
def run_ConvolvedFFTPower(galaxy_path, random_path, output_path, use_systot=True, zmin=None, zmax=None, compmin=0.5, cosmology=None, boxsize=None, nmesh=512, dk=0.002, poles=[0, 2, 4], kmax=None, comm=None, return_pk=False): if isinstance(nmesh, list): if len(nmesh)==1: nmesh=nmesh[0] if isinstance(boxsize, list): if len(boxsize)==1: boxsize=boxsize[0] if (cosmology is None) or (cosmology=='boss'): # the fiducial BOSS DR12 cosmology # see Alam et al. https://arxiv.org/abs/1607.03155 cosmo = Cosmology(h=0.676).match(Omega0_m=0.31) elif cosmology=='ezmock': _h = 0.6777 _Ob0 = 0.048206 _Ocdm0 = 0.307115 - _Ob0 cosmo = Cosmology(h=_h, Omega_b=_Ob0, Omega_cdm=_Ocdm0, m_ncdm=None, n_s=0.9611, T_cmb=2.7255).match(sigma8=0.8225) elif cosmology=='boss2': h = 0.676 redshift = 1.48 cos = Cosmology(h=0.676,Omega0_b=0.022/h**2,n_s=0.97).match(Omega0_m=0.31) cosmo = cos.match(sigma8=0.8) elif isinstance(cosmology, Cosmology): cosmo = cosmology else: raise NotImplementedError(f'{cosmology} is not implemented') data = FITSCat(galaxy_path) random = FITSCat(random_path) # select based on redshift and comp_BOSS kwargs = dict(compmin=compmin, zmin=zmin, zmax=zmax) data = data.trim_redshift_range(**kwargs) random = random.trim_redshift_range(**kwargs) # sky to xyz data.sky_to_xyz(cosmo) random.sky_to_xyz(cosmo) # prepare weights data.apply_weight(use_systot=use_systot) random.apply_weight(use_systot=True) # always weight randoms by systot # combine the data and randoms into a single catalog mesh_kwargs = {'interlaced': True,'window': 'tsc'} fkp = nb.FKPCatalog(data, random, nbar='NZ', BoxSize=boxsize) mesh = fkp.to_mesh(Nmesh=nmesh, fkp_weight='WEIGHT_FKP', **mesh_kwargs) r = nb.ConvolvedFFTPower(mesh, poles=poles, dk=dk, kmin=0.0, kmax=kmax) comm.Barrier() if comm.rank == 0: for parameter in ['sigma8', 'Omega0_m', 'h', 'n_s', 'Omega0_b', 'Omega0_lambda']: r.attrs[parameter] = getattr(cosmo, parameter) if comm.rank == 0: output_dir = os.path.dirname(os.path.abspath(output_path)) if not os.path.exists(output_dir): os.makedirs(output_dir) r.save(output_path) if return_pk: if comm.rank == 0: return r