-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcosmo.py
261 lines (208 loc) · 7.09 KB
/
cosmo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
###########################################
### Code for cosmology functions ###
### by Manuel A. Buen-Abad, 2020 ###
### and Chen Sun, 2020 ###
###########################################
from __future__ import division
import numpy as np
from numpy import pi, sqrt, log, log10, exp, power
from scipy.integrate import simps, quad
from ag_probs import omega_plasma, P0, Pnaive
from igm import igm_Psurv
from icm import ne_2beta, B_icm, icm_los_Psurv
# CONSTANTS:
_c_ = 299792458. # [m/s]
_alpha_ = 1./137 # fine structure constant
_me_ = 510998.95 # electron mass in eV
_1_over_cm_eV_ = 1.9732698045930252e-5 # [1/cm/eV]
# FUNCTIONS:
def Ekernel(OmL, z):
try:
res, _ = quad( lambda zp: 1 / sqrt(OmL + (1 - OmL) * (1 + zp)**3), 0, z )
except Warning:
print('OmL=%e, z=%e' % (OmL, z))
raise Exception
return res
def H_at_z(z, h0, OmL, unit='Mpc'):
"""
Hubble at z
:param z: redshift
:param h0: H in [100*km/s/Mpc]
:param OmL: Omega_Lambda
:param unit: flag to change the output unit
:returns: H [1/Mpc] by default, or H [km/s/Mpc]
"""
if unit == 'Mpc':
res = h0*100.*sqrt(OmL + (1 - OmL) * (1 + z)**3)/(_c_/1000.)
else:
res = h0*100.*sqrt(OmL + (1 - OmL) * (1 + z)**3)
return res
def tau_at_z(z, h0, OmL):
"""
Compute the comoving distance, return in Mpc
Parameters
----------
z : scalar
redshift
h0 : scalar
Hubble in 100 km/s/Mpc
OmL : scalar
Omega_Lambda
"""
try:
res, _ = quad( lambda zp: 1. / sqrt(OmL + (1 - OmL) * (1 + zp)**3), 0., z )
except Warning:
print('OmL=%e, z=%e' % (OmL, z))
raise Exception
res = res * _c_/1e5/h0
return res
def dA_at_z(z, h0, OmL):
"""
Angular distance [Mpc]
:param z: redshift
:param h0: H in [100*km/s/Mpc]
:param OmL: Omega_Lambda
:returns: angular distance [Mpc]
"""
return tau_at_z(z, h0, OmL)/(1.+z)
def muLCDM(z, h0, OmL):
try:
res = 5. * log10((1.+z) * Ekernel(OmL, z)) + 5.*log10(_c_/(h0*1e5)) + 25
except Warning:
print('z=%e, OmL=%e' % (z, OmL))
print('h0=%e' % h0)
print('(1+z)*Ekernel=%e, c/h0=%e' % ((1. + z) * Ekernel(OmL, z), _c_ / (h0 * 1e5)))
return res
def LumMod(ma, g, z, B, mg, h, OmL,
s=1.,
omega=1.,
axion_ini_frac=0.,
smoothed=False,
redshift_dependent=True,
method='simps',
prob_func='norm_log',
Nz=501,
mu=1.):
"""
Here we use a simple function to modify the intrinsic luminosity of the SN
so that mu_th = mu_STD - LumMod(). This is the one that takes into account the redshift
Parameters
----------
ma: axion mass [eV]
g: axion photon coupling [1/GeV]
z: redshift
B: magnetic field, today [nG]
mg: photon mass [eV]
h: Hubble [100 km/s/Mpc]
OmL: Omega_Lambda
s: domain size [Mpc]
omega: energy [eV]
Returns
-------
res: scalar, delta M in the note
"""
try:
# 2.5log10(L/L(1e-5Mpc))
res = 2.5 * log10(igm_Psurv(ma, g, z,
s=s,
B=B,
omega=omega,
mg=mg,
h=h,
Omega_L=OmL,
axion_ini_frac=axion_ini_frac,
smoothed=smoothed,
redshift_dependent=redshift_dependent,
method=method,
prob_func=prob_func,
Nz=Nz,
mu=mu))
except Warning:
print('ma=%e, g=%e, y=%e' % (ma, g, y))
raise Exception('Overflow!!!')
return res
def ADDMod(ma, g, z, h, OmL,
omegaX=1.e4,
omegaCMB=2.4e-4,
# IGM
sIGM=1.,
BIGM=1.,
mgIGM=3.e-15,
smoothed_IGM=False,
redshift_dependent=True,
method_IGM='simps',
prob_func_IGM='norm_log',
Nz_IGM=501,
# ICM
ICM_effect=False,
r_low = 0.,
r_up = 1800.,
L=10.,
smoothed_ICM=False,
method_ICM='product',
return_arrays=False,
prob_func_ICM='norm_log',
Nr_ICM=501,
los_method='quad',
los_use_prepared_arrays=False,
los_Nr=501,
mu=1.,
# B_icm
B_ref=10.,
r_ref=0.,
eta=0.5,
#ne_2beta
ne0=0.01,
rc_outer=100.,
beta_outer=1.,
f_inner=0.,
rc_inner=10.,
beta_inner=1.):
"""
Function that modifies the ADDs from clusters, written in Eq. 12 of Manuel's notes.
"""
if ICM_effect:
PICM = icm_los_Psurv(ma, g, r_low, r_up, ne_2beta, B_icm,
L=L,
omega_Xrays=omegaX/1000.,
axion_ini_frac=0.,
smoothed=smoothed_ICM, method=method_ICM, return_arrays=return_arrays, prob_func=prob_func_ICM, Nr=Nr_ICM, los_method=los_method, los_use_prepared_arrays=los_use_prepared_arrays, los_Nr=los_Nr,
mu=mu,
# B_icm
B_ref=B_ref, r_ref=r_ref, eta=eta,
# ne_2beta
ne0=ne0, rc_outer=rc_outer, beta_outer=beta_outer, f_inner=f_inner, rc_inner=rc_inner, beta_inner=beta_inner)
Pg, Pa = PICM, 1.-PICM
IaIg = Pa/Pg
else:
Pg = 1.
IaIg = 0.
Pgg_X = igm_Psurv(ma, g, z,
s=sIGM,
B=BIGM,
omega=omegaX,
mg=mgIGM,
h=h,
Omega_L=OmL,
axion_ini_frac=IaIg,
smoothed=smoothed_IGM,
redshift_dependent=redshift_dependent,
method=method_IGM,
prob_func=prob_func_IGM,
Nz=Nz_IGM,
mu=mu)
Pgg_CMB = igm_Psurv(ma, g, z,
s=sIGM,
B=BIGM,
omega=omegaCMB,
mg=mgIGM,
h=h,
Omega_L=OmL,
axion_ini_frac=0.,
smoothed=smoothed_IGM,
redshift_dependent=redshift_dependent,
method=method_IGM,
prob_func=prob_func_IGM,
Nz=Nz_IGM,
mu=mu)
return Pgg_CMB**2. / (Pgg_X * Pg)