firecrown.likelihood

Likelihood implementations and infrastructure.

This module provides the core likelihood framework and specific likelihood implementations for various cosmological observables.

Core Components:
  • Likelihood: Abstract base class for all likelihoods

  • Statistic: Base class for observable statistics

  • Source: Infrastructure for data sources and systematics

  • Likelihood loading utilities

Likelihood Types:
Subpackages:
  • weak_lensing: Weak lensing systematics and sources

  • number_counts: Galaxy number counts systematics and sources

  • supernova: Supernova-specific implementations

  • factories: Factory functions for creating likelihood components

Submodules

Classes

Likelihood

Likelihood is an abstract class.

NamedParameters

Provides access to a set of parameters of a given set of types.

Source

The abstract base class for all sources.

SourceGalaxyArgs

Class for galaxy based sources arguments.

SourceGalaxySystematic

Abstract base class for all galaxy-based source systematics.

SourceSystematic

An abstract systematic class (e.g., shear biases, photo-z shifts, etc.).

Statistic

The abstract base class for all physics-related statistics.

Tracer

Extending the pyccl.Tracer object with additional information.

TrivialStatistic

A minimal statistic only to be used for testing Gaussian likelihoods.

ConstGaussian

Base class for constant covariance Gaussian likelihoods.

GaussFamily

GaussFamily is the base class for likelihoods based on a chi-squared calculation.

State

The states used in GaussFamily.

StudentT

A T-distribution for the log-likelihood.

ConstGaussianPM

A Gaussian log-like with constant covariance, marginalizing over a point mass.

UpdatableClusterObjects

Class to store updatable parameters for cluster objects.

TwoPoint

A two-point statistic.

TwoPointFactory

Factory class for creating TwoPoint statistics from measurements.

BinnedCluster

A statistic representing clusters in a z, mass bin.

BinnedClusterNumberCounts

A statistic representing the number of clusters in a z, mass bin.

BinnedClusterShearProfile

The Binned Cluster Delta Sigma statistic.

Supernova

A statistic representing the distance modulus for a single supernova.

Functions

load_likelihood(likelihood_name, build_parameters)

Loads a likelihood from the provided likelihood_name.

load_likelihood_from_module_type(module, build_parameters)

Loads a likelihood from a module type.

Package Contents

class firecrown.likelihood.Likelihood(*, parameter_prefix=None, raise_on_unused_parameter=True)

Bases: firecrown.updatable.Updatable

Inheritance diagram of firecrown.likelihood.Likelihood

Likelihood is an abstract class.

Concrete subclasses represent specific likelihood forms (e.g. gaussian with constant covariance matrix, or Student’s t, etc.).

Concrete subclasses must have an implementation of both read() and compute_loglike(). Note that abstract subclasses of Likelihood might implement these methods, and provide other abstract methods for their subclasses to implement.

Parameters:
  • parameter_prefix (None | str)

  • raise_on_unused_parameter (bool)

raise_on_unused_parameter = True
abstractmethod read(sacc_data)

Read the covariance matrix for this likelihood from the SACC file.

Parameters:

sacc_data (sacc.Sacc) – The SACC data object to be read

Return type:

None

abstractmethod make_realization_vector()

Create a new realization of the model.

This new realization uses the previously computed theory vector and covariance matrix.

Returns:

the new realization of the theory vector

Return type:

numpy.typing.NDArray[numpy.float64]

make_realization(sacc_data, add_noise=True, strict=True)

Create a new realization of the model.

This realization uses the previously computed theory vector and covariance matrix.

Parameters:
  • sacc_data (sacc.Sacc) – The SACC data object containing the covariance matrix

  • add_noise (bool) – If True, add noise to the realization. If False, return only the theory vector.

  • strict (bool) – If True, check that the indices of the realization cover all the indices of the SACC data object.

Returns:

the new SACC object containing the new realization

Return type:

sacc.Sacc

compute_loglike_for_sampling(tools)

Compute the log-likelihood of generic CCL data, swallowing some CCL errors.

If CCL raises an error indicating an integration error, this function returns -np.inf.

Parameters:

tools (firecrown.modeling_tools.ModelingTools) – the ModelingTools to be used in calculating the likelihood

Returns:

the log-likelihood

Return type:

float

abstractmethod compute_loglike(tools)

Compute the log-likelihood of generic CCL data.

Parameters:

tools (firecrown.modeling_tools.ModelingTools) – the ModelingTools to be used in calculating the likelihood

Returns:

the log-likelihood

Return type:

float

class firecrown.likelihood.NamedParameters(mapping=None)

Provides access to a set of parameters of a given set of types.

Access to the parameters is provided by a type-safe interface. Each of the access functions assures that the parameter value it returns is of the specified type.

Parameters:

mapping (None | collections.abc.Mapping[str, str | int | bool | float | numpy.typing.NDArray[numpy.int64] | numpy.typing.NDArray[numpy.float64]])

get_bool(name, default_value=None)

Return the named parameter as a bool.

Parameters:
  • name (str) – the name of the parameter to be returned

  • default_value (None | bool) – the default value if the parameter is not found

Returns:

