firecrown.connector.mapping

Facilities for mapping cosmological parameters between frameworks.

The module mapping provides facilities for mapping the cosmological constants and functions used by one body of code to another.

Each supported body of code has its own dedicated class.

Attributes

mapping_classes

Classes

Mapping

Abstract base class defining the interface for each supported code.

MappingCLASS

This class is not yet implemented.

MappingCosmoSIS

Mapping support for CosmoSIS.

MappingCAMB

Mapping support for PyCAMB, the Python version of CAMB.

Functions

build_ccl_background_dict(*, a, chi, h_over_h0)

Builds the CCL dictionary of background quantities.

mapping_builder(*, input_style, **kwargs)

Return the Mapping class for the given input_style.

Module Contents

firecrown.connector.mapping.build_ccl_background_dict(*, a, chi, h_over_h0)[source]

Builds the CCL dictionary of background quantities.

Parameters:
  • a (numpy.typing.NDArray[numpy.float64]) – The scale factor array

  • chi (numpy.typing.NDArray[numpy.float64]) – The comoving distance array

  • h_over_h0 (numpy.typing.NDArray[numpy.float64]) – The Hubble parameter divided by H0

Returns:

the dictionary of background quantities

Return type:

firecrown.ccl_factory.Background

class firecrown.connector.mapping.Mapping[source]

Bases: abc.ABC

Inheritance diagram of firecrown.connector.mapping.Mapping

Abstract base class defining the interface for each supported code.

The interface describes a mapping of cosmological constants from some concrete Boltzmann calculator to the form those constants take in CCL. Each supported Boltzmann calculator must have its own concrete subclass.

The class attributes are all firecrown.connector.descriptors. This is to control the allowed types for the instance attributes. A descriptor of name ‘x’ will provide an apparent attribue with name x in each object, as well as an entry _x in the object’s __dict__.

Omega_c
Omega_b
h
A_s
sigma8
n_s
Omega_k
Neff
m_nu_type
w0
wa
T_CMB
m_nu: float | list[float] | None = None
get_params_names(amplitude=PoweSpecAmplitudeParameter.AS)[source]

Return the names of the expected cosmological parameters for this mapping.

Parameters:

amplitude (firecrown.ccl_factory.PoweSpecAmplitudeParameter)

Return type:

list[str]

transform_k_h_to_k(k_h)[source]

Transform the given k_h (k over h) to k.

Parameters:

k_h – the array of wavenumber/h to be transformed

Returns:

the transformed array

transform_p_k_h3_to_p_k(p_k_h3)[source]

Transform the given \(p_k h^3 \to p_k\).

Parameters:

p_k_h3 – the array of \(p_k h^3\) to be transformed

transform_h_to_h_over_h0(h)[source]

Transform distances h to \(h/h_0\).

Parameters:

h – the array of distances to be transformed

Returns:

the transformed array

set_params(*, Omega_c, Omega_b, h, A_s=None, sigma8=None, n_s, Omega_k, Neff, m_nu, w0, wa, T_CMB)[source]

Sets the cosmological constants suitable a pyccl.core.CosmologyCalculator.

See the documentation of that class for an explanation of the choices and meanings of default values of None.

Parameters:
  • Omega_c (float) – fraction of cold dark matter

  • Omega_b (float) – fraction of baryons

  • h (float) – dimensionless Hubble parameter; h = H0/(100 km/s/Mpc)

  • A_s (None | float) – amplitude of the primordial power spectrum

  • sigma8 (None | float) – s.d. of the matter contrast on a scale of (8 Mpc)/h

  • n_s (float) – scalar spectral index of primordial power spectrum

  • Omega_k (float) – curvature of the universe

  • Neff (float) – effective number of relativistic neutrino species

  • m_nu (float | list[float] | None) – effective mass of neutrinos; None for massless neutrinos

  • w0 (float) – constant of the CPL parameterization of the dark energy equation of state

  • wa (float) – linear coefficient of the CPL parameterization of the dark energy equation of state

  • T_CMB (float) – cosmic microwave background temperature today

static redshift_to_scale_factor(z)[source]

Converts redshift to scale factor.

Given arrays of redshift returns an array of scale factor with the inverse order.

Parameters:

z (numpy.typing.NDArray[numpy.float64]) – array of redshifts

Returns:

array of scale factors

Return type:

numpy.typing.NDArray[numpy.float64]

static redshift_to_scale_factor_p_k(p_k)[source]

Converts power spectrum from redshift to scale factor.

Given an 2d arrays power spectrum ordered by (redshift, mode) return a 2d array with the rows flipped to match the reordering from redshift to scale factor.

Parameters:

