hmf.core.units.quantity_field¶
- hmf.core.units.quantity_field(unit: UnitBase, *, doc: str, optional: bool = False, ndim: int | None = None, **kwargs: Any) Any[source]¶
Define an
attrsfield (of a model or settings class) that carries a unit.The field takes a Quantity in any unit convertible to
unitwithout an H0 (models have no cosmology), and stores it as a read-only float Quantity in exactlyunit, the canonical unit. So reading the field gives a Quantity,attrs.evolveround-trips it, and the field compares and hashes by its value in the canonical unit (hmf.core._serialise.quantity_key()). Kernels read the plain values through a privatefunctools.cached_property()of the class.- Parameters:
unit – The canonical unit, one of the constants of this module (e.g.
h_Mpc).doc – The field’s documentation (see
hmf.core._fields.field()).optional – Whether
Noneis accepted (and stored asNone).ndim – If given, the number of dimensions the value must have: 0 (a scalar) or 1 (a scalar becomes a 1-element array).
**kwargs – Passed on to
attrs.field()(default,validator, …).
- Returns:
The field definition.
- Return type:
Any
- Raises:
UnitBoundaryError – On construction, for a bare number or array (or
Noneif not optional).astropy.units.UnitConversionError – On construction, for a value in physical units, or not convertible to
unit.ValueError – On construction, for a value with the wrong number of dimensions.