MassFunction

class hmf.mass_function.hmf.MassFunction(*args, **kwargs)[source]

An object containing all relevant quantities for the mass function.

The purpose of this class is to calculate many quantities associated with the dark matter halo mass function (HMF). The class is initialized to form a cosmology and takes in various options as to how to calculate all further quantities.

Most outputs are provided as @cached_quantity attributes for ease of access.

Contains an update() method which can be passed arguments to update, in the most optimal manner. All output quantities are calculated only when needed (but stored after first calculation for quick access).

In addition to the parameters directly passed to this class, others are available which are passed on to its superclass (Transfer). To read a standard documented list of (all) available parameters, use parameter_info(). If you want to just see the plain list of available parameters, use get_all_parameters(). To see the actual defaults for each parameter, use get_all_parameter_defaults().

Parameters:
  • Mmin – The log10 of the minimum halo mass to compute quantities for (units Msun/h).

  • Mmax – The log10 of the minimum halo mass to compute quantities for (units Msun/h).

  • dlog10m – The resolution of the mass array (logarithmically spaced).

  • hmf_model – The HMF fitting function to use.

  • hmf_params – Parameters specific to the chosen HMF.

  • mdef_model – The mass definition model to use. By default, use the mass definition in which the chosen HMF was measured. If that does not exist, use SOMean(200). If set, this must be compatible with the halo definition used in measuring the chosen HMF – unless disable_mass_conversion is set to False, in which case the HMF is automatically translated to a new mass definition.

  • mdef_params – Parameters specific to the mass definition model. Typically “overdensity” or “linking_length”.

  • delta_c – The critical overdensity for collapse.

  • filter_model – A model to compute the

Examples

Since all parameters have reasonable defaults, the most obvious thing to do is

>>> h = MassFunction()
>>> h.dndm

Many different parameters may be passed, both models and parameters of those models. For instance:

>>> h = MassFunction(z=1.0,Mmin=8,hmf_model="SMT")
>>> h.dndm

Once instantiated, changing parameters should be done through the update() method:

>>> h.update(z=2)
>>> h.dndm

Attributes

ERROR_ON_BAD_MDEF = True

Switch to turn off exceptions for mdef’s not matching hmf_model

Mmax

Maximum mass at which to perform analysis [units \(\log_{10}M_\odot h^{-1}\)].

Type:

float

Type:

Parameter

Mmin

Minimum mass at which to perform analysis [units \(\log_{10}M_\odot h^{-1}\)].

Type:

float

Type:

Parameter

cosmo

The cosmography object with custom parameters applied.

A astropy.cosmology.FLRW instance with custom cosmology from cosmo_params applied.

cosmo_model

The cosmological model instance.

Basis for the cosmology with custom subclasses supported. Defaults to Planck18. See astropy documentation for details.

Type:

instance of astropy.cosmology.FLRW subclass

Type:

Parameter

cosmo_params

Parameters deviating from the base cosmology.

Useful for repeated updates of a single parameter, leaving others the same. Default is the empty dict. Parameters passed must match the allowed parameters of cosmo_model. For the basic class, these are:

Tcmb0:

Temperature of the CMB at z=0

Neff:

Number of massless neutrino species

M_nu:

Mass of neutrino species (list)

H0:

The hubble constant at z=0

Om0:

The normalised matter density at z=0

Type:

dict

Type:

Parameter

delta_c

The critical overdensity for collapse, \(\delta_c\).

Type:

float

Type:

Parameter

delta_k

Dimensionless power spectrum, \(\Delta_k = \frac{k^3 P(k)}{2\pi^2}\).

disable_mass_conversion

Disable converting mass function from builtin definition to that provided.

Type:

bool

Type:

Parameter

dlnk

Step-size of log wave-numbers.

Type:

float

Type:

Parameter

dlog10m

log10 interval between mass bins.

Type:

float

Type:

Parameter

dndlnm

The differential mass function in terms of natural log of m, len=len(m).

Units: \(h^3 Mpc^{-3}\)

dndlog10m

The differential mass function in terms of log of m, len=len(m).

Units: \(h^3 Mpc^{-3}\)

dndm

The number density of haloes, len=len(m).

Units: \(h^4 M_\odot^{-1} Mpc^{-3}\)].

filter

Instantiated model for filter/window functions.

Note that this filter is not normalised – i.e. the output of filter.sigma(8) will not be the input sigma_8.

Filters whose shape depends on the physical peak height (i.e. SharpKEllipsoid) are also given delta_c and the factor converting their \(\sigma\) to the normalised \(\sigma\) at redshift z.

filter_model

A model for the window/filter function.

Type:

hmf.filters.Filter subclass

Type:

Parameter

filter_params

Model parameters for filter_model.

Type:

dict

Type:

Parameter

fsigma

The multiplicity function, \(f(\sigma)\), for hmf_model. len=len(m).

growth

The instantiated growth model.

growth_factor

The growth factor.

growth_model

The model to use to calculate the growth function/growth rate.

"ClassGrowth" needs the optional classy package (pip install hmf[class]).

Type:

hmf.growth_factor.BaseGrowthFactor subclass

Type:

Parameter

growth_params

Relevant parameters of the growth_model.

Type:

dict

Type:

Parameter

halo_overdensity_crit

The halo overdensity with respect to the critical density.

halo_overdensity_mean

The halo overdensity with respect to the mean background.

hmf

Instantiated model for the hmf fitting function.

hmf_model

A model to use as the fitting function \(f(\sigma)\).

Type:

str or hmf.fitting_functions.FittingFunction subclass

Type:

Parameter

hmf_params

Model parameters for hmf_model.

Type:

dict

Type:

Parameter

how_big

Expected simulation volume per halo.

Size of simulation volume in which to expect one halo of mass m (with 95% probability), in units \(Mpch^{-1}\), with length len(m).

k

Wavenumbers, [h/Mpc].

lnk_max

Maximum (natural) log wave-number, k [h/Mpc].

Type:

float

Type:

Parameter

lnk_min

Minimum (natural) log wave-number, k [h/Mpc].

Type:

float

Type:

Parameter

lnsigma

Natural log of inverse mass variance, len=len(m).

m

Halo masses (defined via mdef).

mass_nonlinear

The nonlinear mass, \(\nu(M_\star) = 1\).

This is found by root-finding \(\sigma(M_\star) = \delta_c\) directly on the filter, so it does not need to lie within the mass grid m.

Raises:

ValueError – If \(\nu = 1\) is not reached for any radius supported by the k grid.

mdef

The halo mass-definition model instance.

Default mass definition is the one the chosen hmf model was measured with.

mdef_model

A model to use as the mass definition.

Type:

str or hmf.halos.mass_definitions.MassDefinition subclass

Type:

Parameter

mdef_params

Model parameters for mdef_model.

Type:

dict.

Type:

Parameter

mean_density

Mean density of universe at redshift z.

mean_density0

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

n

Spectral index of fluctuations.

Must be greater than -3 and less than 4.

Type:

float

Type:

Parameter

n_eff

Effective spectral index at scale of halo radius, len=len(m).

Notes

This function, and any derived quantities, can show small non-physical ‘wiggles’ at the 0.1% level, if too coarse a grid in ln(k) is used. If applications are sensitive at this level, please use a very fine k-space grid.

Uses eq. 42 in Lukic et. al 2007.

n_eff_at_collapse

Effective spectral index at the scale of the nonlinear mass, \(\nu = 1\).

Evaluated directly from the filter at the radius of mass_nonlinear (which need not lie within m), using eq. 42 of Lukic et al. (2007), as for n_eff.

Raises:

ValueError – If \(\nu = 1\) is not reached for any radius supported by the k grid.

ngtm

The cumulative mass function above m, len=len(m) [units \(h^3 Mpc^{-3}\)].

In the case that m does not extend to sufficiently high masses, this routine will auto-generate dndm for an extended mass range.

In the case of the ff.Behroozi fit, it is impossible to auto-extend the mass range except by the power-law fit, thus one should be careful to supply appropriate mass ranges in this case.

nonlinear_delta_k

Dimensionless nonlinear power spectrum.

\[\Delta_k = \frac{k^3 P_{\rm nl}(k)}{2\pi^2}\]

Non-linear corrections come from HALOFIT.

If you use this, please cite HALOFIT: Smith et al. [1], and also Takahashi et al. [2] when takahashi is True (the default).

References

[1]

Smith, R. E., et al., 2003. MNRAS 341, 1311. arXiv:astro-ph/0207664

[2]

Takahashi, R., et al., 2012. ApJ 761, 152. arXiv:1208.2701

nonlinear_power

Non-linear log power [units \(Mpc^3/h^3\)].

Non-linear corrections come from HALOFIT.

If you use this, please cite HALOFIT: Smith et al. [1], and also Takahashi et al. [2] when takahashi is True (the default).

References

[1]

Smith, R. E., et al., 2003. MNRAS 341, 1311. arXiv:astro-ph/0207664

