fips.covariance.distances.chordal_matrix#

fips.covariance.distances.chordal_matrix(lats, lons)[source]#

Calculate the pairwise chordal distance matrix between points on the Earth.

The chordal distance is the length of the straight line through the Earth (a sphere of radius R = 6371 km) between two points, 2 R sin(c / 2) for a great-circle angle c. A Gaussian or Matérn correlation of it is positive-definite on the sphere, which one of the great-circle distance is not (Gneiting 2013).

Parameters:
  • lats (ArrayLike) – 1D array-like of latitudes in degrees.

  • lons (ArrayLike) – 1D array-like of longitudes in degrees.

Returns:

The matrix of distances in kilometers, zero on the diagonal.

Return type:

ndarray

Raises:

ValueError – If lats or lons is not 1D.

Examples

A quarter of the equator is 10,008 km along the surface and 9,010 km through the Earth:

>>> from fips.covariance.distances import chordal_matrix, haversine_matrix
>>> haversine_matrix([0.0, 0.0], [0.0, 90.0]).round()
array([[    0., 10008.],
       [10008.,     0.]])
>>> chordal_matrix([0.0, 0.0], [0.0, 90.0]).round()
array([[   0., 9010.],
       [9010.,    0.]])