Skip to main content

HMCode 的 Python 接口

项目描述

密码

这个库为 Alexander Mead 的库提供了一个方便的接口,该库是 HMCode 和 HMx 代码的基础,用于预测非线性功率谱。有关 Fortran 版本的详细信息,请参阅https://github.com/alexander-mead/HMcodepyhmcode接口使用优秀的f90wrap生成python接口。这允许访问库中的几乎所有功能,尽管为了加快编译速度,该接口仅限于常用子例程。如果您使用pyhmcode,请引用Tröster、Mead 等人。2021 年和描述该模型的相关论文:

安装

pyhmcode是可pip安装的,所以

pip install pyhmcode

应该做的伎俩。为了更好地控制安装和访问替代界面以及 CosmoSIS 支持,可以使用以下命令克隆存储库

git clone --recursive https://github.com/tilmantroester/pyhmcode

替代接口和 CosmoSIS 支持

powerspectrum_interface在子目录中有一个计算功率谱的替代接口。该接口使用ctypes一个瘦 Fortran 包装器来访问 HMCode 和 HMx 的主要功能,即预测非线性功率谱。安装通过

cd powerspectrum_interface
pip install .

这将安装pyhmxpython 模块,该模块又使用该模块与 CosmoSIS 接口cosmosis_interface.py

演示

notebooksexample子目录包含许多关于如何使用接口的示例。下面显示了一个基本示例(来自examples/basic_example.py),显示了使用pyhmcode生成非线性功率谱,以及它与 CCL 的集成。

import pyhmcode
import pyhmcode.halo_profile_utils

# We use CCL to generate the linear power spectrum
import pyccl as ccl

import numpy as np


ccl_cosmology = ccl.CosmologyVanillaLCDM()

k = np.logspace(-4, 1.5, 100)
a = np.linspace(1/(1+6), 1, 10)
z = 1/a - 1

pofk_lin = np.array([ccl.linear_matter_power(ccl_cosmology, k=k, a=a_)
                     for a_ in a])

# CCL uses units of Mpc, while pyhmcode uses Mpc/h. Hence we need to convert
# the units here.
h = ccl_cosmology["h"]
k = k/h
pofk_lin = pofk_lin * h**3

# Create the pyhmcode cosmology object. Beside the cosmology parameters, it
# also holds the linear power spectrum.
hmcode_cosmology = pyhmcode.halo_profile_utils.ccl2hmcode_cosmo(
                        ccl_cosmo=ccl_cosmology,
                        pofk_lin_k_h=k,
                        pofk_lin_z=z[::-1],
                        pofk_lin=pofk_lin[::-1],
                        log10_T_heat=7.8)

# Create the halo model object, which holds information on the specific halo
# model to use. E.g., the HMCode or HMx version.
hmcode_model = pyhmcode.Halomodel(
                    pyhmcode.HMx2020_matter_pressure_w_temp_scaling)

# Now we can compute the non-linear power spectrum, given the cosmology,
# halo model, and a list of fields.
hmcode_pofk = pyhmcode.calculate_nonlinear_power_spectrum(
                                    cosmology=hmcode_cosmology,
                                    halomodel=hmcode_model, 
                                    fields=[pyhmcode.field_matter,
                                            pyhmcode.field_electron_pressure])

# The output of calculate_nonlinear_power_spectrum has
# shape (n_field, n_field, n_z, n_k).
matter_matter_pofk = hmcode_pofk[0, 0]
matter_electron_pressure_pofk = hmcode_pofk[0, 1]

# We can also use the halo profiles from HMCode or HMx and use them in another
# halo model code.
profile_generator = pyhmcode.halo_profile_utils.HMxProfileGenerator(
                        hmcode_cosmology,
                        a_arr=a, k_arr=k,
                        fields=[pyhmcode.field_matter,
                                pyhmcode.field_cdm,
                                pyhmcode.field_electron_pressure],
                        add_diffuse=False)

# Here we use the halo profile in the CCL halo model framework. 
# First setup the CCL halo model specification
mass_def = ccl.halos.MassDef("vir", 'matter')
hmf = ccl.halos.MassFuncSheth99(ccl_cosmology, mass_def=mass_def,
                                mass_def_strict=False, use_delta_c_fit=True)
hbf = ccl.halos.HaloBiasSheth99(ccl_cosmology, mass_def=mass_def,
                                mass_def_strict=False, use_delta_c_fit=True)
hmc = ccl.halos.HMCalculator(ccl_cosmology, hmf, hbf, mass_def)

# Compute the CCL halo model power spectrum, using the halo profile from HMx
ccl_halomodel_pofk = ccl.halos.halomod_Pk2D(
                            cosmo=ccl_cosmology,
                            hmc=hmc, 
                            prof=profile_generator.matter_profile,
                            normprof1=False,
                            a_arr=a, lk_arr=np.log(k*h))

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

pyhmcode-1.0.0.tar.gz (352.6 kB 查看哈希

已上传 source