|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
z_max_pk = 46000 |
|
k_per_decade = 400 |
|
k_min_tau0 = 40. |
|
P_k_max_inv_Mpc =1.0 |
|
tau_num_early = 2000 |
|
tau_num_late = 200 |
|
tau_ini = 10. |
|
tau_label_Hubble = 20. |
|
tau_label_ks = 40. |
|
tau_label_kd = 230. |
|
|
|
|
|
|
|
common_settings = { |
|
'output':'mTk', |
|
|
|
'h':0.67556, |
|
'omega_b':0.022032, |
|
'omega_cdm':0.12038, |
|
'A_s':2.215e-9, |
|
'n_s':0.9619, |
|
'tau_reio':0.0925, |
|
|
|
'YHe':0.246, |
|
|
|
'z_max_pk':z_max_pk, |
|
'k_per_decade_for_pk':k_per_decade, |
|
'k_per_decade_for_bao':k_per_decade, |
|
'k_min_tau0':k_min_tau0, |
|
'perturbations_sampling_stepsize':'0.05', |
|
'P_k_max_1/Mpc':P_k_max_inv_Mpc, |
|
'compute damping scale':'yes', |
|
'gauge':'newtonian', |
|
'matter_source_in_current_gauge':'yes'} |
|
|
|
|
|
|
|
|
|
|
|
|
|
M = Class() |
|
M.set(common_settings) |
|
M.compute() |
|
|
|
|
|
|
|
times = M.get_current_derived_parameters(['tau_rec','conformal_age']) |
|
tau_rec=times['tau_rec'] |
|
tau_0 = times['conformal_age'] |
|
tau1 = np.logspace(math.log10(tau_ini),math.log10(tau_rec),tau_num_early) |
|
tau2 = np.logspace(math.log10(tau_rec),math.log10(tau_0),tau_num_late)[1:] |
|
tau2[-1] *= 0.999 |
|
tau = np.concatenate((tau1,tau2)) |
|
tau_num = len(tau) |
|
|
|
|
|
|
|
|
|
|
|
background = M.get_background() |
|
|
|
thermodynamics = M.get_thermodynamics() |
|
|
|
|
|
background_tau = background['conf. time [Mpc]'] |
|
background_z = background['z'] |
|
background_aH = 2.*math.pi*background['H [1/Mpc]']/(1.+background['z'])/M.h() |
|
background_ks = 2.*math.pi/background['comov.snd.hrz.']/M.h() |
|
background_rho_m_over_r =\ |
|
(background['(.)rho_b']+background['(.)rho_cdm'])\ |
|
/(background['(.)rho_g']+background['(.)rho_ur']) |
|
background_rho_l_over_m =\ |
|
background['(.)rho_lambda']\ |
|
/(background['(.)rho_b']+background['(.)rho_cdm']) |
|
thermodynamics_tau = thermodynamics['conf. time [Mpc]'] |
|
thermodynamics_kd = 2.*math.pi/thermodynamics['r_d']/M.h() |
|
|
|
|
|
|
|
background_z_at_tau = interp1d(background_tau,background_z) |
|
background_aH_at_tau = interp1d(background_tau,background_aH) |
|
background_ks_at_tau = interp1d(background_tau,background_ks) |
|
background_tau_at_mr = interp1d(background_rho_m_over_r,background_tau) |
|
background_tau_at_lm = interp1d(background_rho_l_over_m,background_tau) |
|
thermodynamics_kd_at_tau = interp1d(thermodynamics_tau, thermodynamics_kd) |
|
|
|
|
|
|
|
aH = background_aH_at_tau(tau) |
|
ks = background_ks_at_tau(tau) |
|
kd = thermodynamics_kd_at_tau(tau) |
|
|
|
|
|
|
|
tau_eq = background_tau_at_mr(1.) |
|
tau_lambda = background_tau_at_lm(1.) |
|
|
|
|
|
max_z_needed = background_z_at_tau(tau[0]) |
|
if max_z_needed > z_max_pk: |
|
print ('you must increase the value of z_max_pk to at least ',max_z_needed) |
|
() + 1 |
|
else: |
|
print ('in a next run with the same values of tau, you may decrease z_max_pk from ',z_max_pk,' to ',max_z_needed) |
|
|
|
|
|
|
|
for i in range(tau_num): |
|
one_time = M.get_transfer(background_z_at_tau(tau[i])) |
|
if i ==0: |
|
k = one_time['k (h/Mpc)'] |
|
k_num = len(k) |
|
Theta0 = np.zeros((tau_num,k_num)) |
|
phi = np.zeros((tau_num,k_num)) |
|
Theta0[i,:] = 0.25*one_time['d_g'][:] |
|
phi[i,:] = one_time['phi'][:] |
|
|
|
|
|
|
|
Theta_amp = max(Theta0.max(),-Theta0.min()) |
|
phi_amp = max(phi.max(),-phi.min()) |
|
|
|
|
|
|
|
K,T = np.meshgrid(k,tau) |
|
|
|
|
|
|
|
print ('grid size:',len(k),len(tau),Theta0.shape) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fig = plt.figure(figsize=(18,8)) |
|
|
|
|
|
|
|
ax_Theta = fig.add_subplot(121) |
|
print ('> Plotting Theta_0') |
|
fig_Theta = ax_Theta.pcolormesh(K,T,Theta0,cmap='coolwarm',vmin=-Theta_amp,vmax=Theta_amp,shading='auto') |
|
print ('> Done') |
|
|
|
|
|
|
|
ax_Theta.axhline(y=tau_rec,color='k',linestyle='-') |
|
ax_Theta.axhline(y=tau_eq,color='k',linestyle='-') |
|
ax_Theta.axhline(y=tau_lambda,color='k',linestyle='-') |
|
ax_Theta.plot(aH,tau,'r-',linewidth=2) |
|
ax_Theta.plot(ks,tau,color='#FFFF33',linestyle='-',linewidth=2) |
|
ax_Theta.plot(kd,tau,'b-',linewidth=2) |
|
|
|
|
|
|
|
ax_Theta.set_title(r'$\Theta_0$') |
|
ax_Theta.text(1.5*k[0],0.9*tau_rec,r'$\mathrm{rec.}$') |
|
ax_Theta.text(1.5*k[0],0.9*tau_eq,r'$\mathrm{R/M} \,\, \mathrm{eq.}$') |
|
ax_Theta.text(1.5*k[0],0.9*tau_lambda,r'$\mathrm{M/L} \,\, \mathrm{eq.}$') |
|
ax_Theta.annotate(r'$\mathrm{Hubble} \,\, \mathrm{cross.}$', |
|
xy=(background_aH_at_tau(tau_label_Hubble),tau_label_Hubble), |
|
xytext=(0.1*background_aH_at_tau(tau_label_Hubble),0.8*tau_label_Hubble), |
|
arrowprops=dict(facecolor='black', shrink=0.05, width=1, headlength=5, headwidth=5)) |
|
ax_Theta.annotate(r'$\mathrm{sound} \,\, \mathrm{horizon} \,\, \mathrm{cross.}$', |
|
xy=(background_ks_at_tau(tau_label_ks),tau_label_ks), |
|
xytext=(0.07*background_aH_at_tau(tau_label_ks),0.8*tau_label_ks), |
|
arrowprops=dict(facecolor='black', shrink=0.05, width=1, headlength=5, headwidth=5)) |
|
ax_Theta.annotate(r'$\mathrm{damping} \,\, \mathrm{scale} \,\, \mathrm{cross.}$', |
|
xy=(thermodynamics_kd_at_tau(tau_label_kd),tau_label_kd), |
|
xytext=(0.2*thermodynamics_kd_at_tau(tau_label_kd),2.0*tau_label_kd), |
|
arrowprops=dict(facecolor='black', shrink=0.05, width=1, headlength=5, headwidth=5)) |
|
|
|
|
|
|
|
ax_Theta.set_xlim(k[0],k[-1]) |
|
ax_Theta.set_xscale('log') |
|
ax_Theta.set_yscale('log') |
|
ax_Theta.set_xlabel(r'$k \,\,\, \mathrm{[h/Mpc]}$') |
|
ax_Theta.set_ylabel(r'$\tau \,\,\, \mathrm{[Mpc]}$') |
|
ax_Theta.invert_yaxis() |
|
|
|
|
|
|
|
fig.colorbar(fig_Theta) |
|
|
|
|
|
|
|
ax_phi = fig.add_subplot(122) |
|
ax_phi.set_xlim(k[0],k[-1]) |
|
|
|
print ('> Plotting phi') |
|
fig_phi = ax_phi.pcolormesh(K,T,phi,cmap='coolwarm',vmin=-0.,vmax=phi_amp,shading='auto') |
|
print ('> Done') |
|
|
|
|
|
|
|
ax_phi.axhline(y=tau_rec,color='k',linestyle='-') |
|
ax_phi.axhline(y=tau_eq,color='k',linestyle='-') |
|
ax_phi.axhline(y=tau_lambda,color='k',linestyle='-') |
|
ax_phi.plot(aH,tau,'r-',linewidth=2) |
|
ax_phi.plot(ks,tau,color='#FFFF33',linestyle='-',linewidth=2) |
|
|
|
|
|
|
|
ax_phi.set_title(r'$\phi$') |
|
ax_phi.text(1.5*k[0],0.9*tau_rec,r'$\mathrm{rec.}$') |
|
ax_phi.text(1.5*k[0],0.9*tau_eq,r'$\mathrm{R/M} \,\, \mathrm{eq.}$') |
|
ax_phi.text(1.5*k[0],0.9*tau_lambda,r'$\mathrm{M/L} \,\, \mathrm{eq.}$') |
|
ax_phi.annotate(r'$\mathrm{Hubble} \,\, \mathrm{cross.}$', |
|
xy=(background_aH_at_tau(tau_label_Hubble),tau_label_Hubble), |
|
xytext=(0.1*background_aH_at_tau(tau_label_Hubble),0.8*tau_label_Hubble), |
|
arrowprops=dict(facecolor='black', shrink=0.05, width=1, headlength=5, headwidth=5)) |
|
ax_phi.annotate(r'$\mathrm{sound} \,\, \mathrm{horizon} \,\, \mathrm{cross.}$', |
|
xy=(background_ks_at_tau(tau_label_ks),tau_label_ks), |
|
xytext=(0.07*background_aH_at_tau(tau_label_ks),0.8*tau_label_ks), |
|
arrowprops=dict(facecolor='black', shrink=0.05, width=1, headlength=5, headwidth=5)) |
|
|
|
|
|
|
|
ax_phi.set_xscale('log') |
|
ax_phi.set_yscale('log') |
|
ax_phi.set_xlabel(r'$k \,\,\, \mathrm{[h/Mpc]}$') |
|
ax_phi.set_ylabel(r'$\tau \,\,\, \mathrm{[Mpc]}$') |
|
ax_phi.invert_yaxis() |
|
|
|
|
|
|
|
fig.colorbar(fig_phi) |
|
|
|
|
|
|
|
|
|
plt.savefig('many_times.png',dpi=300) |
|
|
|
|
|
|