如何用哈弗森公式配置两个不同分辨率的数控文件

2024-09-30 08:18:46 发布

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

我试图用python中的haversine公式来配置两个不同分辨率的数据集

这个循环使用哈弗斯公式计算距离花费了太多时间。为了减少不必要的两个非常远的数据点的并置,我给出了一个跳到下一个网格点的条件

for i in range(len(lati1)):
for j in range (len(long1)):
    for x in range(len(lati2)):
        for y in range(len(long2)):

            lat1 = radians(lati1[i])
            lon1 = radians(long1[j])
            lat2 = radians(lati2[x])
            lon2 = radians(long2[y])



       temp[0][i][j]
            dlat = lat2 - lat1
            dlon = lon2 - lon1
            a = sin(dlat/2)**2 + cos(lat1) * cos(lat2) * sin(dlon / 2)**2
            c = 2 * atan2(sqrt(a), sqrt(1 - a))
            distance = R * c 
            print distance
            if ( distance <= 3.5):
                print distance, lati1[i], long1[j],lati2[x], long2[y], temp[i][j], preci[x][y]
                writer.writelines("\r")
                writer.writelines( (' ').join([distance, lati1[i], long1[j], temp[i][j], preci[x][y]]))
            elif (distance < 5.0):
                break
    break
j=j+1

在运行这个程序很长时间后,它是这样显示的

572
572
3.2412380942 0.13999939 60.100006 0.125 60.125 287.77 0.0
Traceback (most recent call last):

  File "<ipython-input-36-ac8328bf9abd>", line 40, in <module>
    writer.writelines( (' ').join([distance, btlat[i], btlon[j], btlat[0,i,j], predata[x,y]]))

  File "/home/krishna/.local/lib/python2.7/site-packages/numpy/ma/core.py", line 3174, in __getitem__
    dout = self.data[indx]

IndexError: too many indices for array

~我可以更改数组索引,但有更好的解决方案吗? 并置

你能帮我解决这个问题吗? 谢谢


Tags: inforwritelineslenrangetempwriterdistance

热门问题