Skip to content

Commit

Permalink
added OurAirport data; improved docs
Browse files Browse the repository at this point in the history
  • Loading branch information
espinielli committed Mar 29, 2024
1 parent a614c53 commit 7b43ca6
Show file tree
Hide file tree
Showing 13 changed files with 273 additions and 27 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: eurocontrol
Title: Helper functions for EUROCONTROL useRs
Version: 0.1.3
Version: 0.1.5
Authors@R: c(
person("Enrico", "Spinielli", , "enrico.spinielli@eurocontrol.int", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-8584-9131")),
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export(":=")
export(.data)
export(airlines_tbl)
export(airlines_tidy)
export(airports_oa)
export(airspace_profile_tbl)
export(airspace_profiles_tidy)
export(aodf_tbl)
Expand Down
21 changes: 17 additions & 4 deletions R/db.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,14 @@ db_connection <- function(schema = "PRU_PROD") {
#' arl <- airlines_tbl()
#' # other operations on arl, i.e. filtering,
#' # followed by a collect() to retrieve the concrete data frame
#' arl_filtered <- arl |> dplyr::filter(AO_ISO_CTRY_CODE == "IT") |> collect()
#' # IMPORTANT: close the DB connection
#' arl_filtered <- arl |>
#' dplyr::filter(AO_ISO_CTRY_CODE == "IT") |>
#' collect()
#'
#' # NOTE: you can reuse the connection for other API calls
#' arl$src$con
#'
#' # IMPORTANT: at the end close the DB connection
#' DBI::dbDisconnect(arl$src$con)
#' }
airlines_tbl <- function(conn = NULL) {
Expand Down Expand Up @@ -98,9 +104,16 @@ airlines_tbl <- function(conn = NULL) {
#' @examples
#' \dontrun{
#' flt <- flights_tbl()
#' # other operations on arl, i.e. filtering,
#' # other operations on flt, i.e. filtering,
#' # followed by a collect() to retrieve the concrete data frame
#' flt_filtered <- flt |> dplyr::filter(AO_ISO_CTRY_CODE == "IT") |> collect()
#' flt_filtered <- flt |>
#' filter(TO_DATE("2023-06-01 10:00", "YYYY-MM-DD HH24:MI") <= IOBT,
#' IOBT < TO_DATE("2023-06-02 10:30", "YYYY-MM-DD HH24:MI")) |>
#'
#'
#' # NOTE: you can reuse the connection for other API calls
#' arl$src$con
#'
#' # IMPORTANT: close the DB connection
#' DBI::dbDisconnect(flt$src$con)
#' }
Expand Down
94 changes: 94 additions & 0 deletions R/other.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#' retrieve latest airport list from OurAirports
#'
#' @return a data frame
#' @export
#'
#' @examples
#' \dontrun{
#' apts <- airports_oa()
#' }
airports_oa <- function() {
oa_url <- "https://raw.githubusercontent.com/davidmegginson/ourairports-data/main/airports.csv"
oa <- readr::read_csv(oa_url) |>
dplyr::mutate(
gps_code = stringr::str_trim(.data$gps_code),
ident = stringr::str_trim(.data$ident)) |>
dplyr::mutate(icao = dplyr::if_else(.data$ident != .data$gps_code,
.data$gps_code,
.data$ident)) |>
dplyr::filter(
# keep the closed ones...EDDT is closed after 2019!
!.data$type %in% c("closed"),
stringr::str_detect(.data$gps_code, "^[A-Z]{4}"),
.data$icao != "EDDT") |>
dplyr::select(
"icao",
"iata" = "iata_code",
"latitude" = "latitude_deg",
"longitude" = "longitude_deg",
"elevation" = "elevation_ft",
"type",
"name",
"iso_country",
"iso_region",
"continent",
NULL
) |>
dplyr::union(
# from https://metar-taf.com/airport/ENFB-statfjord-b
dplyr::tribble(
# ,
~icao, ~iata, ~longitude, ~latitude, ~elevation, ~type, ~name, ~iso_country, ~iso_region, ~continent,
"EHFO", "", 4.82722, 54.21583, 400.0, "heliport", "F15-A", "NL", "", "EU",
"EHGO", "", 5.43472, 54.16944, 400.0, "heliport", "G14-B", "NL", "", "EU",
"EHGQ", "", 5.43194, 54.04917, 400.0, "heliport", "G17D-A", "NL", "", "EU",
"EHGN", "", 5.49861, 54.22389, 400.0, "heliport", "G14-A", "NL", "", "EU",
"EHFT", "", 4.51278, 53.81806, 400.0, "heliport", "L5-D", "NL", "", "EU",
"EHFR", "", 4.35111, 53.81083, 400.0, "heliport", "L5-FA-1", "NL", "", "EU",
"EHFD", "", 4.69472, 54.85306, 400.0, "heliport", "F3-FB-1", "NL", "", "EU",
"EHFB", "", 4.5725, 54.94444, 400.0, "heliport", "F2-A", "NL", "", "EU",
"EHAX", "", 3.83167, 55.105, 400.0, "heliport", "A18-A", "NL", "", "EU",
"EHFQ", "", 4.49611, 53.96056, 400.0, "heliport", "L2-FA-1", "NL", "", "EU",
"EKAF", "", 3.99, 55.8, 400.0, "heliport", "A6A", "NL", "", "EU",
"ENUG", "", 22.25, 71.3, 400.0, "heliport", "Goliat", "NO", "", "EU",
"ENDR", "", 7.79167, 64.35556, 400.0, "heliport", "Draugen", "NO", "", "EU",
"ENFB", "", 1.82889, 61.20639, 400.0, "heliport", "Statfjord B", "NO", "", "EU",
"ENGA", "", 2.1875, 61.17556, 400.0, "heliport", "Gullfaks A", "NO", "", "EU",
"ENGC", "", 2.2709835,61.2140628, 400.0, "heliport", "Gullfaks C", "NO", "", "EU",
"ENHE", "", 7.31583, 65.32556, 400.0, "heliport", "Heidrun A", "NO", "", "EU",
"ENHM", "", 2.23333, 59.56667, 400.0, "heliport", "Heimdal", "NO", "", "EU",
"ENJS", "", 2.54556, 58.83528, 400.0, "heliport", "Johan Sverdrup", "NO", "", "EU",
"ENLE", "", 3.21667, 56.5333, 400.0, "heliport", "Ekofisk Oil Pltf", "NO", "", "EU",
"ENNE", "", 8.08333, 66.03333, 400.0, "heliport", "Norne A", "NO", "", "EU",
"ENQG", "", 2.1988320,61.2021082, 400.0, "heliport", "Gullfaks B", "NO", "", "EU",
"ENQJ", "", 3.895, 61.33167, 400.0, "heliport", "Gjoa", "NO", "", "EU",
"ENQK", "", 2.5, 61.08333, 400.0, "heliport", "Kvitebjorn", "NO", "", "EU",
"ENQL", "", 2.07333, 60.49833, 400.0, "heliport", "Martin Linge B", "NO", "", "EU",
"ENQM", "", 2.01472, 60.5075, 400.0, "heliport", "Martin Linge A", "NO", "", "EU",
"ENQW", "", 2.36694, 61.04, 400.0, "heliport", "Valemon", "NO", "", "EU",
"ENQR", "", 2.21667, 61.51667, 400.0, "heliport", "Snorre B", "NO", "", "EU",
"ENQS", "", 1.90083, 61.2961, 400.0, "heliport", "Statfjord C", "NO", "", "EU",
# little evidence of geo coordinates for ENUC
"ENUC", "", 6.9259, 65.0863, 400.0, "heliport", "Asgard C", "NO", "", "EU",
"ENQV", "", 2.45722, 61.36972, 400.0, "heliport", "Visund A", "NO", "", "EU",
"ENQW", "", 2.36694, 61.04, 400.0, "heliport", "Valemon", "NO", "", "EU",
"ENSE", "", 2.15, 61.45, 400.0, "heliport", "Snorre A", "NO", "", "EU",
"ENSF", "", 1.8521147,61.2551784, 400.0, "heliport", "Statfjord A", "NO", "", "EU",
"ENUA", "", 6.72556, 65.06417, 400.0, "heliport", "Kristin", "NO", "", "EU",
"ENUB", "", 6.78944, 65.11, 400.0, "heliport", "Aasgard B", "NO", "", "EU",
"ENUS", "", 7.65083, 65.69972, 400.0, "heliport", "Skarv", "NO", "", "EU",
"ENUK", "", 6.55056, 64.99417, 400.0, "heliport", "Aasgard A", "NO", "", "EU",
"ENUR", "", 7.36722, 65.34333, 400.0, "heliport", "Heidrun B", "NO", "", "EU",
"ENXW", "", 2.48667, 59.165, 400.0, "heliport", "Grane", "NO", "", "EU",
"ENWE", "", 2.24722, 58.8425, 400.0, "heliport", "Edvard Grieg", "NO", "", "EU",
"ENWG", "", 1.74333, 58.845, 400.0, "heliport", "Gudrun", "NO", "", "EU",
"ENWI", "", 2.19778, 58.92222, 400.0, "heliport", "Ivar Aasen", "NO", "", "EU",
"ENWK", "", 1.69528, 58.57139, 400.0, "heliport", "Gina Krog", "NO", "", "EU",
"ENWR", "", 1.73278, 58.58333, 400.0, "heliport", "Randgrid", "NO", "", "EU",
"ENWS", "", 3.26278, 56.37361, 400.0, "heliport", "Eldfisk S", "NO", "", "EU",
"ENWV", "", 3.4, 56.28333, 400.0, "heliport", "Valhall PH", "NO", "", "EU"
)
)


}
71 changes: 62 additions & 9 deletions R/trajectories.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,20 @@
#'
#' @examples
#' \dontrun{
#' prf <- airspace_profile_tbl()
#' pp <- airspace_profile_tbl()
#' # other operations on pp, i.e. filtering,
#' # followed by a collect() to retrieve the concrete data frame
#' # IMPORTANT: close the DB connection when done
#' DBI::dbDisconnect(pp$src$con)
#'
#' # if you use a DB connection for many different APIs
#' conn <- eurocontrol::db_connection("PRU_DEV")
#' pp <- airspace_profile_tbl(conn = conn)
#'
#' # ... do something else with conn
#' # ...
#' # then manually close the connection to the DB
#' DBI::dbDisconnect(conn)
#' }
airspace_profile_tbl <- function(conn = NULL) {
if (is.null(conn)) {
Expand Down Expand Up @@ -81,7 +94,18 @@ airspace_profile_tbl <- function(conn = NULL) {
#'
#' @examples
#' \dontrun{
#' asp_profs <- airspace_profiles_tidy(wef = "2023-01-01", til = "2023-04-01")
#' ps <- airspace_profiles_tidy(wef = "2023-01-01", til = "2023-04-01")
#' # IMPORTANT: always close the DB connection when done
#' DBI::dbDisconnect(ps$src$con)
#'
#' # if you re-use DB connections
#' conn <- eurocontrol::db_connection("PRU_DEV")
#' ps <- airspace_profiles_tidy(conn = conn)
#'
#' # ... do something else with conn
#' # ...
#' # then manually close the connection to the DB
#' DBI::dbDisconnect(conn)
#' }
airspace_profiles_tidy <- function(conn = NULL, wef, til, airspace = "FIR", profile = "CTFM") {
# magic numbers: tables are indexed on LOBT, but LOBT is not precise to
Expand Down Expand Up @@ -174,7 +198,18 @@ airspace_profiles_tidy <- function(conn = NULL, wef, til, airspace = "FIR", prof
#'
#' @examples
#' \dontrun{
#' asp_profs <- flights_airspace_profiles_tidy(wef = "2023-01-01", til = "2023-04-01")
#' aa <- flights_airspace_profiles_tidy(wef = "2023-01-01", til = "2023-04-01")
#'
#' # if you re-use DB connections
#' conn <- eurocontrol::db_connection("PRU_DEV")
#' flights_airspace_profiles_tidy(conn = conn,
#' wef = "2023-01-01",
#' til = "2023-04-01")
#'
#' # ... do something else with conn
#' # ...
#' # then manually close the connection to the DB
#' DBI::dbDisconnect(conn)
#' }
flights_airspace_profiles_tidy <- function(conn = NULL, wef, til, airspace = "FIR", profile = "CTFM") {
# magic numbers: tables are indexed on LOBT, but LOBT is not precise to
Expand Down Expand Up @@ -229,7 +264,16 @@ flights_airspace_profiles_tidy <- function(conn = NULL, wef, til, airspace = "FI
#'
#' @examples
#' \dontrun{
#' prf <- point_profile_tbl()
#' pt <- point_profile_tbl()
#'
#' # if you re-use DB connections
#' conn <- eurocontrol::db_connection("PRU_DEV")
#' pt <- point_profile_tbl(conn = conn)
#'
#' # ... do something else with conn
#' # ...
#' # then manually close the connection to the DB
#' DBI::dbDisconnect(conn)
#' }
point_profile_tbl <- function(conn = NULL) {
if (is.null(conn)) {
Expand Down Expand Up @@ -285,22 +329,31 @@ point_profile_tbl <- function(conn = NULL) {
#' @examples
#' \dontrun{
#' # export 1 day of NM (planned) trajectories
#' point_profiles_tidy(wef = "2019-07-14", til = "2019-07-15", profile = "FTFM")
#' pf1 <- point_profiles_tidy(wef = "2019-07-14",
#' til = "2019-07-15",
#' profile = "FTFM")
#'
#' # export 2 hours of NM (flown) trajectories
#' point_profiles_tidy(wef = "2019-07-14 22:00", til = "2019-07-15")
#' pf2 <- point_profiles_tidy(wef = "2019-07-14 22:00",
#' til = "2019-07-15")
#'
#' # export 1 day of NM (flown) trajectories
#' point_profiles_tidy(wef = "2019-07-14", til = "2019-07-15", profile = "CTFM")
#' pf3 <- point_profiles_tidy(wef = "2019-07-14",
#' til = "2019-07-15",
#' profile = "CTFM")
#'
#' # export all CTFM trajectories within a bounding box 40 NM around EDDF
#' bb <- c(xmin = 7.536746, xmax = 9.604390, ymin = 49.36732, ymax = 50.69920)
#' point_profiles_tidy(wef = "2019-01-01 00:00", til = "2019-01-02 00:00", bbox = bb)
#' pf4 <- point_profiles_tidy(wef = "2019-01-01 00:00",
#' til = "2019-01-02 00:00",
#' bbox = bb)
#'
#'
#' # if you re-use DB connections
#' conn <- eurocontrol::db_connection("PRU_DEV")
#' point_profiles_tidy(conn = conn, "2020-01-01")
#' pf <- point_profiles_tidy(conn = conn,
#' wef = "2020-01-01",
#' til = "2020-01-10")
#'
#' # ... do something else with conn
#' # ...
Expand Down
10 changes: 8 additions & 2 deletions man/airlines_tbl.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions man/airports_oa.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion man/airspace_profile_tbl.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion man/airspace_profiles_tidy.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion man/flights_airspace_profiles_tidy.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions man/flights_tbl.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion man/point_profile_tbl.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7b43ca6

Please sign in to comment.