TrajSpeedIntervals: Calculate speed time intervals

View source: R/speed.R

TrajSpeedIntervalsR Documentation

Calculate speed time intervals

Description

Calculates and returns a list of time intervals during which speed is slower and/or faster than specified values. Speed is calculated by taking the modulus of velocity (TrajVelocity).

Usage

TrajSpeedIntervals(
  trj,
  fasterThan = NULL,
  slowerThan = NULL,
  interpolateTimes = TRUE,
  diff = c("backward", "central", "forward")
)

Arguments

trj

Trajectory to be analysed.

fasterThan, slowerThan

If not NULL, intervals will cover time periods where speed exceeds/is lower than this value. At least one of fasterThan, or slowerThan must be specified.

interpolateTimes

If TRUE, times will be linearly interpolated between frames.

diff

Method used to calculate speed, see TrajVelocity for details. The default is "backward" to maintain backwards compatibility; in general, "central" provides a more accurate estimate of velocity.

Value

A data frame of class "TrajSpeedIntervals", each row is an interval, columns are:

startFrame

Indices of frames at the start of each interval.

stopFrame

Indices of frames at the end of each interval.

startTime

Time since start of trajectory at the start of each interval.

stopTime

Time since start of trajectory at the end of each interval

duration

Duration of each interval.

The data frame will also have non-standard attributes:

trajectory

Value of the trj argument.

slowerThan

Value of the slowerThan argument.

fasterThan

Value of the fasterThan argument.

speed

Data frame with columns speed and time.

derivs

Value returned by calling TrajDerivatives(trj). Provided for backwards-compatibility; use of the speed attribute is now preferred to the derivs attribute.

See Also

TrajVelocity for calculating trajectory velocity, plot.TrajSpeedIntervals for plotting speed over time with intervals highlighted.

Examples

# Plot speed, highlighting intervals where speed drops below 50 units/sec
set.seed(4)
trj <- TrajGenerate(200, random = TRUE)
smoothed <- TrajSmoothSG(trj, 3, 101)
intervals <- TrajSpeedIntervals(smoothed, diff = "central", slowerThan = 50, fasterThan = NULL)
plot(intervals)

# Report the duration of the longest period of low speed
cat(sprintf("Duration of the longest low-speed interval was %g secs\n", max(intervals$duration)))


JimMcL/trajr documentation built on July 23, 2024, 2:06 a.m.