Basic cosmology operations¶
Documentation introducing the Cosmo class
-
class
Cosmo(h, omega0_b, omega0_cdm, k_max, n_s, sigma_8, verbose, gauge, output, **kwargs)¶
Class to calculate basic cosmology functions
- Parameters
h (float) : the dimensionless Hubble parameter
omega0_b (float) : the current baryon density, \(\Omega_{b,0}h^2\)
omega0_cdm (float) : the current cold dark matter density, \(\Omega_{cdm,0}h^2\)
k_max (float) : the maximum \(k\) value used when calculating the linear power spectrum
n_s (float) : the tilt of the primordial power spectrum
sigma_8 (float) : the amplitude of matter fluctuations within a sphere of radius \(r=8\ \mathrm{Mpc}\ \mathrm{h}^{-1}\) at \(z=0\)
verbose (bool) : whether to turn on the default
classlogginggauge (string) : whether to use the synchronous or newtonian gauge
output (string) : whether to output the matter power spectrum or CMB power spectrum
-
scale_factor(z_val)¶
Function to calculate the scale factor defined as \(a=\left(1+z\right)^{-1}\)
- Parameters
z_val (float) : the redshift at which the scale factor is computed
- Returns
a_val (float) : the scale factor value at z_val
-
calc_hubble(z_val)¶
Function to calculate the Hubble parameter, \(H\left(z\right)\), at a given redshift
- Parameters
z_val (float) : the redshift at which the Hubble parameter is computed
- Returns
hubble_val (float) : the Hubble parameter at z_val
-
Omega_m()¶
Function to calculate \(\Omega_m=\Omega_{cdm}+\Omega_b\)
- Returns
omega_m (float) : the \(\Omega_m\) value
-
H0()¶
Function to calculate \(H_0=h\times100\)
- Returns
H0 (float) : the \(H_0\) value
-
calc_linear_growth(z_val)¶
Function to calculate the linear growth factor, \(D_1\left(z\right)\), at a given redshift
- Parameters
z_val (float) : the redshift at which the linear growth factor is computed
- Returns
linear_growth_val (float) : the \(D_1\) value at z_val
-
calc_independent_linear_growth(z_val)¶
Function to calculate the independent linear growth factor, \(f=\frac{d\ln{D_1}}{d\ln{a}}\), at a given redshift
- Parameters
z_val (float) : the redshift at which the linear growth factor is computed
- Returns
independent_growth_val (float) : the \(f\) value at z_val
-
calc_linear_power(k, z_val)¶
Function to calculate the linear power spectrum at a given redshift using classylss
- Parameters
z_val (float) : the redshift at which the linear growth factor is computed
k (array, float) : log-spaced array of \(k\) values
- Returns
linear_power (array) : the linear power spectrum evaluated at the given \(k\) values and redshift value
Examples¶
We can plot the linear growth factor for a range of redshifts
import numpy as np
import matplotlib.pyplot as plt
from ctm import Cosmo
# Define the redshift values
z_vals=np.linspace(0.0, 200.0, 100)
# Calculate the linear growth factor values
D_1_vals=Cosmo(h=0.7, omega0_b=0.02233, omega0_cdm=0.112, n_s=0.96, sigma_8=0.8, k_max=10.0, verbose=False, gauge='sync', output='mPk').calc_linear_growth(z_vals)
# Plot the results
plt.plot(z_vals, D_1_vals, color="black", linestyle='-', linewidth=2.2, alpha=0.8)
plt.xlabel(r"$z$", fontsize=14.)
plt.ylabel(r"$D_1$", fontsize=14.)
plt.xlim([-2, 202])
plt.ylim([-0.2, 1.2])
plt.show()
We can also plot the independent growth factor for a range of redshifts
# Calculate the independent growth factor values
f_vals=Cosmo(h=0.7, omega0_b=0.02233, omega0_cdm=0.112, n_s=0.96, sigma_8=0.8, k_max=10.0, verbose=False, gauge='sync', output='mPk').calc_independent_linear_growth(z_vals)
# Plot the results
plt.plot(z_vals, f_vals, color="black", linestyle='-', linewidth=2.2, alpha=0.8)
plt.xlabel(r"$z$", fontsize=14.)
plt.ylabel(r"$f$", fontsize=14.)
plt.xlim([-2, 202])
plt.ylim([0.5, 1.2])
plt.show()