Title: | Statistical Estimation of Phenological Parameters |
---|---|
Description: | Provides functions and methods for estimating phenological dates (green up, start of a season, maturity, senescence, end of a season and dormancy) from (nearly) periodic Earth Observation time series. These dates are critical points of some derivatives of an idealized curve which, in turn, is obtained through a functional principal component analysis-based regression model. Some of the methods implemented here are based on T. Krivobokova, P. Serra and F. Rosales (2022) <https://www.sciencedirect.com/science/article/pii/S0167947322000998>. Methods for handling and plotting Earth observation time series are also provided. |
Authors: | Inder Tecuapetla-Gómez [cre, aut] (0000-0001-6251-972X), Fanny Galicia-Gómez [ctb], Francisco Rosales-Marticorena [ctb] |
Maintainer: | Inder Tecuapetla-Gómez <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.1.31 |
Built: | 2024-12-13 07:04:04 UTC |
Source: | CRAN |
Estimates phenological dates of satellite imagery time series. Originally conceived to handle MODIS time series (especifically MOD13Q1), this package can handle Earth Observation time series from any satellite mission.
The main function of this package, phenopar
, allows a numeric
vector containing satellite-based measurements (preferably, vegetation indices for better results).
These observations can be construed as realizations of an underlying periodic stochastic process that has been recorded
from the first day of the year (DoY) of startYear
to the last DoY of endYear
.
Thus, each numeric vector can be assembled as a matrix whose number of rows and columns equal
to length(startYear:endYear)
and frequency
, respectively, see get_metadata_years
. Moreover,
each row of this matrix can be thought as the realization of the periodic stochastic
process throughout a season. Thus, having multiple measurements of such a process, functional
principal component methods are employed to extract an underlying idealized (vegetation index) curve.
The phenological dates that can be estimated with sephora are:
Green Up (GU).
Start of Season (SoS).
Maturity (Mat).
Senescence (Sen).
End of Season (EoS).
Dormancy (Dor).
The following functions allow to access numeric vectors of time series satellite imagery, in particular, MOD13Q1 time series starting at February 18, 2000.
fill_initialgap_MOD13Q1
|
Fill first 3 MOD13Q1 observations |
vecFromData
|
Get numeric vector from an RData file |
vecToMatrix
|
Set numeric vector as a matrix |
get_metadata_years
|
Get metadata useful in certain visualizations |
The following functions allow to smooth out and fit a regression model based on Functional Principal Components. Applications of these functions allow to estimate phenological parameters of numeric vectors of Earth Observation time series:
ndvi_derivatives
|
Derivatives of idealized NDVI curve |
phenopar
|
Estimate phenological dates |
phenopar_polygon
|
Estimate phenological dates (parallel processing) |
Plot methods for numeric and sephora
objects:
getSpiralPlot
|
Spiral plot of polygon-based phenological date estimates |
plot.sephora
|
Plot methods for sephora-class object |
datesToDoY
|
Maps estimated phenological dates to days of a year |
getDist_phenoParam
|
Access to vectors of phenological date estimates from a list |
global_min_max
|
Global critical points of a curve on a closed interval |
local_min_max
|
Local critical points of a curve on a union of open intervals |
Tecuapetla-Gómez, I. [email protected]
This function maps estimated phenological dates to days of a year.
datesToDoY( start = 1, end = 12, phenodates, totalDoY = c(0, cumsum(c(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31))) )
datesToDoY( start = 1, end = 12, phenodates, totalDoY = c(0, cumsum(c(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31))) )
start |
numeric, first month in mapping range. Default is 1. |
end |
numeric, last month in mapping range. Default is 12. |
phenodates |
numeric vector of length 6 containing estimates of phenological dates (green up, start of season, maturity, senescence, end of season and dormancy) |
totalDoY |
numeric vector, each entry (except for the first) gives a month's total number of days |
Length of start:end
must be equal to length(totalDoY)-1
.
A data.frame
with variables month
and day
x <- c(102,140,177,301,339,242) names(x) <- c("GU", "SoS", "Mat", "Sen", "EoS", "Dor") datesToDoY(phenodates = x)
x <- c(102,140,177,301,339,242) names(x) <- c("GU", "SoS", "Mat", "Sen", "EoS", "Dor") datesToDoY(phenodates = x)
Small spatial subset of a MOD13Q1 time series from 2000 to 2021. The MOD13Q1 provides measurements of the Normalized Difference Vegetation Index (NDVI), a variable that is suitable to conduct mid-term vegetation studies remotely. The pixels provided by this dataset were recorded from a deciduous forest zone.
data(deciduous_polygon)
data(deciduous_polygon)
An object of class matrix
.
The dataset is distributed through an RData
file containing a
matrix
object with 128 rows and 506 columns.
Since MOD13Q1 was released on 18-02-2000 and its temporal resolution is 16 days, there are no measurements available for the first three acquisition dates of 2000. This function allows to fill these three dates using historic data.
fill_initialgap_MOD13Q1(m, fun = stats::median)
fill_initialgap_MOD13Q1(m, fun = stats::median)
m |
matrix with |
fun |
a function employed to impute missing values. Default, |
The missing values of m
are m[1,1]
, m[1,2]
and m[1,3]
. For instance,
to fill m[1,1]
the values of m[2:nrow(m),1]
are used, and consequently, it
is expected that the larger the numeric vector, the smaller the variability of the imputed
value for m[1,1]
.
A numeric vector of length 3
It is recommended to use vecToMatrix
to transfer
the values of a numeric vector of MOD13Q1 measurements into a matrix.
data("deciduous_polygon") str(deciduous_polygon, vec.len = 1) x <- deciduous_polygon[1,] # check x[1:3] x_asMatrix <- vecToMatrix(x, lenPeriod = 23) # check str(x_asMatrix) x_asMat_complete <- fill_initialgap_MOD13Q1(m=x_asMatrix) #filled first three values of x x[1:3] <- x_asMat_complete
data("deciduous_polygon") str(deciduous_polygon, vec.len = 1) x <- deciduous_polygon[1,] # check x[1:3] x_asMatrix <- vecToMatrix(x, lenPeriod = 23) # check str(x_asMatrix) x_asMat_complete <- fill_initialgap_MOD13Q1(m=x_asMatrix) #filled first three values of x x[1:3] <- x_asMat_complete
plot.sephora
Metadata either from a numeric vector or a sephora-class
object
get_metadata_years(x, startYear = 2000, endYear = 2021, frequency = 23)
get_metadata_years(x, startYear = 2000, endYear = 2021, frequency = 23)
x |
numeric vector or |
startYear |
integer, |
endYear |
integer, |
frequency |
integer giving number of observations per season. Default is 23. |
A list of 2 components:
xDates |
date vector containing DoY (acquisition date) using format yyyy-mm-dd |
xLabels |
character vector containing period of study years using format "'YY" |
x <- deciduous_polygon[1,] y <- get_metadata_years(x=x) str(y)
x <- deciduous_polygon[1,] y <- get_metadata_years(x=x) str(y)
Extracts an estimated phenological parameter from a list
. Useful when
phenopar_polygon
was applied to estimate phenological dates over a polygon.
getDist_phenoParam( LIST, phenoParam = c("GU", "SoS", "Mat", "Sen", "EoS", "Dor") )
getDist_phenoParam( LIST, phenoParam = c("GU", "SoS", "Mat", "Sen", "EoS", "Dor") )
LIST |
list, containing 6 estimated phenological parameters |
phenoParam |
character. What phenological parameter should be extracted? |
A numeric vector
getSpiralPlot
, phenopar_polygon
This utility function yields a spiral plot based on phenological dates estimated from a polygon.
getSpiralPlot(LIST, MAT = NULL, height = 0.2, LABELS, ...)
getSpiralPlot(LIST, MAT = NULL, height = 0.2, LABELS, ...)
LIST |
list, containing 6 estimated phenological parameters. |
MAT |
matrix, containing 6 estimated phenological parameters. Default, |
height |
numeric, height parameter of |
LABELS |
character, labels parameter of |
... |
additional parameters to |
No value is returned
getSpiralPlot
, phenopar_polygon
, spiral_track
,
spiral_axis
, spiral_initialize
Gets global minimum and maximum of a given function expression on an interval using basic calculus criteria
global_min_max(f, f1der, f2der, D)
global_min_max(f, f1der, f2der, D)
f |
function expression |
f1der |
function expression of first derivative of |
f2der |
function expression of second derivative of |
D |
numeric vector specifying the interval over which |
This function uses uniroot.all
to get all roots of f1der
over D
, additionally,
the second derivative criterion is used to determine the global minimum and
maximum.
A list containing:
min |
numeric giving critical point where global minimum is achieved |
max |
numeric giving critical point where global maximum is achieved |
mins |
numeric vector giving all critical points satisfying second derivative criterion for minimum |
maxs |
numeric vector giving all critical points satisfying second derivative criterion for maximum |
Gets local minimum and maximum of a given function expression on an interval using basic calculus criteria
local_min_max(f, f1der, f2der, what = c("min", "max"), x0, D)
local_min_max(f, f1der, f2der, what = c("min", "max"), x0, D)
f |
function expression |
f1der |
function expression of first derivative of |
f2der |
function expression of second derivative of |
what |
character. What to look for? A local |
x0 |
numeric givin global minimum or maximum of |
D |
numeric vector specifying the interval over which |
This function looks for critical values
over the interval [D[1],x0-1)
(x0+1, D[length(D)]]
.
A list containing:
x_opt
numeric giving the critical point where the local min or max
is achieved. When local min or max cannot be determined, this function returns NA
.
locals
numeric vector giving all critical points satisfying second derivative criteria.
crtPts
a list with 2 entries:
x_d1
numeric vector with local critical points over [D[1],x-1)
x_d2
numeric vector with local critical points over (x0+1,D[length(D)]]
type
character, what was found? A min
or a max
?
Provides function expression of derivatives of an idealized NDVI curve fitted through a harmonic regression model
ndvi_derivatives(amp, pha, degree, L)
ndvi_derivatives(amp, pha, degree, L)
amp |
numeric vector specifying amplitude parameter |
pha |
numeric vector specifying phase angle parameter |
degree |
integer. What derivative's degree should be calculated?
|
L |
integer giving the number of observations per period |
This function returns the derivatives of , with respect
to
, when
has the representation:
,
where and
are substituted by the vectors
amp
and phase
, respectively. The degree of the derivative is given by the
argument degree
.
A function expression
For historic reasons, we ended up using the name ndvi_derivatives
for this function, but it can be used to calculate derivatives of any function
expression defined through amp
, pha
, degree
and L
.
phenopar
, phenopar_polygon
, haRmonics
Estimation of 6 phenological parameters from a numeric vector. The estimated parameters are: green up, start of season, maturity, senescence, end of season and dormancy. These parameters are critical points of some derivatives of an idealized curve which, in turn, is obtained through a functional principal component analysis (FPCA)-based regression model.
phenopar( x, startYear, endYear, frequency = 23, method = c("OLS", "WLS"), sigma = NULL, numFreq, delta = 0, distance, samples, basis, corr = NULL, k, trace = FALSE )
phenopar( x, startYear, endYear, frequency = 23, method = c("OLS", "WLS"), sigma = NULL, numFreq, delta = 0, distance, samples, basis, corr = NULL, k, trace = FALSE )
x |
a numeric vector. |
startYear |
integer, time series initial year |
endYear |
integer, time series final year |
frequency |
integer giving number of observations per season. Default, 23. |
method |
character. Should |
sigma |
numeric vector of length equal to |
numFreq |
integer specifying number of frequencies used in harmonic regression model. |
delta |
numeric. Default, 0. When harmonic regression problem is ill-posed, this parameter allows a simple regularization. See Details. |
distance |
character indicating what distance to use in hierarchical clustering.
All distances in |
samples |
integer with number of samples to draw from smoothed version of |
basis |
list giving numeric basis used in FPCA-based regression. See Details. |
corr |
Default |
k |
integer, number of principal components used in FPCA-based regression. |
trace |
logical. If |
In order to estimate the phenological parameters, first x
is assembled
as a matrix. This matrix has as many rows as years (length(startYear:endYear)
) in the studied period and as many columns
as observations (frequency
) per year. Then, each vector row is smoothed through
the harmonic regression model haRmonics
. This function allows
for homogeneous (OLS
) and heterogeneous (WLS
) errors in the model. When
method=WLS
, sigma
must be provided, hetervar
is recommended for such a purpose.
Additional parameters for haRmonics
are numFreq
and
delta
.
Next, equally spaced samples
are drawn from each harmonic regression fit,
the resulting observations are stored in the matrix m_aug_smooth
.
tsclust
is applied to m_aug_smooth
in order to obtain clusters of years sharing
similar characteristics; 2 clusters are produced. The next step is applied
to the dominating cluster (the one with the majority of years, >=10), or to the
whole of columns of m_aug_smooth
when no dominating cluster can be determined.
Based on the observations produced in the hierarchical clustering step, a regression model with the following representation is applied:
,
where is substituted by the vector of sample observations of the
-th
year;
is the
-th functional principal component (FPC);
is the score associated with the
-th FPC and the
-th vector
of sampled observations; and
is a normally distributed random variable
with variance
, see Krivobokova et al. (2022) for further details.
From this step, an estimate of
is produced -
fpca
-
this is an idealized version of the original observations contained in x
.
Parameter basis
can be supplied through a call to drbasis
with parameters nn=samples
and qq=2
. Parameter corr
indicates
whether correlation between annual curves must be considered; the current implementation
does not incorporate correlation. The number of principal components is controlled
by k
.
Next, a harmonic regression is fitted to fpca
(a numeric vector of length
equal to samples
) with the parameters provided above (method
, sigma
,
numFreq
, delta
). Based on the estimated parameters of this fit
(fpca_harmfit_params
) a R function is calculated along with its first,
second, third and fourth derivatives. These derivatives are used in establishing
the phenological parameters (phenoparams
) utilizing basic calculus
criteria similar to what Baumann et al. (2017) have proposed.
Finally, when 6 phenoparams
are found status=Success
, otherwise
status=Partial
.
A sephora-class
object containing 14 elements
x |
numeric vector |
startYear |
integer, time series initial year |
endYear |
integer, time series final year |
freq |
numeric giving number of observations per season. Default is 23. |
sigma |
when |
m_aug_smooth |
matrix with |
clustering |
Formal class |
fpca |
numeric vector of length equal to |
fpca_harmfit_params |
list of 4: |
fpca_fun_0der |
function, harmonic fit for |
fpca_fun_1der |
function, first derivative of harmonic fit for |
fpca_fun_2der |
function, second derivative of harmonic fit for |
fpca_fun_3der |
function, third derivative of harmonic fit for |
fpca_fun_4der |
function, fourth derivative of harmonic fit for |
phenoparams |
named numeric vector of length 6 |
status |
character, specifying whether FPCA model was inverted successfully
( |
Krivobokova, T. and Serra, P. and Rosales, F. and Klockmann, K. (2022). Joint non-parametric estimation of mean and auto-covariances for Gaussian processes. Computational Statistics & Data Analysis, 173, 107519.
Baumann, M. and Ozdogan, M. and Richardson, A. and Radeloff, V. (2017). Phenology from Landsat when data is scarce: Using MODIS and Dynamic Time-Warping to combine multi-year Landsat imagery to derive annual phenology curves. International Journal of Applied Earth Observation and Geoinformation, 54, 72–83
haRmonics
, hetervar
,
tsclust
, drbasis
.
# --- 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
# --- 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
Estimation of phenological parameters from a set of numeric vectors stored in a RData file.
Output is saved as a RData file at the destination specified by dirToSave
phenopar_polygon( path = NULL, product = c("MOD13Q1", "independent"), data, frequency = 23, method = c("OLS", "WLS"), sigma = NULL, numFreq, delta = 0, distance, samples, basis, corr = NULL, k, trace = FALSE, numCores = 20, dirToSave, reportFileBaseName = "phenopar_progress", outputFileBaseName = "polygon" )
phenopar_polygon( path = NULL, product = c("MOD13Q1", "independent"), data, frequency = 23, method = c("OLS", "WLS"), sigma = NULL, numFreq, delta = 0, distance, samples, basis, corr = NULL, k, trace = FALSE, numCores = 20, dirToSave, reportFileBaseName = "phenopar_progress", outputFileBaseName = "polygon" )
path |
character with full path of RData file containing numeric vectors to analyze. |
product |
character specifying whether dataset is the |
data |
matrix with dataset to analyze. Pertinent when |
frequency |
integer giving number of observations per season. Default, 23. |
method |
character. Should |
sigma |
numeric vector of length equal to |
numFreq |
integer specifying number of frequencies to use in harmonic regression model. |
delta |
numeric. Default, 0. When regression problem is ill-posed, this parameter allows a simple regularization. |
distance |
character indicating what distance to use in hierarchical clustering.
All distances in |
samples |
integer with number of samples to draw from smoothed version of numeric vector to analyze. Used exclusively in Functional Principal Components Analysis (FPCA)-based regression. |
basis |
list giving numeric basis used in FPCA-based regression. See details. |
corr |
Default |
k |
integer, number of principal components used in FPCA-based regression. |
trace |
logical. If |
numCores |
integer. How many processing cores can be used? |
dirToSave |
character. In which directory to save analysis results? |
reportFileBaseName |
character. What base name should be given to a progress report file?
Default, |
outputFileBaseName |
character. What base name should be given to the output file?
Default, |
At the location specified by dirToSave
, a file containing a matrix
with nrow
equal to the number of numeric vectors analyzed and 6 columns, is saved.
The name of this file is:
paste0(tools::file_path_sans_ext(basename(path)), "_phenoparams.RData")
.
phenopar
, getSpiralPlot
,
tsclust
.
dirOUTPUT <- system.file("data", package = "sephora") BASIS <- drbasis(n=100, q=2) polygon_deciduous <- deciduous_polygon for(i in 1:nrow(polygon_deciduous)){ polygon_deciduous[i,] <- vecFromData(data=deciduous_polygon, numRow=i)$vec } # --- In the following example 'numCores=2' for CRAN # --- testing purposes only. In a real life example # --- users are encouraged to set 'numCores' to a number # --- that reflects the size of their data set as well # --- as the number of available cores phenopar_polygon(data=polygon_deciduous, product="independent", numFreq = 3, distance = "dtw2", samples=100, basis=BASIS, k=3, numCores=2, dirToSave=dirOUTPUT, outputFileBaseName = "deciduous") # --- Auxiliary function to read phenopar_polygon output, # --- used below to define deciduous_params object LoadToEnvironment <- function(RData, env = new.env()){ load(RData, env) return(env)} # --- colors used in spiralPlot below cgu <- rgb(173/255,221/255,142/255) csos <- rgb(120/255,198/255,121/255) cmat <- rgb(49/255, 163/255,84/255) csen <- rgb(217/255, 95/255, 14/255) ceos <- rgb(254/255, 153/255, 41/255) cdor <- rgb(208/255, 209/255, 230/255) colores <- c(cgu,csos,cmat,csen,ceos,cdor) # --- how to get a SpiralPlot listRDatas <- list.files(path=dirOUTPUT, pattern=".RData", full.names=TRUE) deciduous_params <- LoadToEnvironment(listRDatas[1]) getSpiralPlot(MAT=deciduous_params$output, LABELS=month.name, vp_param=list(width=0.5, height=0.7)) vcd::grid_legend(x=1.215, y=0.125, pch=18, col=colores, frame=FALSE, labels=c("GU","SoS","Mat","Sen","EoS","Dor"), title="Params") # --- cleaning up after work unlink(paste0(dirOUTPUT, "/deciduous_phenoParams.RData")) unlink(paste0(dirOUTPUT, "/phenopar_progress.txt"))
dirOUTPUT <- system.file("data", package = "sephora") BASIS <- drbasis(n=100, q=2) polygon_deciduous <- deciduous_polygon for(i in 1:nrow(polygon_deciduous)){ polygon_deciduous[i,] <- vecFromData(data=deciduous_polygon, numRow=i)$vec } # --- In the following example 'numCores=2' for CRAN # --- testing purposes only. In a real life example # --- users are encouraged to set 'numCores' to a number # --- that reflects the size of their data set as well # --- as the number of available cores phenopar_polygon(data=polygon_deciduous, product="independent", numFreq = 3, distance = "dtw2", samples=100, basis=BASIS, k=3, numCores=2, dirToSave=dirOUTPUT, outputFileBaseName = "deciduous") # --- Auxiliary function to read phenopar_polygon output, # --- used below to define deciduous_params object LoadToEnvironment <- function(RData, env = new.env()){ load(RData, env) return(env)} # --- colors used in spiralPlot below cgu <- rgb(173/255,221/255,142/255) csos <- rgb(120/255,198/255,121/255) cmat <- rgb(49/255, 163/255,84/255) csen <- rgb(217/255, 95/255, 14/255) ceos <- rgb(254/255, 153/255, 41/255) cdor <- rgb(208/255, 209/255, 230/255) colores <- c(cgu,csos,cmat,csen,ceos,cdor) # --- how to get a SpiralPlot listRDatas <- list.files(path=dirOUTPUT, pattern=".RData", full.names=TRUE) deciduous_params <- LoadToEnvironment(listRDatas[1]) getSpiralPlot(MAT=deciduous_params$output, LABELS=month.name, vp_param=list(width=0.5, height=0.7)) vcd::grid_legend(x=1.215, y=0.125, pch=18, col=colores, frame=FALSE, labels=c("GU","SoS","Mat","Sen","EoS","Dor"), title="Params") # --- cleaning up after work unlink(paste0(dirOUTPUT, "/deciduous_phenoParams.RData")) unlink(paste0(dirOUTPUT, "/phenopar_progress.txt"))
sephora
Methods associated with sephora-class
.
## S3 method for class 'sephora' plot( x, y, startYear, endYear, frequency, type = NULL, sizeLine = 1, sizePoint = 2, position_legend = "none", title_legend = NULL, xLab = "Time", yLab = "Index", xLim, msTitle = "Cluster", pointShape = 16, pointSize = 2, pointStroke = 3, textFontface = 2, textSize = 5, text_hjust = 0.5, text_vjust = -0.5, ... )
## S3 method for class 'sephora' plot( x, y, startYear, endYear, frequency, type = NULL, sizeLine = 1, sizePoint = 2, position_legend = "none", title_legend = NULL, xLab = "Time", yLab = "Index", xLim, msTitle = "Cluster", pointShape = 16, pointSize = 2, pointStroke = 3, textFontface = 2, textSize = 5, text_hjust = 0.5, text_vjust = -0.5, ... )
x |
a numeric vector or a |
y |
ignored. |
startYear |
integer, time series initial year. |
endYear |
integer, time series final year. |
frequency |
integer giving number of observations per season. |
type |
character specifying type of plot. By default, |
sizeLine |
integer giving line size |
sizePoint |
integer giving point size |
position_legend |
character. Should a legend be added? Where? See
|
title_legend |
character. Should a legend be added? What would it be? See
|
xLab |
character, label to display in x-axis. |
yLab |
character, label to display in y-axis. See Details. |
xLim |
date vector of length 2 indicating limits of x-axis. When no
supplied, |
msTitle |
character. Default "Cluster". See Details. |
pointShape |
|
pointSize |
|
pointStroke |
|
textFontface |
|
textSize |
|
text_hjust |
|
text_vjust |
|
... |
additional |
By default, type=NULL
and this option allows for plotting numeric
vectors and sephora
objects; argument title_legend
is only pertinent in this case.
Other allowed options for type
are "profiles", "ms" and "derivatives". When
type="profiles"
all the arguments used in the default case are allowed except for
title_legend
. When type="ms"
, arguments msTitle
, pointShape
,
pointSize
, pointStroke
, textFontface
, textSize
, text_hjust
and text_vjust
are pertinent. When type="derivatives"
, the default value of
argument yLab
will be used.
A gg
object (or NULL
(invisible) when type="derivatives"
).
This function draws either a graphic based on a ggplot
or a plot
object.
The default is intended for numeric
vectors and sephora-class
objects.
This method employs the ggplot2
system and returns a sort of time series plot.
The method profiles, selected when type="profiles"
, is also intended for numeric
vectors and sephora-class
objects. This method is based on the ggplot2
system
and draws curves, one for each period (
p=length(startYear:endYear)
), on
the same time scale (days of the year).
The method ms, selected when type="ms"
, is intended for sephora-class
objects
only. Using the ggplot2
system this method draws the result of a multidimensional
scaling analysis performed on the smoothed version of the curves described above.
The method derivative, selected when type="derivatives"
, is intended for
sephora-class
objects only. A 5-panel plot is drawn showing (from top
to bottom):
FPCA estimate: the fpca
entry of sephora-class
object. See phenopar
.
First, second, third and fourht derivative of FPCA estimate: curve obtained by applying ndvi_derivatives
to FPCA estimate.
Definition of the sephora
class
x
Original time series (as a numeric vector)
startYear
Beginning of time series
endYear
End of time series
freq
Number of observations per season
sigma
Variability estimate
m_aug_smooth
Samples of smoothed version of x
, in matricial form
clustering
An object of class HierarchicalTSClusters
fpca
Numeric, FPCA-based regression fit
fpca_harmfit_params
a list, harmonic fit
fpca_fun_0der
Function fpca fit
fpca_fun_1der
Function fpca fit first derivative
fpca_fun_2der
Function fpca fit second derivative
fpca_fun_3der
Function fpca fit third derivative
fpca_fun_4der
Function fpca fit fourth derivative
phenoparams
Phenological dates estimate
status
Character, was phenopar estimation successful?
Extract a numeric vector from an RData file
vecFromData( product = c("MOD13Q1", "independent"), data, numRow, lenPeriod = 23 )
vecFromData( product = c("MOD13Q1", "independent"), data, numRow, lenPeriod = 23 )
product |
character indicating whether |
data |
a matrix containing measurements of subsets (polygons) of a time series of satellite images.
|
numRow |
numeric, number of row to extract from |
lenPeriod |
numeric, number of observations per period. Default, 23. |
Although the first available MOD13Q1 product dates back to 18-02-2000,
when product="MOD13Q1"
this function assumes that data
contains observations from
01-01-2000 and fill_initialgap_MOD13Q1
is used to impute
the first three missing values of 2000.
A list with two components:
mat |
extracted vector in matricial form |
vec |
extracted vector |
fill_initialgap_MOD13Q1
, phenopar
,
raster_intersect_sp
, vecToMatrix
.
Maps a vector (pixel of a satellite time series) to a matrix.
vecToMatrix(x, lenPeriod = 23)
vecToMatrix(x, lenPeriod = 23)
x |
a numeric vector whose length must be a multiple of |
lenPeriod |
a numeric, number of observations per period |
A matrix with nrow
equal to length(x)/lenPeriod
and
ncol
equal to lenPeriod
.
fill_initialgap_MOD13Q1
, phenopar
,
vecFromData
.