p_k (numpy.typing.NDArray[numpy.float64]) – a power spectrum, ordered by (redshift, mode)

Returns:

array of power spectrum, ordered by (scale factor, mode)

Return type:

numpy.typing.NDArray[numpy.float64]

asdict()[source]

Return a dictionary containing the cosmological constants.

Returns:

the dictionary, containing keys:

  • Omega_c: fraction of cold dark matter

  • Omega_b: fraction of baryons

  • h: dimensionless Hubble parameter; h = H0/(100 km/s/Mpc)

  • A_s: amplitude of the primordial power spectrum

  • sigma8: s.d. of the matter contrast on a scale of (8 Mpc)/h

  • n_s: scalar spectral index of primordial power spectrum

  • Omega_k: curvature of the universe

  • Neff: effective number of relativistic neutrino species

  • m_nu: effective mass of neutrinos

  • w0: constant of the CPL parameterization of the dark energy

    equation of state

  • wa: linear coefficient of the CPL parameterization of the

    dark energy equation of state

  • T_CMB: cosmic microwave background temperature today

Return type:

dict[str, float | list[float]]

get_H0()[source]

Return the value of H0.

Returns:

H0 in km/s/Mpc

Return type:

float

class firecrown.connector.mapping.MappingCLASS[source]

Bases: Mapping

Inheritance diagram of firecrown.connector.mapping.MappingCLASS

This class is not yet implemented.

This stub is here to satisfy IDEs that complain about using the names of missing classes.

class firecrown.connector.mapping.MappingCosmoSIS[source]

Bases: Mapping

Inheritance diagram of firecrown.connector.mapping.MappingCosmoSIS

Mapping support for CosmoSIS.

get_params_names(amplitude=PoweSpecAmplitudeParameter.AS)[source]

Return the names of the expected cosmological parameters for this mapping.

Returns:

a list of the cosmological parameter names

Parameters:

amplitude (firecrown.ccl_factory.PoweSpecAmplitudeParameter)

Return type:

list[str]

transform_k_h_to_k(k_h)[source]

Transform the given k_h (k over h) to k.

Parameters:

k_h (numpy.typing.NDArray[numpy.float64]) – the array of wavenumber/h to be transformeed

Returns:

the transformed array

Return type:

numpy.typing.NDArray[numpy.float64]

transform_p_k_h3_to_p_k(p_k_h3)[source]

Transform the given \(p_k h^3 \to p_k\).

Parameters:

p_k_h3 (numpy.typing.NDArray[numpy.float64]) – the array of \(p_k h^3\) to be transformed

Returns:

the transformed array

Return type:

numpy.typing.NDArray[numpy.float64]

transform_h_to_h_over_h0(h)[source]

Transform distances h to \(h/h_0\).

Parameters:

h (numpy.typing.NDArray[numpy.float64]) – the array of distances to be transformed

Returns:

the transformed distances

Return type:

numpy.typing.NDArray[numpy.float64]

set_params_from_cosmosis(cosmosis_params)[source]

Set the parameters in this mapping from the given CosmoSIS parameters.

Parameters:

cosmosis_params (firecrown.likelihood.likelihood.NamedParameters) – the cosmological parameters read from CosmoSIS

Return type:

None

calculate_ccl_args(sample)[source]

Calculate the arguments necessary for CCL for this sample.

Parameters:

sample (cosmosis.datablock) – the datablock for the current sample

Returns:

the arguments required by CCL

Return type:

firecrown.ccl_factory.CCLCalculatorArgs

class firecrown.connector.mapping.MappingCAMB[source]

Bases: Mapping

Inheritance diagram of firecrown.connector.mapping.MappingCAMB

Mapping support for PyCAMB, the Python version of CAMB.

Note that the Python version of CAMB uses some different conventions from the Fortran version of CAMB. The two are not interchangeable.

get_params_names(amplitude=PoweSpecAmplitudeParameter.AS)[source]

Return the names of the expected cosmological parameters for this mapping.

Returns:

a list of the cosmological parameter names

Parameters:

amplitude (firecrown.ccl_factory.PoweSpecAmplitudeParameter)

Return type:

list[str]

set_params_from_camb(**params_values)[source]

Set the parameters in this mapping from the given CAMB-style parameters.

Return type:

None

firecrown.connector.mapping.mapping_classes: Mapping[str, Type[Mapping]]
firecrown.connector.mapping.mapping_builder(*, input_style, **kwargs)[source]

Return the Mapping class for the given input_style.

If input_style is not recognized raise an exception.

Parameters:
  • input_style (str) – the name of the mapping

  • kwargs – the parameters of the mapping

Returns:

the mapping object

Return type:

Mapping