pycontrails.physics.units

Unit conversion support.

Functions

degrees_to_radians(degrees)

Convert from degrees to radians.

dt_to_seconds(dt[, dtype])

Convert a time delta to seconds as a float with specified dtype precision.

ft_to_m(ft)

Convert length from feet to meter.

ft_to_pl(h)

Convert from altitude (ft) to pressure level (hPa).

kelvin_to_celsius(kelvin)

Convert temperature from Kelvin to Celsius.

knots_to_m_per_s(knots)

Convert speed from knots to meters per second (m/s).

latitude_distance_to_m(distance_degrees)

Convert latitude degrees distance between two points to cartesian distances in meters.

lbs_to_kg(lbs)

Convert mass from pounds (lbs) to kilograms (kg).

longitude_distance_to_m(distance_degrees, ...)

Convert longitude degrees distance between two points to cartesian distances in meters.

m_per_s_to_knots(m_per_s)

Convert speed from meters per second (m/s) to knots.

m_to_T_isa(h)

Calculate the ambient temperature (K) for a given altitude (m).

m_to_ft(m)

Convert length from meters to feet.

m_to_latitude_distance(distance_m)

Convert cartesian distance (meters) to differences in latitude degrees.

m_to_longitude_distance(distance_m, ...)

Convert cartesian distance (meters) to differences in longitude degrees.

m_to_pl(h)

Convert from altitude (m) to pressure level (hPa).

mach_number_to_tas(mach_number, T)

Calculate true airspeed from the Mach number at a specified ambient temperature.

pl_to_ft(pl)

Convert from pressure level (hPa) to altitude (ft).

pl_to_m(pl)

Convert from pressure level (hPa) to altitude (m).

radians_to_degrees(radians)

Convert from radians to degrees.

tas_to_mach_number(true_airspeed, T)

Calculate Mach number from true airspeed at a specified ambient temperature.

pycontrails.physics.units.degrees_to_radians(degrees)

Convert from degrees to radians.

Parameters:

degrees (ArrayScalarLike) – Degrees values, [\(\deg\)]

Returns:

ArrayScalarLike – Radians values

pycontrails.physics.units.dt_to_seconds(dt, dtype=<class 'numpy.float64'>)

Convert a time delta to seconds as a float with specified dtype precision.

Parameters:
  • dt (numpy.ndarray) – Time delta for each waypoint

  • dtype (np.dtype) – Data type of the output array

Returns:

numpy.ndarray – Time delta in seconds as a float

pycontrails.physics.units.ft_to_m(ft)

Convert length from feet to meter.

Parameters:

ft (ArrayScalarLike) – length, [\(ft\)]

Returns:

ArrayScalarLike – length, [\(m\)]

pycontrails.physics.units.ft_to_pl(h)

Convert from altitude (ft) to pressure level (hPa).

Assumes the ICAO standard atmosphere.

Parameters:

h (ArrayScalarLike) – altitude, [\(ft\)]

Returns:

ArrayScalarLike – pressure level, [\(hPa\)], [\(mbar\)]

pycontrails.physics.units.kelvin_to_celsius(kelvin)

Convert temperature from Kelvin to Celsius.

Parameters:

kelvin (ArrayScalarLike) – temperature [\(K\)]

Returns:

ArrayScalarLike – temperature [\(C\)]

pycontrails.physics.units.knots_to_m_per_s(knots)

Convert speed from knots to meters per second (m/s).

Parameters:

knots (ArrayScalarLike) – Speed, [\(knots\)]

Returns:

ArrayScalarLike – Speed, [\(m \ s^{-1}\)]

pycontrails.physics.units.latitude_distance_to_m(distance_degrees)

Convert latitude degrees distance between two points to cartesian distances in meters.

Parameters:

distance_degrees (ArrayScalarLike) – latitude distance, [\(\deg\)]

Returns:

ArrayScalarLike – Cartesian distance along the latitude axis, [\(m\)]

pycontrails.physics.units.lbs_to_kg(lbs)

Convert mass from pounds (lbs) to kilograms (kg).

Parameters:

lbs (ArrayScalarLike) – mass, pounds [\(lbs\)]

Returns:

ArrayScalarLike – mass, kilograms [\(kg\)]

pycontrails.physics.units.longitude_distance_to_m(distance_degrees, latitude_mean)

Convert longitude degrees distance between two points to cartesian distances in meters.

