# flightpathr

Tools to analyze aircraft and flight path data.

commit b0492157a131d728f81ef8252f34d407aa588323
parent 025b2ab47b115956e45bfb003fd9202999d194bd
Date:   Tue, 20 Sep 2016 10:36:09 -0400

Helper function to calculate signed angular differences, helps pass tests.

Diffstat:
MR/coordsToBearing.R | 9+++++++++
Aman/angleDiff.Rd | 20++++++++++++++++++++
Mman/createTrajectory.Rd | 18+++++++++---------
Mtests/testthat/test_coordsToBearing.R | 6++++--

4 files changed, 42 insertions(+), 11 deletions(-)
diff --git a/R/coordsToBearing.R b/R/coordsToBearing.R
@@ -25,3 +25,12 @@ coordsToBearing <- function(trajectory) {

return(c(bearings, NA))
}
+
+#' Calculate the signed difference between angles (in degrees)
+#'
+#' @param angle1 Source angle
+#' @param angle2 Target angle
+#' @return The signed difference between the two angles
+angleDiff <- function(angle1, angle2) {
+  return(((angle2 - angle1) + 180) %% 360 - 180)
+}
diff --git a/man/angleDiff.Rd b/man/angleDiff.Rd
@@ -0,0 +1,20 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/coordsToBearing.R
+\name{angleDiff}
+\alias{angleDiff}
+\title{Calculate the signed difference between angles (in degrees)}
+\usage{
+angleDiff(angle1, angle2)
+}
+\arguments{
+\item{angle1}{Source angle}
+
+\item{angle2}{Target angle}
+}
+\value{
+The signed difference between the two angles
+}
+\description{
+Calculate the signed difference between angles (in degrees)
+}
+
diff --git a/man/createTrajectory.Rd b/man/createTrajectory.Rd
@@ -8,23 +8,23 @@ createTrajectory(longitude, latitude, altitude = 0, timestamp = NULL,
bearing = NULL, groundspeed = NULL)
}
\arguments{
-\item{longitude}{Required; numeric vector giving aircraft longitude in
+\item{longitude}{Required; numeric vector giving aircraft longitude in
degrees.}

\item{latitude}{Required; numeric vector giving aircraft latitude in degrees.}

-\item{altitude}{Optional; numeric vector giving aircraft altitude (AGL) in
+\item{altitude}{Optional; numeric vector giving aircraft altitude (AGL) in
feet. If missing, it will be set to 0.}

\item{timestamp}{Optional; numeric vector giving the time of each observation
in seconds. If missing, the observation period is assumed to be 1 s.}

-\item{bearing}{Optional; numeric vector giving the current bearing in
-degrees. If missing, it is estimated using pairs of successive lon/lat
+\item{bearing}{Optional; numeric vector giving the current bearing in
+degrees. If missing, it is estimated using pairs of successive lon/lat
observations.}

-\item{groundspeed}{Optional; numeric vector giving the current ground speed
-of the aircraft in knots. If missing, it is estimated using pairs of
+\item{groundspeed}{Optional; numeric vector giving the current ground speed
+of the aircraft in knots. If missing, it is estimated using pairs of
successive lon/lat observations.}
}
\value{
@@ -35,9 +35,9 @@ A flighttrajectory object encapsulating these parameters (with
Create a flighttrajectory object from the flight info.
}
\details{
-\code{longitude} and \code{latitude} must be the same length.
-  \code{timestamp}, \code{bearing}, and \code{groundspeed}, if present, must
-  also match this length. \code{altitude} must also have a length equal to
+\code{longitude} and \code{latitude} must be the same length.
+  \code{timestamp}, \code{bearing}, and \code{groundspeed}, if present, must
+  also match this length. \code{altitude} must also have a length equal to
these parameters or be scalar.
}

diff --git a/tests/testthat/test_coordsToBearing.R b/tests/testthat/test_coordsToBearing.R
@@ -11,8 +11,10 @@ test_that("Equatorial routes have constant bearing", {
trajectory2 <- cbind(longitude = -74.6,
latitude = seq(89, -89, length.out = 100))

-  expect_equal(coordsToBearing(trajectory1), c(rep(90, 99), NA))
-  expect_equal(coordsToBearing(trajectory2), c(rep(180, 99), NA))
+  expect_equal(angleDiff(coordsToBearing(trajectory1), rep(90, 100)),
+               c(rep(0, 99), NA))
+  expect_equal(angleDiff(coordsToBearing(trajectory2), rep(180, 100)),
+               c(rep(0, 99), NA))
})

test_that("Non-equatorial routes look OK", {