Skip to content

Commit e3b5ccd

Browse files
committed
Update many features
- Support the 6-parameter double-logistic function - Support threshold-based phenometrics extraction method, which gives us 7 phenometrics including Greenup, MidGreenup, Maturity, Peak, Senescence, MidGreendown, and Dormancy. - Fix bugs. - Need to update the vignette.
1 parent 677d473 commit e3b5ccd

17 files changed

Lines changed: 979 additions & 426 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
inst/doc
55
/doc/
66
/Meta/
7+
zzz*

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ License: MIT + file LICENSE
1313
Encoding: UTF-8
1414
LazyData: true
1515
Roxygen: list(markdown = TRUE)
16-
RoxygenNote: 7.2.3
16+
RoxygenNote: 7.3.1
1717
Imports:
1818
coda,
1919
data.table,

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Generated by roxygen2: do not edit by hand
22

33
export("%>%")
4+
export(BLSPFitted)
45
export(FitAvgModel)
56
export(FitBLSP)
67
export(FitBLSP_spring)

R/base.R

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -7,83 +7,4 @@
77

88
usethis::use_pipe(export = TRUE)
99

10-
# The double-logistic function equation
11-
model_str <- "m1 + (m2 - m7 * t) * ((1 / (1 + exp((m3 - t) / m4))) -
12-
(1 / (1 + exp((m5 - t) / m6))))"
1310

14-
15-
#' Make a standard color transparent.
16-
#' This function is borrowed from 'yarrr' package, but I changed the trans.val
17-
#' to use alpha value directly.
18-
#' @param orig.col: the original color, can be a color name, a hexadecimal code,
19-
#' or a rgb vector.
20-
#' @param alpha: define the transparent level.
21-
#' @param maxColorValue: used to convert the color to rgb format before making
22-
#' it transparent.
23-
#' @return color code.
24-
#'
25-
#' @noRd
26-
Transparent <- function(orig.col, alpha = 1, maxColorValue = 255) {
27-
n.cols <- length(orig.col)
28-
orig.col <- grDevices::col2rgb(orig.col)
29-
final.col <- rep(NA, n.cols)
30-
for (i in 1:n.cols) {
31-
final.col[i] <- grDevices::rgb(
32-
orig.col[1, i], orig.col[2, i], orig.col[3, i],
33-
alpha = alpha[i] * 255,
34-
maxColorValue = maxColorValue
35-
)
36-
}
37-
return(final.col)
38-
}
39-
40-
41-
#' Format input date and VI vectors to the structure needed for fitting averaged
42-
#' phenology models such as Fisher et al 2006, Elmore et al 2012.
43-
#'
44-
#' @param date_vec the date vector, be sure to convert the vector to "Date"
45-
#' format or use "yyyy-mm-dd" format string.
46-
#' @param vi_vec The vegetation index vector.
47-
#' @return A list that contains formated data.
48-
#' @import data.table
49-
#'
50-
#' @noRd
51-
FormatAvgData <- function(date_vec, vi_vec) {
52-
# Check if date_vec is in Date format
53-
if (sum(!is.na(lubridate::parse_date_time(date_vec, orders = "ymd"))) !=
54-
length(date_vec)) {
55-
stop("There're invalid Date values in the `date_vec`!
56-
Be sure to use `yyyy-mm-dd` format.")
57-
}
58-
59-
# Make it a data table
60-
vi_dt <- data.table::data.table(
61-
date = as.Date(date_vec),
62-
evi2 = vi_vec,
63-
avg_date = ""
64-
)
65-
vi_dt[, avg_date := as.Date(paste0("1970", substr(vi_dt$date, 5, 10)))]
66-
vi_dt <- stats::na.omit(vi_dt)
67-
data.table::setorder(vi_dt, date)
68-
69-
# Find unique dates in the averaged year
70-
unique_dates <- unique(vi_dt$avg_date)
71-
72-
# Deal with multiple observations on the same date in the averaged year.
73-
# When that happens, we choose the one whose EVI2 value is the highest.
74-
merge_dt <- sapply(unique_dates, function(x) {
75-
# find how many records this day has
76-
evi2 <- NA
77-
find_idx <- which(x == vi_dt$avg_date)
78-
if (length(find_idx) == 1) {
79-
evi2 <- vi_dt[find_idx]$evi2
80-
} else if (length(find_idx) > 1) { # we have multiple values for this date
81-
# compute the max
82-
evi2 <- max(vi_dt[avg_date == x]$evi2, na.rm = TRUE)
83-
}
84-
return(list(date = x, evi2 = evi2))
85-
})
86-
merge_dt <- data.table::as.data.table(t(merge_dt))
87-
88-
return(merge_dt)
89-
}

R/dat_dl_point_ts.R

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,7 @@ GetEvi2PointTs <- function(pt_coords, focalDates = "1984-01-01/2022-12-31",
131131
ncores
132132
)
133133
cl <- parallel::makeCluster(ncores)
134-
calls <- parallel::clusterCall(cl, function() {
135-
suppressWarnings({
136-
require(terra)
137-
require(magrittr)
138-
})
139-
})
134+
calls <- parallel::clusterCall(cl, function() {})
140135
parallel::clusterExport(cl,
141136
c("CalEVI2", "pt_coords"),
142137
envir = environment()

0 commit comments

Comments
 (0)