Likelihoods

base

class desilike.likelihoods.base.BaseGaussianLikelihood(*args, **kwargs)[source]

Bases: BaseLikelihood

Base class for Gaussian likelihood, which allows parameters the theory is linear with to be analytically marginalized over.

Parameters:
  • data (array) – Data.

  • covariance (array, default=None) – Covariance matrix (or its diagonal).

  • precision (array, default=None) – If covariance is not provided, precision matrix (or its diagonal).

class desilike.likelihoods.base.BaseLikelihood(*args, **kwargs)[source]

Bases: BaseCalculator

Base class for likelihood.

get()[source]

Return quantity of main interest, e.g. loglikelihood + logprior if self is a likelihood.

classmethod sum(*others)[source]

Sum likelihoods: return SumLikelihood instance.

class desilike.likelihoods.base.ObservablesGaussianLikelihood(*args, **kwargs)[source]

Bases: BaseGaussianLikelihood

Gaussian likelihood of observables.

Parameters:
  • observables (list, BaseCalculator) – List of (or single) observable, e.g. TracerPowerSpectrumMultipolesObservable or TracerCorrelationFunctionMultipolesObservable.

  • covariance (array, default=None) – Covariance matrix (or its diagonal) for input observables. If None, covariance matrix is computed on-the-fly using observables’ mocks.

  • scale_covariance (float, default=1.) – Scale precision by the inverse of this value.

  • correct_covariance (str, default=’hartlap-percival2014’) – Only applies if mocks are provided to input observables. ‘hartlap’ to apply Hartlap 2007 factor (https://arxiv.org/abs/astro-ph/0608064). ‘percival2014’ to apply Percival 2014 factor (https://arxiv.org/abs/1312.4841). Can be a dictionary to specify the number of observations, {'nobs': nobs, 'correction': 'hartlap-percival2014'}.

  • precision (array, default=None) – Precision matrix to be used instead of the inverse covariance.

plot_covariance_matrix(corrcoef=True, **kwargs)[source]

Plot covariance matrix.

Parameters:
  • corrcoef (bool, default=True) – If True, plot the correlation matrix; else the covariance.

  • barlabel (str, default=None) – Optionally, label for the color bar.

  • label1 (str, list of str, default=None) – Optionally, label(s) for the observable(s).

  • figsize (int, tuple, default=None) – Optionally, figure size.

  • norm (matplotlib.colors.Normalize, default=None) – Scales the covariance / correlation to the canonical colormap range [0, 1] for mapping to colors. By default, the covariance / correlation range is mapped to the color bar range using linear scaling.

  • labelsize (int, default=None) – Optionally, size for labels.

  • fig (matplotlib.figure.Figure, default=None) – Optionally, a figure with at least len(self.observables) * len(self.observables) axes.

Returns:

fig

Return type:

matplotlib.figure.Figure

class desilike.likelihoods.base.SumLikelihood(*args, **kwargs)[source]

Bases: BaseLikelihood

cmb

class desilike.likelihoods.cmb.planck2018_clik.BasePlanck2018ClikLikelihood(*args, **kwargs)[source]

Bases: BaseLikelihood

Base class for clik likelihood of Planck’s 2018 data release.

Reference

https://arxiv.org/abs/1807.06209

https://wiki.cosmos.esa.int/planck-legacy-archive/index.php/CMB_spectrum_%26_Likelihood_Code

Parameters:
  • theory (ClTheory, default=None) – Theory calculator for CMB \(C_{\ell}^{xy}\). If None, instantiated using cosmo.

  • cosmo (BasePrimordialCosmology, default=None) – Optionally, cosmology calculator. Defaults to Cosmoprimo().

  • data_dir (str, Path, default=None) – Data directory. Defaults to path saved in desilike’s configuration, as provided by Installer if likelihood has been installed.

class desilike.likelihoods.cmb.planck2018_clik.EELowlPlanck2018ClikLikelihood(*args, **kwargs)[source]

Bases: BasePlanck2018ClikLikelihood

Low-\(\ell\) polarization plik likelihood of Planck’s 2018 data release.

Reference

https://arxiv.org/abs/1807.06209

https://wiki.cosmos.esa.int/planck-legacy-archive/index.php/CMB_spectrum_%26_Likelihood_Code

Parameters:
  • theory (ClTheory, default=None) – Theory calculator for CMB \(C_{\ell}^{xy}\). If None, instantiated using cosmo.

  • cosmo (BasePrimordialCosmology, default=None) – Optionally, cosmology calculator. Defaults to Cosmoprimo().

  • data_dir (str, Path, default=None) – Data directory. Defaults to path saved in desilike’s configuration, as provided by Installer if likelihood has been installed.

class desilike.likelihoods.cmb.planck2018_clik.LensingPlanck2018ClikLikelihood(*args, **kwargs)[source]

Bases: BasePlanck2018ClikLikelihood

Lensing likelihood of Planck’s 2018 data release based on temperature+polarization map-based lensing reconstruction.

Reference

https://arxiv.org/abs/1807.06209

https://wiki.cosmos.esa.int/planck-legacy-archive/index.php/CMB_spectrum_%26_Likelihood_Code

Parameters:
  • theory (ClTheory, default=None) – Theory calculator for CMB \(C_{\ell}^{xy}\). If None, instantiated using cosmo.

  • cosmo (BasePrimordialCosmology, default=None) – Optionally, cosmology calculator. Defaults to Cosmoprimo().

  • data_dir (str, Path, default=None) – Data directory. Defaults to path saved in desilike’s configuration, as provided by Installer if likelihood has been installed.

class desilike.likelihoods.cmb.planck2018_clik.TTHighlPlanck2018PlikLikelihood(*args, **kwargs)[source]

Bases: BasePlanck2018ClikLikelihood

High-\(\ell\) temperature-only plik likelihood of Planck’s 2018 data release.

Reference

https://arxiv.org/abs/1807.06209

https://wiki.cosmos.esa.int/planck-legacy-archive/index.php/CMB_spectrum_%26_Likelihood_Code

Parameters:
  • theory (ClTheory, default=None) – Theory calculator for CMB \(C_{\ell}^{xy}\). If None, instantiated using cosmo.

  • cosmo (BasePrimordialCosmology, default=None) – Optionally, cosmology calculator. Defaults to Cosmoprimo().

  • data_dir (str, Path, default=None) – Data directory. Defaults to path saved in desilike’s configuration, as provided by Installer if likelihood has been installed.

class desilike.likelihoods.cmb.planck2018_clik.TTHighlPlanck2018PlikLiteLikelihood(*args, **kwargs)[source]

Bases: BasePlanck2018ClikLikelihood

High-\(\ell\) temperature-only plik likelihood of Planck’s 2018 data release, marginalized over the foreground model.

Reference

https://arxiv.org/abs/1807.06209

https://wiki.cosmos.esa.int/planck-legacy-archive/index.php/CMB_spectrum_%26_Likelihood_Code

Parameters:
  • theory (ClTheory, default=None) – Theory calculator for CMB \(C_{\ell}^{xy}\). If None, instantiated using cosmo.

  • cosmo (BasePrimordialCosmology, default=None) – Optionally, cosmology calculator. Defaults to Cosmoprimo().

  • data_dir (str, Path, default=None) – Data directory. Defaults to path saved in desilike’s configuration, as provided by Installer if likelihood has been installed.

class desilike.likelihoods.cmb.planck2018_clik.TTHighlPlanck2018PlikUnbinnedLikelihood(*args, **kwargs)[source]

Bases: BasePlanck2018ClikLikelihood

High-\(\ell\) temperature-only plik likelihood of Planck’s 2018 data release.

Reference

https://arxiv.org/abs/1807.06209

https://wiki.cosmos.esa.int/planck-legacy-archive/index.php/CMB_spectrum_%26_Likelihood_Code

Parameters:
  • theory (ClTheory, default=None) – Theory calculator for CMB \(C_{\ell}^{xy}\). If None, instantiated using cosmo.

  • cosmo (BasePrimordialCosmology, default=None) – Optionally, cosmology calculator. Defaults to Cosmoprimo().

  • data_dir (str, Path, default=None) – Data directory. Defaults to path saved in desilike’s configuration, as provided by Installer if likelihood has been installed.

class desilike.likelihoods.cmb.planck2018_clik.TTLowlPlanck2018ClikLikelihood(*args, **kwargs)[source]

Bases: BasePlanck2018ClikLikelihood

Low-\(\ell\) temperature-only plik likelihood of Planck’s 2018 data release.

Reference

https://arxiv.org/abs/1807.06209

https://wiki.cosmos.esa.int/planck-legacy-archive/index.php/CMB_spectrum_%26_Likelihood_Code

Parameters:
  • theory (ClTheory, default=None) – Theory calculator for CMB \(C_{\ell}^{xy}\). If None, instantiated using cosmo.

  • cosmo (BasePrimordialCosmology, default=None) – Optionally, cosmology calculator. Defaults to Cosmoprimo().

  • data_dir (str, Path, default=None) – Data directory. Defaults to path saved in desilike’s configuration, as provided by Installer if likelihood has been installed.

class desilike.likelihoods.cmb.planck2018_clik.TTTEEEHighlPlanck2018PlikLikelihood(*args, **kwargs)[source]

Bases: BasePlanck2018ClikLikelihood

High-\(\ell\) temperature and polarization plik likelihood of Planck’s 2018 data release.

Reference

https://arxiv.org/abs/1807.06209

https://wiki.cosmos.esa.int/planck-legacy-archive/index.php/CMB_spectrum_%26_Likelihood_Code

Parameters:
  • theory (ClTheory, default=None) – Theory calculator for CMB \(C_{\ell}^{xy}\). If None, instantiated using cosmo.

  • cosmo (BasePrimordialCosmology, default=None) – Optionally, cosmology calculator. Defaults to Cosmoprimo().

  • data_dir (str, Path, default=None) – Data directory. Defaults to path saved in desilike’s configuration, as provided by Installer if likelihood has been installed.

class desilike.likelihoods.cmb.planck2018_clik.TTTEEEHighlPlanck2018PlikLiteLikelihood(*args, **kwargs)[source]

Bases: BasePlanck2018ClikLikelihood

High-\(\ell\) temperature and polarization plik likelihood of Planck’s 2018 data release, marginalized over the foreground model.

Reference

https://arxiv.org/abs/1807.06209

https://wiki.cosmos.esa.int/planck-legacy-archive/index.php/CMB_spectrum_%26_Likelihood_Code

Parameters:
  • theory (ClTheory, default=None) – Theory calculator for CMB \(C_{\ell}^{xy}\). If None, instantiated using cosmo.

  • cosmo (BasePrimordialCosmology, default=None) – Optionally, cosmology calculator. Defaults to Cosmoprimo().

  • data_dir (str, Path, default=None) – Data directory. Defaults to path saved in desilike’s configuration, as provided by Installer if likelihood has been installed.

class desilike.likelihoods.cmb.planck2018_clik.TTTEEEHighlPlanck2018PlikUnbinnedLikelihood(*args, **kwargs)[source]

Bases: BasePlanck2018ClikLikelihood

High-\(\ell\) temperature and polarization plik likelihood of Planck’s 2018 data release.

Reference

https://arxiv.org/abs/1807.06209

https://wiki.cosmos.esa.int/planck-legacy-archive/index.php/CMB_spectrum_%26_Likelihood_Code

Parameters:
  • theory (ClTheory, default=None) – Theory calculator for CMB \(C_{\ell}^{xy}\). If None, instantiated using cosmo.

  • cosmo (BasePrimordialCosmology, default=None) – Optionally, cosmology calculator. Defaults to Cosmoprimo().

  • data_dir (str, Path, default=None) – Data directory. Defaults to path saved in desilike’s configuration, as provided by Installer if likelihood has been installed.

class desilike.likelihoods.cmb.planck2018_gaussian.BasePlanck2018GaussianLikelihood(*args, **kwargs)[source]

Bases: BaseGaussianLikelihood

Gaussian approximation of “base” likelihoods of Planck’s 2018 data release.

Reference

https://arxiv.org/abs/1807.06209

https://wiki.cosmos.esa.int/planck-legacy-archive/index.php/CMB_spectrum_%26_Likelihood_Code

Parameters:
  • cosmo (BasePrimordialCosmology, default=None) – Cosmology calculator. Defaults to Cosmoprimo().

  • data_dir (str, Path, default=None) – Data directory. Defaults to path saved in desilike’s configuration, as provided by Installer if likelihood has been installed.

  • basename (str, default=’base_plikHM_TTTEEE_lowl_lowE_lensing’) – Likelihood base name, e.g. ‘base_plikHM_TT’, ‘base_plikHM_TTTEEE’, ‘base_plikHM_TTTEEE_lowl_lowE_lensing’.

  • source (str, default=None) – Source, either:

    • ‘covmat’: use ‘.margestats’ for mean and ‘.covmat’ file as covariance.

    • ‘chains’: compute mean and covariance from chains

    Both options are very close (within precision in provided file). Defaults to ‘chains’ if weights is not None, else ‘covmat’.

  • weights (str, callable, default=None) – Callable that takes a Chain as input and returns weights (float), e.g. weights = lambda chain: 1. / np.exp(chain['logposterior'] + 0.5 * chain['chi2_prior'] + 0.5 * chain['chi2_CMB']). If weights is ‘cmb_only’, the lambda function above is used to “importance unweight” the non-CMB datasets (useful e.g. to get an approximation of the CMB-only posterior for \(w_{0}\) and \(w_{a}\) extensions). Only available if source is ‘chains’.

class desilike.likelihoods.cmb.planck2018_gaussian.FullGridPlanck2018GaussianLikelihood(*args, **kwargs)[source]

Bases: BasePlanck2018GaussianLikelihood

Gaussian approximation of the full grid of likelihoods of Planck’s 2018 data release.

Reference

https://arxiv.org/abs/1807.06209

https://wiki.cosmos.esa.int/planck-legacy-archive/index.php/CMB_spectrum_%26_Likelihood_Code

Parameters:
  • cosmo (BasePrimordialCosmology, default=None) – Cosmology calculator. Defaults to Cosmoprimo().

  • data_dir (str, Path, default=None) – Data directory. Defaults to path saved in desilike’s configuration, as provided by Installer if likelihood has been installed.

  • basename (str, default=’base_plikHM_TTTEEE_lowl_lowE_lensing’) – Likelihood base name, e.g. ‘base_plikHM_TT’, ‘base_plikHM_TTTEEE’, ‘base_plikHM_TTTEEE_lowl_lowE_lensing’, ‘base_mnu_plikHM_TTTEEE_lowl_lowE_lensing’.

  • source (str, default=’covmat’) – Source, either:

    • ‘covmat’: use ‘.margestats’ for mean and ‘.covmat’ file as covariance.

    • ‘chains’: compute mean and covariance from chains

    Both options are very close (within precision in provided file).

desilike.likelihoods.cmb.planck2018_gaussian.planck2018_base_fn(basename, data_dir=None)[source]

Return paths to chains and corresponding summary statistics given input base chain name, and data directory data_dir. If data_dir is None, defaults to path saved in desilike’s configuration, as provided by Installer if BasePlanck2018GaussianLikelihood or FullGridPlanck2018GaussianLikelihood have been installed.

desilike.likelihoods.cmb.planck2018_gaussian.read_planck2018_chain(basename='base_plikHM_TTTEEE_lowl_lowE_lensing', data_dir=None, weights=None, params=None)[source]

Read Planck chains, operating basic conversion in parameters.

Parameters:
  • basename (str, default=’base_plikHM_TTTEEE_lowl_lowE_lensing’) – Likelihood base name, e.g. ‘base_plikHM_TT’, ‘base_plikHM_TTTEEE’, ‘base_plikHM_TTTEEE_lowl_lowE_lensing’.

    data_dirstr, Path, default=None

    Data directory. Defaults to path saved in desilike’s configuration, as provided by Installer if BasePlanck2018GaussianLikelihood or FullGridPlanck2018GaussianLikelihood have been installed.

    weightsstr, callable, default=None

    Callable that takes a Chain as input and returns weights (float), e.g. weights = lambda chain: 1. / np.exp(chain['logposterior'] + 0.5 * chain['chi2_prior'] + 0.5 * chain['chi2_CMB']). If weights is ‘cmb_only’, the lambda function above is used to “importance unweight” the non-CMB datasets (useful e.g. to get an approximation of the CMB-only posterior for \(w_{0}\) and \(w_{a}\) extensions).

  • params (list, ParameterCollection) – List of parameters to convert the chain to; e.g. [‘h’, ‘Omega_m’, ‘A_s’].

Returns:

chain

Return type:

Chain

hubble

Hubble parameter likelihoods from Riess et al. (2020).

class desilike.likelihoods.hubble.riess2020.Riess2020H0Likelihood(*args, **kwargs)[source]

Bases: H0Likelihood

Local \(H_0\) measurement from Riess et al. (2020).

Reference

https://arxiv.org/abs/2012.08534

class desilike.likelihoods.hubble.riess2020.Riess2020MbLikelihood(*args, **kwargs)[source]

Bases: MbLikelihood

Magnitude measurement from Riess et al. (2020).

Reference

https://arxiv.org/abs/2012.08534

https://github.com/CobayaSampler/cobaya/blob/master/cobaya/likelihoods/H0/riess2020Mb.yaml

supernovae

class desilike.likelihoods.supernovae.pantheon.PantheonSNLikelihood(*args, **kwargs)[source]

Bases: BaseSNLikelihood

Likelihood for Pantheon type Ia supernovae sample. TODO: organize as SNObservable / ObservablesGaussianLikelihood?

Reference

https://arxiv.org/abs/1710.00845

Parameters:

data_dir (str, Path, default=None) – Data directory. Defaults to path saved in desilike’s configuration, as provided by Installer if likelihood has been installed.

plot(fig=None)[source]

Plot Hubble diagram: Hubble residuals as a function of distance.

Parameters:
  • fig (matplotlib.figure.Figure, default=None) – Optionally, a figure with at least 2 axes.

  • fn (str, Path, default=None) – Optionally, path where to save figure. If not provided, figure is not saved.

  • kw_save (dict, default=None) – Optionally, arguments for matplotlib.figure.Figure.savefig().

  • show (bool, default=False) – If True, show figure.