forked from CRPropa/CRPropa3-data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphotonField.py
405 lines (351 loc) · 13.9 KB
/
photonField.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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
import numpy as np
from os import path
cdir = path.split(__file__)[0]
datadir = path.join(cdir, 'tables/')
eV = 1.60217657e-19 # [J]
erg = 1e-7 # [J]
c0 = 299792458 # [m/s]
h = 6.62606957e-34 # [m^2 kg / s]
kB = 1.3806488e-23 # [m^2 kg / s^2 / K]
Hz = 1. # [1 / s]
T_CMB = 2.72548 # CMB temperature [K]
# --------------------------------------------------------
# interfaces
# --------------------------------------------------------
class CMB:
"""
Cosmic microwave background radiation
"""
name = 'CMB'
info = 'CMB'
redshift = None
def getDensity(self, eps, z=0):
"""
Comoving spectral number density dn/deps [1/m^3/J] at given photon energy eps [J] and redshift z.
Multiply with (1+z)^3 for the physical number density.
"""
return 8*np.pi / c0**3 / h**3 * eps**2 / np.expm1(eps / (kB * T_CMB))
def getEmin(self, z=0):
"""Minimum effective photon energy in [J]"""
return 1e-10 * eV
def getEmax(self, z=0):
"""Maximum effective photon energy in [J]"""
return 0.1 * eV
class EBL:
"""
Base class for extragalactic background light (EBL) models
"""
def __init__(self):
self.data = {} # dictionary {redshift : (eps, dn/deps)}
def getDensity(self, eps, z=0):
"""
Comoving spectral number density dn/deps [1/m^3/J] at given photon energy eps [J] and redshift z.
Multiply with (1+z)^3 for the physical spectral number density.
The tabulated data is interpolated linearly in log-log; no extrapolation is performed.
"""
tab_eps, tab_n = self.data[z]
# return np.interp(eps, tab_eps, tab_n, 0, 0) # linear interpolation
x = np.log10(eps)
tx = np.log10(tab_eps)
ty = np.log10(tab_n)
return 10**np.interp(x, tx, ty, -np.inf, -np.inf) # log-log interpolation
def getEmin(self, z=0):
"""Minimum tabulated photon energy in [J]"""
return self.data[z][0][0]
def getEmax(self, z=0):
"""Maximum tabulated photon energy in [J]"""
return self.data[z][0][-1]
# --------------------------------------------------------
# EBL (optical and infrared) models
# --------------------------------------------------------
class EBL_Kneiske04(EBL):
name = 'IRB_Kneiske04'
info = 'cosmic infrared and optical background radiation model of Kneiske et al. 2004'
files = datadir + 'EBL_Kneiske_2004/all_z'
redshift = np.linspace(0, 5, 51)
def __init__(self):
EBL.__init__(self)
# d[0] : eps [eV]
# d[1-51] : n(eps), [1/m^3/eV]
d = np.genfromtxt(self.files, unpack=True)
eps = d[0] * eV
n = d[1:] / eV
for i,z in enumerate(self.redshift):
self.data[z] = eps, n[i]
class EBL_Kneiske10(EBL):
name = 'IRB_Kneiske10'
info = 'cosmic infrared and optical background radiation lower limit model of Kneiske et al. 2010'
files = datadir + 'EBL_Kneiske_2010/%.1f'
redshift = (0, .1, .3, .8, 2)
def __init__(self):
EBL.__init__(self)
for z in self.redshift:
# x : wavelength in [mu m]
# y : lambda I_lambda [nW/m^2/sr]
x, y = np.genfromtxt(self.files%z, unpack=True)
wl = (10**x * 1e-6) # wavelength in [m]
eps = h * c0 / wl
n = (10**y * 1e-9) * (4 * np.pi / c0) / eps**2
self.data[z] = eps[::-1], n[::-1]
class EBL_Dole06(EBL):
name = 'IRB_Dole06'
info = 'cosmic infrared and optical background radiation model of Dole et al. 2006'
files = datadir + 'EBL_Dole_2006/0.0'
redshift = (0)
def __init__(self):
EBL.__init__(self)
# d[0] : lambda [mu m]
# d[1] : n(eps), [W/m^2/sr]
d = np.genfromtxt(self.files, unpack=True)
eps = h * c0 / (d[0] * 1e-6) # photon energy [J]
n = d[1] * (4 * np.pi / c0) / eps**2
self.data[0] = eps[::-1], n[::-1]
class EBL_Franceschini08(EBL):
name = 'IRB_Franceschini08'
info = 'cosmic infrared and optical background radiation model of Franceschini et al. 2008'
files = datadir + 'EBL_Franceschini_2008/%1.1f'
redshift = (0, .2, .4, .6, .8, 1.0, 1.2, 1.4, 1.6, 1.8, 2.0)
def __init__(self):
EBL.__init__(self)
for z in self.redshift:
# x : log10(eps / eV)
# y : eps * dn/deps [1/cm^3]
x, y = np.genfromtxt(self.files%z, unpack=True)
eps = 10**x * eV
n = 10**y / eps * 1e6
n /= (1 + z)**3 # make comoving
self.data[z] = eps, n
class EBL_Stecker05(EBL):
name = 'IRB_Stecker05'
info = 'cosmic infrared and optical background radiation model of Stecker at al. 2005'
files = datadir + 'EBL_Stecker_2005/data2.txt'
redshift = np.linspace(0, 5, 26)
def __init__(self):
EBL.__init__(self)
# d[0] : log10(eps/eV)
# d[1-26] : log10(eps*n(eps)/cm^3), not comoving
d = np.genfromtxt(self.files, unpack=True)
eps = 10**d[0] * eV
n = 10**d[1:] / eps * 1e6
for i,z in enumerate(self.redshift):
# convert n(eps) to comoving density
self.data[z] = eps, n[i] / (1+z)**3
class EBL_Finke10(EBL):
name = 'IRB_Finke10'
info = 'cosmic infrared and optical background radiation model of Finke et al. 2010 (Model C)'
files = datadir + 'EBL_Finke_2010/z%.2f.dat'
redshift = np.arange(0, 5, 0.01)
def __init__(self):
EBL.__init__(self)
for z in self.redshift:
# d[0] : eps / eV
# d[1] : comoving energy density in erg / cm^3
d = np.genfromtxt(self.files % z, unpack=True)
eps = d[0] * eV
n = d[1] * erg * 1e6 / eps**2 # [J/m^3]
self.data[z] = eps, n
class EBL_Gilmore12(EBL):
name = 'IRB_Gilmore12'
info = 'cosmic infrared and optical background radiation model of Gilmore et al. 2012 (Evolving dust model, arXiv:1104.0671)'
files = datadir + 'EBL_Gilmore_2012/eblflux_fiducial.dat'
redshift = np.array([0, 0.015, 0.025, 0.044, 0.05, 0.2, 0.4, 0.5, 0.6, 0.8, 1.0, 1.25, 1.5, 2.0, 2.5, 3.0, 4.0, 5.0, 6.0, 7.0])
def __init__(self):
EBL.__init__(self)
# d[0] : rest frame wavelength in [angstrom]
# d[1-21] : proper flux [erg/s/cm^2/ang/sr]
d = np.genfromtxt(self.files, unpack=True)
eps = h * c0 / (d[0] * 1e-10) # [J]
n = d[1:] * erg / 1e-4 * d[0] / eps**2 * (4 * np.pi / c0)
for i,z in enumerate(self.redshift):
n[i] /= (1 + z)**3 # make comoving
self.data[z] = eps[::-1], n[i][::-1]
class EBL_Dominguez11(EBL):
def __init__(self, which='best'):
EBL.__init__(self)
if which == 'best':
fname = 'EBL_Dominguez_2011/ebl_dominguez11.out'
self.name = 'IRB_Dominguez11'
elif which == 'upper':
fname = 'EBL_Dominguez_2011/ebl_upper_uncertainties_dominguez11.out'
self.name = 'IRB_Dominguez11_upper'
elif which == 'lower':
fname = 'EBL_Dominguez_2011/ebl_lower_uncertainties_dominguez11.out'
self.name = 'IRB_Dominguez11_lower'
else:
raise ValueError('EBL_Dominguez11 only provides "best", "upper" and "lower" models')
self.info = 'cosmic infrared and optical background radiation (%s) model of Dominguez et al. 2011 (arXiv:1007.1459)' % which
self.redshift = np.array([0, 0.01, 0.03, 0.05, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.8, 1.0, 1.25, 1.5, 2.0, 2.5, 3.0, 3.9])
# d[0] : rest frame wavelength in [mu m]
# d[1-18] : proper flux [nW/m^2/sr]
d = np.genfromtxt(datadir + fname, unpack=True)
eps = h * c0 / (d[0] * 1e-6) # [J]
n = d[1:] * 1e-9 / eps**2 * (4 * np.pi / c0)
for i, z in enumerate(self.redshift):
self.data[z] = eps[::-1], n[i][::-1] # sort by ascending energy
class EBL_Stecker16(EBL):
def __init__(self, which='upper'):
EBL.__init__(self)
if which == 'upper':
fname = 'EBL_Stecker_2016/comoving_enerdens_up.csv'
elif which == 'lower':
fname = 'EBL_Stecker_2016/comoving_enerdens_lo.csv'
else:
raise ValueError('EBL_Stecker16 only provides "upper" and "lower" models')
self.name = 'IRB_Stecker16_%s' % which
self.info = 'cosmic infrared and optical background radiation (%s) model of Stecker et al. 2016 (arXiv:1605.01382)' % which
self.redshift = np.linspace(0, 5, 501)
# rows: log10(photon energy / eV) ranging from -2.84 to 1.14 in steps of 0.01
# columns: redshifts from 0 to 5 in steps of 0.01
# units: erg / Hz / cm^3 -->
d = np.genfromtxt(datadir + fname, delimiter=',').T
eps = 10**np.arange(-2.84, 1.14001, 0.01) * eV
n = d * erg / h * 1E6 / eps
for i, z in enumerate(self.redshift):
self.data[z] = eps, n[i]
# --------------------------------------------------------
# CRB (radio) models
# --------------------------------------------------------
class URB_Protheroe96:
"""
Universal Radio Background from Protheroe & Bierman 1996.
Taken from EleCa implementation.
Reference
R. J. Protheroe and P. L. Biermann
Astroparticle Physics 6 (1996) 45.
"""
name = "URB_Protheroe96"
info = "URB_Protheroe96"
redshift = None
def getDensity(self, eps, z=0):
"""
Comoving spectral number density dn/deps [1/m^3/J] at given photon energy eps [J]
"""
p0 = -2.23791e+01
p1 = -2.59696e-01
p2 = 3.51067e-01
p3 = -6.80104e-02
p4 = 5.82003e-01
p5 = -2.00075e+00
p6 = -1.35259e+00
p7 = -7.12112e-01 # xbreak
eps = np.r_[eps]
x = np.log10(eps / h / 1e9)
I = p0 + p1 * x + p2 * x**2 + p3 * x**3 / (np.exp(p4 * x) - 1)
I[x > p7] += p6 + p5 * x[x > p7] - p2 * x[x > p7]**2
I = 4 * np.pi / (h * c0) * (10**I / eps)
I[eps < self.getEmin()] = 0
I[eps > self.getEmax()] = 0
return I
def getEmin(self, z=0):
"""Minimum effective photon energy in [J]"""
return 4.1e-12 * eV
def getEmax(self, z=0):
"""Maximum effective photon energy in [J]"""
return 2E-6 * eV # 0.825e-6 * eV
class URB_Fixsen11:
"""
Universal Radio Background as measured by ARCADE2.
Note that the frequency range in this reference is more narrow than for other models.
Therefore, this should be used carefully.
Reference:
D. J. Fixsen et al.
The Astrophysical Journal 734 (2011) 5.
https://arxiv.org/abs/0901.0555
"""
name = 'URB_Fixsen11'
info = 'URB_Fixsen11'
redshift = None
def getDensity(self, eps, z = 0.):
"""
Spectral number density dn/deps [1/m^3/J] at z = 0.
"""
eps = np.r_[eps]
nu = eps / h
T = T_CMB + 24.1 * np.power(nu / 3.1e8, -2.6)
I = 8. * np.pi / c0 ** 3 / h ** 3 * eps ** 2 / (np.expm1(eps / (kB * T)))
I[eps < self.getEmin()] = 0.
I[eps > self.getEmax()] = 0.
return I
def getEmin(self, z = 0.):
"""Minimum effective photon energy in [J]"""
return 2.2e6 * Hz * h
def getEmax(self, z = 0.):
"""Maximum effective photon energy in [J]"""
return 1e10 * Hz * h
class URB_Nitu21:
"""
Universal Radio Background from Nitu et al. 2021.
Reference:
I. C. Nitu, H. T. J. Bevings, J. D. Bray, A. M. M. Scaife
Astroparticle Physics 126 (2021) 102532.
https://arxiv.org/abs/2004.13596
"""
name = 'URB_Nitu21'
info = 'URB_Nitu21'
redshift = None
def getDensity(self, eps, z=0):
"""
Comoving spectral number density dn/deps [1/m^3/J] at given photon energy eps [J]
"""
p0 = -1.9847e1
p1 = -2.9857e-1
p2 = -2.6984e-1
p3 = 9.5394e-2
p4 = -4.9059e-2
p5 = 4.4297e-3
p6 = 7.6038e-3
p7 = -1.9690e-3
p8 = -2.2573e-4
p9 = 1.1762e-4
p10 = -9.9443e-6
p = [p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10]
eps = np.r_[eps]
nu = eps / h
I = 0.
for k in range(len(p)):
I += (p[k] * np.power(np.log10(nu / 1e6), k))
I = 10. ** I
I = 4 * np.pi / (h * c0) * (I / eps)
I[eps < self.getEmin()] = 0.
I[eps > self.getEmax()] = 0.
return I
def getEmin(self, z=0):
"""Minimum effective photon energy in [J]"""
return 1e3 * Hz * h
def getEmax(self, z=0):
"""Maximum effective photon energy in [J]"""
return 1e12 * Hz * h
# --------------------------------------------------------
#
# --------------------------------------------------------
if __name__ == '__main__':
from pylab import *
eps = logspace(-3, 1, 200) * eV
x = eps / eV
c = eps**2 / eV
y1 = c * EBL_Kneiske04().getDensity(eps)
y3 = c * EBL_Stecker05().getDensity(eps)
y5 = c * EBL_Franceschini08().getDensity(eps)
y6 = c * EBL_Finke10().getDensity(eps)
y7 = c * EBL_Dominguez11().getDensity(eps)
y8 = c * EBL_Gilmore12().getDensity(eps)
y7up = c * EBL_Dominguez11('upper').getDensity(eps)
y7lo = c * EBL_Dominguez11('lower').getDensity(eps)
y9up = c * EBL_Stecker16('upper').getDensity(eps)
y9lo = c * EBL_Stecker16('lower').getDensity(eps)
figure()
plot(x, y1, label='Kneiske 2004')
plot(x, y3, label='Stecker 2005')
plot(x, y5, label='Franceschini 2008')
plot(x, y6, label='Finke 2010')
plot(x, y7, label='Dominguez 2011')
plot(x, y8, label='Gilmore 2012')
fill_between(x, y7lo, y7up, facecolor='m', edgecolor='none', alpha=0.2, zorder=-1, label='Dominguez 2011 (limits)')
fill_between(x, y9lo, y9up, facecolor='g', edgecolor='none', alpha=0.2, zorder=-1, label='Stecker 2016 (limits)')
legend(loc='lower center', fontsize='x-small')
loglog()
grid()
ylabel('$\epsilon^2 ~ dn/d\epsilon$ [eV/m$^3$]')
xlabel('$\epsilon$ [eV]')
savefig('plots/EBL.png')
show()