flightconflicts

Tools to analyze conflicts between aircraft.
git clone https://git.eamoncaddigan.net/flightconflicts.git
Log | Files | Refs | README | LICENSE

commit 1b99e7365545c71831f982916a682f4b4a1356c7
parent ba0530a9b30d1bc33485ec69bb2efcfabf8f351a
Author: eamoncaddigan <eamon.caddigan@gmail.com>
Date:   Fri, 20 May 2016 16:39:56 -0400

SLoWC is passing its first tests

Diffstat:
MR/calculateSLoWC.R | 4++--
Atests/testthat/test_calculateSLoWC.R | 31+++++++++++++++++++++++++++++++
2 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/R/calculateSLoWC.R b/R/calculateSLoWC.R @@ -35,8 +35,8 @@ calculateSLoWC <- function(trajectory1, trajectory2) { lon0, lat0), trajectory2$altitude) - ac1Velocity <- bearingToXY(trajectory1$bearing, trajectory1$velocity) - ac2Velocity <- bearingToXY(trajectory2$bearing, trajectory2$velocity) + ac1Velocity <- bearingToXY(trajectory1$bearing, trajectory1$groundspeed) + ac2Velocity <- bearingToXY(trajectory2$bearing, trajectory2$groundspeed) dXYZ <- ac2XYZ - ac1XYZ dXYZ[, 3] <- abs(dXYZ[, 3]) diff --git a/tests/testthat/test_calculateSLoWC.R b/tests/testthat/test_calculateSLoWC.R @@ -0,0 +1,31 @@ +library(flightconflicts) +context("calculateSLoWC") + +library(geosphere) + +# I'll attempt to replicate the values in Appendix A of SC-228. + +test_that("co-altitude head-on examples match", { + kacy <- c(-74.5771667, 39.4575833) + # Traveling at 100 kt for 3 nm. + ownshipCoords <- destPoint(kacy, 90, seq(0, 5556, length.out = 108)) + intruderCoords <- apply(ownshipCoords, 2, rev) + + ownshipTrajectory <- createTrajectory(ownshipCoords[, 1], ownshipCoords[, 2]) + intruderTrajectory <- list() + hmd <- c(0, 500, 1000, 2000, 3000, 3999, 5000) + + for (i in seq_along(hmd)) { + intruderCoordsHMD <- destPoint(intruderCoords, 0, hmd[i]*0.3048) + intruderTrajectory[[i]] <- createTrajectory(intruderCoordsHMD[, 1], intruderCoordsHMD[, 2]) + } + + # High tolerances to deal with different sampling rates + expect_equal(max(calculateSLoWC(ownshipTrajectory, intruderTrajectory[[1]])), 100.00, tolerance = 5) + expect_equal(max(calculateSLoWC(ownshipTrajectory, intruderTrajectory[[2]])), 85.65, tolerance = 5) + expect_equal(max(calculateSLoWC(ownshipTrajectory, intruderTrajectory[[3]])), 71.47, tolerance = 5) + expect_equal(max(calculateSLoWC(ownshipTrajectory, intruderTrajectory[[4]])), 44.42, tolerance = 5) + expect_equal(max(calculateSLoWC(ownshipTrajectory, intruderTrajectory[[5]])), 20.00, tolerance = 5) + expect_equal(max(calculateSLoWC(ownshipTrajectory, intruderTrajectory[[6]])), 0.02, tolerance = 5) + expect_equal(max(calculateSLoWC(ownshipTrajectory, intruderTrajectory[[7]])), 0) +})