the value of the parameter (or the default value)

Return type:

bool

get_string(name, default_value=None)

Return the named parameter as a string.

Parameters:
  • name (str) – the name of the parameter to be returned

  • default_value (None | str) – the default value if the parameter is not found

Returns:

the value of the parameter (or the default value)

Return type:

str

get_int(name, default_value=None)

Return the named parameter as an int.

Parameters:
  • name (str) – the name of the parameter to be returned

  • default_value (None | int) – the default value if the parameter is not found

Returns:

the value of the parameter (or the default value)

Return type:

int

get_float(name, default_value=None)

Return the named parameter as a float.

Parameters:
  • name (str) – the name of the parameter to be returned

  • default_value (None | float) – the default value if the parameter is not found

Returns:

the value of the parameter (or the default value)

Return type:

float

get_int_array(name)

Return the named parameter as a numpy array of int.

Parameters:

name (str) – the name of the parameter to be returned

Returns:

the value of the parameter

Return type:

numpy.typing.NDArray[numpy.int64]

get_float_array(name)

Return the named parameter as a numpy array of float.

Parameters:

name (str) – the name of the parameter to be returned

Returns:

the value of the parameter

Return type:

numpy.typing.NDArray[numpy.float64]

to_set()

Return the contained data as a set.

Returns:

the value of the parameter as a set

Return type:

set[str | int | bool | float | numpy.typing.NDArray[numpy.int64] | numpy.typing.NDArray[numpy.float64]]

set_from_basic_dict(basic_dict)

Set the contained data from a dictionary of basic types.

Parameters:

basic_dict (dict[str, str | float | int | bool | collections.abc.Sequence[float] | collections.abc.Sequence[int] | collections.abc.Sequence[bool]]) – the mapping from strings to values used for initialization

Return type:

None

convert_to_basic_dict()

Convert a NamedParameters object to a dictionary of built-in types.

Returns:

a dictionary containing the parameters as built-in Python types

Return type:

dict[str, str | float | int | bool | collections.abc.Sequence[float] | collections.abc.Sequence[int] | collections.abc.Sequence[bool]]

__contains__(key)

Check if a key is in the NamedParameters object.

Parameters:

key (str) – the key to check

Returns:

True if the key is in the NamedParameters object, False otherwise

Return type:

bool

class firecrown.likelihood.Source(sacc_tracer)

Bases: firecrown.updatable.Updatable

Inheritance diagram of firecrown.likelihood.Source

The abstract base class for all sources.

Parameters:

sacc_tracer (str)

cosmo_hash: None | int
tracers: collections.abc.Sequence[Tracer]
sacc_tracer
abstractmethod read_systematics(sacc_data)

Abstract method to read the systematics for this source from the SACC file.

Parameters:

sacc_data (sacc.Sacc) – The SACC data object to be read

Return type:

None

read(sacc_data)

Read the data for this source from the SACC file.

Parameters:

sacc_data (sacc.Sacc) – The SACC data object to be read

Return type:

None

abstractmethod get_scale()

Abstract method to return the scale for this Source.

Returns:

the scale

Return type:

float

abstractmethod create_tracers(tools)

Abstract method to create tracers for this Source.

Parameters:

tools (firecrown.modeling_tools.ModelingTools) – The modeling tools used for creating the tracers

get_tracers(tools)

Return the tracer for the given cosmology.

This method caches its result, so if called a second time with the same cosmology, no calculation needs to be done.

Parameters:

tools (firecrown.modeling_tools.ModelingTools) – The modeling tools used for creating the tracers

Returns:

the list of tracers

Return type:

collections.abc.Sequence[Tracer]

class firecrown.likelihood.SourceGalaxyArgs

Class for galaxy based sources arguments.

z: numpy.typing.NDArray[numpy.float64]
dndz: numpy.typing.NDArray[numpy.float64]
scale: float = 1.0
field: str = 'delta_matter'
class firecrown.likelihood.SourceGalaxySystematic(parameter_prefix=None)

Bases: SourceSystematic, Generic[_SourceGalaxyArgsT]

Inheritance diagram of firecrown.likelihood.SourceGalaxySystematic

Abstract base class for all galaxy-based source systematics.

Parameters:

parameter_prefix (None | str)

abstractmethod apply(tools, tracer_arg)

Apply method to include systematics in the tracer_arg.

Parameters:
  • tools (firecrown.modeling_tools.ModelingTools) – the modeling tools use to update the tracer arg

  • tracer_arg (_SourceGalaxyArgsT) – the original source galaxy tracer arg to which we apply the systematic.

Returns:

a new source galaxy tracer arg with the systematic applied

Return type:

_SourceGalaxyArgsT

class firecrown.likelihood.SourceSystematic(parameter_prefix=None)

Bases: firecrown.updatable.Updatable

Inheritance diagram of firecrown.likelihood.SourceSystematic

An abstract systematic class (e.g., shear biases, photo-z shifts, etc.).

This class currently has no methods at all, because the argument types for the apply method of different subclasses are different.

Parameters:

parameter_prefix (None | str)

read(sacc_data)

