forked from rich-iannone/splitr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_met_gdas1.R
77 lines (64 loc) · 2.24 KB
/
get_met_gdas1.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#' Get GDAS1 meteorology data files
#'
#' Downloads GDAS1 meteorology data files from the NOAA FTP server and saves
#' them to a specified folder. Files can be downloaded by specifying a list of
#' filenames (in the form of `"gdas1.{month-abbrev}{year-2}.w{wk-num}"`).
#'
#' @inheritParams hysplit_trajectory
#' @param path_met_files A full directory path to which the meteorological data
#' files will be saved.
#'
#' @export
get_met_gdas1 <- function(days,
duration,
direction,
path_met_files) {
# Determine the minimum month (as a `Date`) for the model run
if (direction == "backward") {
min_month <-
(lubridate::as_date(days[1]) - (duration / 24)) %>%
lubridate::floor_date(unit = "month")
} else if (direction == "forward") {
min_month <-
(lubridate::as_date(days[1]) + (duration / 24)) %>%
lubridate::floor_date(unit = "month")
}
# Determine the maximum month (as a `Date`) for the model run
if (direction == "backward") {
max_month <-
(lubridate::as_date(days[length(days)]) - (duration / 24)) %>%
lubridate::floor_date(unit = "month")
} else if (direction == "forward") {
max_month <-
(lubridate::as_date(days[length(days)]) + (duration / 24)) %>%
lubridate::floor_date(unit = "month")
}
met_months <-
seq(min_month, max_month, by = "1 month") %>%
rep(each = 5)
month_names <-
met_months %>%
lubridate::month(label = TRUE, abbr = TRUE) %>%
as.character() %>%
tolower()
met_years <-
met_months %>%
substr(3, 4)
if (!all(lubridate::leap_year(lubridate::year(days)))) {
not_leap_years_lgl <- !lubridate::leap_year(lubridate::ymd(days))
exclusion_years_feb_5 <-
lubridate::year(days[not_leap_years_lgl]) %>%
unique()
excluded_files <-
paste0("gdas1.feb", substr(exclusion_years_feb_5, 3, 4), ".w5")
} else {
excluded_files <- character(0)
}
files <- paste0("gdas1.", month_names, met_years, ".w", 1:5)
files <- files %>% base::setdiff(excluded_files)
get_met_files(
files = files,
path_met_files = path_met_files,
ftp_dir = "ftp://arlftp.arlhq.noaa.gov/archives/gdas1"
)
}