util.py 文件源码

python
阅读 40 收藏 0 点赞 0 评论 0

项目:wxgen 作者: metno 项目源码 文件源码
def get_i_j(lats, lons, lat, lon):
   """
   Finds the nearest neighbour in a lat lon grid. If the point is outside the grid, the nearest
   point within the grid is still returned.

   Arguments:
      lats (np.array): 2D array of latitudes
      lons (np.array): 2D array of longitude
      lat (float): Loopup latitude
      lon (float): Loopup longitude

   Returns:
      I (int): First index into lats/lons arrays
      J (int): Second index into lats/lons arrays
   """
   dist = distance(lat, lon, lats, lons)
   indices = np.unravel_index(dist.argmin(), dist.shape)
   X = lats.shape[0]
   Y = lats.shape[1]
   I = indices[0]
   J = indices[1]
   if(indices[0] == 0 or indices[0] >= X-1 or indices[1] == 0 or indices[1] >= Y-1):
      debug("Lat/lon %g,%g outside grid" % (lat, lon))
   return I, J
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号