spiketools.spatial.speed.compute_speed

spiketools.spatial.speed.compute_speed(position, timestamps, align_output=True)[source]

Compute speeds across a sequence of positions.

Parameters:
position1d or 2d array

Position values.

timestamps1d array

Timestamps, in seconds, corresponding to the position values.

align_outputbool, optional, default: True

If True, aligns the output with the sampling of the input, to match length. To do so, value of 0 is prepended to the output array.

Returns:
speed1d array

Vector of speeds across each position step.

Examples

Compute speed across a sequence of 1d positions:

>>> position = np.array([1., 2., 4., 5.])
>>> timestamps = np.array([0, 1, 2, 2.5])
>>> compute_speed(position, timestamps)
array([0., 1., 2., 2.])

Compute speed across a sequence of 2d positions:

>>> position = np.array([[1, 2, 2, 3],
...                      [1, 1, 2, 3]])
>>> timestamps = np.array([0, 1, 1.5, 2.5])
>>> compute_speed(position, timestamps)
array([0.        , 1.        , 2.        , 1.41421356])