/
get_yeardates.R
85 lines (68 loc) · 2.94 KB
/
get_yeardates.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
78
79
80
81
82
83
84
85
#' @title identify dates to be processed for a year
#' @description helper function needed to identify the ranges of dates to
#' be processed for a given year as a function of `download_range` selection
#' and starting/ending dates and years
#' @param yy `numeric` year for which the processing dates need to be identified
#' @param start_year `numeric` start year of current `MODIStsp_process` run
#' @param end_year `numeric` end year of current `MODIStsp_process` run.
#' @param start_date `character`` Start date for images download and preprocessing
#' (yyyy.mm.dd) of current `MODIStsp_process` run.
#' @param end_date `character` Start date for images download and preprocessing
#' (yyyy.mm.dd) of current `MODIStsp_process` run.
#' @inheritParams MODIStsp
#' @return OUTPUT_DESCRIPTION
#' @rdname get_yeardates
#' @author Lorenzo Busetto, phD (2017)
get_yeardates <- function(download_range,
yy,
start_year, end_year,
start_date, end_date) {
if (download_range == "Full") {
# Create string representing the dates to be processed in the case
# of "full" time processing
if (yy == start_year & yy == end_year) {
dates <- c(start_date, end_date)
}
if (yy == start_year & yy != end_year) {
dates <- c(start_date, paste0(as.character(yy), ".12.31"))
}
if (yy != start_year & yy != end_year) {
dates <- c(paste0(as.character(yy), ".1.1"),
paste0(as.character(yy), ".12.31"))
}
if (yy != start_year & yy == end_year) {
dates <- c(paste0(as.character(yy), ".1.1"), end_date)
}
} else {
# Create string representing the dates to be processed in the case
# of splitted processing
# the starting month-day
start_seas <- as.Date(strftime(as.Date(start_date, format = "%Y.%m.%d"),
"0-%m-%d"))
# the ending month-day
end_seas <- as.Date(strftime(as.Date(end_date, format = "%Y.%m.%d"),
"0-%m-%d"))
# TRUE if the period includes new year's eve, false if not
nye_incl <- start_seas > end_seas
if (!nye_incl) {
dates <- c(gsub(paste0("^", start_year), yy, start_date),
gsub(paste0("^", end_year), yy, end_date))
} else {
if (yy == start_year & yy != end_year) {
dates <- c(gsub(paste0("^", start_year), yy, start_date),
paste0(as.character(yy), ".12.31"))
}
if (yy != start_year & yy != end_year) {
dates <- c(paste0(as.character(yy), ".1.1"),
gsub(paste0("^", end_year), yy, end_date),
gsub(paste0("^", start_year), yy, start_date),
paste0(as.character(yy), ".12.31"))
}
if (yy != start_year & yy == end_year) {
dates <- c(paste0(as.character(yy), ".1.1"),
gsub(paste0("^", end_year), yy, end_date))
}
}
}
dates
}