Call to allow this object to read from the appropriate sacc data.

Parameters:

sacc_data (sacc.Sacc) – The SACC data object to be read

Return type:

None

class firecrown.likelihood.Statistic(parameter_prefix=None)

Bases: firecrown.updatable.Updatable

Inheritance diagram of firecrown.likelihood.Statistic

The abstract base class for all physics-related statistics.

Statistics read data from a SACC object as part of a multi-phase initialization. They manage a DataVector and, given a ModelingTools object, can compute a TheoryVector.

Statistics represent things like two-point functions and mass functions.

Parameters:

parameter_prefix (None | str)

sacc_indices: None | numpy.typing.NDArray[numpy.int64]
ready = False
computed_theory_vector = False
theory_vector: None | firecrown.data_types.TheoryVector = None
read(_)

Read the data for this statistic and mark it as ready for use.

Derived classes that override this function should make sure to call the base class method using:

super().read(sacc_data)

as the last thing they do.

Parameters:

_ (sacc.Sacc) – currently unused, but required by the interface.

Return type:

None

abstractmethod get_data_vector()

Gets the statistic data vector.

Returns:

The data vector.

Return type:

firecrown.data_types.DataVector

compute_theory_vector(tools)

Compute a statistic from sources, applying any systematics.

Parameters:

tools (firecrown.modeling_tools.ModelingTools) – the modeling tools used to compute the theory vector.

Returns:

The computed theory vector.

Return type:

firecrown.data_types.TheoryVector

get_theory_vector()

Returns the last computed theory vector.

Raises a RuntimeError if the vector has not been computed.

Returns:

The already-computed theory vector.

Return type:

firecrown.data_types.TheoryVector

class firecrown.likelihood.Tracer(tracer, tracer_name=None, field=None, pt_tracer=None, halo_profile=None, halo_2pt=None)

Extending the pyccl.Tracer object with additional information.

Bundles together a pyccl.Tracer object with optional information about the underlying 3D field, or a pyccl.nl_pt.PTTracer and halo profiles.

Parameters:
  • tracer (pyccl.Tracer)

  • tracer_name (None | str)

  • field (None | str)

  • pt_tracer (None | pyccl.nl_pt.PTTracer)

  • halo_profile (None | pyccl.halos.HaloProfile)

  • halo_2pt (None | pyccl.halos.Profile2pt)

static determine_field_name(field, tracer)

Gets a field name for a tracer.

This function encapsulates the policy for determining the value to be assigned to the field attribute of a Tracer.

It is a static method only to keep it grouped with the class for which it is defining the initialization policy.

Parameters:
  • field (None | str) – the (stub) name of the field

  • tracer (None | str) – the name of the tracer

Returns:

the full name of the field

Return type:

str

ccl_tracer
tracer_name: str
field
pt_tracer = None
halo_profile = None
halo_2pt = None
property has_pt: bool

Answer whether we have a perturbation theory tracer.

Returns:

True if we have a pt_tracer, and False if not.

Return type:

bool

property has_hm: bool

Answer whether we have a halo model profile.

Return True if we have a halo_profile, and False if not.

Return type:

bool

class firecrown.likelihood.TrivialStatistic

Bases: Statistic

Inheritance diagram of firecrown.likelihood.TrivialStatistic

A minimal statistic only to be used for testing Gaussian likelihoods.

It returns a DataVector and TheoryVector each of which is three elements long. The SACC data provided to TrivialStatistic.read() must supply the necessary values.

count = 3
data_vector: None | firecrown.data_types.DataVector = None
mean
computed_theory_vector = False
read(sacc_data)

Read the necessary items from the sacc data.

Parameters:

sacc_data (sacc.Sacc) – The SACC data object to be read

Return type:

None

get_data_vector()

Return the data vector; raise exception if there is none.

Returns:

The data vector.

Return type:

firecrown.data_types.DataVector

firecrown.likelihood.load_likelihood(likelihood_name, build_parameters)

Loads a likelihood from the provided likelihood_name.

After loading, this method returns a tuple of the likelihood and the modeling tools.

Parameters:
  • likelihood_name (str) – script filename or module name

  • build_parameters (firecrown.likelihood._base.NamedParameters) – a NamedParameters object containing the factory function parameters

Returns:

a tuple of the likelihood and the modeling tools

Return type:

tuple[firecrown.likelihood._base.Likelihood, firecrown.modeling_tools.ModelingTools]

firecrown.likelihood.load_likelihood_from_module_type(module, build_parameters, build_likelihood_name='build_likelihood')

Loads a likelihood from a module type.

After loading, this method returns a tuple of the likelihood and the modeling tools.

This function is used by both load_likelihood_from_script() and load_likelihood_from_module(). It is not intended to be called directly.

Parameters:
  • module (types.ModuleType) – a loaded module

  • build_parameters (firecrown.likelihood._base.NamedParameters) – a NamedParameters object containing the factory function parameters

  • build_likelihood_name (str)

Returns:

a tuple of the likelihood and the modeling tools

Return type:

tuple[firecrown.likelihood._base.Likelihood, firecrown.modeling_tools.ModelingTools]