[2]

Takahashi, R., et al., 2012. ApJ 761, 152. arXiv:1208.2701

normalised_filter

A normalised filter, such that filter.sigma(8) == sigma8.

nu

the squared peak height, \((\delta_c/\sigma)^2\).

Deprecated since version 3.7: nu is \(\nu^2\), not the peak height \(\nu\). It will be removed in v4. Use nu2 for \(\nu^2\), or peak_height for \(\nu = \delta_c/\sigma\).

Type:

Deprecated

nu2

The squared peak height, \(\nu^2 = \left(\frac{\delta_c}{\sigma}\right)^2\), len=len(m).

nu_fn

The squared peak height as a callable function of mass.

A spline of nu2, \(\nu^2 = \left(\frac{\delta_c}{\sigma}\right)^2\), against m.

The spline is a cubic in \(\ln m\)-\(\ln \nu^2\) space, in which \(\nu^2(m)\) is close to a power law, so interpolation is accurate between the grid points. It extrapolates (as a cubic in log-log space) outside m.

parameter_values

Dictionary of all parameters and their current values.

peak_height

The peak height, \(\nu = \delta_c/\sigma\), len=len(m).

This is the same \(\nu\) as the fitting function’s hmf.nu.

power

Normalised log power spectrum [units \(Mpc^3/h^3\)].

radii

The radii corresponding to the masses m.

Note that these are not the halo radii – they are the radii containing mass m given a purely background density.

references: ClassVar[tuple[str, ...]] = ()

References for the framework itself (not its component models), each a formatted citation string. References of parent framework classes are included too.

rho_gtm

Mass density in haloes >m, len=len(m) [units \(M_\odot h^2 Mpc^{-3}\)].

In the case that m does not extend to sufficiently high masses, this routine will auto-generate dndm for an extended mass range.

In the case of the ff.Behroozi fit, it is impossible to auto-extend the mass range except by the power-law fit, thus one should be careful to supply appropriate mass ranges in this case.

rho_ltm

Mass density in haloes <m, len=len(m) [units \(M_\odot h^2 Mpc^{-3}\)].

Note

As of v1.6.2, this assumes that the entire mass density of halos is encoded by the mean_density0 parameter (ie. all mass is found in halos). This is not explicitly true of all fitting functions (eg. Warren), in which case the definition of this property is somewhat inconsistent, but will still work.

In the case that m does not extend to sufficiently high masses, this routine will auto-generate dndm for an extended mass range.

In the case of the ff.Behroozi fit, it is impossible to auto-extend the mass range except by the power-law fit, thus one should be careful to supply appropriate mass ranges in this case.

sigma

The sqrt of the mass variance at z, len=len(m).

sigma8_z

sigma(8) at redshif z.

sigma_8

RMS linear density fluctuations in spheres of radius 8 Mpc/h.

Type:

float

Type:

Parameter

sigma_8_species

"tot", "cb" or None.

The default, "tot", means sigma_8 is the r.m.s. of the total matter field (including massive neutrinos), which is how experiments such as Planck quote it, and how the default sigma_8 is defined. When the transfer model computes the CDM+baryon field (matter_species="cb", the default), its power spectrum is normalised so that the total matter field from the same model has r.m.s. sigma_8. "cb" means sigma_8 is that of the CDM+baryon field, and None means whichever field the transfer model computes.

This has no effect with massless neutrinos (the fields are then identical) or for transfer models that don’t distinguish the two fields (i.e. have no matter_species parameter, like EH or BBKS). Otherwise, normalising a field other than the computed one needs that field’s transfer function too. With CAMB or CLASS this reuses the same run, which gives both fields. See Massive neutrinos: which matter field to use.

Type:

str or None

Type:

Parameter

Type:

Which matter field sigma_8 describes

takahashi

Whether to use updated HALOFIT coefficients from Takahashi+12.

If False, use the original coefficients from Smith+2003.

Type:

bool

Type:

Parameter

transfer

The instantiated transfer model.

transfer_function

Normalised CDM log transfer function.

transfer_model

Defines which transfer function model to use.

Built-in available models are found in the hmf.transfer_models module. Default is CAMB if installed, otherwise EH. "CLASS" needs the optional classy package (pip install hmf[class]).

Type:

str or hmf.transfer_models.TransferComponent subclass, optional

Type:

Parameter

transfer_params

Relevant parameters of the transfer_model.

Type:

dict

Type:

Parameter

z

Redshift.

Must be non-negative.

Type:

float

Type:

Parameter

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()[source]

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