PTEmu
bispectrum
cosmology
Cosmology module.
- class comet.cosmology.Cosmology(Om0, H0, Ok0=0.0, Or0=0.0, de_model='lambda', w0=-1.0, wa=0.0)[source]
Bases:
objectClass containing cosmological parameters and background quantities.
This object is used to compute background quantities (expansion, growth) of the specific cosmology passed as input.
In all cases including an evolving dark energy density, its equation of state is parametrized as \(w(a)=w_0+w_a(1-a)\) (Chevalier & Polansky 2001, Linder 2003).
Class constructor.
- Parameters:
Om0 (float) – Fractional total matter density at present time, \(\Omega_\mathrm{m,0}\).
H0 (float) – Hubble constant at present time, \(H_0\).
Ok0 (float, optional) – Fractional curvature density at present time, \(\Omega_\mathrm{k,0}\). Defaults to 0.0.
Or0 (float, optional) – Fractional radiation density at present time, \(\Omega_\mathrm{r,0}\), Defaults to 0.0.
de_model (str, optional) – Selected dark energy model. It can be chosen from the list [“lambda”, “w0”, “w0wa”], whose entries correspond to a LCDM, \(w\) CDM, and quintessence model, respectively. Defaults to “lambda”.
w0 (float, optional) – Dark energy equation of state at present time, \(w_0\). Only used if de_model is not “lambda”. Defaults to -1.0.
wa (float, optional) – Negative derivative of the dark energy equation of state with respect to the scale factor, \(w_a\). Only used if de_model is “w0wa”. Defaults to 0.0.
- update_cosmology(Om0, H0, Ok0=0.0, Or0=0.0, de_model='lambda', w0=-1.0, wa=0.0)[source]
Update the class to a new cosmology.
Overwrites the current class attributes to assign the new cosmological parameters passed as input.
- Parameters:
Om0 (float) – Fractional total matter density at present time, \(\Omega_\mathrm{m,0}\).
H0 (float) – Hubble constant at present time, \(H_0\).
Ok0 (float, optional) – Fractional curvature density at present time, \(\Omega_\mathrm{k,0}\). Defaults to 0.0.
Or0 (float, optional) – Fractional radiation density at present time, \(\Omega_\mathrm{r,0}\), Defaults to 0.0.
de_model (str, optional) – Selected dark energy model. It can be chosen from the list [“lambda”, “w0”, “w0wa”], whose entries correspond to a LCDM, \(w\) CDM, and quintessence model, respectively. Defaults to “lambda”.
w0 (float, optional) – Dark energy equation of state at present time, \(w_0\). Only used if de_model is not “lambda”. Defaults to -1.0.
wa (float, optional) – Negative derivative of the dark energy equation of state with respect to the scale factor, \(w_a\). Only used if de_model is “w0wa”. Defaults to 0.0.
- DE_z(z)[source]
Dark energy density as a function of redshift.
Returns the energy density of the specified dark energy component, normalised to the value at present time,
\[\frac{\rho_\mathrm{DE}(z)}{\rho_\mathrm{DE}(0)} = \ \exp\left[-\int_0^z \frac{dz'}{1+z'}\left(1+w\left(z'\right)\ \right) \right]\,.\]- Parameters:
z (float or numpy.ndarray) – Redshifts at which to evaluate the dark energy density.
- Returns:
de_z – Energy density of the dark energy component at the specified redshifts.
- Return type:
- wz(z)[source]
Dark energy equation of state as a function of redshift.
Returns the equation of state of the dark energy component,
\[w(z) = w_0+w_a\frac{z}{1+z}\,.\]- Parameters:
z (float or numpy.ndarray) – Redshifts at which to evaluate the dark energy equation of state.
- Returns:
w – Dark energy equation of state at the specified redshifts.
- Return type:
- Ez(z)[source]
Normalised expansion factor as a function of redshift.
Returns the value of the Hubble factor at the specified redshift, normalised to the value at present time,
\begin{split} E(z) = \frac{H(z)}{H_0} = \bigg[ \ &\Omega_\mathrm{m,0}(1+z)^3 \ + \Omega_\mathrm{r,0}(1+z)^4 \ + \Omega_\mathrm{k,0}(1+z)^2 \\ &+ \Omega_\mathrm{DE,0}\exp\Big[-\int_0^z \ \frac{dz'}{1+z'} \left(1+w\left(z'\right)\right) \Big] \bigg]^\frac{1}{2}\,. \end{split}- Parameters:
z (float or numpy.ndarray) – Redshifts at which to evaluate the normalised expansion factor.
- Returns:
Ez – Normalised expansion factor at the specified redshifts.
- Return type:
- one_over_Ez(z)[source]
Inverse normalised expansion factor as a function of redshift.
Return the inverse of the normalised expansion factor defined in Ez.
- Parameters:
z (float or numpy.ndarray) – Redshifts at which to evaluate the inverse expansion factor.
- Returns:
inv_Ez – Inverse normalised expansion factor at the specified redshifts.
- Return type:
- Hz(z)[source]
Hubble expansion factor.
Returns the Hubble parameter \(H(z)\), defined as
\[H(z) = H_0\, E(z) \, .\]- Parameters:
z (float or numpy.ndarray) – Redshifts at which to evaluate the Hubble factor.
- Returns:
Hz – Hubble expansion factor at the specified redshifts.
- Return type:
- Om(z)[source]
Fractional total matter density as a function of redshift.
Returns the total matter density at the specified redshifts in units of the critical density \(\rho_\mathrm{crit}(z)=\frac{3H^2(z)}{8\pi G}\), as
\[\Omega_\mathrm{m}(z) = \ \frac{\rho_\mathrm{m}(z)}{\rho_\mathrm{crit}(z)} = \ \frac{\Omega_\mathrm{m,0}\,(1+z)^3}{E^2(z)} \, .\]- Parameters:
z (float or numpy.ndarray) – Redshifts at which to evaluate the fractional matter density.
- Returns:
Om – Fractional matter density at the specified redshifts.
- Return type:
- Ode(z)[source]
Fractional dark energy density as a function of redshift.
Returns the dark energy density at the specified redshifts in units of the critical density \(\rho_\mathrm{crit}(z)=\frac{3H^2(z)}{8\pi G}\), as
\[\Omega_\mathrm{DE}(z) = \ \frac{\rho_\mathrm{DE}(z)}{\rho_\mathrm{crit}(z)} = \ \frac{\Omega_\mathrm{DE,0}\exp\left[ \ -\int_0^z \frac{dz'}{1+z'}\left(1+w\left(z'\right)\right) \ \right]}{E^2(z)} \, .\]- Parameters:
z (float or numpy.ndarray) – Redshifts at which to evaluate the fractional dark energy density.
- Returns:
Ode – Fractional dark energy density at the specified redshifts.
- Return type:
- comoving_transverse_distance(z)[source]
Transverse comoving distance as a function of redshift.
Returns the transverse comoving distance defined as
\begin{gather*} D_\mathrm{M}(z) = \begin{cases} \frac{D_H}{\sqrt{-\Omega_\mathrm{k,0}}}\sin \left(\ \frac{\sqrt{-\Omega_\mathrm{k,0}}D_\mathrm{C}(z)}{D_H}\ \right), & \text{if}\ \Omega_\mathrm{k,0}<0 \\ D_\mathrm{C}(z), & \text{if}\ \Omega_\mathrm{k,0}=0 \, ,\\ \frac{D_H}{\sqrt{\Omega_\mathrm{k,0}}}\sinh \left(\ \frac{\sqrt{\Omega_\mathrm{k,0}}D_\mathrm{C}(z)}{D_H}\ \right), & \text{if}\ \Omega_\mathrm{k,0}>0 \end{cases} \end{gather*}where
\[D_\mathrm{C}(z) = D_H \int_0^z \frac{dz'}{E(z')}\]is the comoving distance, and
\[D_H = \frac{c}{H_0}\]is the Hubble distance.
- angular_diameter_distance(z)[source]
Angular diameter distance as a function of redshift.
Returns the angular diameter distance defined as
\[D_\mathrm{A}(z) = \frac{1}{1+z}D_\mathrm{M}(z) \, .\]
- growth_factor(z, get_growth_rate=False)[source]
Linear growth factor as a function of redshift.
Returns the linear growth factor \(D(z)\) (and the linear growth rate \(f(z)\) at user request).
- Parameters:
- Returns:
Dz – Linear growth factor, or list containing both the linear growth factor and growth rate, at the specified redshift.
- Return type:
- growth_rate(z)[source]
Linear growth rate as a function of redshift.
Returns the linear growth rate \(f(z)\).
- comoving_volume(zmin, zmax, fsky)[source]
Comoving volume as a function of redshift and sky fraction.
Computes the transverse comoving volume between \(z_\mathrm{min}\) and \(z_\mathrm{max}\) for a given sky fraction \(f_\mathrm{sky}\), as
\[V_\mathrm{M}(z_\mathrm{min}, z_\mathrm{max}, f_\mathrm{sky}) = \ \frac{4\pi f_\mathrm{sky}}{3} \left[D_\mathrm{M}^3 \ (z_\mathrm{max}) - D_\mathrm{M}^3(z_\mathrm{min})\right]\]- Parameters:
- Returns:
vol – Transverse comoving volume between the specified minimum and maximum redshifts, and for the given sky fraction.
- Return type:
data
Data module.
- class comet.data.MeasuredData(**kwargs)[source]
Bases:
objectClass for handling data structures (data vectors and covariances).
Class constructor.
Keywords argument kwargs are summarised in the Parameters section below. An instance of the class can be created without specifying any of the keyword arguments, and subsequently updated with the update method.
- Parameters:
bins (numpy.ndarray, optional) – Array containing the sampled wavemodes \(k\).
signal (numpy.ndarray, optional) – Array containing the power spectrum multipoles \(P_{\ell}(k)\). If more than one multipole is provided, the first and second index of the array runs over the different \(k\) and the different multipole \(\ell\), respectively.
cov (numpy.ndarray, optional) – Covariance matrix corresponding to signal. The covariance is in the form of a 2d array, whose blocks correspond to the auto- (along the diagonal) and cross-covariances of the multipoles.
theory_cov (bool, optional) – Flag to determine if the provided covariance matrix is theoretical (True) or estimated from simulations (False). Defaults to True.
n_realizations (int, optional) – If the provided covariance is estimated from numerical simulations, this parameter is required, and specifies the total number of resamplings (needed for Hartlap corrections).
- update(**kwargs)[source]
Update the class with new data.
Keywords argument kwargs are summarised in the Parameters section below.
- Parameters:
bins (numpy.ndarray, optional) – Array containing the sampled wavemodes \(k\).
signal (numpy.ndarray, optional) – Array containing the power spectrum multipoles \(P_{\ell}(k)\). If more than one multipole is provided, the first and second index of the array runs over the different \(k\) and the different multipole \(\ell\), respectively.
cov (numpy.ndarray, optional) – Covariance matrix corresponding to signal. The covariance is in the form of a 2d array, whose blocks correspond to the auto- (along the diagonal) and cross-covariances of the multipoles.
theory_cov (bool, optional) – Flag to determine if the provided covariance matrix is theoretical (True) or estimated from simulations (False). Defaults to True.
n_realizations (int, optional) – If the provided covariance is estimated from numerical simulations, this parameter is required, and specifies the total number of resamplings (needed for Hartlap corrections).
- set_kmax(kmax)[source]
Set the maximum mode used in the computation of the \(\chi^2\).
Sets the class attribute corresponding to the maximum wavemode \(k_\mathrm{max}\) to be used in the calculation of the \(\chi^2\). In addition, it applies the corresponding scale cuts to both data vectors and covariance matrix.
- AHfactor(nbins)[source]
Compute corrections to the inverse covariance matrix.
Depending on the value of the theory_cov attribute, returns the correction factor to the inverse covariance matrix (to take into account the limited number of independent realizations, in case the covariance is estimated from numerical simulations).
Returns 1 if the class attribute theory_cov is set to True. Otherwise, returns
\[\frac{N_\mathrm{sim}-N_\mathrm{bins}-2}{N_\mathrm{sim}-1}\,,\]with \(N_\mathrm{sim}\) and \(N_\mathrm{bins}\) being the number of independent realizations from which the covariance has been estimated and the total number of bins at which it is sampled, respectively (see Hartlap 2007).
- get_signal(ell, kmax=None)[source]
Get power spectrum multipole from data sample.
Returns the input data power spectrum multipole of order \(\ell\) up to \(k_\mathrm{max}\).
- Parameters:
ell (int) – Specific multipole order \(\ell\). Can be chosen from the list [0,2,4], whose entries correspond to monopole (\(\ell=0\)), quadrupole (\(\ell=2\)) and hexadecapole (\(\ell=4\)).
kmax (float, optional) – Maximum wavemode \(k_\mathrm{max}\) up to which the multipole is provided. If None, the corresponding class attribute is used instead.
- Returns:
signal_kmax – Data power spectrum multipole of order \(\ell\) up to \(k_\mathrm{max}\).
- Return type:
- get_std(ell, kmax=None)[source]
Get standard deviation of power spectrum multipole from sample.
Returns the standard deviation of the input data power spectrum multipole of order \(\ell\) up to \(k_\mathrm{max}\).
- Parameters:
ell (int) – Specific multipole order \(\ell\). Can be chosen from the list [0,2,4], whose entries correspond to monopole (\(\ell=0\)), quadrupole (\(\ell=2\)) and hexadecapole (\(\ell=4\)).
kmax (float, optional) – Maximum wavemode \(k_\mathrm{max}\) up to which the standard deviation is provided. If None, the corresponding class attribute is used instead.
- Returns:
std_kmax – Standard deviation of the data power spectrum multipole of order \(\ell\) up to \(k_\mathrm{max}\).
- Return type:
tables
Tables module.
- class comet.tables.Tables(params, real_space=False)[source]
Bases:
objectClass for handling the tables of the emulator.
It handles both the training and validation sets, in the form of tables containing the different contributions to \(P_\mathrm{gg}(k,\mu)\). Provides routine to convert the raw tables into their transformed versions, which span a shorter dynamical range (to increase the accuracy of the emulator), to train the emulator, and to transform back the emulator predictions in the original metric.
Class constructor.
- Parameters:
- set_param_ranges(ranges)[source]
Set ranges for the parameters of the emulator.
Sets the internal class attribute defining the prior for the parameters of the emulator.
- Parameters:
ranges (dict) – Dictionary containing the parameter ranges. Keys correspond to the name of the parameters, while values are list with two entries, which correspond to the minimum and maximum value of the parameter.
- assign_samples(samples_hdu)[source]
Read parameter sample from HDU object.
Reads parameter sample from a Header Data Unit object, and stores it as class attribute. If the sample is meant for validation, determines the parameters from the header of the HDU object, otherwise uses the parameters defined as class attributes.
- Parameters:
samples_hdu (astropy.io.fits.BinTableHDU) – Header Data Unit containing the parameter sample.
- assign_table(table_hdu, nk, nkloop)[source]
Read model table from HDU object.
Reads a model table from a Header Data Unit object, and stores it as class attribute. If the sample is a training one, additionally calls the routine to convert the model table into its transformed version.
- Parameters:
table_hdu (astropy.io.fits.BinTableHDU) – Header Data Unit containing the model table.
nk (int) – Number of \(k\) bins of the table.
nkloop (int) – Number of \(k\) bins of the table corresponding to the loop predictions.
- get_flip_and_offset(table)[source]
Compute flip and offset to rescale an input model table.
- Parameters:
table (numpy.ndarray) – Model table containing a given term as a function of \(k\) (first index) and the different parameter sample (second index).
- Returns:
flip (list) – Flip value for each \(k\) entry.
max_offset (list) – Maximum offset for each \(k\) entry.
- transform(table, data_type)[source]
Rescale the dynamical range of a table for the emulation.
Applies flip, offset, and rescales the model table. This step is performed by first taking the logarithm of the model table, and then subtracting its mean and dividing by its standard deviation.
- Parameters:
table (numpy.ndarray) – Model table containing a given term as a function of \(k\) (first index) and the different parameter sample (second index).
data_type (str) – Type of the table that is passed as input. This is used as a keyword for the dictionary where the values of flip, offset, mean and standard deviation are stored.
- Returns:
resc_table – Rescaled table.
- Return type:
- transform_inv(table, data_type)[source]
Rescale back the dynamical range of a table.
Performs the inverse operations defined in the transform method. Needed to obtain predictions from the emulator in the original metric.
- Parameters:
table (numpy.ndarray) – Table containing a given term as a function of \(k\) (first index) and the different parameter sample (second index).
data_type (str) – Type of the table that is passed as input. This is used as a keyword for the dictionary where the values of flip, offset, mean and standard deviation are stored.
- Returns:
resc_table – Rescaled table.
- Return type: