API reference

Everything importable from CosmoFit itself is on this page; the subpackages below carry the rest.

Models

Twenty expansion histories written out by hand, and three routes to one that is not here. Every one is a Cosmology subclass, so every dataset, likelihood, sampler and plot works on all of them without knowing which.

Cosmology

Base class for all cosmological models.

CosmologyParameters

Generic container for the parameters shared by every cosmological model implemented in CosmoFit (LCDM, CPL, ...).

ModelConfigurationError

The model cannot answer this question at any parameter values.

LCDM

Flat or curved Lambda-CDM.

WCDM

Flat or curved wCDM: dark energy with a constant equation of state w0 (does not evolve with redshift; wa is ignored, same as LCDM ignoring w0/wa and CPL being the two-parameter, wa-evolving generalization of this model).

CPL

Chevallier-Polarski-Linder (CPL) dark-energy model.

JBP

Jassal-Bagla-Padmanabhan (JBP) dark-energy model.

BA

Barboza-Alcaniz (BA) dark-energy model.

LogarithmicDE

Logarithmic (Efstathiou) dark-energy parametrization,

PEDE

Phenomenologically Emergent Dark Energy (Li & Shafieloo 2019).

GEDE

Generalized Emergent Dark Energy (Li & Shafieloo 2020).

LsCDM

Lambda_s CDM (Akarsu et al. 2021): LCDM, except that the cosmological constant changes sign at a redshift z_dagger.

GCG

Generalized Chaplygin Gas (GCG).

IDE

Interacting Dark Energy: dark matter and dark energy exchange energy, with a coupling Q = 3 xi H rho_de.

RunningVacuum

Running Vacuum Model: a cosmological "constant" that runs with the expansion rate,

Cardassian

Modified Polytropic Cardassian expansion (Freese & Lewis 2002; Wang et al. 2003),.

HDE

Holographic dark energy with a future-event-horizon cutoff.

ADE

New agegraphic dark energy: the holographic cutoff is the age of the universe, in conformal time.

RDE

Ricci dark energy: the holographic cutoff is the Ricci scalar.

DGP

Dvali-Gabadadze-Porrati braneworld gravity, self-accelerating branch.

FQExponential

f(Q) gravity, exponential model.

FRTLinear

f(R,T) gravity, linear model: f(R,T) = R + 2*lambda*T.

FRHuSawicki

f(R) gravity, Hu & Sawicki (2007) model.

define_model

Build a new Cosmology subclass from a plain E(z) function.

model_from_expression

Same as define_model(), but E/w/dEdz/ Omega_de/mu are given as Python expression strings (e.g. "sqrt(Omega_m*(1+z)**3 + (1-Omega_m)*(1+z)**(3*(1+w0)))") instead of callables -- convenient for text-entry UIs (see the Streamlit app under app/), where asking for a Python function isn't practical.

Likelihoods

One class per dataset, plus the joint likelihood that combines them. Three of these are tabulated rather than Gaussian – they carry a released likelihood surface instead of a mean and a covariance.

BaseLikelihood

JointLikelihood

Joint likelihood composed of multiple independent likelihoods.

CCLikelihood

DESILikelihood

SDSSBAOLikelihood

Combined SDSS BAO-only likelihood: BOSS DR12 (z=0.38, 0.51) + eBOSS DR16 LRG (z=0.698) + eBOSS DR16 QSO (z=1.48), each an independent, non-overlapping-redshift measurement -- see load_sdss_bao() for why BOSS DR12's usual third bin (z=0.61) is omitted.

SDSSFullShapeLikelihood

SDSS BAO + full-shape consensus: D_M/r_d, D_H/r_d and f sigma_8 at z = 0.38, 0.51, 0.698 and 1.48, twelve numbers with the covariance between them.

EBOSSELGLikelihood

eBOSS DR16 emission-line galaxies, D_V/r_d at z_eff = 0.845, as a tabulated likelihood.

EBOSSELGFullShapeLikelihood

eBOSS DR16 emission-line galaxies, full shape: the joint likelihood of (D_M/r_d, D_H/r_d, f sigma_8) at z_eff = 0.845, on a 100x100x100 grid.

EBOSSLyaLikelihood

eBOSS DR16 Lyman-alpha forest BAO, (D_M/r_d, D_H/r_d) at z_eff = 2.334, as a tabulated two-dimensional likelihood.

BAOLowZLikelihood

