Saving time between each timestamp in an array

I am working on a python script to get the speed of an object between one point and the next. I have a function already created (see below) and it works when I test it, but now that I know that it works and wants to use it, I hit the road block. I cannot find a way to calculate the time between each point and save it as an array using numpy. My file contains hundreds of different points.

def speed(lat1, long1, time1, lat2, long2, time2):
    distance = haversine_distance(lat1, long1, lat2, long2)  # meter
    delta_time = time2 - time1 # second
    speed = distance / delta_time # speed in m/s
    speed = speed * 3.6 # speed in km/h

    return speed

Timestamps in the following format for each item:

timestamp.roundHr
12/8/2009 7:00
12/8/2009 8:00
12/8/2009 9:00
12/8/2009 10:00
+4
source share
1 answer

timestamp1 timestamp2. datetime , -, :

from datetime import datetime as dt

def speed(lat1, long1, time1, lat2, long2, time2):
    distance = haversine_distance(lat1, long1, lat2, long2)  # meter

    # here the fun stuff
    time1 = dt.strptime(time1, "%m/%d/%Y %H:%M")
    time2 = dt.strptime(time2, "%m/%d/%Y %H:%M")
    delta_time = (time2 - time1).total_seconds() # second

    # continue with the rest of your code
    speed = (distance / delta_time) # speed in m/s
    speed = speed * 3.6 # speed in km/h

    return speed

n, n-1, i th - i th i+1 th , :

def computeDeltaTimes(L):
    answer = []
    a, b = itertools.tee(L)
    next(B, None)
    fmt = "%m/%d/%Y %H:%M"
    for start, end in zip(a,b):  # or itertools.izip in python2
        answer.append((dt.strptime(end, fmt) - dt.strptime(start, fmt)).total_seconds())
    return answer
+2

Source: https://habr.com/ru/post/1614202/


All Articles