class firecrown.likelihood.ConstGaussian(statistics, use_cholesky=True)

Bases: firecrown.likelihood._gaussfamily.GaussFamily

Inheritance diagram of firecrown.likelihood.ConstGaussian

Base class for constant covariance Gaussian likelihoods.

Provides shared implementations of compute_loglike and make_realization_vector for all constant covariance Gaussian likelihood variants.

Parameters:
  • statistics (collections.abc.Sequence[firecrown.likelihood._base.Statistic])

  • use_cholesky (bool)

compute_loglike(tools)

Compute the log-likelihood.

Params tools:

The modeling tools used to compute the likelihood.

Returns:

The log-likelihood.

Parameters:

tools (firecrown.modeling_tools.ModelingTools)

Return type:

float

make_realization_vector()

Create a new (randomized) realization of the model.

Returns:

A new realization of the model

Return type:

numpy.ndarray

class firecrown.likelihood.GaussFamily(statistics, use_cholesky=True)

Bases: firecrown.likelihood._base.Likelihood

Inheritance diagram of firecrown.likelihood.GaussFamily

GaussFamily is the base class for likelihoods based on a chi-squared calculation.

It provides an implementation of Likelihood.compute_chisq. Derived classes must implement the abstract method compute_loglike, which is inherited from Likelihood.

GaussFamily (and all classes that inherit from it) must abide by the the following rules regarding the order of calling of methods.

  1. after a new object is created, read() must be called before any other method in the interface.

  2. after read() has been called it is legal to call get_data_vector(), or to call update().

  3. after update() is called it is then legal to call calculate_loglike() or get_data_vector(), or to reset the object (returning to the pre-update state) by calling reset(). It is also legal to call compute_theory_vector().

  4. after compute_theory_vector() is called it is legal to call get_theory_vector() to retrieve the already-calculated theory vector.

This state machine behavior is enforced through the use of the decorator enforce_states(), above.

Parameters:
  • statistics (collections.abc.Sequence[firecrown.likelihood._base.Statistic])

  • use_cholesky (bool)

state: State
statistics: firecrown.updatable.UpdatableCollection[firecrown.likelihood._base.GuardedStatistic]
cov: None | numpy.typing.NDArray[numpy.float64] = None
cholesky: None | numpy.typing.NDArray[numpy.float64] = None
inv_cov: None | numpy.typing.NDArray[numpy.float64] = None
cov_index_map: None | dict[int, int] = None
theory_vector: None | numpy.typing.NDArray[numpy.double] = None
data_vector: None | numpy.typing.NDArray[numpy.double] = None
classmethod create_ready(statistics, covariance)

Create a GaussFamily object in the READY state.

Parameters:
  • statistics (collections.abc.Sequence[firecrown.likelihood._base.Statistic]) – A list of statistics to be include in chisquared calculations

  • covariance (numpy.typing.NDArray[numpy.float64]) – The covariance matrix of the statistics

Returns:

A ready GaussFamily object

Return type:

GaussFamily

read(sacc_data)

Read the covariance matrix for this likelihood from the SACC file.

Parameters:

sacc_data (sacc.Sacc) – The SACC data object to be read

Return type:

None

get_cov(statistic=None)

Gets the current covariance matrix.

Parameters:

statistic (firecrown.likelihood._base.Statistic | list[firecrown.likelihood._base.Statistic] | None) – The statistic for which the sub-covariance matrix should be returned. If not specified, return the covariance of all statistics.

Returns:

The covariance matrix (or portion thereof)

Return type:

numpy.typing.NDArray[numpy.float64]

get_data_vector()

Get the data vector from all statistics in the right order.

Returns:

The data vector

Return type:

numpy.typing.NDArray[numpy.float64]

compute_theory_vector(tools)

Computes the theory vector using the current instance of pyccl.Cosmology.

Parameters:

tools (firecrown.modeling_tools.ModelingTools) – Current ModelingTools object

Returns:

The computed theory vector

Return type:

numpy.typing.NDArray[numpy.float64]

get_theory_vector()

Get the already-computed theory vector from all statistics.

Returns:

The theory vector, with all statistics in the right order

Return type:

numpy.typing.NDArray[numpy.float64]

compute(tools)

Calculate and return both the data and theory vectors.

This method is deprecated and will be removed in a future version of Firecrown.

Parameters:

tools (firecrown.modeling_tools.ModelingTools) – the ModelingTools to be used in the calculation of the theory vector

Returns:

a tuple containing the data vector and the theory vector

Return type:

tuple[numpy.typing.NDArray[numpy.float64], numpy.typing.NDArray[numpy.float64]]

compute_chisq_impl(residuals)

Implementation of chi-squared calculation.

This method can be overridden by subclasses that need different chi-squared calculation strategies. By default, it uses either Cholesky decomposition (more stable) or direct inverse covariance multiplication, depending on the _use_cholesky_for_chisq flag.

Parameters:

residuals (numpy.typing.NDArray[numpy.float64]) – The residuals (data - theory)

Returns:

The chi-squared value

Return type:

float

compute_chisq(tools)

Calculate and return the chi-squared for the given cosmology.

