Cosmology

class hmf.cosmology.cosmo.Cosmology(*args, **kwargs)[source]

Basic Cosmology object.

This class thinly wraps cosmology objects from the astropy package. The full functionality of the astropy cosmology objects are available in the cosmo attribute. What the class adds to the existing astropy implementation is the specification of the cosmological parameters as parameter inputs to an over-arching Framework.

In particular, while any instance of a subclass of astropy.cosmology.FLRW may be passed as the base cosmology, the specific parameters can be updated individually by passing them through the cosmo_params dictionary (both in the constructor and the update() method.

This dictionary is kept in memory and so adding a different parameter on a later update will update the dictionary, rather than replacing it.

To read a standard documented list of parameters, use Cosmology.parameter_info(). If you want to just see the plain list of available parameters, use Cosmology.get_all_parameters(). To see the actual defaults for each parameter, use Cosmology.get_all_parameter_defaults().

Attributes

cosmo

The cosmography object with custom parameters applied.

cosmo_model

The cosmological model instance.

cosmo_params

Parameters deviating from the base cosmology.

mean_density0

Mean density of universe at z=0, [Msun h^2 / Mpc**3].

parameter_values

Dictionary of all parameters and their current values.

references

References for the framework itself (not its component models), each a formatted citation string.

Methods

clone(**kwargs)

Create and return an updated clone of the current object.

get_acknowledgments(flat: bool = False) → dict[str, tuple[str, ...]] | list[str]

Get the references to cite for the current setup of the framework.

The references are grouped by where they come from, in this order:

  • "hmf": the paper describing hmf itself.

  • The framework’s class name (e.g. "MassFunction"): the framework’s own references, including those of its parent framework classes. Only present if there are any.

  • Each *_model parameter (e.g. "hmf_model", "transfer_model"): the references of the model currently set on it. A model with nothing to cite gives an empty tuple; a parameter set to None is left out.

  • Each sub-framework, with its keys prefixed by the sub-framework’s name (e.g. "tracer.transfer_model").

The keys say which model each citation belongs to, not whether that model was used in a quantity you computed. All references are read from the model classes, so this does not compute anything.

Parameters:

flat – If True, return a single list of all the references with duplicates removed (keeping the first occurrence), e.g. for a paper’s bibliography.

Returns:

A dict mapping each source to a tuple of formatted citations, or a flat list of citations if flat is True.

Return type:

dict or list

Examples

>>> from hmf import MassFunction
>>> mf = MassFunction(hmf_model="Tinker08")
>>> by_model = mf.get_acknowledgments()
>>> bibliography = mf.get_acknowledgments(flat=True)
classmethod get_all_parameter_defaults(recursive=True)

Dictionary of all parameters and defaults.

Defaults may be set with some logic in __init__, so they are read from an instance. The instance is not validated, so no quantities are computed.

classmethod get_all_parameter_names() → list[str]

Return all parameter names in the class.

These are read from the class’s @parameter definitions, so the class is not instantiated.

get_dependencies(*q)

Determine all parameter dependencies of the quantities in q.

Parameters:

q (str) – String(s) labelling a quantity

Returns:

deps – A set containing all parameters on which quantities in q are dependent.

Return type:

set

classmethod parameter_info(names=None)

Prints information about each parameter in the class.

Optionally, restrict printed parameters to those found in the list of names provided.

classmethod quantities_available() → list[str]

Obtain a list of all available (public) output quantities.

These are the class’s @cached_quantity and @subframework definitions, read without instantiating the class.

update(**kwargs)

Update parameters of the framework with kwargs.

The update is atomic: if setting any parameter, or the validation of the new set of parameters, fails, all parameters are restored to their values from before the call, and the error is re-raised.

Parameters:

**kwargs – New values of parameters of the framework. A key <name>_params, where <name> is a sub-framework, takes a dict of parameters with which to update that sub-framework.

Raises:

ValueError – If a key is not a parameter of the framework (or a sub-framework’s _params), or if the new parameters fail validation.

validate()

Perform validation of the input parameters as they relate to each other.