The two BAO measurements below z = 0.2: 6dFGS at z = 0.106 (Beutler et al. 2011) and the SDSS DR7 Main Galaxy Sample at z = 0.15 (Ross et al. 2015).

PantheonLikelihood

Pantheon+ / Pantheon+SH0ES Supernova likelihood.

DESSN5YRLikelihood

DES-SN5YR (Dark Energy Survey 5-year) Supernova likelihood.

Union3Likelihood

Union3 (Rubin et al. 2023): 2087 supernovae compressed into 22 binned distance moduli with a full 22x22 covariance.

PlanckLikelihood

PlanckLiteLikelihood

Planck 2018 plik_lite binned TT/TE/EE bandpowers against a Boltzmann-computed C_l spectrum.

PlanckLensingLikelihood

Planck 2018 lensing-potential bandpowers against a Boltzmann-computed C_L^{phiphi}.

PlanckLowEELikelihood

Planck 2018 low-multipole EE, via its released probability table.

ACTDR6LensingLikelihood

ACT DR6 lensing bandpowers against a Boltzmann-computed C_L^{kappakappa}.

FSigma8Likelihood

Growth-rate (fsigma8) likelihood, e.g. the "Gold-2018" RSD compilation (load_fsigma8()).

S8Likelihood

A single Gaussian S8 = sigma8 * sqrt(Omega_m / 0.3) constraint from a weak-lensing survey (default: KiDS-1000; also DES Y3 -- see load_s8()).

H0Likelihood

A local distance-ladder H0 measurement.

OmegaBLikelihood

A BBN constraint on the physical baryon density omega_b h^2.

TauLikelihood

The Planck 2018 large-scale-polarization constraint on the reionization optical depth, tau = 0.0544 +- 0.0073.

Fitting

Fitter

Ties together a cosmological model, one or more datasets, a prior, and (optionally) an MCMC run and best-fit search.

BaseSampler

Interface a sampling backend must implement to be usable by Fitter.

EnsembleSampler

emcee.EnsembleSampler backend: affine-invariant ensemble MCMC, the default (and currently only) way Fitter.run_mcmc explores a posterior.

FitResult

Everything a finished (or in-progress) fit produced, in one object: which model/datasets/parameters it is, the best-fit point (if best_fit() was called), and the MCMC posterior (if run_mcmc() was called).

BestFitResult

Maximum-likelihood point, as found by Fitter.best_fit().

MCMCResult

Posterior summary of an MCMC run, as found by Fitter.run_mcmc().

Plotting

FitPlotter

Plotting methods for a Fitter.

Saved chains

A chain is written as it is sampled, resumed rather than re-sampled next time, and can be reopened months later without loading a single dataset.

ChainFile

An HDF5 file holding one MCMC chain, plus the CosmoFit metadata describing it.

StoredSampler

A chain read back from disk, wearing the small part of the emcee.EnsembleSampler interface that CosmoFit actually asks of it.

open_chain

Read a saved chain back for analysis, without a Fitter and without touching any dataset.

chain_info

What's in a chain file -- model, datasets, parameters, how many steps -- without reading the chain itself.

Datasets

available_datasets

available_versions

Return all available versions of a dataset.

dataset_reference

The citation string for a dataset version, without loading any of its files.

Types

The two array types this library’s public surface speaks in.

Every model here takes a redshift and returns a number per redshift, and both ends are deliberately loose about shape: you may pass a Python float, a list, or an array, and what comes back matches.

Spelling that out once is what makes the rest of the annotations honest. E(0.5) returns np.float64 and E([0.1, 0.2]) returns an ndarraynp.asarray(z, dtype=float) on a scalar gives a 0-d array, and numpy’s ufuncs turn that back into a scalar on the way out. Annotating the return as np.ndarray alone would be wrong for the commonest call in the library.

>>> from CosmoFit.typing import Array, Redshift
>>>
>>> def E(self, z: Redshift) -> Array:
...     ...
CosmoFit.typing.Array = numpy.float64 | NDArray[numpy.float64]

a scalar for a scalar, an array for an array.

Type:

What comes back

CosmoFit.typing.PathLike = str | os.PathLike

a string, or anything implementing the os.PathLike protocol (pathlib.Path, most obviously).

Type:

Anywhere a file is written or read

type CosmoFit.typing.Redshift = Buffer | _DualArrayLike[dtype, complex | bytes | str]

A redshift, scale factor or wavenumber: anything numpy can make an array of floats from – a scalar, a sequence, or an array.

Subpackages