Parameters:

tools (firecrown.modeling_tools.ModelingTools) – the ModelingTools to be used in the calculation of the theory vector

Returns:

the chi-squared

Return type:

float

get_sacc_indices(statistic=None)

Get the SACC indices of the statistic or list of statistics.

If no statistic is given, get the indices of all statistics of the likelihood.

Parameters:
  • statistics – The statistic or list of statistics for which the SACC indices are desired

  • statistic (firecrown.likelihood._base.Statistic | list[firecrown.likelihood._base.Statistic] | None)

Returns:

The SACC indices

Return type:

numpy.typing.NDArray[numpy.int64]

make_realization(sacc_data, add_noise=True, strict=True)

Create a new realization of the model.

Parameters:
  • sacc_data (sacc.Sacc) – The SACC data object containing the covariance matrix to be read

  • add_noise (bool) – If True, add noise to the realization.

  • strict (bool) – If True, check that the indices of the realization cover all the indices of the SACC data object.

Returns:

The SACC data object containing the new realization

Return type:

sacc.Sacc

class firecrown.likelihood.State

Bases: enum.Enum

Inheritance diagram of firecrown.likelihood.State

The states used in GaussFamily.

GaussFamily and all subclasses enforce a state machine behavior based on these states to ensure that the necessary initialization and setup is done in the correct order.

INITIALIZED = 1
READY = 2
UPDATED = 3
COMPUTED = 4
class firecrown.likelihood.StudentT(statistics, nu=None)

Bases: firecrown.likelihood._gaussfamily.GaussFamily

Inheritance diagram of firecrown.likelihood.StudentT

A T-distribution for the log-likelihood.

This distribution is appropriate when the covariance has been obtained from a finite number of simulations. See Sellentin & Heavens (2016; arXiv:1511.05969). As the number of simulations increases, the T-distribution approaches a Gaussian.

Parameters:
  • statistics (list[firecrown.likelihood._base.Statistic])

  • nu (None | float)

nu
compute_loglike(tools)

Compute the log-likelihood.

Parameters:

tools (firecrown.modeling_tools.ModelingTools) – The modeling tools used to compute the likelihood.

Returns:

The log-likelihood.

Return type:

float

class firecrown.likelihood.ConstGaussianPM(statistics)

Bases: firecrown.likelihood._gaussian.ConstGaussian

Inheritance diagram of firecrown.likelihood.ConstGaussianPM

A Gaussian log-like with constant covariance, marginalizing over a point mass.

Parameters:

statistics (collections.abc.Sequence[firecrown.likelihood._base.Statistic])

inv_cov_correction: numpy.ndarray | None = None
property pm_maps_ready: bool

Check if point mass maps have been generated.

Return type:

bool

compute_chisq_impl(residuals)

Override chi-squared calculation to use direct inv_cov.

We must use direct inv_cov multiplication because the point mass correction makes the Cholesky decomposition incompatible.

Parameters:

residuals (numpy.typing.NDArray[numpy.float64]) – The residuals (data - theory)

Returns:

The chi-squared value

Return type:

float

compute_pointmass(cosmo, sigma_B=DEFAULT_SIGMA_B, point_mass=DEFAULT_POINT_MASS)

Update the inverse covariance matrix to marginalize over the point mass.

The procedure follows MacCrann et al. (2019).

Parameters:
  • cosmo (pyccl.Cosmology) – A pre-initialized CCL Cosmology object to compute distances.

  • sigma_B (float) – The PM prior width defined in MacCrann et al. (2019).

  • point_mass (float) – The fiducial value of the point mass in units of Mpc/h.

Returns:

The new inverse covariance matrix.

Return type:

numpy.ndarray

class firecrown.likelihood.UpdatableClusterObjects(cluster_objects_configs)

Bases: firecrown.updatable.Updatable

Inheritance diagram of firecrown.likelihood.UpdatableClusterObjects

Class to store updatable parameters for cluster objects.

This class passes updatable parameters to all objects within a cluster recipe.

Attributes

cluster_objects_configs: tuple

List of dictionaries containing configuration on which parameters of each cluster objects in the recipe that will be updated.

Examples

cluster_objects_configs = (
{

“recipe_attribute_name”: “mass_distribution”, “parameters”: [“mu0”, “mu1”, “mu2”, “sigma0”, “sigma1”, “sigma2”],

}, {

“recipe_attribute_name”: “cluster_theory”, “parameters”: [“cluster_concentration”], # if wl profile “has_cosmo”: True,

}, {

“recipe_attribute_name”: “completeness”, “parameters”: [“a_n”, “b_n”, “a_logm_piv”, “b_logm_piv”],

}, {

“recipe_attribute_name”: “purity”, “parameters”: [“a_n”, “b_n”, “a_logm_piv”, “b_logm_piv”],

},

)

cluster_objects_configs
my_updatables: firecrown.updatable.UpdatableCollection
init_all_parameters(cluster_recipe)

Instanciate all updatables parameiters.

Parameters

cluster_recipe: recipe object

Recipe containing all cluster objects (as attributes) to get the defalt parameters from.

