I have a netCDF file with multiple cyclone positions (lat, lon) and air temperature across the southern hemisphere in a particular time.
What I want is to extract the temperature values that are within a radius of 10 geodesic degrees (~1110 km) from the center of each cyclone position. The idea is to identify the temperature values associated with each cyclone (assuming a maximum radial distance of 10º from the cyclone center) and plot one global contourf map with only those temperature values.
I searched a lot here, but I only found codes that applies to distances from just one specific lat lon center (like this one: how to find values within a radius from a central position of latitude and longitude value).
Im stuck in how to apply the Haversine formula for multiple centers at once.
import xarray as xr
import numpy as np
import matplotlib.pyplot as plt
d = xr.open_dataset('cyc_temp.nc')
lat = d['lat']
lon = d['lon']
cyc_pos = d['id'][:,:]
temp = d['temp'][:,:]
# Haversine formula
def haversine(lon1, lat1, lon2, lat2):
# convert decimal degrees to radians
lon1 = np.deg2rad(lon1)
lon2 = np.deg2rad(lon2)
lat1 = np.deg2rad(lat1)
lat2 = np.deg2rad(lat2)
# haversine formula
dlon = lon2 - lon1
dlat = lat2 - lat1
a = np.sin(dlat/2)**2 + np.cos(lat1) * np.cos(lat2) * np.sin(dlon/2)**2
c = 2 * np.arcsin(np.sqrt(a))
r = 6371
return c * r
If anyone can help me, I would aprecciate.