forked from nanoomlee/HYREC-2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.py
56 lines (39 loc) · 1.28 KB
/
example.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
import matplotlib.pyplot as plt
import numpy as np
import pyhyrec as pyhy
cosmo = pyhy.HyRecCosmoParams()
inj = pyhy.HyRecInjectionParams()
z, xe, Tm = pyhy.call_run_hyrec(cosmo(), inj())
# load data for comparisons to the precomputed default case
data = np.loadtxt("./tests/output_xe.dat")
z_c = np.flip(data[:, 0])
xe_c = np.flip(data[:, 1])
Tm_c = np.flip(data[:, 2])
# create a cosmo params and injection params object with Primordial Black Holes
inj_pbh = pyhy.HyRecInjectionParams({'fpbh' : 1.0, 'Mpbh': 1e+3})
z_pbh, xe_pbh, Tm_pbh = pyhy.call_run_hyrec(cosmo(), inj_pbh())
# plotting xe
fig = plt.figure()
ax = fig.gca()
ax.plot(z, xe, '-b', label='without pbh')
ax.plot(z_pbh, xe_pbh, '-r', label='with pbh')
ax.plot(z_c, xe_c, 'c-.', label='without pbh (default)')
ax.set_xscale("log")
ax.set_yscale("log")
ax.set_ylabel('xe')
ax.set_xlabel('z')
ax.legend()
fig.savefig("../test_xe.pdf")
# plotting Tm
fig = plt.figure()
ax = fig.gca()
ax.plot(z, Tm, '-b', label='without pbh')
ax.plot(z_pbh, Tm_pbh, '-r', label='with pbh')
ax.plot(z_c, Tm_c, 'c-.', label='without pbh (default)')
ax.plot(z, cosmo.T0 * (1+z), color='k', linestyle=':', label='CMB temp.')
ax.set_xscale("log")
ax.set_yscale("log")
ax.set_ylabel('Tm [K]')
ax.set_xlabel('z')
ax.legend()
fig.savefig("../test_TK.pdf")