export_all_parameters(cluster_recipe, cosmo)

Passes internal parameters to cluster object.

Parameters

cluster_object: list

Recipe containing all cluster objects (as attributes) to export internal parameters to.

class firecrown.likelihood.TwoPoint(sacc_data_type, source0, source1, *, interp_ells_gen=gen.LogLinearElls(), ell_or_theta=None, tracers=None, int_options=None, apply_interp=ApplyInterpolationWhen.DEFAULT, normalize_window=True)

Bases: firecrown.likelihood._base.Statistic

Inheritance diagram of firecrown.likelihood.TwoPoint

A two-point statistic.

A two-point statistic represents the correlation between two measurements. If the same source is used twice, this produces an autocorrelation.

This class supports various two-point statistics including shear correlation functions, galaxy-shear correlation functions, and galaxy clustering statistics in both harmonic and real space.

The sacc_data_type parameter specifies the type of two-point statistic. Valid SACC data types map to CCL correlation function types or power spectra:

  • galaxy_density_cl: CCL angular power spectrum (cl)

  • galaxy_density_xi: CCL angular position correlation (gg)

  • galaxy_shearDensity_cl_e: CCL angular power spectrum (cl)

  • galaxy_shearDensity_xi_t: CCL position-shear cross-correlation (gl)

  • galaxy_shear_cl_ee: CCL angular power spectrum (cl)

  • galaxy_shear_xi_minus: CCL angular shear correlation xi-

  • galaxy_shear_xi_plus: CCL angular shear correlation xi+

  • cmbGalaxy_convergenceDensity_xi: CCL position correlation (gg)

  • cmbGalaxy_convergenceShear_xi_t: CCL position-shear cross-correlation (gl)

The ell_or_theta parameter allows generating ell or theta values for computing statistics when the corresponding data is not present in the SACC file. It accepts a dictionary with keys: minimum (float), maximum (float), n (int), and binning (str, ‘log’ or ‘lin’).

The ell_for_xi parameter configures ell values for computing power spectra used in real-space integrations. It accepts a dictionary with keys: minimum (int, default 2), midpoint (int, default 50), maximum (int, default 60000), and n_log (int, default 200).

Variables:
  • ccl_kind – The CCL correlation function kind or ‘cl’ for power spectra.

  • sacc_tracers – The SACC tracer names for this statistic, set after read.

Parameters:
property sacc_data_type: str

Backwards compatibility for sacc_data_type.

Return type:

str

property source0: firecrown.likelihood._base.Source

Backwards compatibility for source0.

Return type:

firecrown.likelihood._base.Source

property source1: firecrown.likelihood._base.Source

Backwards compatibility for source1.

Return type:

firecrown.likelihood._base.Source

property window: None | numpy.typing.NDArray[numpy.float64]

Backwards compatibility for window.

Return type:

None | numpy.typing.NDArray[numpy.float64]

property sacc_tracers: None | firecrown.metadata_types.TracerNames

Backwards compatibility for sacc_tracers.

Return type:

None | firecrown.metadata_types.TracerNames

property ells: None | numpy.typing.NDArray[numpy.int64]

Backwards compatibility for ells.

Return type:

None | numpy.typing.NDArray[numpy.int64]

property thetas: None | numpy.typing.NDArray[numpy.float64]

Backwards compatibility for thetas.

Return type:

None | numpy.typing.NDArray[numpy.float64]

property ells_for_xi: None | numpy.typing.NDArray[numpy.int64]

Backwards compatibility for ells_for_xi.

Return type:

None | numpy.typing.NDArray[numpy.int64]

property cells

Backwards compatibility for cells.

theory
normalize_window = True
classmethod from_metadata_index(metadata_indices, tp_factory)

Create an UpdatableCollection of TwoPoint statistics.

This constructor creates an UpdatableCollection of TwoPoint statistics from a list of TwoPointCellsIndex or TwoPointXiThetaIndex metadata index objects. The purpose of this constructor is to create a TwoPoint statistic from metadata index, which requires a follow-up call to read to read the data and metadata from the SACC object.

Parameters:
Returns:

An UpdatableCollection of TwoPoint statistics.

Return type:

firecrown.updatable.UpdatableCollection[TwoPoint]

classmethod from_metadata(metadata_seq, tp_factory)

Create an UpdatableCollection of TwoPoint statistics from metadata.

This constructor creates an UpdatableCollection of TwoPoint statistics from a list of TwoPointHarmonic or TwoPointReal metadata objects. The metadata objects are used to initialize the TwoPoint statistics. The sources are initialized using the factories provided.

Note that TwoPoint created with this constructor are ready to be used, but contain no data.

Parameters:
Returns:

An UpdatableCollection of TwoPoint statistics.

Return type:

firecrown.updatable.UpdatableCollection[TwoPoint]

classmethod create_two_point(measurement, tp_factory)

Create a single TwoPoint statistic from a measurement.

Parameters:
Return type:

TwoPoint

classmethod from_measurement(measurements, tp_factory)

Create an UpdatableCollection of TwoPoint statistics from measurements.

