MassConversion¶
- class hmf.core.mass_conversion.MassConversion[source]¶
The kind of conversions of halo masses between mass definitions.
Subclasses implement
check_definitions()andconvert_kernel().Attributes
- alias: ClassVar[str | None] = None¶
The short name the model is registered under, if any. Set by the
aliasclass keyword; never inherited.
- parameter_source: ClassVar[str] = ''¶
The exact source (paper, version, table or equation) of the parameter defaults, e.g. “Tinker et al. 2008, ApJ 688, 709 (published), Table 2”.
- references: ClassVar[tuple[str, ...]] = ()¶
References to cite when the model is used, each a formatted citation.
Methods
- abstractmethod check_definitions(source: MassDefinition, target: MassDefinition) None[source]¶
Raise
ValueErrorif masses can’t be converted fromsourcetotarget.- Parameters:
source – The mass definitions.
target – The mass definitions.
- Raises:
ValueError – If the conversion is not possible.
- classmethod coerce(value: object) Self¶
Convert a value to a model of this kind: the converter of a model field.
- Parameters:
value – An instance of
cls, which is returned as it is; or a name, import path or class thatget()accepts, which is looked up and instantiated with its default parameters.- Returns:
An instance of
cls.- Return type:
- Raises:
ModelNotFoundError – If
valueis a name that no model of this kind is known by.TypeError – If
valueis of any other type, or names a class that is not a concrete subclass ofcls.
Examples
>>> from hmf.core.filters import Filter, TopHat >>> Filter.coerce("TopHat") == TopHat() True
- convert(*, m: Any, z: ArrayLike, omega_m_z: ArrayLike, source: MassDefinition, target: MassDefinition) tuple[ndarray[tuple[Any, ...], dtype[float64]], ndarray[tuple[Any, ...], dtype[float64]]][source]¶
Convert masses from
sourcetotarget(seeconvert_kernel()).- Parameters:
m (Quantity) – Masses in Msun/h, in
source.z (float or array_like) – Redshifts, broadcast with
m.omega_m_z (float or array_like) – \(\Omega_m(z)\) of CDM + baryons (e.g.
hmf.core.species.omega_m()).source (MassDefinition) – The mass definitions.
target (MassDefinition) – The mass definitions.
- Returns:
m_new (Quantity) – The masses in
target, in Msun/h.dm_new_dm (numpy.ndarray) – The Jacobian dM’/dM.
- abstractmethod convert_kernel(*, m: ArrayLike, z: ArrayLike, omega_m_z: ArrayLike, source: MassDefinition, target: MassDefinition) ConvertedMasses[source]¶
Convert masses from
sourcetotargetat z, at kernel level.- Parameters:
m – Masses in Msun/h, in
source: a plain array.z – Redshifts, broadcast with
m.omega_m_z – \(\Omega_m(z)\) of CDM + baryons at
z, broadcast withm.source – The mass definitions.
target – The mass definitions.
- Returns:
The masses in
targetand dM’/dM, with the broadcast shape.- Return type:
- Raises:
DomainError – If an input is outside the conversion’s valid domain.
- classmethod fields_info() tuple[FieldInfo, ...]¶
Describe this class’s fields, without creating an instance.
- Returns:
The name, type, default and documentation of each field.
- Return type:
tuple of FieldInfo
- classmethod get(name: str | type[Model]) type[Self]¶
Look up a model of this kind.
- Parameters:
name – An alias (
"Tinker08"), a qualified name ("hmf.core.fits:Tinker08"), an import path to a class not yet imported ("pkg.mod:Cls"or"pkg.mod.Cls"), or a class.- Returns:
The model class (not an instance). It is always a subclass of
cls.- Return type:
- Raises:
ModelNotFoundError – If no model of this kind is known by
name, even after loading thehmf.modelsentry points and tryingnameas an import path.TypeError – If
nameresolves to something that is not a concrete subclass ofcls.
- classmethod get_aliases() Mapping[str, str]¶
Return a read-only mapping from alias to qualified name, for this kind.
- classmethod get_models() Mapping[str, type[Self]]¶
Return the registered models of this kind, by qualified name.
Plugins advertised in the
hmf.modelsentry-point group are loaded first.- Returns:
A read-only mapping from qualified name to class. Called on a kind, it is a live view of the registry. Called on a non-kind subclass, it holds only the models that subclass it.
- Return type:
Mapping