diff --git a/modules/util/util.py b/modules/util/util.py index 8ad1d742cdf1d9e842ae3575e88b3e33ca650522..9116e4ef1ba384571be5744095a87a0049fe1d1d 100644 --- a/modules/util/util.py +++ b/modules/util/util.py @@ -135,14 +135,14 @@ def add_time_range_to_filename(pathname, tstart, tend=None): return path -def haversine_np(lon1, lat1, lon2, lat2): +def haversine_np(lon1, lat1, lon2, lat2, earth_radius=6367.0): """ Calculate the great circle distance between two points on the earth (specified in decimal degrees) (lon1, lat1) must be broadcastable with (lon2, lat2). - """ + lon1, lat1, lon2, lat2 = map(np.radians, [lon1, lat1, lon2, lat2]) dlon = lon2 - lon1 @@ -150,8 +150,8 @@ def haversine_np(lon1, lat1, lon2, lat2): a = np.sin(dlat/2.0)**2 + np.cos(lat1) * np.cos(lat2) * np.sin(dlon/2.0)**2 - c = 2 * np.arcsin(np.sqrt(a)) - km = 6367 * c + c = 2.0 * np.arcsin(np.sqrt(a)) + km = earth_radius * c return km