# --- Load dataset for testing
data("deciduous_polygon")
# --- Extracting first pixel of deciduous_polygon
pixel_deciduous <- vecFromData(data=deciduous_polygon, numRow=3)
# --- Following objects are used in this example
# --- for CRAN testing purposes only. In real life examples
# --- there is no need to shorten time series length
EndYear <- 2010
number_observations <- 23*11
# --- needed parameter
BASIS <- drbasis(n=50, q=2)
# --- testing phenopar
sephora_deciduous <- phenopar(x=pixel_deciduous$vec[1:number_observations],
startYear=2000, endYear=EndYear,
numFreq=3, distance="dtw2",
samples=50, basis=BASIS, k=3)
# --- testing ndvi_derivatives
f <- ndvi_derivatives(amp = sephora_deciduous$fpca_harmfit_params$amplitude,
pha = sephora_deciduous$fpca_harmfit_params$phase,
degree = 0, L = 365)
fprime <- ndvi_derivatives(amp = sephora_deciduous$fpca_harmfit_params$amplitude,
pha = sephora_deciduous$fpca_harmfit_params$phase,
degree = 1, L = 365)
fbiprime <- ndvi_derivatives(amp = sephora_deciduous$fpca_harmfit_params$amplitude,
pha = sephora_deciduous$fpca_harmfit_params$phase,
degree = 2, L = 365)
f3prime <- ndvi_derivatives(amp = sephora_deciduous$fpca_harmfit_params$amplitude,
pha = sephora_deciduous$fpca_harmfit_params$phase,
degree = 3, L = 365)
f4prime <- ndvi_derivatives(amp = sephora_deciduous$fpca_harmfit_params$amplitude,
pha = sephora_deciduous$fpca_harmfit_params$phase,
degree = 4, L = 365)
# --- testing global_min_max and local_min_max
intervalo <- seq(1,365, length=365)
GU_Mat <- global_min_max(f=fbiprime, f1der=f3prime, f2der=f4prime, D=intervalo)
Sen <- local_min_max(f=fbiprime, f1der=f3prime, f2der=f4prime,
what="min", x0=GU_Mat$min, D=intervalo)
SoS_EoS <- global_min_max(f=fprime, f1der=fbiprime, f2der=f3prime, D=intervalo)
Dor <- local_min_max(f=fbiprime, f1der=f3prime, f2der=f4prime,
what="max", x0=GU_Mat$max, D=intervalo)
# --- phenological dates (rough estimates)
c(GU=GU_Mat$max, SoS=SoS_EoS$max, Mat=GU_Mat$min,
Sen=Sen$x_opt, EoS=SoS_EoS$min, Dor=Dor$x_opt)
# --- phenological dates provided by sephora
sephora_deciduous$phenoparams
# --- testing plotting methods
plot(x=sephora_deciduous, yLab="NDVI (no rescaled)")
plot(x=sephora_deciduous, type="profiles",
xLab="DoY", yLab="NDVI (no rescaled)")
# --- 2015 forms Cluster 2
plot(x=sephora_deciduous, type="ms")
# --- graphical definition of phenological dates
plot(x=sephora_deciduous, type="derivatives")
# --- Overlapping FPCA fit to original time series
gg <- plot(x=sephora_deciduous, type="profiles",
xLab="DoY", yLab="NDVI (no rescaled)")
x_axis <- get_metadata_years(x=pixel_deciduous$vec,
startYear=2000, endYear=EndYear, frequency=23)
DoY <- seq(1,365, by=16)
fpca_DoY <- sephora_deciduous$fpca_fun_0der(t=DoY)
COLORS <- unique( ggplot_build(gg)$data[1][[1]]$colour )
df <- data.frame(values=c(sephora_deciduous$x, fpca_DoY),
years=as.factor(rep(c(x_axis$xLabels,"FPCA"), each=23)),
DoY=factor(DoY, levels=DoY), class=c(rep(1,number_observations), rep(2,23)))
gg_fpca <- ggplot(data=df,
aes(x=DoY, y=values, group=years, colour=years)) +
ggplot2::geom_line(linewidth = c(rep(1,number_observations), rep(4,23))) +
ggplot2::labs(y="NDVI", x="DoY", color="years+FPCA") +
ggplot2::scale_color_manual(values = c(COLORS, "#FF4500")) +
ggplot2::theme(legend.position = "right")
gg_fpca
Run the code above in your browser using DataLab