Filter

class hmf.core.filters.Filter[source]

The kind of smoothing filters.

A filter defines:

  • the window \(W(x)\) of \(x = kR\) (window()), with \(W(0) = 1\);

  • its derivatives \(W' = dW/d\ln x\) and \(W'' = d^2W/d(\ln x)^2\) (window_derivatives_kernel());

  • the mass-assignment constant \(c\) (mass_assignment), in \(m = \frac{4\pi}{3} \bar\rho\, (cR)^3\);

  • envelopes bounding \(W^2\) and \(|W W'|\) far beyond the ends of the k grid (tail_bounds()), for the truncation estimator of MassVariance.

A filter whose window is a sharp cut-off sets sharp_cutoff; its variance is then integrated up to the cut-off exactly, not through the window.

Attributes

alias: ClassVar[str | None] = None

The short name the model is registered under, if any. Set by the alias class keyword; never inherited.

calibration

Where this model was calibrated, with its source (None if it was not).

The class’s calibration_domain, unless it depends on the instance’s parameters.

calibration_domain: ClassVar[Domain | None] = None

Filters are not calibrated against simulations.

mass_assignment

The constant \(c\) of the mass assignment \(m \propto (cR)^3\).

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.

sharp_cutoff: ClassVar[bool] = False

Whether the window is the sharp cut-off \(\Theta(1 - x)\).

valid_domain: ClassVar[Domain] = Domain(bounds=(('x', Interval(lower=0.0, upper=inf, unit=None, lower_open=False, upper_open=True)),), source='x = kR >= 0.')

\(x = kR \ge 0\). window() and dwindow_dlnx() raise a DomainError outside it.

Type:

Where the window can be evaluated

Methods

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 that get() accepts, which is looked up and instantiated with its default parameters.

Returns:

An instance of cls.

Return type:

Model

Raises:
  • ModelNotFoundError – If value is a name that no model of this kind is known by.

  • TypeError – If value is of any other type, or names a class that is not a concrete subclass of cls.

Examples

>>> from hmf.core.filters import Filter, TopHat
>>> Filter.coerce("TopHat") == TopHat()
True
dwindow_dlnx(x: ArrayLike) → ndarray[tuple[Any, ...], dtype[float64]][source]

The derivative \(dW/d\ln x\), with \(x = kR\).

Parameters:

x – \(kR\), dimensionless, >= 0.

Returns:

The derivative, of the shape of x (a scalar for a scalar x).

Return type:

numpy.float64 or ndarray

Raises:
  • DomainError – If an x is outside valid_domain (negative or NaN).

  • ValueError – For a filter whose derivative can’t be evaluated pointwise (SharpK).

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:

type

Raises:
  • ModelNotFoundError – If no model of this kind is known by name, even after loading the hmf.models entry points and trying name as an import path.

  • TypeError – If name resolves to something that is not a concrete subclass of cls.

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.models entry-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

classmethod qualified_name() → str

Return this class’s qualified name, package.module:Class.

abstractmethod tail_bounds() → TailBounds[source]

Bounds on the window beyond the ends of the k grid.

Returns:

The bounds on \(W^2\) and \(|W W'|\) at both ends.

Return type:

TailBounds

window(x: ArrayLike) → ndarray[tuple[Any, ...], dtype[float64]][source]

The window \(W(x)\), with \(x = kR\).

Parameters:

x – \(kR\), dimensionless, >= 0.

Returns:

The window, of the shape of x (a scalar for a scalar x).

Return type:

numpy.float64 or ndarray

Raises:

DomainError – If an x is outside valid_domain (negative or NaN).

window_derivatives_kernel(x: ArrayLike, order: int = 2) → tuple[ndarray[tuple[Any, ...], dtype[float64]], ...][source]

The window and its logarithmic derivatives at \(x = kR\).

This is the kernel-level method, which library code (e.g. MassVariance) calls: it returns plain arrays, 0-d for a scalar x. window() and dwindow_dlnx() are the public methods, which follow the scalar rule of unit_boundary().

Parameters:
  • x – \(kR\), dimensionless, >= 0.

  • order – The highest derivative to return: 0, 1 or 2.

Returns:

\((W,)\), \((W, W')\) or \((W, W', W'')\).

Return type:

tuple of ndarray

Raises:
  • DomainError – If an x is outside valid_domain (negative or not finite).

  • ValueError – If the filter has no pointwise derivative of that order (SharpK, for order > 0).