1
|
import numpy as np
|
2
|
import crab
|
3
|
|
4
|
|
5
|
def check_eval():
|
6
|
|
7
|
|
8
|
|
9
|
e, e1, e2 = 1, 1, 1e3
|
10
|
for ref, values in crab.refs.items():
|
11
|
f = crab.diff_flux(e, ref)
|
12
|
try:
|
13
|
I = crab.int_flux(e1, e2, ref)
|
14
|
except ImportError:
|
15
|
print('No scipy, no integral flux.')
|
16
|
I = 0
|
17
|
g = crab.spectral_index(e, ref)
|
18
|
f_ref = values['diff_flux']
|
19
|
if ref == 'hess_ecpl':
|
20
|
f_ref *= np.exp(-e / values['cutoff'])
|
21
|
|
22
|
I_ref = values['int_flux']
|
23
|
g_ref = values['index']
|
24
|
f_err = (f - f_ref) / f_ref
|
25
|
I_err = (I - I_ref) / I_ref
|
26
|
g_err = g - g_ref
|
27
|
print(('%15s ' + '%13.5g' * 6) %
|
28
|
(ref, f, I, g, f_err, I_err, g_err))
|
29
|
|
30
|
|
31
|
def plot_spectra(what="flux", extension='png'):
|
32
|
import matplotlib.pyplot as plt
|
33
|
plt.clf()
|
34
|
e = np.logspace(-2, 3, 100)
|
35
|
for ref in crab.refs.keys():
|
36
|
if what == 'flux':
|
37
|
tev_to_erg = 1.60217653
|
38
|
y = tev_to_erg * e ** 2 * crab.diff_flux(e, ref)
|
39
|
elif what == 'int_flux':
|
40
|
|
41
|
e2 = 1e4 * np.ones_like(e)
|
42
|
y = crab.int_flux(e, e2, ref=ref)
|
43
|
if what == 'ratio':
|
44
|
y = (crab.diff_flux(e, ref) /
|
45
|
crab.diff_flux(e, 'meyer'))
|
46
|
elif what == 'index':
|
47
|
y = crab.spectral_index(e, ref)
|
48
|
plt.plot(e, y, label=ref)
|
49
|
|
50
|
plt.xlabel('Energy (TeV)')
|
51
|
if what == 'int_flux':
|
52
|
plt.ylabel('Integral Flux (cm^-2 s^-1)')
|
53
|
plt.ylim(1e-15, 1e-8)
|
54
|
plt.loglog()
|
55
|
filename = 'crab_int_flux.%s' % extension
|
56
|
elif what == 'flux':
|
57
|
plt.ylabel('Flux (erg cm^-2 s^-1)')
|
58
|
plt.ylim(1e-12, 1e-9)
|
59
|
plt.loglog()
|
60
|
filename = 'crab_flux.%s' % extension
|
61
|
elif what == 'ratio':
|
62
|
plt.ylabel('Flux Ratio wrt. Meyer')
|
63
|
plt.ylim(1e-1, 1e1)
|
64
|
plt.loglog()
|
65
|
filename = 'crab_ratio.%s' % extension
|
66
|
elif what == 'index':
|
67
|
plt.ylabel('Flux (erg cm^-2 s^-1)')
|
68
|
plt.ylim(1, 5)
|
69
|
plt.semilogx()
|
70
|
filename = 'crab_index.%s' % extension
|
71
|
|
72
|
plt.grid(which='both')
|
73
|
plt.legend(loc='best')
|
74
|
plt.savefig(filename)
|
75
|
|
76
|
if __name__ == '__main__':
|
77
|
check_eval()
|
78
|
plot_spectra('flux')
|
79
|
plot_spectra('int_flux')
|
80
|
plot_spectra('ratio')
|
81
|
plot_spectra('index')
|