firecrown.modeling_tools
Basic Cosmology and cosmological tools definitions.
modeling_tools contains the ModelingTools class, which is
built around the pyccl.Cosmology class. This is used by likelihoods
that need to access reusable objects, such as perturbation theory or halo model
calculators.
This module also contains the CCL factory functionality for creating
pyccl.Cosmology instances.
Attributes
Classes
Modeling tools for likelihoods. |
|
Abstract base class for power spectrum modifiers. |
|
This class defines the CCL instance creation mode. |
|
This class defines the transfer function to use in PURE_CCL_MODE. |
|
This class defines the two-point correlation space. |
|
Factory class for creating instances of the pyccl.Cosmology class. |
|
Extra parameters for CAMB. |
|
Params to control CCL spline interpolation. |
|
Model for the mu-sigma modified gravity model. |
|
Type representing cosmological background quantities. |
|
Arguments for the CCLCalculator. |
Package Contents
- class firecrown.modeling_tools.ModelingTools(*, pt_calculator=None, hm_calculator=None, cM_relation=None, pk_modifiers=None, ccl_factory=None, cluster_abundance=_UNSET, cluster_deltasigma=_UNSET, **_)
Bases:
firecrown.updatable.Updatable
Modeling tools for likelihoods.
A class that bundles together a
pyccl.Cosmologyobject and associated objects, such as perturbation theory or halo model calculator workspaces.- Parameters:
pt_calculator (None | pyccl.nl_pt.EulerianPTCalculator)
hm_calculator (None | pyccl.halos.HMCalculator)
cM_relation (None | str)
pk_modifiers (None | collections.abc.Collection[PowerspectrumModifier])
ccl_factory (None | firecrown.modeling_tools._ccl_factory.CCLFactory)
cluster_abundance (object)
cluster_deltasigma (object)
_ (object)
- ccl_cosmo: None | pyccl.Cosmology = None
- pt_calculator: None | pyccl.nl_pt.EulerianPTCalculator = None
- hm_calculator: None | pyccl.halos.HMCalculator = None
- cM_relation: None | str = None
- pk_modifiers: firecrown.updatable.UpdatableCollection
- powerspectra: dict[str, pyccl.Pk2D]
- ccl_factory
- add_pk(name, powerspectrum)
Add a
pyccl.Pk2Dto the table of power spectra.- Parameters:
name (str) – the name of the power spectrum
powerspectrum (pyccl.Pk2D) – the power spectrum
- Return type:
None
- get_pk(name)
Access a power spectrum from the table of power spectra.
Either retrieve a pyccl.Pk2D from the table of power spectra, or fall back to what the pyccl.Cosmology object can provide. :param name: the name of the desired power spectrum
- Parameters:
name (str)
- Return type:
pyccl.Pk2D
- has_pk(name)
Check if a power spectrum with name name is available.
- Parameters:
name (str)
- Return type:
bool
- prepare(*, calculator_args=None)
Prepare the Cosmology for use in likelihoods.
This method will prepare the ModelingTools for use in likelihoods. This includes building the perturbation theory and halo model calculators if they are needed.
- Parameters:
calculator_args (None | firecrown.modeling_tools._ccl_types.CCLCalculatorArgs) – the CCL calculator arguments
- Return type:
None
- get_ccl_cosmology()
Return the CCL cosmology object.
- Return type:
pyccl.Cosmology
- get_pt_calculator()
Return the perturbation theory calculator object.
- Return type:
pyccl.nl_pt.EulerianPTCalculator
- get_hm_calculator()
Return the halo model calculator object.
- Return type:
pyccl.halos.HMCalculator
- get_cM_relation()
Return the concentration-mass relation.
- Return type:
str
- class firecrown.modeling_tools.PowerspectrumModifier(parameter_prefix=None)
Bases:
firecrown.updatable.Updatable,abc.ABC
Abstract base class for power spectrum modifiers.
- Parameters:
parameter_prefix (None | str)
- name: str = 'base:base'
- abstractmethod compute_p_of_k_z(tools)
Compute the 3D power spectrum P(k, z).
- Parameters:
tools (ModelingTools)
- Return type:
pyccl.Pk2D
- class firecrown.modeling_tools.CCLCreationMode
Bases:
enum.StrEnum
This class defines the CCL instance creation mode.
The DEFAULT mode represents the current CCL behavior. It will use CCL’s calculator mode if prepare is called with a CCLCalculatorArgs object. Otherwise, it will use the default CCL mode.
The MU_SIGMA_ISITGR mode enables the mu-sigma modified gravity model with the ISiTGR transfer function, it is not compatible with the Calculator mode.
The PURE_CCL_MODE mode will create a CCL instance with the default parameters. It is not compatible with the Calculator mode.
- DEFAULT
- MU_SIGMA_ISITGR
- PURE_CCL_MODE
- classmethod __get_pydantic_core_schema__(_source_type, _handler)
Get the Pydantic core schema for the CCLCreationMode class.
- Parameters:
_source_type (Any)
_handler (Any)
- Return type:
pydantic_core.core_schema.CoreSchema
- class firecrown.modeling_tools.CCLPureModeTransferFunction
Bases:
enum.StrEnum
This class defines the transfer function to use in PURE_CCL_MODE.
The options are those available in CCL for the transfer_function argument. See https://ccl.readthedocs.io/en/latest/api/pyccl.cosmology.html
- BBKS
- BOLTZMANN_CAMB
- BOLTZMANN_CLASS
- EISENSTEIN_HU
- EISENSTEIN_HU_NOWIGGLES
- classmethod __get_pydantic_core_schema__(_source_type, _handler)
Get the Pydantic core schema for the CCLPureModeTransferFunction class.
- Parameters:
_source_type (Any)
_handler (Any)
- Return type:
pydantic_core.core_schema.CoreSchema
- class firecrown.modeling_tools.PoweSpecAmplitudeParameter
Bases:
firecrown.utils.YAMLSerializable,enum.StrEnum
This class defines the two-point correlation space.
The two-point correlation space can be either real or harmonic. The real space corresponds measurements in terms of angular separation, while the harmonic space corresponds to measurements in terms of spherical harmonics decomposition.
- AS
- SIGMA8
- classmethod __get_pydantic_core_schema__(_source_type, _handler)
Get the Pydantic core schema for the PoweSpecAmplitudeParameter class.
- Parameters:
_source_type (Any)
_handler (Any)
- Return type:
pydantic_core.core_schema.CoreSchema
- class firecrown.modeling_tools.CCLFactory(**data)
Bases:
firecrown.updatable.Updatable,pydantic.BaseModel
Factory class for creating instances of the pyccl.Cosmology class.
- model_config
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- require_nonlinear_pk: Annotated[bool, Field(frozen=True)] = False
- amplitude_parameter: Annotated[firecrown.modeling_tools._ccl_enums.PoweSpecAmplitudeParameter, Field(frozen=True)]
- mass_split: Annotated[pyccl.neutrinos.NeutrinoMassSplits, BeforeValidator(_validate_neutrino_mass_splits), Field(frozen=True)]
- num_neutrino_masses: Annotated[int | None, Field(frozen=True, ge=1)] = None
- creation_mode: Annotated[firecrown.modeling_tools._ccl_enums.CCLCreationMode, Field(frozen=True)]
- pure_ccl_transfer_function: Annotated[firecrown.modeling_tools._ccl_enums.CCLPureModeTransferFunction, Field(frozen=True)]
- use_camb_hm_sampling: Annotated[bool, Field(frozen=True)] = False
- allow_multiple_camb_instances: Annotated[bool, Field(frozen=True)] = False
- camb_extra_params: Annotated[firecrown.modeling_tools._ccl_models.CAMBExtraParams | None, Field(frozen=True)] = None
- ccl_spline_params: Annotated[firecrown.modeling_tools._ccl_models.CCLSplineParams | None, Field(frozen=True)] = None
- Omega_c
- Omega_b
- h
- n_s
- Omega_k
- Neff
- m_nu: float | None
- w0
- wa
- T_CMB
- using_camb()
Return True if the CCLFactory is using CAMB for the matter power spectrum.
- Returns:
True if the CCLFactory is using CAMB for the matter power spectrum.
- Return type:
bool
- serialize_model(nxt, _)
Serialize the CCLFactory object.
- Parameters:
nxt (pydantic.SerializerFunctionWrapHandler)
_ (pydantic.SerializationInfo)
- classmethod serialize_mass_split(value)
Serialize the mass split parameter.
- Parameters:
value (pyccl.neutrinos.NeutrinoMassSplits)
- Return type:
str
- model_post_init(_, /)
Initialize the WeakLensingFactory object.
- Return type:
None
- create(calculator_args=None)
Create a pyccl.Cosmology object.
- Parameters:
calculator_args (firecrown.modeling_tools._ccl_types.CCLCalculatorArgs | None)
- Return type:
pyccl.Cosmology
- get()
Return the pyccl.Cosmology object.
- Return type:
pyccl.Cosmology
- class firecrown.modeling_tools.CAMBExtraParams(/, **data)
Bases:
pydantic.BaseModel
Extra parameters for CAMB.
- Parameters:
data (Any)
- model_config
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- HMCode_A_baryon: Annotated[float | None, Field(frozen=False)] = None
- HMCode_eta_baryon: Annotated[float | None, Field(frozen=False)] = None
- HMCode_logT_AGN: Annotated[float | None, Field(frozen=False)] = None
- halofit_version: Annotated[str | None, Field(frozen=True)] = None
- kmax: Annotated[float | None, Field(frozen=True)] = None
- lmax: Annotated[int | None, Field(frozen=True)] = None
- dark_energy_model: Annotated[str | None, Field(frozen=True)] = None
- model_post_init(_, /)
Validate that HMCode parameters are compatible with halofit_version.
- get_dict()
Return the extra parameters as a dictionary.
- Return type:
dict
- update(params)
Update the CAMB sampling parameters.
- Parameters:
params (firecrown.updatable.ParamsMap) – The parameters to update.
- Returns:
None
- Return type:
None
- is_mead2020_feedback()
Return True if the halofit_version is mead2020_feedback.
- Return type:
bool
- is_mead()
Return True if the halofit_version is mead, mead2015, or mead2016.
CAMB treats None as mead.
- Returns:
True if the halofit_version is mead, mead2015, or mead2016
- Return type:
bool
- class firecrown.modeling_tools.CCLSplineParams(/, **data)
Bases:
pydantic.BaseModel
Params to control CCL spline interpolation.
- Parameters:
data (Any)
- model_config
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- a_spline_na: Annotated[int | None, Field(frozen=True)] = None
- a_spline_min: Annotated[float | None, Field(frozen=True)] = None
- a_spline_minlog_pk: Annotated[float | None, Field(frozen=True)] = None
- a_spline_min_pk: Annotated[float | None, Field(frozen=True)] = None
- a_spline_minlog_sm: Annotated[float | None, Field(frozen=True)] = None
- a_spline_min_sm: Annotated[float | None, Field(frozen=True)] = None
- a_spline_minlog: Annotated[float | None, Field(frozen=True)] = None
- a_spline_nlog: Annotated[int | None, Field(frozen=True)] = None
- logm_spline_delta: Annotated[float | None, Field(frozen=True)] = None
- logm_spline_nm: Annotated[int | None, Field(frozen=True)] = None
- logm_spline_min: Annotated[float | None, Field(frozen=True)] = None
- logm_spline_max: Annotated[float | None, Field(frozen=True)] = None
- a_spline_na_sm: Annotated[int | None, Field(frozen=True)] = None
- a_spline_nlog_sm: Annotated[int | None, Field(frozen=True)] = None
- a_spline_na_pk: Annotated[int | None, Field(frozen=True)] = None
- a_spline_nlog_pk: Annotated[int | None, Field(frozen=True)] = None
- k_max_spline: Annotated[float | None, Field(frozen=True)] = None
- k_max: Annotated[float | None, Field(frozen=True)] = None
- k_min: Annotated[float | None, Field(frozen=True)] = None
- dlogk_integration: Annotated[float | None, Field(frozen=True)] = None
- dchi_integration: Annotated[float | None, Field(frozen=True)] = None
- n_k: Annotated[int | None, Field(frozen=True)] = None
- n_k_3dcor: Annotated[int | None, Field(frozen=True)] = None
- ell_min_corr: Annotated[float | None, Field(frozen=True)] = None
- ell_max_corr: Annotated[float | None, Field(frozen=True)] = None
- n_ell_corr: Annotated[int | None, Field(frozen=True)] = None
- check_spline_params()
Check that the spline parameters are valid.
- Return type:
- __enter__()
Enter the context manager.
This method saves the current CCL global spline parameters, updates them with the values from this CCLSplineParams instance, and returns the instance itself. This allows for temporary modification of CCL spline parameters using a with statement.
- Returns:
The current instance with updated spline parameters.
- Return type:
- __exit__(exc_type, exc_value, traceback)
Exit the context manager.
This method resets the CCL global spline parameters to their original values, as saved when entering the context manager. It ensures that any temporary modifications made to the CCL spline parameters within a with statement are reverted upon exit.
- Parameters:
exc_type – The exception type, if an exception occurred.
exc_value – The exception value, if an exception occurred.
traceback – The traceback object, if an exception occurred.
- class firecrown.modeling_tools.MuSigmaModel
Bases:
firecrown.updatable.Updatable
Model for the mu-sigma modified gravity model.
- mu
- sigma
- c1
- c2
- lambda0
- create()
Create a pyccl.modified_gravity.MuSigmaMG object.
- Return type:
pyccl.modified_gravity.MuSigmaMG
- class firecrown.modeling_tools.Background
Bases:
TypedDict
Type representing cosmological background quantities.
Contains arrays for scale factor, comoving distance, and Hubble parameter ratio.
- a: numpy.typing.NDArray[numpy.float64]
- chi: numpy.typing.NDArray[numpy.float64]
- h_over_h0: numpy.typing.NDArray[numpy.float64]
- class firecrown.modeling_tools.CCLCalculatorArgs
Bases:
TypedDict
Arguments for the CCLCalculator.
Contains background cosmology and optional linear/nonlinear power spectra.
- background: Background
- firecrown.modeling_tools.PowerSpec