This constructor creates an UpdatableCollection of TwoPoint statistics from a list of TwoPointMeasurement objects. The measurements are used to initialize the TwoPoint statistics. The sources are initialized using the factories provided.

Note that TwoPoint created with this constructor are ready to be used and contain data.

Parameters:
  • measurements (collections.abc.Sequence[firecrown.data_types.TwoPointMeasurement]) – The measurements objects to initialize the TwoPoint statistics.

  • wl_factory – The weak lensing factory to use.

  • nc_factory – The number counts factory to use.

  • tp_factory (TwoPointFactory)

Returns:

An UpdatableCollection of TwoPoint statistics.

Return type:

firecrown.updatable.UpdatableCollection[TwoPoint]

read(sacc_data)

Read the data for this statistic from the SACC file.

Parameters:

sacc_data (sacc.Sacc) – The data in the sacc format.

Return type:

None

read_real_space(sacc_data)

Read the data for this statistic from the SACC file.

Parameters:

sacc_data (sacc.Sacc)

read_harmonic_space(sacc_data)

Read the data for this statistic from the SACC file.

Parameters:

sacc_data (sacc.Sacc)

Return type:

None

read_harmonic_spectrum_data(ells_cells_indices, sacc_data)

Read all the data for this statistic from the SACC file.

Parameters:
  • ells_cells_indices (None | tuple[numpy.typing.NDArray[numpy.int64], numpy.typing.NDArray[numpy.float64], numpy.typing.NDArray[numpy.int64]]) – The ells, the cells and the indices of the data in the SACC file.

  • sacc_data (sacc.Sacc) – The data in the sacc format.

Returns:

The ells, the cells and the indices, and window function if there is one.

Return type:

tuple[numpy.typing.NDArray[numpy.float64], numpy.typing.NDArray[numpy.int64], numpy.typing.NDArray[numpy.int64] | None, numpy.typing.NDArray[numpy.float64] | None]

get_data_vector()

Return this statistic’s data vector.

Return type:

firecrown.data_types.DataVector

set_data_vector(value)

Set this statistic’s data vector.

Parameters:

value (firecrown.data_types.DataVector)

Return type:

None

compute_theory_vector_real_space(tools)

Compute a two-point statistic in real space.

This method computes the two-point statistic in real space. It first computes the Cl’s in harmonic space and then translates them to real space using CCL.

Parameters:

tools (firecrown.modeling_tools.ModelingTools)

Return type:

firecrown.data_types.TheoryVector

compute_theory_vector_harmonic_space(tools)

Compute a two-point statistic in harmonic space.

This method computes the two-point statistic in harmonic space. It computes either the Cl’s at the ells provided by the SACC file or the ells required for the window function.

Parameters:

tools (firecrown.modeling_tools.ModelingTools)

Return type:

firecrown.data_types.TheoryVector

compute_cells(ells, scale0, scale1, tools, tracers0, tracers1, interpolate=False)

Compute the power spectrum for the given ells and tracers.

This method computes the power spectrum for the given ells and tracers. If interpolate is True, it will interpolate the power spectrum to the ells provided.

Parameters:
  • ells (numpy.typing.NDArray[numpy.int64])

  • scale0 (float)

  • scale1 (float)

  • tools (firecrown.modeling_tools.ModelingTools)

  • tracers0 (collections.abc.Sequence[firecrown.likelihood._base.Tracer])

  • tracers1 (collections.abc.Sequence[firecrown.likelihood._base.Tracer])

  • interpolate (bool)

Return type:

numpy.typing.NDArray[numpy.float64]

class firecrown.likelihood.TwoPointFactory(/, **data)

Bases: pydantic.BaseModel

Inheritance diagram of firecrown.likelihood.TwoPointFactory

Factory class for creating TwoPoint statistics from measurements.

This factory manages the creation of TwoPoint statistics by coordinating multiple source factories (WeakLensing, NumberCounts, and CMBConvergence) and applying them to measurements. It specifies the correlation space (harmonic or real) and optional integration options for C_ℓ calculations.

Users typically instantiate this class from YAML configuration and use it to build TwoPoint objects from measurements extracted from SACC files.

Parameters:

data (Any)

model_config

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

correlation_space: Annotated[firecrown.metadata_types.TwoPointCorrelationSpace, BeforeValidator(make_correlation_space), Field(description='The two-point correlation space.')]
weak_lensing_factories: list[firecrown.likelihood._weak_lensing.WeakLensingFactory] = None
number_counts_factories: list[firecrown.likelihood.number_counts.NumberCountsFactory] = None
cmb_factories: list[firecrown.likelihood._cmb.CMBConvergenceFactory] = None
int_options: firecrown.utils.ClIntegrationOptions | None = None
model_post_init(_, /)

Initialize the WeakLensingFactory object.

Return type:

None

get_factory(measurement, type_source=TypeSource.DEFAULT)

Get the Factory for the given Measurement and TypeSource.

Parameters:
Return type:

firecrown.likelihood._weak_lensing.WeakLensingFactory | firecrown.likelihood.number_counts.NumberCountsFactory | firecrown.likelihood._cmb.CMBConvergenceFactory

from_measurement(tpms)

