shakelib.utils.distance

shakelib.utils.distance.geodetic_distance_fast(lons1, lats1, lons2, lats2)[source]

Calculate the geodetic distance between two points or two collections of points using a formula that is substantially faster than the Haversine formula, but is nearly as accurate for distances up to a few hundred km.

Parameters are coordinates in RADIANS. They could be scalar float numbers or numpy arrays, in which case they should be either the same dimensions (in which case the returned distances will be an array of the same shape with point for point distances), or they should broadcast together (in which case the returned distances will be a matrix of each point in the first set to every point in the second set.

Parameters:
  • lons1 (numpy array) – An array of longitudes.
  • lats1 (numpy array) – An array of latitudes the same shape as lons1.
  • lons2 (numpy array) – An array of longitudes.
  • lats2 (numpy array) – An array of latitudes the same shape as lons2.
Returns:

Distances in km.

Return type:

(numpy array)

shakelib.utils.distance.geodetic_distance_haversine(lons1, lats1, lons2, lats2)[source]

Calculate the geodetic distance between two points or two collections of points using the Haversine formula.

Parameters are coordinates in RADIANS. They could be scalar float numbers or numpy arrays, in which case they should be either the same dimensions (in which case the returned distances will be an array of the same shape with point for point distances), or they should broadcast together (in which case the returned distances will be a matrix of each point in the first set to every point in the second set.

Parameters:
  • lons1 (numpy array) – An array of longitudes.
  • lats1 (numpy array) – An array of latitudes the same shape as lons1.
  • lons2 (numpy array) – An array of longitudes.
  • lats2 (numpy array) – An array of latitudes the same shape as lons2.
Returns:

Distances in km.

Return type:

(numpy array)