Parameters:
  • distance_degrees (ArrayScalarLike) – longitude distance, [\(\deg\)]

  • latitude_mean (ArrayScalarLike, optional) – mean latitude between longitude_1 and longitude_2, [\(\deg\)]

Returns:

ArrayScalarLike – cartesian distance along the longitude axis, [\(m\)]

pycontrails.physics.units.m_per_s_to_knots(m_per_s)

Convert speed from meters per second (m/s) to knots.

Parameters:

m_per_s (ArrayScalarLike) – Speed, [\(m \ s^{-1}\)]

Returns:

ArrayScalarLike – Speed, [\(knots\)]

pycontrails.physics.units.m_to_T_isa(h)

Calculate the ambient temperature (K) for a given altitude (m).

Assumes the ICAO standard atmosphere.

Parameters:

h (ArrayScalarLike) – altitude, [\(m\)]

Returns:

ArrayScalarLike – ICAO standard atmosphere ambient temperature, [\(K\)]

References

Notes

See https://en.wikipedia.org/wiki/International_Standard_Atmosphere

See also

m_to_pl, ft_to_pl

pycontrails.physics.units.m_to_ft(m)

Convert length from meters to feet.

Parameters:

m (ArrayScalarLike) – length, [\(m\)]

Returns:

ArrayScalarLike – length, [\(ft\)]

pycontrails.physics.units.m_to_latitude_distance(distance_m)

Convert cartesian distance (meters) to differences in latitude degrees.

Small angle approximation for distance_m << constants.radius_earth

Parameters:

distance_m (ArrayScalarLike) – cartesian distance along latitude axis, [\(m\)]

Returns:

ArrayScalarLike – latitude distance, [\(\deg\)]

pycontrails.physics.units.m_to_longitude_distance(distance_m, latitude_mean)

Convert cartesian distance (meters) to differences in longitude degrees.

Small angle approximation for distance_m << constants.radius_earth

Parameters:
  • distance_m (ArrayScalarLike) – cartesian distance along longitude axis, [\(m\)]

  • latitude_mean (ArrayScalarLike) – mean latitude between longitude_1 and longitude_2, [\(\deg\)]

Returns:

ArrayScalarLike – longitude distance, [\(\deg\)]

pycontrails.physics.units.m_to_pl(h)

Convert from altitude (m) to pressure level (hPa).

Parameters:

h (npt.NDArray[np.float64]) – altitude, [\(m\)]

Returns:

npt.NDArray[np.float64] – pressure level, [\(hPa\)], [\(mbar\)]

References

Notes

See https://en.wikipedia.org/wiki/Barometric_formula

See also

m_to_T_isa, ft_to_pl

pycontrails.physics.units.mach_number_to_tas(mach_number, T)

Calculate true airspeed from the Mach number at a specified ambient temperature.

Parameters:
  • mach_number (float | npt.NDArray[np.float64]) – Mach number, [:math: Ma]

  • T (npt.NDArray[np.float64]) – Ambient temperature, [\(K\)]

Returns:

npt.NDArray[np.float64] – True airspeed, [\(m \ s^{-1}\)]

References

pycontrails.physics.units.pl_to_ft(pl)

Convert from pressure level (hPa) to altitude (ft).

Assumes the ICAO standard atmosphere.

Parameters:

pl (ArrayScalarLike) – pressure level, [\(hPa\)], [\(mbar\)]

Returns:

ArrayScalarLike – altitude, [\(ft\)]

pycontrails.physics.units.pl_to_m(pl)

Convert from pressure level (hPa) to altitude (m).

Function is slightly different from the classical formula: constants.T_msl / 0.0065) * (1 - (pl_pa / constants.p_surface) ** (1 / 5.255) in order to provide a mathematical inverse to m_to_pl().

For low altitudes (below the tropopause), this implementation closely agrees to classical formula.

Parameters:

pl (ArrayLike) – pressure level, [\(hPa\)], [\(mbar\)]

Returns:

ArrayLike – altitude, [\(m\)]

References

Notes

See https://en.wikipedia.org/wiki/Barometric_formula

pycontrails.physics.units.radians_to_degrees(radians)

Convert from radians to degrees.

Parameters:

radians (ArrayScalarLike) – degrees values, [\(\rad\)]

Returns:

ArrayScalarLike – Radian values

pycontrails.physics.units.tas_to_mach_number(true_airspeed, T)

Calculate Mach number from true airspeed at a specified ambient temperature.

Parameters:
Returns:

ArrayScalarLike – Mach number, [:math: Ma]

References