BaseFittingFunction

class hmf.mass_function.fitting_functions.BaseFittingFunction(nu2: ndarray, m: ndarray | None = None, z: float = 0.0, n_eff: ndarray | None = None, mass_definition: BaseMassDefinition | None = None, cosmo: FLRW = FlatLambdaCDM(name='Planck18', H0=<Quantity 67.66 km / (Mpc s)>, Om0=0.30966, Tcmb0=<Quantity 2.7255 K>, Neff=3.046, m_nu=<Quantity [0., 0., 0.06] eV>, Ob0=0.04897), delta_c: float = 1.68647, **model_parameters)[source]

Base-class for a halo mass function fit.

This class should not be called directly, rather use a subclass which is specific to a certain fitting formula. The only property necessary to define for any subclass is fsigma, as well as a dictionary of default parameters as a class variable _defaults. Model parameters defined here are accessed through the params instance attribute (and may be overridden at instantiation by the user). A subclass may optionally define a cutmask property, to override the default behaviour of returning True for the whole range.

In addition, the class attributes req_mass and req_neff say whether a subclass needs m and n_eff to be passed. These must be set accordingly.

Every subclass is registered as a plugin (unless defined with abstract=True), so it can be used by name, e.g. MassFunction(hmf_model="MySMT"). When a subclass is defined, a table of its _defaults is added to the Notes section of its docstring, and undocumented fsigma and cutmask overrides get the docstrings defined here.

Examples

The following defines the Sheth-Mo-Tormen mass function (which is already included as SMT), showing the basic idea of subclassing this class:

>>> from typing import ClassVar
>>> import numpy as np
>>> from hmf.mass_function.fitting_functions import BaseFittingFunction
>>> class MySMT(BaseFittingFunction):
...     # Default parameters
...     _defaults: ClassVar[dict[str, float]] = {"a": 0.707, "p": 0.3, "A": 0.3222}
...
...     @property
...     def fsigma(self):
...         A = self.params["A"]
...         a = self.params["a"]
...         p = self.params["p"]
...         return (
...             A
...             * np.sqrt(2.0 * a / np.pi)
...             * self.nu
...             * np.exp(-(a * self.nu2) / 2.0)
...             * (1 + (1.0 / (a * self.nu2)) ** p)
...         )
>>> fit = MySMT(nu2=np.array([1.0, 4.0, 9.0]), a=0.75)
>>> fit.params["a"]
0.75
>>> fit.fsigma.shape
(3,)

In that example, we did not specify cutmask, so all elements are considered to be within the fitted range.

Parameters:
nu2array_like

A vector of peak-heights, \(\delta_c^2/\sigma^2\) corresponding to m

marray_like, optional

A vector of halo masses [units M_sun/h]. Only necessary if req_mass is True. Typically provides limits of applicability. Must correspond to nu2.

zfloat, optional

The redshift. Only used by models that depend on redshift. Default is 0.

n_effarray_like, optional

The effective spectral index at m. Only required if req_neff is True.

mass_definitionhmf.halos.mass_definitions.MassDefinition instance

A halo mass definition. Only required for fits which explicitly include a parameterization for halo definition.

cosmoastropy.cosmology.FLRW instance, optional

A cosmology. Default is hmf.cosmology.cosmo.DEFAULT_COSMOLOGY (Planck18), as for the frameworks. Either omegam_z or cosmo is required if req_omz is True. If both are passed, omegam_z takes precedence.

**model_parametersunpacked-dictionary

These parameters are model-specific. The available parameters and their defaults are listed in the Notes section of each model (and are also available as <model>._defaults).

Attributes

cutmask

Boolean mask of the elements within the fit's calibrated range.

fsigma

The function \(f(\sigma)\equiv\nu f(\nu)\).

lnsigma

Negative log of sigma.

normalized

Whether this model is normalized so that all mass is in halos

nu

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

omegam_z

Normalised matter density at current redshift.

references

References to cite when this model is used, each a formatted citation string.

req_mass

Whether m is required for this subclass

req_neff

Whether n_eff is required for this subclass

sigma

The sqrt of mass variance as a function of mass.

sim_definition

Details of the defining simulation, instance of SimDetails

Methods

classmethod get_measured_mdef()[source]

Get the mass definition used in the defining simulation.

classmethod get_models() → Mapping[str, type]

Get a read-only mapping of all implemented models for this component.

The mapping is a live view of the registry, so it shows models registered later, but it can not be used to add or remove models.