Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Closest Points Python
abslat = np.abs(lats-stn_lat)
abslon= np.abs(lons-stn_lon)
c = np.maximum(abslon,abslat)
latlon_idx = np.argpartition(-c.flatten(), -4)[-4:]
x, y = np.unravel_index(latlon_idx,c.shape)
latlon_dist = c[x, y]
# Avoid divide by zero if exactly on point
latlon_dist=np.maximum(latlon_dist, 0.000001)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment