| |
| |
|
|
| |
|
|
|
|
| |
| |
| get_ipython().run_line_magic('matplotlib', 'inline') |
| import matplotlib |
| import matplotlib.pyplot as plt |
| import numpy as np |
| from classy import Class |
| from scipy.optimize import fsolve |
| from scipy.interpolate import interp1d |
| import math |
|
|
|
|
| |
|
|
|
|
| |
| |
| |
| |
| k = 0.5 |
| |
| |
| |
| common_settings = { |
| |
| 'output':'mPk', |
| |
| 'k_output_values':k, |
| |
| 'h':0.67810, |
| 'omega_b':0.02238280, |
| 'omega_cdm':0.1201075, |
| 'A_s':2.100549e-09 , |
| 'n_s':0.9660499, |
| 'tau_reio':0.05430842, |
| |
| 'YHe':0.2454, |
| |
| 'compute damping scale':'yes', |
| 'gauge':'newtonian'} |
| |
| |
| |
| |
| M = Class() |
| M.set(common_settings) |
| M.compute() |
| |
| |
| |
| all_k = M.get_perturbations() |
| print (all_k['scalar'][0].keys()) |
| |
| one_k = all_k['scalar'][0] |
| |
| tau = one_k['tau [Mpc]'] |
| Theta0 = 0.25*one_k['delta_g'] |
| phi = one_k['phi'] |
| psi = one_k['psi'] |
| theta_b = one_k['theta_b'] |
| a = one_k['a'] |
| |
| R = 3./4.*M.Omega_b()/M.Omega_g()*a |
| zero_point = -(1.+R)*psi |
| |
| |
| |
| Theta0_amp = max(Theta0.max(),-Theta0.min()) |
| |
| |
| |
| quantities = M.get_current_derived_parameters(['tau_rec']) |
| |
| tau_rec = quantities['tau_rec'] |
| |
| |
| |
| |
| background = M.get_background() |
| |
| |
| background_tau = background['conf. time [Mpc]'] |
| background_z = background['z'] |
| background_k_over_aH = k/background['H [1/Mpc]']*(1.+background['z']) |
| background_k_rs = k * background['comov.snd.hrz.'] |
| background_rho_m_over_r =\ |
| (background['(.)rho_b']+background['(.)rho_cdm'])\ |
| /(background['(.)rho_g']+background['(.)rho_ur']) |
| |
| |
| |
| tau_at_k_over_aH = interp1d(background_k_over_aH,background_tau) |
| tau_at_k_rs = interp1d(background_k_rs,background_tau) |
| tau_at_rho_m_over_r = interp1d(background_rho_m_over_r,background_tau) |
| |
| |
| |
| tau_Hubble = tau_at_k_over_aH(2.*math.pi) |
| tau_s = tau_at_k_rs(2.*math.pi) |
| tau_eq = tau_at_rho_m_over_r(1.) |
| |
| |
| |
| |
| |
| |
| |
| plt.xlim([tau[0],tau_rec*1.3]) |
| plt.ylim([-1.3*Theta0_amp,1.3*Theta0_amp]) |
| plt.xlabel(r'$\tau \,\,\, \mathrm{[Mpc]}$') |
| plt.title(r'$\mathrm{Transfer} (\tau,k) \,\,\, \mathrm{for} \,\,\, k=%g \,\,\, [1/\mathrm{Mpc}]$'%k) |
| plt.grid() |
| |
| plt.axvline(x=tau_Hubble,color='r') |
| plt.axvline(x=tau_s,color='y') |
| plt.axvline(x=tau_eq,color='k') |
| plt.axvline(x=tau_rec,color='k') |
| |
| plt.annotate(r'Hubble cross.', |
| xy=(tau_Hubble,1.08*Theta0_amp), |
| xytext=(0.15*tau_Hubble,1.18*Theta0_amp), |
| arrowprops=dict(facecolor='black', shrink=0.05, width=1, headlength=5, headwidth=5)) |
| plt.annotate(r'sound hor. cross.', |
| xy=(tau_s,-1.0*Theta0_amp), |
| xytext=(1.5*tau_s,-1.2*Theta0_amp), |
| arrowprops=dict(facecolor='black', shrink=0.05, width=1, headlength=5, headwidth=5)) |
| plt.annotate(r'eq.', |
| xy=(tau_eq,1.08*Theta0_amp), |
| xytext=(0.45*tau_eq,1.18*Theta0_amp), |
| arrowprops=dict(facecolor='black', shrink=0.05, width=1, headlength=5, headwidth=5)) |
| plt.annotate(r'rec.', |
| xy=(tau_rec,1.08*Theta0_amp), |
| xytext=(0.45*tau_rec,1.18*Theta0_amp), |
| arrowprops=dict(facecolor='black', shrink=0.05, width=1, headlength=5, headwidth=5)) |
| |
| |
| |
| plt.semilogx(tau,psi,'y-',label=r'$\psi$') |
| |
| |
| |
| plt.semilogx(tau,phi,'r-',label=r'$\phi$') |
| |
| |
| |
| plt.semilogx(tau,zero_point,'k:',label=r'$-(1+R)\psi$') |
| |
| |
| |
| plt.semilogx(tau,Theta0,'b-',linewidth=2,label=r'$\Theta_0$') |
| |
| |
| |
| plt.semilogx(tau,Theta0+psi,'c-',linewidth=2,label=r'$\Theta_0+\psi$') |
| |
| |
| |
| plt.semilogx(tau,theta_b,'g-',label=r'$\theta_b$') |
| plt.legend(loc='right',bbox_to_anchor=(1.4, 0.5)) |
| plt.savefig('one_k.pdf',bbox_inches='tight') |
| |
|
|
|
|