# In the following example, we will retrieve all state vectors for a flight
# along route SCX624, from Harlingen to Minneapolis. We will then identify
# the different phases of the flight, and plot it together with altitude values.
# Note that when retrieving the state vectors, the username and password should
# be substituted by your own, for which you should have received authorization
# to access the OpenSky Trino interface
if (FALSE) {
state_vectors <- getIntervalStateVectors(aircraft = "ab3da7",
startTime = "2021-12-12 04:20:00",
endTime = "2021-12-12 07:40:00",
username="your_username",
password="your_password")
flights <- state_vectors$split_into_flights()
length(flights)
# Only one flight identified in the time period, as expected
flight <- flights[[1]]
# Let's extract the data required for detection of flight phases
data <- flight$state_vectors$get_values(c("requested_time", "baro_altitude",
"vertical_rate", "velocity"))
data$requested_time <- data$requested_time - data$requested_time[1]
# We can now identify flight phases. We will use a time window of 60 s
phases <- findFlightPhases(times=data$requested_time,
altitudes=data$baro_altitude,
verticalRates=data$vertical_rate,
speeds=data$velocity,
window=60)
# We can now plot the phases together with the altitude values
library(ggplot2)
data <- cbind(data, phases)
ggplot(data[!is.na(data$baro_altitude), ], aes(x = requested_time, y = baro_altitude)) +
geom_line() +
geom_point(aes(color=phases))
}
Run the code above in your browser using DataLab