Sorry for the large code dump. My problem is with my last for loop. I am attempting to set up a new dictionary, "candidates," that contains all of the possible combinations of one site with another site, mapped to the distance between them. For instance, say that site 1 has ID 1234, site 2 has ID 1235, and site 3 has ID 1236. What I want the candidates dictionary to be eventually is {'1234_1235' : distance, '1234_1236' : distance}, i.e. all possible combinations from one site to other sites. These combinations are already contained in dictkey; I just need to reorganize them. This is so I can pop off the shortest distance, and eventually get a list of the "nearest neighbor" to each site.
for i in np.arange(num_sites):
lat1 = lat[i]
lon1 = lon[i]
site1=site[i]
rat1 = lat1*np.pi/180.0
ron1 = lon1*np.pi/180.0
for j in np.arange(i+1,num_sites):
lat2 = lat[j]
lon2 = lon[j]
site2= site[j]
rat2 = lat2*np.pi/180.0
ron2 = lon2*np.pi/180.0
Calculate the distance using the Haversine Formula
d = 2.0*np.arcsin(np.sqrt((np.sin((rat1-rat2)/2))**2 +
np.cos(rat1)*np.cos(rat2)*(np.sin((ron1-ron2)/2))**2))
# dist_arr[i,j] = 6371.0 * d
dictkey[site1+"_"+site2] = 6371.0*d
temporary = set()
for key in dictkey:
parts = key.split("_")
site_one = parts[0]
site_two = parts[1]
temporary.add(site_one)
for temps in temporary:
candidates = dict()
for key in dictkey:
parts = key.split("_")
site_one = parts[0]
site_two = parts[1]
if site_one == temps:
candidates[site_one] = dictkey[key]