flightpathr

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

test_interpolateTrajectory.R (1394B)


      1 library(flightpathr)
      2 context("interpolateTrajectory")
      3 
      4 library(geosphere)
      5 
      6 kacy <- c(-74.5771667, 39.4575833)
      7 k17n <- c(-75.0330031, 39.7054758)
      8 
      9 # Two identical trajectories with different sampling rates
     10 coords1 <-  gcIntermediate(kacy, k17n, n = 61)
     11 trajectory1 <-createTrajectory(coords1[, 1], coords1[, 2], altitude = 3500,
     12                                timestamp = seq(0, 800, length.out = 61))
     13 coords2 <- gcIntermediate(kacy, k17n, n = 229)
     14 trajectory2 <-createTrajectory(coords2[, 1], coords2[, 2], altitude = 3500,
     15                                timestamp = seq(0, 800, length.out = 229))
     16 
     17 test_that("Interpolated trajectory is close to correct", {
     18   trajectoryInterpolated <- interpolateTrajectory(trajectory1,
     19                                                   trajectory2$timestamp)
     20 
     21   for (tf in names(trajectoryInterpolated)) {
     22     expect_equal(trajectoryInterpolated[[tf]], trajectory2[[tf]], tolerance = 1)
     23   }
     24 })
     25 
     26 test_that("Correctly handling times outside original range", {
     27   trajectoryInterpolated <- interpolateTrajectory(trajectory1,
     28                                                   c(-100, 0, 800, 900))
     29 
     30   for (tf in names(trajectoryInterpolated)[names(trajectoryInterpolated) != "timestamp"]) {
     31     expect_equal(trajectoryInterpolated[[tf]][1], trajectoryInterpolated[[tf]][2])
     32     expect_equal(trajectoryInterpolated[[tf]][3], trajectoryInterpolated[[tf]][4])
     33   }
     34 })