Units¶
- magnitude_in(value, unit)[source]¶
Return
valueas a float inunit.Accepts either a
pint.Quantity(which is converted tounitand stripped to its magnitude) or a bare numeric (which is assumed to already be inunitand is returned as a float). Use this at module boundaries where the caller may pass either form.For the common case where
valueis already known to be a Quantity, prefer pint’s built-inpint.Quantity.m_as()directly –q.m_as("meter")is equivalent toq.to("meter").magnitudebut shorter, and doesn’t need this helper.- Return type:
- convert_distance(distance, from_unit, to_unit)[source]¶
Convert distance between specified units.
- Parameters:
- Returns:
Distance converted to the target unit.
- Return type:
- convert_angle(angle, from_unit, to_unit)[source]¶
Convert angle between specified units.
- Parameters:
- Returns:
Angle converted to the target unit.
- Return type:
- convert_time(time, from_unit, to_unit)[source]¶
Convert a time duration between specified units.
- Parameters:
- Returns:
Duration converted to the target unit.
- Return type:
- altitude_to_flight_level(altitude, pressure=1013.25)[source]¶
Converts altitude to flight level (FL), considering atmospheric pressure.
- Parameters:
altitude (float or pint.Quantity) – Altitude to convert. If a float, it is assumed to be in meters.
pressure (float or pint.Quantity) – Atmospheric pressure. If a float, it is assumed to be in hPa.
- Returns:
Flight level (FL) as a string (e.g., “FL030”, “FL350”).
- Return type:
- Raises:
ValueError – If altitude is not a float or a pint length.
ValueError – If pressure is not a float or a pint pressure unit.