flightpathr

Tools to analyze aircraft and flight path data.
git clone https://git.eamoncaddigan.net/flightpathr.git
Log | Files | Refs | README | LICENSE

commit e4df477e28518a1c99f8b8f9b3bc7827c916d384
parent a82806ce3b9a08a20581f37c5f2c141856522c0b
Author: eamoncaddigan <eamon.caddigan@gmail.com>
Date:   Wed, 21 Sep 2016 13:03:02 -0400

Handling coordsToBearing() new args, including unit tests

Diffstat:
MR/createTrajectory.R | 2+-
Atests/testthat/test_createTrajectory.R | 28++++++++++++++++++++++++++++
2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/R/createTrajectory.R b/R/createTrajectory.R @@ -56,7 +56,7 @@ createTrajectory <- function(longitude, latitude, altitude = 0, timestamp = NULL # Use flightpathr to calculate bearing between successive points if not # specified. if (is.null(bearing)) { - bearing <- coordsToBearing(cbind(coords, altitude)) + bearing <- coordsToBearing(longitude, latitude) bearing[nCoord] <- bearing[nCoord-1] } else { checkLength(bearing) diff --git a/tests/testthat/test_createTrajectory.R b/tests/testthat/test_createTrajectory.R @@ -0,0 +1,28 @@ +library(flightpathr) +context("createTrajectory") + +library(geosphere) + +# Find the lon/lat of the flight path between KACY and K17N flying at 100 knots +kacy <- c(-74.5771667, 39.4575833) +k17n <- c(-75.0330031, 39.7054758) +distMeters <- distHaversine(kacy, k17n) +# distMeters m * (1 hr / 100 nmi) * (1 nmi / 1852 m) * (3600 s / 1 hr) +timeSec <- round(distMeters * (1/100) * (3600/1852)) +trajectoryMat <- gcIntermediate(kacy, k17n, n = timeSec-2, addStartEnd = TRUE) +trajectory <- createTrajectory(trajectoryMat[, "lon"], + trajectoryMat[, "lat"], + rep(2500, timeSec)) + +test_that("Passed arguments are stored correctly", { + expect_equal(trajectory$longitude, trajectoryMat[, "lon"]) + expect_equal(trajectory$latitude, trajectoryMat[, "lat"]) + expect_equal(trajectory$altitude, rep(2500, timeSec)) +}) + +test_that("Bearing and groundspeed calculations are correct", { + expect_equal(trajectory$timestamp, seq(1, timeSec)) + expect_equal(trajectory$groundspeed, rep(100, timeSec), tolerance = 0.5) + expect_equal(trajectory$bearing[1:(timeSec-1)], + bearing(trajectoryMat[1:(timeSec-1), ], trajectoryMat[2:timeSec, ])) +})