Create a TwoPoint object from a list of TwoPointMeasurement.

Parameters:

tpms (list[firecrown.data_types.TwoPointMeasurement])

Return type:

firecrown.updatable.UpdatableCollection[TwoPoint]

from_metadata(metadata_seq)

Create a TwoPoint object from a list of TwoPointHarmonic or TwoPointReal.

Parameters:

metadata_seq (list[firecrown.metadata_types.TwoPointHarmonic | firecrown.metadata_types.TwoPointReal])

Return type:

firecrown.updatable.UpdatableCollection[TwoPoint]

class firecrown.likelihood.BinnedCluster(cluster_properties, survey_name, cluster_recipe, systematics=None)

Bases: firecrown.likelihood._base.Statistic

Inheritance diagram of firecrown.likelihood.BinnedCluster

A statistic representing clusters in a z, mass bin.

Parameters:
  • cluster_properties (crow.properties.ClusterProperty)

  • survey_name (str)

  • cluster_recipe (crow.recipes.binned_parent.BinnedClusterRecipe)

  • systematics (None | list[firecrown.likelihood._base.SourceSystematic])

systematics = []
theory_vector: None | firecrown.data_types.TheoryVector = None
cluster_properties
survey_name
cluster_recipe
data_vector
sky_area = 0.0
bins: list[firecrown.models.cluster.SaccBin] = []
get_data_vector()

Gets the statistic data vector.

Returns:

The statistic data vector.

Return type:

firecrown.data_types.DataVector

check_mor_murata_variance()

Check if variance is negative.

class firecrown.likelihood.BinnedClusterNumberCounts(cluster_properties, survey_name, cluster_recipe, systematics=None)

Bases: firecrown.likelihood._binned_cluster.BinnedCluster

Inheritance diagram of firecrown.likelihood.BinnedClusterNumberCounts

A statistic representing the number of clusters in a z, mass bin.

Parameters:
  • cluster_properties (crow.properties.ClusterProperty)

  • survey_name (str)

  • cluster_recipe (crow.recipes.binned_parent.BinnedClusterRecipe)

  • systematics (None | list[firecrown.likelihood._base.SourceSystematic])

read(sacc_data)

Read the data for this statistic and mark it as ready for use.

Parameters:

sacc_data (sacc.Sacc) – The data in the sacc format.

Return type:

None

get_binned_cluster_property(cluster_counts, cluster_properties)

Computes the mean mass of clusters in each bin.

Using the data from the sacc file, this function evaluates the likelihood for a single point of the parameter space, and returns the predicted mean mass of the clusters in each bin.

Parameters:
  • cluster_counts (list[float]) – The number of clusters in each bin.

  • cluster_properties (crow.properties.ClusterProperty) – The cluster observables to use.

Return type:

list[float]

get_binned_cluster_counts()

Computes the number of clusters in each bin.

Using the data from the sacc file, this function evaluates the likelihood for a single point of the parameter space, and returns the predicted number of clusters in each bin.

Parameters:

tools – The modeling tools used to compute the statistic.

Returns:

The number of clusters in each bin.

Return type:

list[float]

class firecrown.likelihood.BinnedClusterShearProfile(cluster_properties, survey_name, cluster_recipe, systematics=None)

Bases: firecrown.likelihood._binned_cluster.BinnedCluster

Inheritance diagram of firecrown.likelihood.BinnedClusterShearProfile

The Binned Cluster Delta Sigma statistic.

This class will make a prediction for the shear of clusters in a z, mass, radial bin and compare that prediction to the data provided in the sacc file.

Parameters:
  • cluster_properties (crow.properties.ClusterProperty)

  • survey_name (str)

  • cluster_recipe (crow.recipes.binned_parent.BinnedClusterRecipe)

  • systematics (None | list[firecrown.likelihood._base.SourceSystematic])

read(sacc_data)

Read the data for this statistic and mark it as ready for use.

Parameters:

sacc_data (sacc.Sacc) – The data in the sacc format.

Return type:

None

get_binned_cluster_property(cluster_properties)

Computes the mean deltasigma of clusters in each bin.

Using the data from the sacc file, this function evaluates the likelihood for a single point of the parameter space, and returns the predicted mean deltasigma of the clusters in each bin.

Parameters:

cluster_properties (crow.properties.ClusterProperty)

Return type:

list[float]

class firecrown.likelihood.Supernova(sacc_tracer)

Bases: firecrown.likelihood._base.Statistic

Inheritance diagram of firecrown.likelihood.Supernova

A statistic representing the distance modulus for a single supernova.

This statistic that applies an additive shift M to a supernova’s distance modulus.

Parameters:

sacc_tracer (str)

sacc_tracer
data_vector: None | firecrown.data_types.DataVector = None
a: None | numpy.typing.NDArray[numpy.float64] = None
M
read(sacc_data)

Read the data for this statistic from the SACC file.

Parameters:

sacc_data (sacc.Sacc) – The data in the sacc format.

Return type:

None

get_data_vector()

Return the data vector; raise exception if there is none.

Returns:

The data vector.

Return type:

firecrown.data_types.DataVector