Define a function to calculate distance between two latitudes and longitudes. I found php implementation of below here. I converted it to python.
import numpy as np
import math
def getDistanceBetweenPoints(latitude1, longitude1, latitude2, longitude2):
theta = longitude1 - longitude2
distance = math.sin(np.radians(latitude1)) * math.sin(np.radians(latitude2)) + math.cos(np.radians(latitude1)) * math.cos(np.radians(latitude2)) * math.cos(np.radians(theta))
distance = math.acos(distance)
distance = np.degrees(distance)
return distance
Import TC data in the pandas dataframe and apply below function to call on the DataFrame. The function would call above function getDistanceBetweenPoints
for each latitude and longitude
# create a dataframe
df = pd.DataFrame(tc_csv_file_path)
# take subset of the data frame with columns we want
df_lat_long = df[['latitude', 'longitude']]
# insert a new column in dataframe which would hold distance between the latitudes and longitudes
df_lat_long.insert(df_lat_long.shape[1], "distance", [0.0 for val in range(df_lat_long.shape[0])], True)
Define a function which would be invoked row wise on a data frame
def getDistanceBetweenPoints_df(row):
# Place latitude/longitude for a centre point here
# I have filled 0.0, you replace with with actual values
centre_lat = 0.0
centre_long = 0.0
row['distance'] = getDistanceBetweenPoints(centre_lat, centre_long, row['longitude'], row['latitude'], unit='Km')
Now invoke this function on data frame. It will called row wise and it will populate the column distance
in the dataframe with the distance between center latitude/longitude and the row's latitude/longitude
# Invoke function on dataframe
df_lat_long.agg(getDistanceBetweenPoints_df, axis='columns')
# View the dataframe for values only where distance is less than or equal to 2.5◦
df_lat_long[df_lat_long['distance'] <= 2.5]
So, these are the latitudes and longitudes where distance from the given centre is less than of equal to 2.5◦. Do whatever you want to do with these
latitude
andlongitude
in TC data and you have alatitude
andlongitude
in NC data. You want to find out mean of what value ? What is the column name which contains values whose mean is to be found out ? $\endgroup$