flightconflicts

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

test_calculateSLoWC.R (2668B)


      1 library(flightconflicts)
      2 context("calculateSLoWC")
      3 
      4 library(geosphere)
      5 library(flightpathr)
      6 
      7 # I'll attempt to replicate the values in Appendix A of SC-228.
      8 
      9 kacy <- c(-74.5771667, 39.4575833)
     10 # Traveling at 100 kt for 3 nm.
     11 ownshipCoords <-  destPoint(kacy, 90, seq(0, 5556, length.out = 108))
     12 intruderCoords <- apply(ownshipCoords, 2, rev)
     13 ownshipTrajectory <- createTrajectory(ownshipCoords[, 1], ownshipCoords[, 2], 10000)
     14 
     15 
     16 test_that("co-altitude head-on examples match", {
     17   intruderTrajectory <- list()
     18   hmd <- c(0, 500, 1000, 2000, 3000, 3999, 5000)
     19 
     20   for (i in seq_along(hmd)) {
     21     intruderCoordsHMD <- destPoint(intruderCoords, 0, hmd[i]*0.3048)
     22     intruderTrajectory[[i]] <- createTrajectory(intruderCoordsHMD[, 1], intruderCoordsHMD[, 2], 10000)
     23   }
     24   
     25   # High tolerances to deal with different sampling rates
     26   expect_equal(max(calculateSLoWC(ownshipTrajectory, intruderTrajectory[[1]])), 100.00, tolerance = 5)
     27   expect_equal(max(calculateSLoWC(ownshipTrajectory, intruderTrajectory[[2]])), 85.65, tolerance = 5)
     28   expect_equal(max(calculateSLoWC(ownshipTrajectory, intruderTrajectory[[3]])), 71.47, tolerance = 5)
     29   expect_equal(max(calculateSLoWC(ownshipTrajectory, intruderTrajectory[[4]])), 44.42, tolerance = 5)
     30   expect_equal(max(calculateSLoWC(ownshipTrajectory, intruderTrajectory[[5]])), 20.00, tolerance = 5)
     31   expect_equal(max(calculateSLoWC(ownshipTrajectory, intruderTrajectory[[6]])), 0.02, tolerance = 5)
     32   expect_equal(max(calculateSLoWC(ownshipTrajectory, intruderTrajectory[[7]])), 0)
     33 })
     34 
     35 test_that("level head-on with 100' vertical offset examples match", {
     36   intruderTrajectory <- list()
     37   hmd <- c(0, 500, 1000, 2000, 3000, 3999, 5000)
     38   offset <- 100
     39   
     40   for (i in seq_along(hmd)) {
     41     intruderCoordsHMD <- destPoint(intruderCoords, 0, hmd[i]*0.3048)
     42     intruderTrajectory[[i]] <- createTrajectory(intruderCoordsHMD[, 1], intruderCoordsHMD[, 2], 10000 - offset)
     43   }
     44   
     45   # High tolerances to deal with different sampling rates
     46   expect_equal(max(calculateSLoWC(ownshipTrajectory, intruderTrajectory[[1]])), 77.78, tolerance = 5)
     47   expect_equal(max(calculateSLoWC(ownshipTrajectory, intruderTrajectory[[2]])), 73.74, tolerance = 5)
     48   expect_equal(max(calculateSLoWC(ownshipTrajectory, intruderTrajectory[[3]])), 64.39, tolerance = 5)
     49   expect_equal(max(calculateSLoWC(ownshipTrajectory, intruderTrajectory[[4]])), 41.43, tolerance = 5)
     50   expect_equal(max(calculateSLoWC(ownshipTrajectory, intruderTrajectory[[5]])), 18.90, tolerance = 5)
     51   expect_equal(max(calculateSLoWC(ownshipTrajectory, intruderTrajectory[[6]])), 0.02, tolerance = 5)
     52   expect_equal(max(calculateSLoWC(ownshipTrajectory, intruderTrajectory[[7]])), 0)
     53 })