classy-szfast 0.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- classy_szfast/__init__.py +14 -0
- classy_szfast/classy_sz.py +547 -0
- classy_szfast/classy_szfast.py +933 -0
- classy_szfast/config.py +10 -0
- classy_szfast/cosmopower.py +259 -0
- classy_szfast/cosmosis_classy_szfast_interface.py +331 -0
- classy_szfast/custom_bias/__init__.py +0 -0
- classy_szfast/custom_bias/custom_bias.py +20 -0
- classy_szfast/custom_profiles/__init__.py +0 -0
- classy_szfast/custom_profiles/custom_profiles.py +45 -0
- classy_szfast/pks_and_sigmas.py +150 -0
- classy_szfast/restore_nn.py +395 -0
- classy_szfast/suppress_warnings.py +10 -0
- classy_szfast/utils.py +62 -0
- classy_szfast-0.0.0.dist-info/METADATA +15 -0
- classy_szfast-0.0.0.dist-info/RECORD +18 -0
- classy_szfast-0.0.0.dist-info/WHEEL +5 -0
- classy_szfast-0.0.0.dist-info/top_level.txt +1 -0
classy_szfast/config.py
ADDED
@@ -0,0 +1,259 @@
|
|
1
|
+
from .utils import *
|
2
|
+
from .config import *
|
3
|
+
|
4
|
+
from .restore_nn import Restore_NN
|
5
|
+
from .restore_nn import Restore_PCAplusNN
|
6
|
+
from .suppress_warnings import suppress_warnings
|
7
|
+
|
8
|
+
dofftlog_alphas = False
|
9
|
+
|
10
|
+
cosmopower_derived_params_names = ['100*theta_s',
|
11
|
+
'sigma8',
|
12
|
+
'YHe',
|
13
|
+
'z_reio',
|
14
|
+
'Neff',
|
15
|
+
'tau_rec',
|
16
|
+
'z_rec',
|
17
|
+
'rs_rec',
|
18
|
+
'ra_rec',
|
19
|
+
'tau_star',
|
20
|
+
'z_star',
|
21
|
+
'rs_star',
|
22
|
+
'ra_star',
|
23
|
+
'rs_drag']
|
24
|
+
|
25
|
+
cp_l_max_scalars = 11000 # max multipole of train ing data
|
26
|
+
|
27
|
+
cosmo_model_list = [
|
28
|
+
'lcdm',
|
29
|
+
'mnu',
|
30
|
+
'neff',
|
31
|
+
'wcdm',
|
32
|
+
'ede',
|
33
|
+
'mnu-3states',
|
34
|
+
'ede-v2'
|
35
|
+
]
|
36
|
+
|
37
|
+
emulator_dict = {}
|
38
|
+
emulator_dict['lcdm'] = {}
|
39
|
+
emulator_dict['mnu'] = {}
|
40
|
+
emulator_dict['neff'] = {}
|
41
|
+
emulator_dict['wcdm'] = {}
|
42
|
+
emulator_dict['ede'] = {}
|
43
|
+
emulator_dict['mnu-3states'] = {}
|
44
|
+
emulator_dict['ede-v2'] = {}
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
emulator_dict['lcdm']['TT'] = 'TT_v1'
|
50
|
+
emulator_dict['lcdm']['TE'] = 'TE_v1'
|
51
|
+
emulator_dict['lcdm']['EE'] = 'EE_v1'
|
52
|
+
emulator_dict['lcdm']['PP'] = 'PP_v1'
|
53
|
+
emulator_dict['lcdm']['PKNL'] = 'PKNL_v1'
|
54
|
+
emulator_dict['lcdm']['PKL'] = 'PKL_v1'
|
55
|
+
emulator_dict['lcdm']['PKLFFTLOG_ALPHAS_REAL'] = 'PKLFFTLOGALPHAS_creal_v1'
|
56
|
+
emulator_dict['lcdm']['PKLFFTLOG_ALPHAS_IMAG'] = 'PKLFFTLOGALPHAS_cimag_v1'
|
57
|
+
emulator_dict['lcdm']['DER'] = 'DER_v1'
|
58
|
+
emulator_dict['lcdm']['DAZ'] = 'DAZ_v1'
|
59
|
+
emulator_dict['lcdm']['HZ'] = 'HZ_v1'
|
60
|
+
emulator_dict['lcdm']['S8Z'] = 'S8Z_v1'
|
61
|
+
emulator_dict['lcdm']['default'] = {}
|
62
|
+
emulator_dict['lcdm']['default']['tau_reio'] = 0.054
|
63
|
+
emulator_dict['lcdm']['default']['N_ur'] = 2.0328
|
64
|
+
emulator_dict['lcdm']['default']['N_ncdm'] = 1
|
65
|
+
emulator_dict['lcdm']['default']['m_ncdm'] = 0.06
|
66
|
+
|
67
|
+
emulator_dict['mnu']['TT'] = 'TT_mnu_v1'
|
68
|
+
emulator_dict['mnu']['TE'] = 'TE_mnu_v1'
|
69
|
+
emulator_dict['mnu']['EE'] = 'EE_mnu_v1'
|
70
|
+
emulator_dict['mnu']['PP'] = 'PP_mnu_v1'
|
71
|
+
emulator_dict['mnu']['PKNL'] = 'PKNL_mnu_v1'
|
72
|
+
emulator_dict['mnu']['PKL'] = 'PKL_mnu_v1'
|
73
|
+
emulator_dict['mnu']['DER'] = 'DER_mnu_v1'
|
74
|
+
emulator_dict['mnu']['DAZ'] = 'DAZ_mnu_v1'
|
75
|
+
emulator_dict['mnu']['HZ'] = 'HZ_mnu_v1'
|
76
|
+
emulator_dict['mnu']['S8Z'] = 'S8Z_mnu_v1'
|
77
|
+
emulator_dict['mnu']['default'] = {}
|
78
|
+
emulator_dict['mnu']['default']['tau_reio'] = 0.054
|
79
|
+
emulator_dict['mnu']['default']['N_ur'] = 2.0328
|
80
|
+
emulator_dict['mnu']['default']['N_ncdm'] = 1
|
81
|
+
emulator_dict['mnu']['default']['m_ncdm'] = 0.06
|
82
|
+
|
83
|
+
emulator_dict['neff']['TT'] = 'TT_neff_v1'
|
84
|
+
emulator_dict['neff']['TE'] = 'TE_neff_v1'
|
85
|
+
emulator_dict['neff']['EE'] = 'EE_neff_v1'
|
86
|
+
emulator_dict['neff']['PP'] = 'PP_neff_v1'
|
87
|
+
emulator_dict['neff']['PKNL'] = 'PKNL_neff_v1'
|
88
|
+
emulator_dict['neff']['PKL'] = 'PKL_neff_v1'
|
89
|
+
emulator_dict['neff']['DER'] = 'DER_neff_v1'
|
90
|
+
emulator_dict['neff']['DAZ'] = 'DAZ_neff_v1'
|
91
|
+
emulator_dict['neff']['HZ'] = 'HZ_neff_v1'
|
92
|
+
emulator_dict['neff']['S8Z'] = 'S8Z_neff_v1'
|
93
|
+
emulator_dict['neff']['default'] = {}
|
94
|
+
emulator_dict['neff']['default']['tau_reio'] = 0.054
|
95
|
+
emulator_dict['neff']['default']['N_ur'] = 2.0328
|
96
|
+
emulator_dict['neff']['default']['N_ncdm'] = 1
|
97
|
+
emulator_dict['neff']['default']['m_ncdm'] = 0.06
|
98
|
+
|
99
|
+
|
100
|
+
emulator_dict['wcdm']['TT'] = 'TT_w_v1'
|
101
|
+
emulator_dict['wcdm']['TE'] = 'TE_w_v1'
|
102
|
+
emulator_dict['wcdm']['EE'] = 'EE_w_v1'
|
103
|
+
emulator_dict['wcdm']['PP'] = 'PP_w_v1'
|
104
|
+
emulator_dict['wcdm']['PKNL'] = 'PKNL_w_v1'
|
105
|
+
emulator_dict['wcdm']['PKL'] = 'PKL_w_v1'
|
106
|
+
emulator_dict['wcdm']['DER'] = 'DER_w_v1'
|
107
|
+
emulator_dict['wcdm']['DAZ'] = 'DAZ_w_v1'
|
108
|
+
emulator_dict['wcdm']['HZ'] = 'HZ_w_v1'
|
109
|
+
emulator_dict['wcdm']['S8Z'] = 'S8Z_w_v1'
|
110
|
+
emulator_dict['wcdm']['default'] = {}
|
111
|
+
emulator_dict['wcdm']['default']['tau_reio'] = 0.054
|
112
|
+
emulator_dict['wcdm']['default']['N_ur'] = 2.0328
|
113
|
+
emulator_dict['wcdm']['default']['N_ncdm'] = 1
|
114
|
+
emulator_dict['wcdm']['default']['m_ncdm'] = 0.06
|
115
|
+
|
116
|
+
emulator_dict['ede']['TT'] = 'TT_v1'
|
117
|
+
emulator_dict['ede']['TE'] = 'TE_v1'
|
118
|
+
emulator_dict['ede']['EE'] = 'EE_v1'
|
119
|
+
emulator_dict['ede']['PP'] = 'PP_v1'
|
120
|
+
emulator_dict['ede']['PKNL'] = 'PKNL_v1'
|
121
|
+
emulator_dict['ede']['PKL'] = 'PKL_v1'
|
122
|
+
emulator_dict['ede']['DER'] = 'DER_v1'
|
123
|
+
emulator_dict['ede']['DAZ'] = 'DAZ_v1'
|
124
|
+
emulator_dict['ede']['HZ'] = 'HZ_v1'
|
125
|
+
emulator_dict['ede']['S8Z'] = 'S8Z_v1'
|
126
|
+
emulator_dict['ede']['default'] = {}
|
127
|
+
emulator_dict['ede']['default']['fEDE'] = 0.001
|
128
|
+
emulator_dict['ede']['default']['tau_reio'] = 0.054
|
129
|
+
emulator_dict['ede']['default']['log10z_c'] = 3.562 # e.g. from https://github.com/mwt5345/class_ede/blob/master/class/notebooks-ede/2-CMB-Comparison.ipynb
|
130
|
+
emulator_dict['ede']['default']['thetai_scf'] = 2.83 # e.g. from https://github.com/mwt5345/class_ede/blob/master/class/notebooks-ede/2-CMB-Comparison.ipynb
|
131
|
+
emulator_dict['ede']['default']['r'] = 0.
|
132
|
+
emulator_dict['ede']['default']['N_ur'] = 0.00641
|
133
|
+
emulator_dict['ede']['default']['N_ncdm'] = 3
|
134
|
+
emulator_dict['ede']['default']['m_ncdm'] = 0.02
|
135
|
+
|
136
|
+
|
137
|
+
emulator_dict['mnu-3states']['TT'] = 'TT_v1'
|
138
|
+
emulator_dict['mnu-3states']['TE'] = 'TE_v1'
|
139
|
+
emulator_dict['mnu-3states']['EE'] = 'EE_v1'
|
140
|
+
emulator_dict['mnu-3states']['PP'] = 'PP_v1'
|
141
|
+
emulator_dict['mnu-3states']['PKNL'] = 'PKNL_v1'
|
142
|
+
emulator_dict['mnu-3states']['PKL'] = 'PKL_v1'
|
143
|
+
emulator_dict['mnu-3states']['DER'] = 'DER_v1'
|
144
|
+
emulator_dict['mnu-3states']['DAZ'] = 'DAZ_v1'
|
145
|
+
emulator_dict['mnu-3states']['HZ'] = 'HZ_v1'
|
146
|
+
emulator_dict['mnu-3states']['S8Z'] = 'S8Z_v1'
|
147
|
+
emulator_dict['mnu-3states']['default'] = {}
|
148
|
+
emulator_dict['mnu-3states']['default']['tau_reio'] = 0.054
|
149
|
+
emulator_dict['mnu-3states']['default']['N_ur'] = 0.00641
|
150
|
+
emulator_dict['mnu-3states']['default']['N_ncdm'] = 3
|
151
|
+
emulator_dict['mnu-3states']['default']['m_ncdm'] = 0.02
|
152
|
+
|
153
|
+
emulator_dict['ede-v2']['TT'] = 'TT_v2'
|
154
|
+
emulator_dict['ede-v2']['TE'] = 'TE_v2'
|
155
|
+
emulator_dict['ede-v2']['EE'] = 'EE_v2'
|
156
|
+
emulator_dict['ede-v2']['PP'] = 'PP_v2'
|
157
|
+
emulator_dict['ede-v2']['PKNL'] = 'PKNL_v2'
|
158
|
+
emulator_dict['ede-v2']['PKL'] = 'PKL_v2'
|
159
|
+
emulator_dict['ede-v2']['DER'] = 'DER_v2'
|
160
|
+
emulator_dict['ede-v2']['DAZ'] = 'DAZ_v2'
|
161
|
+
emulator_dict['ede-v2']['HZ'] = 'HZ_v2'
|
162
|
+
emulator_dict['ede-v2']['S8Z'] = 'S8Z_v2'
|
163
|
+
|
164
|
+
emulator_dict['ede-v2']['default'] = {}
|
165
|
+
emulator_dict['ede-v2']['default']['fEDE'] = 0.001
|
166
|
+
emulator_dict['ede-v2']['default']['tau_reio'] = 0.054
|
167
|
+
emulator_dict['ede-v2']['default']['H0'] = 67.66
|
168
|
+
emulator_dict['ede-v2']['default']['ln10^{10}A_s'] = 3.047
|
169
|
+
emulator_dict['ede-v2']['default']['omega_b'] = 0.02242
|
170
|
+
emulator_dict['ede-v2']['default']['omega_cdm'] = 0.11933
|
171
|
+
emulator_dict['ede-v2']['default']['log10z_c'] = 3.562 # e.g. from https://github.com/mwt5345/class_ede/blob/master/class/notebooks-ede/2-CMB-Comparison.ipynb
|
172
|
+
emulator_dict['ede-v2']['default']['thetai_scf'] = 2.83 # e.g. from https://github.com/mwt5345/class_ede/blob/master/class/notebooks-ede/2-CMB-Comparison.ipynb
|
173
|
+
emulator_dict['ede-v2']['default']['r'] = 0.
|
174
|
+
emulator_dict['ede-v2']['default']['N_ur'] = 0.00441
|
175
|
+
emulator_dict['ede-v2']['default']['N_ncdm'] = 3
|
176
|
+
emulator_dict['ede-v2']['default']['m_ncdm'] = 0.02
|
177
|
+
|
178
|
+
|
179
|
+
cp_tt_nn = {}
|
180
|
+
cp_te_nn = {}
|
181
|
+
cp_ee_nn = {}
|
182
|
+
cp_pp_nn = {}
|
183
|
+
cp_pknl_nn = {}
|
184
|
+
cp_pkl_nn = {}
|
185
|
+
cp_pkl_fftlog_alphas_real_nn = {}
|
186
|
+
cp_pkl_fftlog_alphas_imag_nn = {}
|
187
|
+
cp_pkl_fftlog_alphas_nus = {}
|
188
|
+
cp_der_nn = {}
|
189
|
+
cp_da_nn = {}
|
190
|
+
cp_h_nn = {}
|
191
|
+
cp_s8_nn = {}
|
192
|
+
|
193
|
+
import warnings
|
194
|
+
from contextlib import contextmanager
|
195
|
+
import logging
|
196
|
+
|
197
|
+
# Suppress absl warnings
|
198
|
+
import absl.logging
|
199
|
+
absl.logging.set_verbosity('error')
|
200
|
+
# Suppress TensorFlow warnings
|
201
|
+
import os
|
202
|
+
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
|
203
|
+
with suppress_warnings():
|
204
|
+
import tensorflow as tf
|
205
|
+
tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)
|
206
|
+
|
207
|
+
|
208
|
+
import re
|
209
|
+
|
210
|
+
def split_emulator_string(input_string):
|
211
|
+
match = re.match(r"(.+)-v(\d+)", input_string)
|
212
|
+
if match:
|
213
|
+
folder = match.group(1)
|
214
|
+
version = match.group(2)
|
215
|
+
return folder, version
|
216
|
+
else:
|
217
|
+
folder = input_string
|
218
|
+
version = '1'
|
219
|
+
return folder, version
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
|
224
|
+
for mp in cosmo_model_list:
|
225
|
+
folder, version = split_emulator_string(mp)
|
226
|
+
# print(folder, version)
|
227
|
+
path_to_emulators = path_to_cosmopower_organization + '/' + folder +'/'
|
228
|
+
|
229
|
+
cp_tt_nn[mp] = Restore_NN(restore_filename=path_to_emulators + 'TTTEEE/' + emulator_dict[mp]['TT'])
|
230
|
+
|
231
|
+
cp_te_nn[mp] = Restore_PCAplusNN(restore_filename=path_to_emulators + 'TTTEEE/' + emulator_dict[mp]['TE'])
|
232
|
+
|
233
|
+
with suppress_warnings():
|
234
|
+
cp_ee_nn[mp] = Restore_NN(restore_filename=path_to_emulators + 'TTTEEE/' + emulator_dict[mp]['EE'])
|
235
|
+
|
236
|
+
cp_pp_nn[mp] = Restore_NN(restore_filename=path_to_emulators + 'PP/' + emulator_dict[mp]['PP'])
|
237
|
+
|
238
|
+
cp_pknl_nn[mp] = Restore_NN(restore_filename=path_to_emulators + 'PK/' + emulator_dict[mp]['PKNL'])
|
239
|
+
|
240
|
+
cp_pkl_nn[mp] = Restore_NN(restore_filename=path_to_emulators + 'PK/' + emulator_dict[mp]['PKL'])
|
241
|
+
|
242
|
+
if (mp == 'lcdm') and (dofftlog_alphas == True):
|
243
|
+
cp_pkl_fftlog_alphas_real_nn[mp] = Restore_PCAplusNN(restore_filename=path_to_emulators + 'PK/' + emulator_dict[mp]['PKLFFTLOG_ALPHAS_REAL']
|
244
|
+
)
|
245
|
+
cp_pkl_fftlog_alphas_imag_nn[mp] = Restore_PCAplusNN(restore_filename=path_to_emulators + 'PK/' + emulator_dict[mp]['PKLFFTLOG_ALPHAS_IMAG']
|
246
|
+
)
|
247
|
+
cp_pkl_fftlog_alphas_nus[mp] = np.load(path_to_emulators + 'PK/PKL_FFTLog_alphas_nu_v1.npz')
|
248
|
+
|
249
|
+
cp_der_nn[mp] = Restore_NN(restore_filename=path_to_emulators + 'derived-parameters/' + emulator_dict[mp]['DER'])
|
250
|
+
|
251
|
+
cp_da_nn[mp] = Restore_NN(restore_filename=path_to_emulators + 'growth-and-distances/' + emulator_dict[mp]['DAZ'])
|
252
|
+
|
253
|
+
cp_h_nn[mp] = Restore_NN(restore_filename=path_to_emulators + 'growth-and-distances/' + emulator_dict[mp]['HZ'])
|
254
|
+
|
255
|
+
cp_s8_nn[mp] = Restore_NN(restore_filename=path_to_emulators + 'growth-and-distances/' + emulator_dict[mp]['S8Z'])
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
|
@@ -0,0 +1,331 @@
|
|
1
|
+
from builtins import str
|
2
|
+
import os
|
3
|
+
from cosmosis.datablock import names, option_section
|
4
|
+
import sys
|
5
|
+
import traceback
|
6
|
+
import warnings
|
7
|
+
|
8
|
+
# add class directory to the path
|
9
|
+
dirname = os.path.split(__file__)[0]
|
10
|
+
# enable debugging from the same directory
|
11
|
+
if not dirname.strip():
|
12
|
+
dirname = '.'
|
13
|
+
|
14
|
+
import numpy as np
|
15
|
+
|
16
|
+
# These are pre-defined strings we use as datablock
|
17
|
+
# section names
|
18
|
+
cosmo = names.cosmological_parameters
|
19
|
+
distances = names.distances
|
20
|
+
cmb_cl = names.cmb_cl
|
21
|
+
|
22
|
+
|
23
|
+
def setup(options):
|
24
|
+
# class_version = options.get_string(option_section, "version", "3.2.0")
|
25
|
+
# pyversion = f"{sys.version_info.major}.{sys.version_info.minor}"
|
26
|
+
# install_dir = dirname + f"/class_v{class_version}/classy_install/lib/python{pyversion}/site-packages/"
|
27
|
+
# with open(f"{install_dir}/easy-install.pth") as f:
|
28
|
+
# pth = f.read().strip()
|
29
|
+
# install_dir = install_dir + pth
|
30
|
+
# install_dir = '/Users/boris/opt/miniconda3/lib/python3.9/site-packages/classy_sz-2.9.4-py3.9-macosx-11.0-arm64.egg/classy_sz.cpython-39-darwin.so'
|
31
|
+
# sys.path.insert(0, install_dir)
|
32
|
+
|
33
|
+
import classy_sz as classy
|
34
|
+
print(f"Loaded classy_sz from {classy.__file__}")
|
35
|
+
|
36
|
+
# Read options from the ini file which are fixed across
|
37
|
+
# the length of the chain
|
38
|
+
config = {
|
39
|
+
'lmax': options.get_int(option_section, 'lmax', default=2000),
|
40
|
+
'zmax': options.get_double(option_section, 'zmax', default=3.0),
|
41
|
+
'kmax': options.get_double(option_section, 'kmax', default=50.0),
|
42
|
+
'debug': options.get_bool(option_section, 'debug', default=False),
|
43
|
+
'lensing': options.get_bool(option_section, 'lensing', default=True),
|
44
|
+
'cmb': options.get_bool(option_section, 'cmb', default=True),
|
45
|
+
'mpk': options.get_bool(option_section, 'mpk', default=True),
|
46
|
+
'save_matter_power_lin': options.get_bool(option_section, 'save_matter_power_lin', default=True),
|
47
|
+
'save_cdm_baryon_power_lin': options.get_bool(option_section, 'save_cdm_baryon_power_lin', default=False),
|
48
|
+
}
|
49
|
+
|
50
|
+
|
51
|
+
for _, key in options.keys(option_section):
|
52
|
+
if key.startswith('class_'):
|
53
|
+
config[key] = options[option_section, key]
|
54
|
+
|
55
|
+
|
56
|
+
# Create the object that connects to Class
|
57
|
+
config['cosmo'] = classy.Class()
|
58
|
+
|
59
|
+
# Return all this config information
|
60
|
+
return config
|
61
|
+
|
62
|
+
def choose_outputs(config):
|
63
|
+
outputs = []
|
64
|
+
if config['cmb']:
|
65
|
+
outputs.append("tCl pCl")
|
66
|
+
if config['lensing']:
|
67
|
+
outputs.append("lCl")
|
68
|
+
if config["mpk"]:
|
69
|
+
outputs.append("mPk")
|
70
|
+
return " ".join(outputs)
|
71
|
+
|
72
|
+
def get_class_inputs(block, config):
|
73
|
+
|
74
|
+
# Get parameters from block and give them the
|
75
|
+
# names and form that class expects
|
76
|
+
nnu = block.get_double(cosmo, 'nnu', 3.046)
|
77
|
+
nmassive = block.get_int(cosmo, 'num_massive_neutrinos', default=0)
|
78
|
+
|
79
|
+
# print(nmassive)
|
80
|
+
# print(block.get_double(cosmo, 'mnu', default=0.06))
|
81
|
+
# exit(0)
|
82
|
+
|
83
|
+
params = {
|
84
|
+
'output': choose_outputs(config),
|
85
|
+
'lensing': 'yes' if config['lensing'] else 'no',
|
86
|
+
'A_s': block[cosmo, 'A_s'],
|
87
|
+
'n_s': block[cosmo, 'n_s'],
|
88
|
+
'H0': 100 * block[cosmo, 'h0'],
|
89
|
+
'omega_b': block[cosmo, 'ombh2'],
|
90
|
+
'omega_cdm': block[cosmo, 'omch2'],
|
91
|
+
'tau_reio': block[cosmo, 'tau'],
|
92
|
+
'T_cmb': block.get_double(cosmo, 'TCMB', default=2.726),
|
93
|
+
# 'N_ur': nnu - nmassive,
|
94
|
+
# 'N_ncdm': nmassive,
|
95
|
+
# 'm_ncdm': block.get_double(cosmo, 'mnu', default=0.06)
|
96
|
+
|
97
|
+
# CLASS SETTINGS FOR COSMOPOWER
|
98
|
+
'N_ncdm': 1,
|
99
|
+
'N_ur': 2.0328,
|
100
|
+
'm_ncdm': 0.06,
|
101
|
+
|
102
|
+
# class_sz fast :
|
103
|
+
'ndim_redshifts' : 25 # number of z's in our pk interpolator
|
104
|
+
|
105
|
+
}
|
106
|
+
# print(params)
|
107
|
+
# exit(0)
|
108
|
+
|
109
|
+
if config["cmb"] or config["lensing"]:
|
110
|
+
params.update({
|
111
|
+
'l_max_scalars': config["lmax"],
|
112
|
+
})
|
113
|
+
|
114
|
+
|
115
|
+
if config["mpk"]:
|
116
|
+
params.update({
|
117
|
+
'P_k_max_h/Mpc': config["kmax"],
|
118
|
+
'z_pk': ', '.join(str(z) for z in np.arange(0.0, config['zmax'], 0.01)),
|
119
|
+
'z_max_pk': config['zmax'],
|
120
|
+
})
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
if block.has_value(cosmo, "massless_nu"):
|
125
|
+
warnings.warn("Parameter massless_nu is being ignored. Set nnu, the effective number of relativistic species in the early Universe.")
|
126
|
+
|
127
|
+
if (block.has_value(cosmo, "omega_nu") or block.has_value(cosmo, "omnuh2")) and not (block.has_value(cosmo, "mnu")):
|
128
|
+
warnings.warn("Parameter omega_nu and omnuh2 are being ignored. Set mnu and num_massive_neutrinos instead.")
|
129
|
+
|
130
|
+
|
131
|
+
for key,val in config.items():
|
132
|
+
if key.startswith('class_'):
|
133
|
+
params[key[6:]] = val
|
134
|
+
|
135
|
+
|
136
|
+
return params
|
137
|
+
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
def get_class_outputs(block, c, config):
|
142
|
+
##
|
143
|
+
# Derived cosmological parameters
|
144
|
+
##
|
145
|
+
|
146
|
+
h0 = block[cosmo, 'h0']
|
147
|
+
|
148
|
+
##
|
149
|
+
# Matter power spectrum
|
150
|
+
##
|
151
|
+
|
152
|
+
# Ranges of the redshift and matter power
|
153
|
+
dz = 0.01
|
154
|
+
kmin = 1e-4
|
155
|
+
kmax = config['kmax'] * h0
|
156
|
+
nk = 100
|
157
|
+
|
158
|
+
# Define k,z we want to sample
|
159
|
+
z = np.arange(0.0, config["zmax"] + dz, dz)
|
160
|
+
k = np.logspace(np.log10(kmin), np.log10(kmax), nk)
|
161
|
+
nz = len(z)
|
162
|
+
|
163
|
+
# Extract (interpolate) P(k,z) at the requested
|
164
|
+
# sample points.
|
165
|
+
# print(c.pars['output'])
|
166
|
+
# exit(0)
|
167
|
+
# if 'mPk' in c.pars['output']:
|
168
|
+
if 1==1:
|
169
|
+
#print('trying to get mPk')
|
170
|
+
#print('first getting sigma8')
|
171
|
+
# exit(0)
|
172
|
+
block[cosmo, 'sigma_8'] = c.sigma8()
|
173
|
+
#print('got sigma8:',c.sigma8())
|
174
|
+
#exit(0)
|
175
|
+
|
176
|
+
# Total matter power spectrum (saved as grid)
|
177
|
+
if config['save_matter_power_lin']:
|
178
|
+
P = np.zeros((k.size, z.size))
|
179
|
+
for i, ki in enumerate(k):
|
180
|
+
for j, zi in enumerate(z):
|
181
|
+
P[i, j] = c.pk_lin(ki, zi)
|
182
|
+
# print(np.shape(P * h0**3))
|
183
|
+
# exit(0)
|
184
|
+
# print('matter Pk:',P)
|
185
|
+
# exit(0)
|
186
|
+
block.put_grid("matter_power_lin", "k_h", k / h0, "z", z, "P_k", P * h0**3)
|
187
|
+
|
188
|
+
# CDM+baryons power spectrum
|
189
|
+
if config['save_cdm_baryon_power_lin']:
|
190
|
+
# P = np.zeros((k.size, z.size))
|
191
|
+
# for i, ki in enumerate(k):
|
192
|
+
# for j, zi in enumerate(z):
|
193
|
+
# P[i, j] = c.pk_cb_lin(ki, zi)
|
194
|
+
# block.put_grid('cdm_baryon_power_lin', 'k_h', k/h0, 'z', z, 'P_k', P*h0**3)\
|
195
|
+
print('save_cdm_baryon_power_lin not available with class_szfast yet')
|
196
|
+
exit(0)
|
197
|
+
|
198
|
+
# Get growth rates and sigma_8
|
199
|
+
D = [c.scale_independent_growth_factor(zi) for zi in z] # original class routine
|
200
|
+
# print('got D:',D)
|
201
|
+
f = [c.scale_independent_growth_factor_f(zi) for zi in z] # original class routine
|
202
|
+
# print('got f:',f)
|
203
|
+
# fsigma = [c.effective_f_sigma8(zi) for zi in z] # get this from the emulators
|
204
|
+
fsigma = [c.get_effective_f_sigma8(zi) for zi in z]
|
205
|
+
# print('got fsigma8:',fsigma)
|
206
|
+
# sigma_8_z = [c.sigma(8.0/h0, zi, h_units=True) for zi in z] # get this from the emulators, had to add h0 by hand in class v2.9.4 the hunits thing is not treated properly
|
207
|
+
sigma_8_z = [c.get_sigma8_at_z(zi) for zi in z] # get this from the emulators, had to add h0 by hand in class v2.9.4 the hunits thing is not treated properly
|
208
|
+
# print('sigma8z:',sigma_8_z)
|
209
|
+
# print('z:',z)
|
210
|
+
# exit(0)
|
211
|
+
block[names.growth_parameters, "z"] = z
|
212
|
+
block[names.growth_parameters, "sigma_8"] = np.array(sigma_8_z)
|
213
|
+
block[names.growth_parameters, "fsigma_8"] = np.array(fsigma)
|
214
|
+
block[names.growth_parameters, "d_z"] = np.array(D)
|
215
|
+
block[names.growth_parameters, "f_z"] = np.array(f)
|
216
|
+
block[names.growth_parameters, "a"] = 1/(1+z)
|
217
|
+
|
218
|
+
#print('getting nonlinear')
|
219
|
+
#print(c.nonlinear_method)
|
220
|
+
#print(config)
|
221
|
+
tmp_nonlinear_method = c.nonlinear_method
|
222
|
+
if 'class_non_linear' in config:
|
223
|
+
tmp_nonlinear_method = 1
|
224
|
+
#print(config['class_non_linear'])
|
225
|
+
|
226
|
+
if tmp_nonlinear_method != 0:
|
227
|
+
#print('entering nonlinear block')
|
228
|
+
for i, ki in enumerate(k):
|
229
|
+
for j, zi in enumerate(z):
|
230
|
+
P[i, j] = c.pk(ki, zi)
|
231
|
+
# print('got Pknl:',P)
|
232
|
+
block.put_grid("matter_power_nl", "k_h", k / h0, "z", z, "P_k", P * h0**3)
|
233
|
+
# exit(0)
|
234
|
+
# exit(0)
|
235
|
+
|
236
|
+
|
237
|
+
##
|
238
|
+
# Distances and related quantities
|
239
|
+
##
|
240
|
+
|
241
|
+
# print("moving on")
|
242
|
+
# save redshifts of samples
|
243
|
+
block[distances, 'z'] = z
|
244
|
+
block[distances, 'nz'] = nz
|
245
|
+
block[distances, 'a'] = 1/(1+z)
|
246
|
+
# Save distance samples
|
247
|
+
# print("moving on")
|
248
|
+
d_a = np.array([c.angular_distance(zi) for zi in z]) # original class routine
|
249
|
+
block[distances, 'd_a'] = d_a # original class routine
|
250
|
+
# block[distances, 'd_l'] = np.array([c.luminosity_distance(zi) for zi in z])
|
251
|
+
# print("moving on after ang")
|
252
|
+
block[distances, 'd_l'] = d_a * (1 + z)**2 # original class routine
|
253
|
+
block[distances, 'd_m'] = d_a * (1 + z) # original class routine
|
254
|
+
# print("moving on after distances")
|
255
|
+
# Save some auxiliary related parameters
|
256
|
+
block[distances, 'age'] = c.age() # original class routine
|
257
|
+
# print("moving on after age:",c.age())
|
258
|
+
block[distances, 'rs_zdrag'] = c.rs_drag() # original class routine
|
259
|
+
# print("moving on done after drag:",c.rs_drag())
|
260
|
+
# exit(0)
|
261
|
+
##
|
262
|
+
# Now the CMB C_ell
|
263
|
+
##
|
264
|
+
if config["cmb"]:
|
265
|
+
c_ell_data = c.lensed_cl() if config['lensing'] else c.raw_cl()
|
266
|
+
ell = c_ell_data['ell']
|
267
|
+
ell = ell[2:]
|
268
|
+
|
269
|
+
# Save the ell range
|
270
|
+
block[cmb_cl, "ell"] = ell
|
271
|
+
|
272
|
+
# t_cmb is in K, convert to mu_K, and add ell(ell+1) factor
|
273
|
+
tcmb_muk = block[cosmo, 'tcmb'] * 1e6
|
274
|
+
f = ell * (ell + 1.0) / 2 / np.pi * tcmb_muk**2
|
275
|
+
|
276
|
+
# Save each of the four spectra
|
277
|
+
for s in ['tt', 'ee', 'te', 'bb']:
|
278
|
+
block[cmb_cl, s] = c_ell_data[s][2:] * f
|
279
|
+
|
280
|
+
|
281
|
+
def execute(block, config):
|
282
|
+
import classy_sz as classy
|
283
|
+
c = config['cosmo']
|
284
|
+
|
285
|
+
try:
|
286
|
+
# Set input parameters
|
287
|
+
params = get_class_inputs(block, config)
|
288
|
+
params_values = params.copy()
|
289
|
+
A_s = params_values['A_s']
|
290
|
+
lnAs = np.log(1e10*A_s)
|
291
|
+
params_values['ln10^{10}A_s'] = lnAs
|
292
|
+
params_values.pop('A_s')
|
293
|
+
params_values['output'] = '' # remove all outputs cause things are taken care of by the emulators
|
294
|
+
params_values.pop('non_linear') # also pretend we dont compute mPk...
|
295
|
+
params_values.pop('z_max_pk')
|
296
|
+
params_values.pop('P_k_max_h/Mpc')
|
297
|
+
params_values.pop('z_pk')
|
298
|
+
# params_values['ndim_redshifts'] =
|
299
|
+
# print(params_values)
|
300
|
+
# exit(0)
|
301
|
+
c.set(params_values)
|
302
|
+
# exit(0)
|
303
|
+
|
304
|
+
|
305
|
+
# Run calculations
|
306
|
+
# c.compute()
|
307
|
+
# run the fast class_sz calculation using emulators
|
308
|
+
# print('computing class_sz fast:')
|
309
|
+
c.compute_class_szfast()
|
310
|
+
# print('class_sz fast computed')
|
311
|
+
# exit(0)
|
312
|
+
# restore the original parameter file:
|
313
|
+
# c.set(params)
|
314
|
+
|
315
|
+
# Extract outputs
|
316
|
+
get_class_outputs(block, c, config)
|
317
|
+
except classy.CosmoError as error:
|
318
|
+
if config['debug']:
|
319
|
+
sys.stderr.write("Error in class or class_sz. You set debug=T so here is more debug info:\n")
|
320
|
+
traceback.print_exc(file=sys.stderr)
|
321
|
+
else:
|
322
|
+
sys.stderr.write("Error in class or class_sz. Set debug=T for info: {}\n".format(error))
|
323
|
+
return 1
|
324
|
+
finally:
|
325
|
+
# Reset for re-use next time
|
326
|
+
c.struct_cleanup()
|
327
|
+
return 0
|
328
|
+
|
329
|
+
|
330
|
+
def cleanup(config):
|
331
|
+
config['cosmo'].empty()
|
File without changes
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import numpy as np
|
2
|
+
|
3
|
+
def custom1_b(z,classy_sz,*params):
|
4
|
+
# # e.g., we want (chi_star - chi)/chi
|
5
|
+
# chi_star = classy_sz.chi_star()
|
6
|
+
# chi = classy_sz.get_chi(z)
|
7
|
+
# H = classy_sz.Hubble(z)
|
8
|
+
# Rho_crit_0 = classy_sz.Rho_crit_0()
|
9
|
+
|
10
|
+
# h = classy_sz.h()
|
11
|
+
# H0 = classy_sz.Hubble(0)
|
12
|
+
|
13
|
+
|
14
|
+
# # example: cmb lensing
|
15
|
+
# if z==0.:
|
16
|
+
# w = 1e-100
|
17
|
+
# else:
|
18
|
+
# w = 3./2.*(H0/h)**2/Rho_crit_0*(chi/(1.+z))**-1.*(chi_star-chi)/chi_star #
|
19
|
+
|
20
|
+
return 4.# + 2*z
|
File without changes
|
@@ -0,0 +1,45 @@
|
|
1
|
+
import numpy as np
|
2
|
+
def custom1_ux(x,m,z,classy_sz,*params):
|
3
|
+
# m is m_delta and delta is the definition passed for custom1 profile
|
4
|
+
# x is r/r_delta
|
5
|
+
|
6
|
+
# delta is collected as:
|
7
|
+
delta_def = classy_sz.delta_def_custom1()
|
8
|
+
delta = classy_sz.get_delta_from_delta_def_at_z(delta_def,z)
|
9
|
+
|
10
|
+
# to get r_delta:
|
11
|
+
r_delta = classy_sz.get_r_delta_of_m_delta_at_z(delta,m,z)
|
12
|
+
|
13
|
+
# to get c_delta:
|
14
|
+
c_delta = classy_sz.get_c_delta_at_m_and_z(m,z,delta_def)
|
15
|
+
|
16
|
+
# to get x_out:
|
17
|
+
x_out = classy_sz.x_out_custom1()
|
18
|
+
|
19
|
+
|
20
|
+
# example: nfw profile/cmb lensing
|
21
|
+
rs = r_delta/c_delta
|
22
|
+
xs = x*r_delta/rs
|
23
|
+
prof = xs**-1.*(1.+ xs)**-2.
|
24
|
+
norm = m*c_delta**3/(np.log(1.+x_out*c_delta)-x_out*c_delta/(1.+x_out*c_delta))
|
25
|
+
|
26
|
+
return norm*prof
|
27
|
+
|
28
|
+
def custom1_W(z,classy_sz,*params):
|
29
|
+
# e.g., we want (chi_star - chi)/chi
|
30
|
+
chi_star = classy_sz.chi_star()
|
31
|
+
chi = classy_sz.get_chi(z)
|
32
|
+
H = classy_sz.Hubble(z)
|
33
|
+
Rho_crit_0 = classy_sz.Rho_crit_0()
|
34
|
+
|
35
|
+
h = classy_sz.h()
|
36
|
+
H0 = classy_sz.Hubble(0)
|
37
|
+
|
38
|
+
|
39
|
+
# example: cmb lensing
|
40
|
+
if z==0.:
|
41
|
+
w = 1e-100
|
42
|
+
else:
|
43
|
+
w = 3./2.*(H0/h)**2/Rho_crit_0*(chi/(1.+z))**-1.*(chi_star-chi)/chi_star #
|
44
|
+
|
45
|
+
return w
|