Skip to content

Instantly share code, notes, and snippets.

@alexander0042
Created June 9, 2021 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexander0042/cf4103e3fbbd7d5a6bc949970dc61e09 to your computer and use it in GitHub Desktop.
Save alexander0042/cf4103e3fbbd7d5a6bc949970dc61e09 to your computer and use it in GitHub Desktop.
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