沿未知轨迹查找最近点

2024-03-28 20:28:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我只找到了一些已知轨迹的最近邻的例子。 我的问题是,我想在两个点之间的lat,lon网格中找到最近的邻居

我是这样开始的:

start_point =[-10,  0]            #Lat/Lon
end_point   =[40,  0]            #Lat/lon
def find_closest(A, target):
    #A must be sorted
    idx = A.searchsorted(target)
    idx = np.clip(idx, 1, len(A)-1)
    left = A[idx-1]
    right = A[idx]
    idx -= target - left < right - target
    return idx
        nc = Dataset(datalist , mode='r')       #height_2 = full level
                                                #height, height_4 = halfe level
lat = nc.variables['lat'][:]
lon = nc.variables['lon'][:]
div = nc.variables['div'][stunde,lev_full[0],:,:]

start_lat = find_closest(lat,start_point[0])
start_lon = find_closest(lon, start_point[1])
end_lat = find_closest(lat,end_point[0])
end_lon = find_closest(lon,end_point[1])

lati,loni=np.linspace(start_lat,end_lat, num),np.linspace(start_lon,end_lon,num)
geo_near = scipy.ndimage.map_coordinates(div, np.vstack((lati,loni)))

我现在的问题是。如何将索引转换回?如果我绘制了这些值,这条线看起来不正确

问候