# \dontshow{
## Testing the function with NDVI time series of deciduous N. macrocarpa forest in Central Chile
# Load data
data("phents")
all.dates <- as.Date(phents$dates)
# Reference period: 2000 - 2010 (1:423), anomaly detection period: 2010 onwards (424:929)
anom_rfd <- ExtremeAnom(
x = phents$NDVI, dates = all.dates, h = 2, refp = c(1:423),
anop = c(1:929), rge = c(0, 10000), output = "both", rfd = 0.90
)
selection <- which(anom_rfd[930:1858] > 90)
# basic plot
barplot(names = format.Date(all.dates[selection], format = "%Y-%m"), anom_rfd[selection], col = ifelse(anom_rfd[selection] < 0, "red", "blue"), main = "Anomalies whit rfd > 95%")
abline(h = 0)
# }
# \donttest{
library(lubridate)
library(terra)
## Testing raster data from Central Chile (NDVI), h=2##
# Load data
f <- system.file("extdata/MegaDrought_spatRast.rda", package = "npphen")
MegaDrought <- readRDS(f)
# Dates
data("modis_dates")
# Generate a Raster time series using a raster stack and a date database from Central Chile
# Obtain data from a particular pixel generating a time series
md_pixel <- cellFromXY(MegaDrought, cbind(313395, 6356610))
md_pixelts <- as.numeric(MegaDrought[md_pixel])
plot(modis_dates, md_pixelts, type = "l")
# Anomaly detection for the given pixel
anomRFD_MD <- ExtremeAnom(
x = md_pixelts, dates = modis_dates,
h = 2, refp = c(1:423), anop = c(884:929), rfd = 0.9, output = "both", rge = c(0, 10000)
)
# Basic plot
selection <- which(anomRFD_MD[47:92] > 90)
barplot(
names = format.Date(modis_dates[884:929], format = "%Y-%m"),
anomRFD_MD[1:46], col = ifelse(anomRFD_MD[1:46] < 0, "red", "blue"),
main = "Anomalies whit rfd > 0.90"
)
abline(h = 0)
## Testing with the Bdesert_stack from the Atacama Desert, Northern Chile (NDVI),
# showing extreme positive anomalies (greening)##
# Load data
# SparRaster
f <- system.file("extdata/Bdesert_spatRast.rda", package = "npphen")
Bdesert <- readRDS(f)
# Generate a Raster time series using a raster stack and a date database from Northern Chile
# Obtain data from a particular pixel generating a time series
bd_pixel <- cellFromXY(Bdesert, cbind(286638, 6852107))
bd_pixelts <- as.numeric(Bdesert[bd_pixel])
plot(modis_dates, bd_pixelts, type = "l")
# Anomaly detection for the given pixel
anomRFD_BD <- ExtremeAnom(
x = bd_pixelts, dates = modis_dates,
h = 2, refp = c(1:423), anop = c(723:768), rfd = 0.9, output = "both", rge = c(0, 10000)
)
# Basic plot
selection <- which(anomRFD_BD[47:92] > 95)
# basic plot
barplot(
names = format.Date(modis_dates[723:768], format = "%Y-%m"),
anomRFD_BD[1:46], col = ifelse(anomRFD_BD[1:46] < 0, "red", "blue"),
main = "Anomalies whit rfd > 0.95"
)
abline(h = 0)
# }
Run the code above in your browser using DataLab