2015-10-20 44 views
0

我一直無法找到解決我的問題。重複整個數據集的功能

我有一個非常大的csv文件包含多個點。我創建了兩個不同的函數來計算距離和速度。

我需要的是在第一點和第二點之間執行這些功能的方法,然後是第二點和第三點,等等。我一直在玩弄數組和numpy,但我似乎無法弄清楚。

這裏是我的功能:

# distance 
 
def haversine_distance(lat1, long1, lat2, long2): 
 
    degrees_to_radians = math.pi/180.0 
 
    phi1 = (90.0 - lat1)*degrees_to_radians 
 
    phi2 = (90.0 - lat2)*degrees_to_radians 
 
    theta1 = long1 * degrees_to_radians 
 
    theta2 = long2 * degrees_to_radians 
 
    cos = (math.sin(phi1)*math.sin(phi2)*math.cos(theta1 - theta2) + 
 
      math.cos(phi1)*math.cos(phi2)) 
 
    arc = math.acos(cos) * 6371 
 
    arc = arc * 1000 
 

 
    return arc 
 
     
 
# speed 
 
def speed(lat1, long1, time1, lat2, long2, time2): 
 
    distance = haversine_distance(lat1, long1, lat2, long2) 
 
    delta_time = time2 - time1 
 
    speed = (distance/delta_time) 
 
    speed = speed * 3.6 
 
    
 
    return speed

+0

我要指出,我使用python 2.7,任何幫助將是巨大的或在正確的方向,甚至一個點!謝謝! –

+0

你能告訴你如何稱呼速度嗎? –

+0

請發佈讀取點並調用速度和距離例程的代碼。 – Prune

回答

1

我假定您可以讀取CSV數據到numpy的數組。我們稱之爲資本Lat,LongTime。然後,所有你需要做的就是在適當的點打電話給你的功能:

# initialize correct vectors 
l1=Lat[:-1]  # all points but last 
l2=Lat[1:]  # all points but first 
lg1=Long[:-1]  
lg2=Long[1:]  
t1=Time[:-1] 
t2=Time[1:] 

speed(l1,lg1,t1,l2,lg2,t2) # call the function which will run over your arrays