apatel726 / HurricaneDissertation

2 stars 2 forks source link

Geodetic Distance #32

Closed hammad93 closed 3 years ago

hammad93 commented 3 years ago

When verifying the track forecast compared to ground truth, calculating geodesic distance is required. This issue presents a formula or function used in https://github.com/hammad93/hurricane-net/blob/master/hurricane-net.ipynb but when I made it, there were some uncertainties of the correctness. The goal of the issue is to finalize this function, whether changes are necessary or not.

# Define a function to return the distance between two coordinates in nautical miles
import math

def distance(origin, destination):
    lat1, lon1 = origin
    lat2, lon2 = destination
    radius = 6371 # km

    dlat = math.radians(lat2-lat1)
    dlon = math.radians(lon2-lon1)
    a = math.sin(dlat/2) * math.sin(dlat/2) + math.cos(math.radians(lat1)) \
        * math.cos(math.radians(lat2)) * math.sin(dlon/2) * math.sin(dlon/2)
    c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a))
    d = radius * c

    return d * 0.539957 # km to nautical miles

This problem is nontrivial because the topology of the Earth is not exactly spherical and even projections can lead to errors. A trivial example is on a flat surface.

hammad93 commented 3 years ago

This library can be added to the requirements, thanks @apatel726 !

https://pypi.org/project/haversine/