Units

magnitude_in(value, unit)[source]

Return value as a float in unit.

Accepts either a pint.Quantity (which is converted to unit and stripped to its magnitude) or a bare numeric (which is assumed to already be in unit and is returned as a float). Use this at module boundaries where the caller may pass either form.

For the common case where value is already known to be a Quantity, prefer pint’s built-in pint.Quantity.m_as() directly – q.m_as("meter") is equivalent to q.to("meter").magnitude but shorter, and doesn’t need this helper.

Return type:

float

convert_distance(distance, from_unit, to_unit)[source]

Convert distance between specified units.

Parameters:
  • distance (float) – Distance to convert.

  • from_unit (str) – Unit of the input distance. Must be one of “meters”, “kilometers”, “miles”, “nautical_miles”, “feet”.

  • to_unit (str) – Unit of the output distance. Must be one of “meters”, “kilometers”, “miles”, “nautical_miles”, “feet”.

Returns:

Distance converted to the target unit.

Return type:

float

convert_speed(speed, from_unit, to_unit)[source]

Convert speed between specified units.

Parameters:
  • speed (float) – Speed to convert.

  • from_unit (str) – Unit of the input speed. Must be one of “mps”, “kph”, “mph”, “knots”, “fps”.

  • to_unit (str) – Unit of the output speed. Must be one of “mps”, “kph”, “mph”, “knots”, “fps”.

Returns:

Speed converted to the target unit.

Return type:

float

convert_angle(angle, from_unit, to_unit)[source]

Convert angle between specified units.

Parameters:
  • angle (float) – Angle to convert.

  • from_unit (str) – Unit of the input angle. Must be one of “degrees”, “radians”, “arcminutes”, “arcseconds”.

  • to_unit (str) – Unit of the output angle. Must be one of “degrees”, “radians”, “arcminutes”, “arcseconds”.

Returns:

Angle converted to the target unit.

Return type:

float

convert_time(time, from_unit, to_unit)[source]

Convert a time duration between specified units.

Parameters:
  • time (float) – Time duration to convert.

  • from_unit (str) – Unit of the input duration. Must be one of “seconds”, “minutes”, “hours”, “days”.

  • to_unit (str) – Unit of the output duration. Must be one of “seconds”, “minutes”, “hours”, “days”.

Returns:

Duration converted to the target unit.

Return type:

float

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:

str

Raises:
  • ValueError – If altitude is not a float or a pint length.

  • ValueError – If pressure is not a float or a pint pressure unit.