Helper Functions

Constants

py1090.helpers.EARTH_RADIUS = 6371008.7714

The average earth radius \(R_0\). It is defined as the mean radius of the semi-axes. The values are taken from the WGS 84 (World Geodetic System 1984) ellipsoid (definition of the Department Of Defense, Jan. 2000, p. 37) .

\[R_0 = 6371008.7714 \mathrm{m}\]

Position geometry

py1090.helpers.distance_between(lat1, lon1, lat2, lon2)[source]

Calculates the distance between two locations, in meters, using the Haversine formula.

The bearing between latitude, longitude: \((\phi_1, \lambda_1)\) and \((\phi_2, \lambda_2)\) is given by

\[a = \sin^2(\frac{\phi_2 - \phi_1}{2}) + \cos(\phi_1) \cos(\phi_2) \sin^2(\frac{\lambda_2 - \lambda_1}{2})\]\[d = 2 R_0 \cdot \mathrm{atan2}(\sqrt{a}, \sqrt{1-a})\]

The earth radius \(R_0\) is taken to be py1090.helpers.EARTH_RADIUS. The approximation of a spherical earth is made.

Parameters:
  • lat1 (float) – \(\phi_1\), the latitude of the reference location
  • lon1 (float) – \(\lambda_1\), the longitude of the reference location
  • lat2 (float) – \(\phi_2\), the latitude of the target location
  • lon2 (float) – \(\lambda_2\), the longitude of the target location
Returns:

the distance in meters.

Return type:

float

py1090.helpers.bearing_between(lat1, lon1, lat2, lon2)[source]

Calculates the bearing angle between two locations, in radians.

The bearing between latitude, longitude: \((\phi_1, \lambda_1)\) and \((\phi_2, \lambda_2)\) is given by

\[\mathrm{atan2}(\sin(\lambda_2 - \lambda_1) \cos(\phi_1), \cos(\phi_2) \sin(\phi_1) - \sin(\phi_2) \cos(\phi_2) \cos(\lambda_2 - \lambda_1))\]
Parameters:
  • lat1 (float) – \(\phi_1\), the latitude of the reference location
  • lon1 (float) – \(\lambda_1\), the longitude of the reference location
  • lat2 (float) – \(\phi_2\), the latitude of the target location
  • lon2 (float) – \(\lambda_2\), the longitude of the target location
Returns:

the bearing angle in radians, between \(-\pi\) and \(\pi\).

Return type:

float

Unit conversion

py1090.helpers.knots_to_kmh(knots)[source]

Converts velocity in knots to velocity in km/h.

1 knot is 1 nm/h (nautical mile per hour) and 1.852 km/h.

Parameters:knots (float) – velocity in knots
Returns:velocity in km/h
Return type:float
py1090.helpers.knots_to_mps(knots)[source]

Converts velocity in knots to velocity in m/s (meters per second).

1 knot is 1 nm/h (nautical mile per hour), 1.852 km/h and about 6.67 m/s.

Parameters:knots (float) – velocity in knots
Returns:velocity in m/s
Return type:float