hmf.core.units.to_canonical¶
- hmf.core.units.to_canonical(value: Any, unit: UnitBase, *, context: UnitContext | None = None, where: str, name: str) Any[source]¶
Convert a dimensional value to a plain array in a canonical unit.
This is the conversion
unit_boundary()applies to each dimensional argument, for code that converts a value itself (a field converter, a method with anH0argument, …). Its errors are the boundary’s.- Parameters:
value – A Quantity, or
None(returned as it is, for optional values).unit – The unit to convert to, normally one of
CANONICAL_UNITS.context – The
UnitContextwhose H0 converts physical units.None(the default) means no H0: only units with the canonical power oflittlehare accepted.where – The object or method the value belongs to (e.g.
"CAMB"or"Behroozi.modify_dndm()"), for error messages.name – The name of the value (the argument or field), for error messages.
- Returns:
The values in
unit(for a scalar, a 0-d array or a numpy scalar). Ifvalueis already in exactlyunit(the same object), it is a view ofvalue, not a copy.- Return type:
numpy.ndarray or None
- Raises:
UnitBoundaryError – If
valueis a bare number or array.astropy.units.UnitConversionError – If
valuecan’t be converted tounit(with the context’s H0, if any).
Examples
>>> to_canonical([1, 2] * u.kpc / littleh, Mpc_h, where="example", name="r") array([0.001, 0.002])