nbodykit.cosmology.cosmology module

class nbodykit.cosmology.cosmology.Cosmology(h=0.67556, T_cmb=2.7255, Omega_b=0.0482754208891869, Omega_cdm=0.26377065934278865, N_ur=None, m_ncdm=[0.06], P_k_max=10.0, P_z_max=100.0, gauge='synchronous', n_s=0.9667, nonlinear=False, verbose=False, **kwargs)[source]

Bases: object

A cosmology calculator based on the CLASS binding in classylss.

It is a collection of all method provided by the CLASS interfaces.

The individual interfaces can be accessed too, such that c.Spectra.get_transfer and c.get_transfer are identical.

Important

A default set of units is assumed. Those units are:

  • temperature: \(\mathrm{K}\)
  • distance: \(h^{-1} \mathrm{Mpc}\)
  • wavenumber: \(h \mathrm{Mpc}^{-1}\)
  • power: \(h^{-3} \mathrm{Mpc}^3\)
  • density: \(10^{10} (M_\odot/h) (Mpc/h)^{-3}\)
  • neutrino mass: \(\mathrm{eV}\)
  • time: \(\mathrm{Gyr}\)
  • H0: \((h^{-1} \mathrm{Mpc}) / (\mathrm{km/s})\)

Notes

  • The default configuration assumes a flat cosmology, \(\Omega_{0,k}=0\). Pass Omega_k in the extra keyword dictionary to change this value.
  • By default, a cosmological constant is assumed, with its density value inferred by the curvature condition.
  • Non-cosmological constant dark energy can be used by specifying the w0_fld, wa_fld, and/or Omega_fld values.
  • The sigma8 attribute can be set to the desired value, and the internal value of A_s will be automatically adjusted.
Parameters:
  • h (float) – the dimensionaless Hubble parameter
  • T_cmb (float) – the temperature of the CMB in Kelvins
  • Omega_b (float) – the current baryon density parameter, \(\Omega_{b,0}\)
  • Omega_cdm (float) – the current cold dark matter density parameter, \(\Omega_{cdm,0}\)
  • N_ur (float) – the number of ultra-relativistic (massless neutrino) species; the default number is inferred based on the number of massive neutrinos via the following logic: if you have respectively 1,2,3 massive neutrinos and use the default T_ncdm value (0.71611 K), designed to give m/omega of 93.14 eV, and you wish to have N_eff=3.046 in the early universe, then N_ur is set to 2.0328, 1.0196, 0.00641, respectively.
  • m_ncdm (list, None) – the masses (in eV) for all massive neutrino species; an empty list should be passed for no massive neutrinso. The default is a single massive neutrino with mass of 0.06 eV
  • P_k_max (float) – the maximum k value to compute power spectrum results to, in units of \(h/Mpc\)
  • P_z_max (float) – the maximum redshift to compute power spectrum results to
  • gauge (str,) – either synchronous or newtonian
  • n_s (float) – the tilt of the primordial power spectrum
  • nonlinear (bool) – whether to compute nonlinear power spectrum results via HaloFit
  • verbose (bool) – whether to turn on the default CLASS logging for all submodules
  • **kwargs – extra keyword parameters to pass to CLASS; users should be wary of configuration options that may conflict with the base set of parameters

Attributes

sigma8 The amplitude of matter fluctuations at \(z=0\) in a sphere of radius \(r = 8 \ h^{-1}\mathrm{Mpc}\).

Methods

clone(**kwargs) Create a new cosmology based on modification of self, with the input keyword parameters changed.
from_astropy(cosmo, **kwargs) Initialize and return a Cosmology object from a subclass of astropy.cosmology.FLRW.
from_file(filename, **kwargs) Initialize a Cosmology object from the CLASS parameter file
to_astropy() Initialize and return a subclass of astropy.cosmology.FLRW from the Cosmology class.
__dir__()[source]

a list of all members from all delegate classes

__getattr__(name)[source]

Find the proper delegate, initialize it, and run the method

__iter__()[source]

Allows dict() to be used on class.

clone(**kwargs)[source]

Create a new cosmology based on modification of self, with the input keyword parameters changed.

Parameters:**kwargs – keyword parameters to adjust
Returns:a copy of self, with the input kwargs adjusted
Return type:Cosmology
dro = [<class 'classylss.astropy_compat.AstropyCompat'>, <class 'classylss.binding.Thermo'>, <class 'classylss.binding.Spectra'>, <class 'classylss.binding.Perturbs'>, <class 'classylss.binding.Primordial'>, <class 'classylss.binding.Background'>, <class 'classylss.binding.ClassEngine'>]
dro_dict = {'Primordial': <class 'classylss.binding.Primordial'>, 'Background': <class 'classylss.binding.Background'>, 'Perturbs': <class 'classylss.binding.Perturbs'>, 'Spectra': <class 'classylss.binding.Spectra'>, 'ClassEngine': <class 'classylss.binding.ClassEngine'>, 'Thermo': <class 'classylss.binding.Thermo'>, 'AstropyCompat': <class 'classylss.astropy_compat.AstropyCompat'>}
classmethod from_astropy(cosmo, **kwargs)[source]

Initialize and return a Cosmology object from a subclass of astropy.cosmology.FLRW.

Parameters:
  • cosmo (subclass of astropy.cosmology.FLRW.) – the astropy cosmology instance
  • **kwargs – extra keyword parameters to pass when initializing
Returns:

the initialized cosmology object

Return type:

Cosmology

classmethod from_file(filename, **kwargs)[source]

Initialize a Cosmology object from the CLASS parameter file

Parameters:filename (str) – the name of the parameter file to read
sigma8

The amplitude of matter fluctuations at \(z=0\) in a sphere of radius \(r = 8 \ h^{-1}\mathrm{Mpc}\).

This is not an input CLASS parameter, but users can set this parameter and the scalar amplitude A_s will be internally adjusted to achieve the desired sigma8.

to_astropy()[source]

Initialize and return a subclass of astropy.cosmology.FLRW from the Cosmology class.

Returns:the astropy class holding the cosmology values
Return type:subclass of astropy.cosmology.FLRW
nbodykit.cosmology.cosmology.astropy_to_dict(cosmo)[source]

Convert an astropy cosmology object to a dictionary of parameters suitable for initializing a Cosmology object.

nbodykit.cosmology.cosmology.sanitize_class_params(cosmo, pars)[source]

Given a dictionary of CLASS parameters, construct the args dict and kwargs dict that can used to initialize a Cosmology class, accounting for any possible conflicts.

The args dict holds the main (named) __init__ keywords, and the kwargs holds all of the extra keywords.

nbodykit.cosmology.cosmology.set_sigma8(cosmo, sigma8, inplace=False)[source]

Return a clone of the input Cosmology object, with the sigma8 value set to the specified value.

Parameters:
  • cosmo (Cosmology) – the input cosmology object
  • sigma8 (float) – the desired sigma8 value
  • inplace (bool, optional) – if True, update sigma8 of the input cosmo object, else return a new Cosmology object
nbodykit.cosmology.cosmology.verify_parameters(args, extra)[source]

Verify the input parameters to a Cosmology object and set various default values.