diff --git a/DESCRIPTION b/DESCRIPTION index 4212d6c..e90a88f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -35,7 +35,8 @@ Imports: sp, lubridate, caret, - mgcv + mgcv, + xtable Suggests: testthat, knitr, @@ -45,7 +46,6 @@ Suggests: grid, png, Hmisc, - xtable, tikzDevice License: GPL (>= 2) | file LICENSE URL: https://github.com/vwmaus/dtwSat/ @@ -90,5 +90,6 @@ Collate: 'twdtwAssess.R' 'twdtwClassify.R' 'twdtwCrossValidation.R' + 'xtable.R' 'zzz.R' VignetteBuilder: knitr diff --git a/NAMESPACE b/NAMESPACE index 62d6337..1bad4ce 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -67,6 +67,7 @@ exportMethods(twdtwCrossValidation) exportMethods(twdtwMatches) exportMethods(twdtwRaster) exportMethods(twdtwTimeSeries) +exportMethods(xtable) import(ggplot2) import(methods) import(raster) @@ -110,6 +111,8 @@ importFrom(stats,qnorm) importFrom(stats,sd) importFrom(stats,window) importFrom(stats,xtabs) +importFrom(xtable,print.xtable) +importFrom(xtable,xtable) useDynLib(dtwSat,bestmatches) useDynLib(dtwSat,computecost) useDynLib(dtwSat,g) diff --git a/R/methods.R b/R/methods.R index 27059a0..db2bb0e 100644 --- a/R/methods.R +++ b/R/methods.R @@ -12,7 +12,6 @@ # # ############################################################### - setGeneric("layers", function(x) standardGeneric("layers")) @@ -455,6 +454,8 @@ show.twdtwAssessment = function(object){ print(object@accuracySummary$UsersAccuracy, digits=2) cat("\nProducers\n") print(object@accuracySummary$ProducersAccuracy, digits=2) + cat("\nArea and uncertainty\n") + print(object@accuracySummary$AreaUncertainty, digits=2) invisible(NULL) } @@ -495,7 +496,7 @@ summary.twdtwCrossValidation = function(object, conf.int=.95, ...){ names(l_names) = l_names ic_ov = mean_cl_boot(x = ov[, c("OV")], conf.int = conf.int, ...) names(ic_ov) = NULL - assess_ov = data.frame(Accuracy=ic_ov[1], sd=sd_ov, CImin=ic_ov[2], CImax=ic_ov[3]) + assess_ov = unlist(c(Accuracy=ic_ov[1], sd=sd_ov, CImin=ic_ov[2], CImax=ic_ov[3])) ic_ua = t(sapply(l_names, function(i) mean_cl_boot(x = uapa$UA[uapa$label==i], conf.int = conf.int, ...))) names(ic_ua) = NULL assess_ua = data.frame(Accuracy=unlist(ic_ua[,1]), sd=sd_uapa[,"UA"], CImin=unlist(ic_ua[,2]), CImax=unlist(ic_ua[,3])) @@ -577,3 +578,4 @@ setMethod("projecttwdtwRaster", "twdtwRaster", + diff --git a/R/twdtwAssess.R b/R/twdtwAssess.R index 4fa9673..1bb95f4 100644 --- a/R/twdtwAssess.R +++ b/R/twdtwAssess.R @@ -6,7 +6,7 @@ setGeneric("twdtwAssess", #' @inheritParams twdtwAssessment-class #' @aliases twdtwAssess #' -#' @describeIn This function performs an accuracy assessment +#' @describeIn twdtwAssessment This function performs an accuracy assessment #' of the classified maps. The function returns Overall Accuracy, #' User's Accuracy, Produce's Accuracy, error matrix (confusion matrix), #' and estimated area according to [1]. The function returns the metrics @@ -54,7 +54,12 @@ setGeneric("twdtwAssess", #' # Assess classification #' twdtw_assess = twdtwAssess(r_lucc, validation_samples, proj4string=proj_str) #' twdtw_assess -#' +#' +#' +#' xtable(twdtw_assess, type="matrix") +#' xtable(twdtw_assess, type="accuracy") +#' xtable(twdtw_assess, type="area") +#' #' } #' @export setMethod(f = "twdtwAssess", signature = "twdtwRaster", @@ -134,7 +139,7 @@ twdtwAssess.twdtwRaster = function(object, y, labels, id.labels, proj4string, co # Error matrix - error_matrix = data.frame(cbind(x, Total=total_map, A=mapped_area, w=w)) + error_matrix = data.frame(cbind(x, Total=total_map, Area=mapped_area, w=w)) error_matrix["Total",] = colSums(error_matrix) # Proportions @@ -144,7 +149,7 @@ twdtwAssess.twdtwRaster = function(object, y, labels, id.labels, proj4string, co total_prop_ref = colSums(y, na.rm = TRUE) # Proportions matrix - prop_matrix = data.frame(y, Total = total_prop_map, A = mapped_area, w = w) + prop_matrix = data.frame(y, Total = total_prop_map, Area = mapped_area, w = w) prop_matrix["Total",] = colSums(prop_matrix, na.rm = TRUE) # Accuracy @@ -157,9 +162,6 @@ twdtwAssess.twdtwRaster = function(object, y, labels, id.labels, proj4string, co names(PA) = cnames OA = sum(diag(as.matrix(prop_matrix[cnames,cnames])), na.rm = TRUE) - #a_pixel = as.numeric(prop_matrix["Total",cnames] * prop_matrix["Total","A"]) - #names(a_pixel) = cnames - #a_ha = a_pixel*res^2/100^2 temp = w^2*UA*(1-UA)/(total_map-1) VO = sum(temp, na.rm = TRUE) @@ -170,38 +172,41 @@ twdtwAssess.twdtwRaster = function(object, y, labels, id.labels, proj4string, co SU = sqrt(VU) UCI = SU * mult - fun1 = function(x, xt, A){ - sum(A*x/xt, na.rm = TRUE) + fun1 = function(x, xt, Area){ + sum(Area*x/xt, na.rm = TRUE) } - fun2 = function(i, x, xt, A, PA){ + fun2 = function(i, x, xt, Area, PA){ x = as.numeric(x[,i]) x = x[-i] xt = xt[-i] - A = A[-i] + Area = Area[-i] PA = PA[i] - PA^2*sum(A^2*x/xt*(1-x/xt)/(xt-1), na.rm = TRUE) + PA^2*sum(Area^2*x/xt*(1-x/xt)/(xt-1), na.rm = TRUE) } Nj = apply(x, 2, fun1, total_map, mapped_area) expr1 = mapped_area^2*(1-PA)^2*UA*(1-UA)/(total_map-1) - expr2 = sapply(1:nrow(x), fun2, x=x, xt=total_map, A=mapped_area, PA=PA) - # VP = (1/Nj^2)*(expr1+expr2) + expr2 = sapply(1:nrow(x), fun2, x=x, xt=total_map, Area=mapped_area, PA=PA) VP = (1/sapply(Nj, function(x) ifelse(x==0, 1, x))^2)*(expr1+expr2) SP = sapply(VP, function(x) ifelse(x==0, 0, sqrt(x))) PCI = SP * mult # Compute adjusted area - estimated_area = prop_matrix["Total",cnames] * prop_matrix["Total","A"] + estimated_area = prop_matrix["Total",cnames] * prop_matrix["Total","Area"] sd_error = apply(prop_matrix[cnames,cnames], 2, function(x) sqrt(sum( (prop_matrix[cnames,"w"]*x[cnames]-x[cnames]^2)/(error_matrix[cnames,"Total"]-1) )) ) - sd_error_estimated_area = sd_error * prop_matrix["Total","A"] + sd_error_estimated_area = sd_error * prop_matrix["Total","Area"] CI_estimated_area = sd_error_estimated_area * mult res = list(OverallAccuracy = c(Accuracy=OA, Var=VO, sd=SO, ci=OCI), UsersAccuracy = cbind(Accuracy=UA, Var=VU, sd=SU, ci=UCI), ProducersAccuracy = cbind(Accuracy=PA, Var=VP, sd=SP, ci=PCI), - EstimateArea = cbind(Mapped=c(prop_matrix[cnames,"A"]), Estimated=c(estimated_area), ci=c(CI_estimated_area)), - ErrorMatrix = error_matrix + AreaUncertainty = cbind(Mapped=c(prop_matrix[cnames,"Area"]), + Adjusted=c(estimated_area), + ci=c(CI_estimated_area)), + ErrorMatrix = error_matrix, + ProportionMatrix = prop_matrix, + conf.int = conf.int ) res diff --git a/R/twdtwCrossValidation.R b/R/twdtwCrossValidation.R index d173c39..2d7d777 100644 --- a/R/twdtwCrossValidation.R +++ b/R/twdtwCrossValidation.R @@ -6,7 +6,7 @@ setGeneric("twdtwCrossValidation", #' @inheritParams twdtwCrossValidation-class #' @aliases twdtwCrossValidation #' -#' @describeIn +#' @describeIn twdtwCrossValidation #' Splits the set of time series into training and validation. #' The function uses stratified sampling and a simple random sampling for #' each stratum. For each data partition this function performs a TWDTW diff --git a/R/xtable.R b/R/xtable.R new file mode 100644 index 0000000..5d5ccb2 --- /dev/null +++ b/R/xtable.R @@ -0,0 +1,75 @@ +#' @aliases xtable +#' @inheritParams twdtwAssessment-class +#' @rdname twdtwAssessment-class +#' +#' @param x an object of class \code{\link[dtwSat]{twdtwAssessment}}. +#' @param type table type, 'accuracy' for User's and Producer's Accuracy, +#' 'matrix' for error matrix, and 'area' for area and uncertainty. +#' Default is 'accuracy'. +#' @param time.labels a character or numeric for the time period or NULL to +#' include all classified periods. Default is NULL. +#' @param ... other arguments to pass to \code{\link[xtable]{xtable}}. +#' +#' @export +setMethod("xtable", + signature = signature(x = "twdtwAssessment"), + definition = function(x, type="accuracy", time.labels=NULL, ...){ + xtable(x@accuracySummary$ErrorMatrix, ...) + pt = pmatch(type,c("accuracy","matrix","area")) + switch(pt, + .xtable.accuracy(x=x@accuracySummary, ...), + .xtable.matrix(x=x@accuracySummary$ErrorMatrix, ...), + .xtable.area(x=x@accuracySummary$AreaUncertainty, ...) + ) + } +) + +.xtable.accuracy = function(x, ...){ + + prop = x$ProportionMatrix + prop = data.frame(apply(prop[,!names(prop)%in%c("Area","w")], 1, FUN = sprintf, fmt="%.2f"), stringsAsFactors = FALSE) + prop$`User's` = "" + prop$`Producers's` = "" + prop$`Overall` = "" + + ua = sprintf("%.2f$\\pm$%.2f", round(x$UsersAccuracy[,"Accuracy"],2), round(x$UsersAccuracy[,"ci"], 2)) + pa = sprintf("%.2f$\\pm$%.2f", round(x$ProducersAccuracy[,"Accuracy"],2), round(x$ProducersAccuracy[,"ci"], 2)) + oa = sprintf("%.2f$\\pm$%.2f", round(x$OverallAccuracy["Accuracy"],2), round(x$OverallAccuracy["ci"], 2)) + + prop$`User's`[1:length(ua)] = ua + prop$`Producers's`[1:length(pa)] = pa + prop$`Overall`[1:length(oa)] = oa + tbl = xtable(prop) + + comment = list() + comment$pos = list() + comment$pos[[1]] = c(nrow(tbl)) + comment$command = c(paste("\\hline \n", "Test foot note. \n", sep = "")) + + print.xtable(tbl, add.to.row = comment, sanitize.text.function = function(x) x) +} + +.xtable.matrix = function(x, ...){ + tbl = xtable(x, digits = c(rep(0, ncol(x)-1), 2, 2), ...) + print.xtable(tbl, sanitize.text.function = function(x) x) +} + +.xtable.area = function(x, ...){ + + x=twdtw_assess@accuracySummary$AreaUncertainty + x = data.frame(x) + + mp = sprintf("%.2f", round(unlist(x$Mapped),2)) + ad = sprintf("%.2f", round(unlist(x$Adjusted),2)) + ci = sprintf("$\\pm$%.2f", round(unlist(x$ci),2)) + + tbl = data.frame(mp, ad, ci) + names(tbl) = c("Mapped", "Adjusted", "Margin of error (95\\% CI)") + + tbl = xtable(tbl) + + print.xtable(tbl, sanitize.text.function = function(x) x) +} + + + diff --git a/R/zzz.R b/R/zzz.R index 69ecaeb..5387367 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -34,6 +34,7 @@ #' @importFrom stats xtabs ave window na.omit sd qnorm #' @importFrom lubridate month month<- day day<- year year<- #' @importFrom caret createDataPartition +#' @importFrom xtable xtable print.xtable #' NULL diff --git a/man/MOD13Q1.MT.yearly.patterns.Rd b/man/MOD13Q1.MT.yearly.patterns.Rd new file mode 100644 index 0000000..97e2dba --- /dev/null +++ b/man/MOD13Q1.MT.yearly.patterns.Rd @@ -0,0 +1,31 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/data.R +\docType{data} +\name{MOD13Q1.MT.yearly.patterns} +\alias{MOD13Q1.MT.yearly.patterns} +\title{Data: patterns time series} +\format{A \link[dtwSat]{twdtwTimeSeries} object.} +\usage{ +MOD13Q1.MT.yearly.patterns +} +\description{ +This dataset has a list of patterns with the phenological cycle of: Water, +Cotton-Fallow, Forest, Low vegetation, Pasture, Soybean-Cotton, Soybean-Maize, Soybean-Millet, +Soybean-Sunflower, and Wetland. These time series are based on the MODIS product +MOD13Q1 250 m 16 days [1]. The patterns were build from ground truth samples of each +crop using Generalized Additive Models (GAM), see \link[dtwSat]{createPatterns}. +} +\author{ +Victor Maus, \email{vwmaus1@gmail.com} +} +\references{ +[1] Friedl MA, Sulla-Menashe D, Tan B, Schneider A, Ramankutty N, Sibley A, Huang X. (2010). +MODIS Collection 5 global land cover: Algorithm refinements and characterization of new +datasets. Remote Sensing of Environment, 114(1), 168 182. +} +\seealso{ +MOD13Q1 documentation: See +\url{https://lpdaac.usgs.gov/dataset_discovery/modis/modis_products_table/mod13q1}. +} +\keyword{datasets} + diff --git a/man/MOD13Q1.patterns.list.Rd b/man/MOD13Q1.patterns.list.Rd new file mode 100644 index 0000000..9fb8478 --- /dev/null +++ b/man/MOD13Q1.patterns.list.Rd @@ -0,0 +1,37 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/data.R +\docType{data} +\name{MOD13Q1.patterns.list} +\alias{MOD13Q1.patterns.list} +\title{Data: patterns time series} +\format{A named \code{list} of 3 \link[zoo]{zoo} objects, ''Soybean'', ''Cotton'', +and ''Maize'', whose indices are \code{\link[base]{Dates}} in the format ''yyyy-mm-dd''. +Each node has 6 attributes: ''ndvi'', ''evi'', ''red'', ''nir'', ''blue'', +and ''mir''.} +\usage{ +MOD13Q1.patterns.list +} +\description{ +This dataset has a list of patterns with the phenological cycle of: Soybean, +Cotton, and Maize. These time series are based on the MODIS product +MOD13Q1 250 m 16 days [1]. The patterns were build from ground truth samples of each +crop using Generalized Additive Models (GAM), see \link[dtwSat]{createPatterns}. +} +\author{ +Victor Maus, \email{vwmaus1@gmail.com} +} +\references{ +[1] Friedl MA, Sulla-Menashe D, Tan B, Schneider A, Ramankutty N, Sibley A, Huang X. (2010). +MODIS Collection 5 global land cover: Algorithm refinements and characterization of new +datasets. Remote Sensing of Environment, 114(1), 168 182. +} +\seealso{ +\link[dtwSat]{MOD13Q1.ts}, +\link[dtwSat]{MOD13Q1.ts.list}, and +\link[dtwSat]{createPatterns}. + +MOD13Q1 documentation: See +\url{https://lpdaac.usgs.gov/dataset_discovery/modis/modis_products_table/mod13q1}. +} +\keyword{datasets} + diff --git a/man/MOD13Q1.ts.Rd b/man/MOD13Q1.ts.Rd new file mode 100644 index 0000000..f608bc9 --- /dev/null +++ b/man/MOD13Q1.ts.Rd @@ -0,0 +1,34 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/data.R +\docType{data} +\name{MOD13Q1.ts} +\alias{MOD13Q1.ts} +\title{Data: An example of satellite time series} +\format{A \link[zoo]{zoo} object, whose indices are \code{\link[base]{Dates}} +in the format ''yyyy-mm-dd''. Each node has 6 attributes: ''ndvi'', +''evi'', ''red'', ''nir'', ''blue'', and ''mir''.} +\usage{ +MOD13Q1.ts +} +\description{ +This dataset has a time series based on the +MODIS product MOD13Q1 250 m 16 days [1]. It is an irregularly sampled time series +using the real date of each pixel from ''2009-08-05'' to ''2013-07-31''. +} +\author{ +Victor Maus, \email{vwmaus1@gmail.com} +} +\references{ +[1] Friedl MA, Sulla-Menashe D, Tan B, Schneider A, Ramankutty N, Sibley A, Huang X. (2010). +MODIS Collection 5 global land cover: Algorithm refinements and characterization of new +datasets. Remote Sensing of Environment, 114(1), 168 182. +} +\seealso{ +\link[dtwSat]{MOD13Q1.ts.list}, +\link[dtwSat]{MOD13Q1.patterns.list}. + +MOD13Q1 documentation: +\url{https://lpdaac.usgs.gov/dataset_discovery/modis/modis_products_table/mod13q1}. +} +\keyword{datasets} + diff --git a/man/MOD13Q1.ts.labels.Rd b/man/MOD13Q1.ts.labels.Rd new file mode 100644 index 0000000..26389ee --- /dev/null +++ b/man/MOD13Q1.ts.labels.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/data.R +\docType{data} +\name{MOD13Q1.ts.labels} +\alias{MOD13Q1.ts.labels} +\title{Data: Labels of the satellite time series in MOD13Q1.ts} +\format{An object of class \link[base]{data.frame}, whose attributas are: +the label of the crop class ''label'', the start of the crop period ''from'', +and the end of the crop period ''to''. The dates are in the format ''yyyy-mm-dd''.} +\usage{ +MOD13Q1.ts.labels +} +\description{ +This labels are based on field work. +} +\author{ +Victor Maus, \email{vwmaus1@gmail.com} +} +\seealso{ +\link[dtwSat]{MOD13Q1.ts}. +} +\keyword{datasets} + diff --git a/man/MOD13Q1.ts.list.Rd b/man/MOD13Q1.ts.list.Rd new file mode 100644 index 0000000..c4de6ca --- /dev/null +++ b/man/MOD13Q1.ts.list.Rd @@ -0,0 +1,34 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/data.R +\docType{data} +\name{MOD13Q1.ts.list} +\alias{MOD13Q1.ts.list} +\title{Data: A list of satellite time series} +\format{A \link[zoo]{zoo} object, whose indices are \code{\link[base]{Dates}} +in the format ''yyyy-mm-dd''. Each node has 6 attributes: ''ndvi'', +''evi'', ''red'', ''nir'', ''blue'', and ''mir''.} +\usage{ +MOD13Q1.ts.list +} +\description{ +This dataset has a list of time series based on the +MODIS product MOD13Q1 250 m 16 days [1]. It is an irregularly sampled time series +using the real date of each pixel from ''2009-08-05'' to ''2013-07-31''. +} +\author{ +Victor Maus, \email{vwmaus1@gmail.com} +} +\references{ +[1] Friedl MA, Sulla-Menashe D, Tan B, Schneider A, Ramankutty N, Sibley A, Huang X. (2010). +MODIS Collection 5 global land cover: Algorithm refinements and characterization of new +datasets. Remote Sensing of Environment, 114(1), 168 182. +} +\seealso{ +\link[dtwSat]{MOD13Q1.ts}, and +\link[dtwSat]{MOD13Q1.patterns.list}. + +MOD13Q1 documentation: +\url{https://lpdaac.usgs.gov/dataset_discovery/modis/modis_products_table/mod13q1}. +} +\keyword{datasets} + diff --git a/man/createPatterns.Rd b/man/createPatterns.Rd new file mode 100644 index 0000000..bcf71ce --- /dev/null +++ b/man/createPatterns.Rd @@ -0,0 +1,85 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/createPatterns.R +\docType{methods} +\name{createPatterns} +\alias{createPatterns} +\alias{createPatterns,twdtwTimeSeries-method} +\alias{createPatterns-twdtwMatches} +\title{Create patterns} +\usage{ +createPatterns(x, from = NULL, to = NULL, freq = 1, attr = NULL, + split = TRUE, formula, ...) + +\S4method{createPatterns}{twdtwTimeSeries}(x, from = NULL, to = NULL, + freq = 1, attr = NULL, split = TRUE, formula, ...) +} +\arguments{ +\item{x}{an object of class \code{\link[dtwSat]{twdtwTimeSeries}}.} + +\item{from}{A character or \code{\link[base]{Dates}} object in the format +"yyyy-mm-dd". If not informed it is equal to the smallest date of the +first element in x. See details.} + +\item{to}{A \code{\link[base]{character}} or \code{\link[base]{Dates}} +object in the format "yyyy-mm-dd". If not informed it is equal to the +greatest date of the first element in x. See details.} + +\item{freq}{An integer. The sampling frequency of the output patterns.} + +\item{attr}{A vector character or numeric. The attributes in \code{x} to be used. +If not declared the function uses all attributes.} + +\item{split}{A logical. If TRUE the samples are split by label. If FALSE +all samples are set to the same label.} + +\item{formula}{A formula. Argument to pass to \code{\link[mgcv]{gam}}.} + +\item{...}{other arguments to pass to the function \code{\link[mgcv]{gam}} in the +packege \pkg{mgcv}.} +} +\value{ +an object of class \code{\link[dtwSat]{twdtwTimeSeries}} +} +\description{ +Create temporal patterns from objects of class twdtwTimeSeries. +} +\details{ +The hidden assumption is that the temporal pattern is a cycle the repeats itself +within a given time interval. Therefore, all time series samples in \code{x} are aligned +to each other keeping their respective sequence of days of the year. The function fits a +Generalized Additive Model (GAM) to the aligned set of samples. +} +\examples{ +# Creating patterns from objects of class twdtwTimeSeries +evi = brick(system.file("lucc_MT/data/evi.tif", package="dtwSat")) +ndvi = brick(system.file("lucc_MT/data/ndvi.tif", package="dtwSat")) +timeline = scan(system.file("lucc_MT/data/timeline", package="dtwSat"), what="date") +rts = twdtwRaster(evi, ndvi, timeline=timeline) + +# Read field samples +\dontrun{ +field_samples = read.csv(system.file("lucc_MT/data/samples.csv", package="dtwSat")) +prj_string = scan(system.file("lucc_MT/data/samples_projection", package="dtwSat"), + what = "character") + +# Extract time series +ts = getTimeSeries(rts, y = field_samples, proj4string = prj_string) + +# Create temporal patterns +patt = createPatterns(x=ts, from="2005-09-01", to="2006-09-01", freq=8, formula = y~s(x)) + +# Plot patterns +autoplot(patt[[1]], facets = NULL) + xlab("Time") + ylab("Value") + +} +} +\author{ +Victor Maus, \email{vwmaus1@gmail.com} +} +\seealso{ +\code{\link[dtwSat]{twdtwMatches-class}}, +\code{\link[dtwSat]{twdtwTimeSeries-class}}, +\code{\link[dtwSat]{getTimeSeries}}, and +\code{\link[dtwSat]{twdtwApply}} +} + diff --git a/man/dtwSat.Rd b/man/dtwSat.Rd new file mode 100644 index 0000000..8a9a3e7 --- /dev/null +++ b/man/dtwSat.Rd @@ -0,0 +1,29 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/dwtSat.R +\name{dtwSat} +\alias{dtwSat} +\title{Time-Weighted Dynamic Time Warping for Satellite Image Time Series} +\description{ +Provides an implementation of the Time-Weighted Dynamic Time Warping +(TWDTW) method for land use and land cover mapping using satellite image time series [1]. +TWDTW is based on the Dynamic Time Warping technique and has achieved high accuracy +for land use and land cover classification using satellite data. The method is based +on comparing unclassified satellite image time series with a set of known temporal +patterns (e.g. phenological cycles associated with the vegetation). Using 'dtwSat' +the user can build temporal patterns for land cover types, apply the TWDTW analysis +for satellite datasets, visualize the results of the time series analysis, produce +land cover maps, and create temporal plots for land cover change analysis. +} +\author{ +Victor Maus, \email{vwmaus1@gmail.com} +} +\references{ +[1] Maus V, Camara G, Cartaxo R, Sanchez A, Ramos FM, de Queiroz, GR. +(2016). A Time-Weighted Dynamic Time Warping method for land use and land cover +mapping. Selected Topics in Applied Earth Observations and Remote Sensing, +IEEE Journal of, vol.PP, no.99, pp.1-11. +} +\seealso{ +\code{\link[dtwSat]{twdtwApply}} +} + diff --git a/man/get.Rd b/man/get.Rd new file mode 100644 index 0000000..d72415c --- /dev/null +++ b/man/get.Rd @@ -0,0 +1,55 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/getInternals.R +\docType{methods} +\name{get} +\alias{get} +\alias{getAlignments} +\alias{getAlignments,twdtwMatches-method} +\alias{getInternals} +\alias{getInternals,twdtwMatches-method} +\alias{getMatches} +\alias{getMatches,twdtwMatches-method} +\title{Get elements from twdtwMatches objects} +\usage{ +\S4method{getAlignments}{twdtwMatches}(object, timeseries.labels = NULL, + patterns.labels = NULL) + +\S4method{getInternals}{twdtwMatches}(object, timeseries.labels = NULL, + patterns.labels = NULL) + +\S4method{getMatches}{twdtwMatches}(object, timeseries.labels = NULL, + patterns.labels = NULL) +} +\arguments{ +\item{object}{an object of class twdtwMatches.} + +\item{timeseries.labels}{a vector with labels of the time series.} + +\item{patterns.labels}{a vector with labels of the patterns.} +} +\value{ +a list with TWDTW results or an object \code{\link[dtwSat]{twdtwTimeSeries-class}}. +} +\description{ +Get elements from \code{\link[dtwSat]{twdtwMatches-class}} objects. +} +\examples{ +# Getting patterns from objects of class twdtwMatches +patt = twdtwTimeSeries(MOD13Q1.patterns.list) +ts = twdtwTimeSeries(MOD13Q1.ts.list) +mat = twdtwApply(x=ts, y=patt, weight.fun=logisticWeight(-0.1,100), keep=TRUE) +getPatterns(mat) +getTimeSeries(mat) +getAlignments(mat) +getMatches(mat) +getInternals(mat) + +} +\author{ +Victor Maus, \email{vwmaus1@gmail.com} +} +\seealso{ +\code{\link[dtwSat]{twdtwMatches-class}}, and +\code{\link[dtwSat]{twdtwApply}} +} + diff --git a/man/getDatesFromDOY.Rd b/man/getDatesFromDOY.Rd new file mode 100644 index 0000000..2ca3e5f --- /dev/null +++ b/man/getDatesFromDOY.Rd @@ -0,0 +1,36 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/miscellaneous.R +\docType{methods} +\name{getDatesFromDOY} +\alias{getDatesFromDOY} +\title{Get dates from year and day of the year} +\usage{ +getDatesFromDOY(year, doy) +} +\arguments{ +\item{year}{An vector with the years.} + +\item{doy}{An vector with the day of the year. +It must have the same lenght as \code{year}.} +} +\value{ +A \code{\link[base]{Dates}} object. +} +\description{ +This function retrieves the date corresponding to the ginven +year and day of the year. +} +\examples{ +year = c(2000, 2001) +doy = c(366, 365) +dates = getDatesFromDOY(year, doy) +dates + +} +\author{ +Victor Maus, \email{vwmaus1@gmail.com} +} +\seealso{ +\link[dtwSat]{shiftDates} +} + diff --git a/man/getTimeSeries.Rd b/man/getTimeSeries.Rd new file mode 100644 index 0000000..183ffba --- /dev/null +++ b/man/getTimeSeries.Rd @@ -0,0 +1,91 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/getTimeSeries.R +\docType{methods} +\name{getTimeSeries} +\alias{getPatterns} +\alias{getPatterns,twdtwMatches-method} +\alias{getPatterns-twdtwMatches} +\alias{getTimeSeries} +\alias{getTimeSeries,twdtwMatches-method} +\alias{getTimeSeries,twdtwRaster-method} +\alias{getTimeSeries,twdtwTimeSeries-method} +\alias{getTimeSeries-twdtwMatches} +\alias{getTimeSeries-twdtwRaster} +\alias{getTimeSeries-twdtwTimeSeries} +\title{Get time series from twdtw* objects} +\usage{ +\S4method{getTimeSeries}{twdtwTimeSeries}(object, labels = NULL) + +\S4method{getTimeSeries}{twdtwMatches}(object, labels = NULL) + +\S4method{getPatterns}{twdtwMatches}(object, labels = NULL) + +\S4method{getTimeSeries}{twdtwRaster}(object, y, labels = NULL, + proj4string = NULL, id.labels = NULL) +} +\arguments{ +\item{object}{an object of class of class twdtw*.} + +\item{labels}{character vector with time series labels. For signature +\code{\link[dtwSat]{twdtwRaster}} this argument can be used to set the +labels for each sample in \code{y}, or it can be combined with \code{id.labels} +to select samples with a specific label.} + +\item{y}{a \code{\link[base]{data.frame}} whose attributes are: longitude, +latitude, the start ''from'' and the end ''to'' of the time interval +for each sample. This can also be a \code{\link[sp]{SpatialPointsDataFrame}} +whose attributes are the start ''from'' and the end ''to'' of the time interval. +If missing ''from'' and/or ''to'', they are set to the time range of the +\code{object}.} + +\item{proj4string}{projection string, see \code{\link[sp]{CRS-class}}. Used +if \code{y} is a \code{\link[base]{data.frame}}.} + +\item{id.labels}{a numeric or character with an column name from \code{y} to +be used as samples labels. Optional.} +} +\value{ +An object of class \code{\link[dtwSat]{twdtwTimeSeries}}. + +a list with TWDTW results or an object \code{\link[dtwSat]{twdtwTimeSeries-class}}. +} +\description{ +Get time series from objects of class twdtw*. +} +\examples{ +# Getting time series from objects of class twdtwTimeSeries +ts = twdtwTimeSeries(MOD13Q1.ts.list) +getTimeSeries(ts, 2) +# Getting time series from objects of class twdtwTimeSeries +ts = twdtwTimeSeries(MOD13Q1.ts.list) +patt = twdtwTimeSeries(MOD13Q1.patterns.list) +mat = twdtwApply(x=ts, y=patt) +getTimeSeries(mat, 2) +## This example creates a twdtwRaster object and extract time series from it. + +# Creating objects of class twdtwRaster with evi and ndvi time series +evi = brick(system.file("lucc_MT/data/evi.tif", package="dtwSat")) +ndvi = brick(system.file("lucc_MT/data/ndvi.tif", package="dtwSat")) +timeline = scan(system.file("lucc_MT/data/timeline", package="dtwSat"), what="date") +rts = twdtwRaster(evi, ndvi, timeline=timeline) + +# Location and time range +ts_location = data.frame(longitude = -55.96957, latitude = -12.03864, + from = "2007-09-01", to = "2013-09-01") +prj_string = "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0" + +## Extract time series +ts = getTimeSeries(rts, y = ts_location, proj4string = prj_string) + +autoplot(ts[[1]], facets = NULL) + xlab("Time") + ylab("Value") + +} +\author{ +Victor Maus, \email{vwmaus1@gmail.com} +} +\seealso{ +\code{\link[dtwSat]{twdtwRaster-class}}, +\code{\link[dtwSat]{twdtwTimeSeries-class}}, and +\code{\link[dtwSat]{twdtwMatches-class}} +} + diff --git a/man/linearWeight.Rd b/man/linearWeight.Rd new file mode 100644 index 0000000..b5b3cee --- /dev/null +++ b/man/linearWeight.Rd @@ -0,0 +1,48 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/linearWeight.R +\docType{methods} +\name{linearWeight} +\alias{linearWeight} +\title{Linear weight function} +\usage{ +linearWeight(a, b = 0) +} +\arguments{ +\item{a}{numeric. The slop of the line.} + +\item{b}{numeric. The intercept of the line.} +} +\value{ +An \code{\link[base]{function}} object. +} +\description{ +Builds a linear time weight +function to compute the TWDTW local cost matrix [1]. +} +\details{ +The linear \code{linearWeight} and \code{logisticWeight} weight functions +can be passed to \code{\link[dtwSat]{twdtwApply}} through the argument \code{weight.fun}. +This will add a time-weight to the dynamic time warping analysis. The time weight +creates a global constraint useful to analyse time series with phenological cycles +of vegetation that are usually bound to seasons. In previous studies by [1] the +logistic weight had better results than the linear for land cover classification. +See [1] for details about the method. +} +\examples{ +lin_fun = linearWeight(a=0.1) +lin_fun + +} +\author{ +Victor Maus, \email{vwmaus1@gmail.com} +} +\references{ +[1] Maus V, Camara G, Cartaxo R, Sanchez A, Ramos FM, de Queiroz, GR. +(2016). A Time-Weighted Dynamic Time Warping method for land use and land cover +mapping. Selected Topics in Applied Earth Observations and Remote Sensing, +IEEE Journal of, vol.PP, no.99, pp.1-11. +} +\seealso{ +\code{\link[dtwSat]{twdtwApply}} +} + diff --git a/man/logisticWeight.Rd b/man/logisticWeight.Rd new file mode 100644 index 0000000..980e169 --- /dev/null +++ b/man/logisticWeight.Rd @@ -0,0 +1,48 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/logisticWeight.R +\docType{methods} +\name{logisticWeight} +\alias{logisticWeight} +\title{Logistic weight function} +\usage{ +logisticWeight(alpha, beta) +} +\arguments{ +\item{alpha}{numeric. The steepness of logistic weight.} + +\item{beta}{numeric. The midpoint of logistic weight.} +} +\value{ +An \code{\link[base]{function}} object. +} +\description{ +Builds a logistic time weight +function to compute the TWDTW local cost matrix [1]. +} +\details{ +The linear \code{linearWeight} and \code{logisticWeight} weight functions +can be passed to \code{\link[dtwSat]{twdtwApply}} through the argument \code{weight.fun}. +This will add a time-weight to the dynamic time warping analysis. The time weight +creates a global constraint useful to analyse time series with phenological cycles +of vegetation that are usually bound to seasons. In previous studies by [1] the +logistic weight had better results than the linear for land cover classification. +See [1] for details about the method. +} +\examples{ +log_fun = logisticWeight(alpha=-0.1, beta=100) +log_fun + +} +\author{ +Victor Maus, \email{vwmaus1@gmail.com} +} +\references{ +[1] Maus V, Camara G, Cartaxo R, Sanchez A, Ramos FM, de Queiroz, GR. +(2016). A Time-Weighted Dynamic Time Warping method for land use and land cover +mapping. Selected Topics in Applied Earth Observations and Remote Sensing, +IEEE Journal of, vol.PP, no.99, pp.1-11. +} +\seealso{ +\code{\link[dtwSat]{twdtwApply}} +} + diff --git a/man/plot.Rd b/man/plot.Rd new file mode 100644 index 0000000..49c347f --- /dev/null +++ b/man/plot.Rd @@ -0,0 +1,64 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/plot.R +\docType{methods} +\name{plot} +\alias{plot} +\alias{plot,twdtwCrossValidation,ANY-method} +\alias{plot,twdtwMatches,ANY-method} +\alias{plot,twdtwRaster,ANY-method} +\alias{plot,twdtwTimeSeries,ANY-method} +\alias{plot-twdtwMatches} +\alias{plot-twdtwRaster} +\alias{plot-twdtwTimeSeries} +\title{Plotting twdtw* objects} +\usage{ +\S4method{plot}{twdtwCrossValidation,ANY}(x, type = "crossvalidation", ...) + +\S4method{plot}{twdtwTimeSeries,ANY}(x, type = "timeseries", ...) + +\S4method{plot}{twdtwMatches,ANY}(x, type = "alignments", ...) + +\S4method{plot}{twdtwRaster,ANY}(x, type = "maps", ...) +} +\arguments{ +\item{x}{An object of class twdtw*.} + +\item{type}{A character for the plot type: ''paths'', ''matches'', +''alignments'', ''classification'', ''cost'', ''patterns'', ''timeseries'', +''maps'', ''area'', ''changes'', and ''distance''.} + +\item{...}{additional arguments to pass to plotting functions. +\code{\link[dtwSat]{plotPaths}}, +\code{\link[dtwSat]{plotCostMatrix}}, +\code{\link[dtwSat]{plotAlignments}}, +\code{\link[dtwSat]{plotMatches}}, +\code{\link[dtwSat]{plotClassification}}, +\code{\link[dtwSat]{plotPatterns}}, +\code{\link[dtwSat]{plotTimeSeries}}, +\code{\link[dtwSat]{plotMaps}}, +\code{\link[dtwSat]{plotArea}}, or +\code{\link[dtwSat]{plotChanges}}.} +} +\value{ +A \link[ggplot2]{ggplot} object. +} +\description{ +Methods for plotting objects of class twdtw*. +} +\details{ +\describe{ + \item{Plot types}{: + \cr\code{paths}: Method for plotting the minimum paths in the cost matrix of TWDTW. + \cr\code{matches}: Method for plotting the matching points from TWDTW analysis. + \cr\code{alignments}: Method for plotting the alignments and respective TWDTW dissimilarity measures. + \cr\code{classification}: Method for plotting the classification of each subinterval of the time series based on TWDTW analysis. + \cr\code{cost}: Method for plotting the internal matrices used during the TWDTW computation. + \cr\code{patterns}: Method for plotting the temporal patterns. + \cr\code{timeseries}: Method for plotting the temporal patterns. + } +} +} +\author{ +Victor Maus, \email{vwmaus1@gmail.com} +} + diff --git a/man/plotAlignments.Rd b/man/plotAlignments.Rd new file mode 100644 index 0000000..00a3c51 --- /dev/null +++ b/man/plotAlignments.Rd @@ -0,0 +1,54 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/plotAlignments.R +\name{plotAlignments} +\alias{plotAlignments} +\title{Plotting alignments} +\usage{ +plotAlignments(x, timeseries.labels = NULL, patterns.labels = NULL, + attr = 1, threshold = Inf) +} +\arguments{ +\item{x}{An object of class \code{\link[dtwSat]{twdtwMatches}}.} + +\item{timeseries.labels}{the label or index of the time series. +Default is 1.} + +\item{patterns.labels}{a vector with labels of the patterns. If not +declared the function will plot the alignments for all patterna in \code{x}.} + +\item{attr}{An \link[base]{integer} or \link[base]{character} vector +indicating the attribute for plotting. Default is 1.} + +\item{threshold}{A number. The TWDTW dissimilarity threshold, \emph{i.e.} the +maximum TWDTW cost for consideration. Default is \code{Inf}.} +} +\value{ +A \link[ggplot2]{ggplot} object. +} +\description{ +Method for plotting the alignments and TWDTW +dissimilarity measures. +} +\examples{ +log_fun = logisticWeight(-0.1, 100) +ts = twdtwTimeSeries(MOD13Q1.ts.list) +patt = twdtwTimeSeries(MOD13Q1.patterns.list) +mat1 = twdtwApply(x=ts, y=patt, weight.fun=log_fun) + +plotAlignments(mat1) + +plotAlignments(mat1, attr=c("evi","ndvi")) + +} +\author{ +Victor Maus, \email{vwmaus1@gmail.com} +} +\seealso{ +\code{\link[dtwSat]{twdtwMatches-class}}, +\code{\link[dtwSat]{twdtwApply}}, +\code{\link[dtwSat]{plotPaths}}, +\code{\link[dtwSat]{plotCostMatrix}}, +\code{\link[dtwSat]{plotMatches}}, and +\code{\link[dtwSat]{plotClassification}}. +} + diff --git a/man/plotArea.Rd b/man/plotArea.Rd new file mode 100644 index 0000000..5a368fb --- /dev/null +++ b/man/plotArea.Rd @@ -0,0 +1,75 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/plotArea.R +\name{plotArea} +\alias{plotArea} +\title{Plotting maps} +\usage{ +plotArea(x, time.levels = NULL, time.labels = NULL, class.levels = NULL, + class.labels = NULL, class.colors = NULL) +} +\arguments{ +\item{x}{An object of class \code{\link[dtwSat]{twdtwRaster}}.} + +\item{time.levels}{A \link[base]{character} or \link[base]{numeric} +vector with the layers to plot. For plot type ''change'' the minimum length +is two.} + +\item{time.labels}{A \link[base]{character} or \link[base]{numeric} +vector with the labels of the layers. It must have the same +length as time.levels. Default is NULL.} + +\item{class.levels}{A \link[base]{character} or \link[base]{numeric} +vector with the levels of the raster values. Default is NULL.} + +\item{class.labels}{A \link[base]{character} or \link[base]{numeric} +vector with the labels of the raster values. It must have the same +length as class.levels. Default is NULL.} + +\item{class.colors}{a set of aesthetic values. It must have the same +length as class.levels. Default is NULL. See +\link[ggplot2]{scale_fill_manual} for details.} +} +\value{ +A \link[ggplot2]{ggplot} object. +} +\description{ +Method for plotting time series of maps. +} +\examples{ +\dontrun{ +# Run TWDTW analysis for raster time series +patt = MOD13Q1.MT.yearly.patterns +evi = brick(system.file("lucc_MT/data/evi.tif", package="dtwSat")) +ndvi = brick(system.file("lucc_MT/data/ndvi.tif", package="dtwSat")) +red = brick(system.file("lucc_MT/data/red.tif", package="dtwSat")) +blue = brick(system.file("lucc_MT/data/blue.tif", package="dtwSat")) +nir = brick(system.file("lucc_MT/data/nir.tif", package="dtwSat")) +mir = brick(system.file("lucc_MT/data/mir.tif", package="dtwSat")) +doy = brick(system.file("lucc_MT/data/doy.tif", package="dtwSat")) +timeline = scan(system.file("lucc_MT/data/timeline", package="dtwSat"), what="date") +rts = twdtwRaster(evi, ndvi, red, blue, nir, mir, timeline = timeline, doy = doy) + +time_interval = seq(from=as.Date("2007-09-01"), to=as.Date("2013-09-01"), + by="12 month") +log_fun = weight.fun=logisticWeight(-0.1,50) + +r_twdtw = twdtwApply(x=rts, y=patt, weight.fun=log_fun, breaks=time_interval, + filepath="~/test_twdtw", overwrite=TRUE, format="GTiff", mc.cores=3) + +r_lucc = twdtwClassify(r_twdtw, format="GTiff") + +plotArea(r_lucc) + +} +} +\author{ +Victor Maus, \email{vwmaus1@gmail.com} +} +\seealso{ +\code{\link[dtwSat]{twdtwRaster-class}}, +\code{\link[dtwSat]{twdtwApply}}, +\code{\link[dtwSat]{plotMaps}}, +\code{\link[dtwSat]{plotChanges}}, and +\code{\link[dtwSat]{plotDistance}}. +} + diff --git a/man/plotChanges.Rd b/man/plotChanges.Rd new file mode 100644 index 0000000..800d047 --- /dev/null +++ b/man/plotChanges.Rd @@ -0,0 +1,75 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/plotChanges.R +\name{plotChanges} +\alias{plotChanges} +\title{Plotting changes} +\usage{ +plotChanges(x, time.levels = NULL, time.labels = NULL, + class.levels = NULL, class.labels = NULL, class.colors = NULL) +} +\arguments{ +\item{x}{An object of class \code{\link[dtwSat]{twdtwRaster}}.} + +\item{time.levels}{A \link[base]{character} or \link[base]{numeric} +vector with the layers to plot. For plot type ''change'' the minimum length +is two.} + +\item{time.labels}{A \link[base]{character} or \link[base]{numeric} +vector with the labels of the layers. It must have the same +length as time.levels. Default is NULL.} + +\item{class.levels}{A \link[base]{character} or \link[base]{numeric} +vector with the levels of the raster values. Default is NULL.} + +\item{class.labels}{A \link[base]{character} or \link[base]{numeric} +vector with the labels of the raster values. It must have the same +length as class.levels. Default is NULL.} + +\item{class.colors}{a set of aesthetic values. It must have the same +length as class.levels. Default is NULL. See +\link[ggplot2]{scale_fill_manual} for details.} +} +\value{ +A \link[ggplot2]{ggplot} object. +} +\description{ +Method for plotting changes over time. +} +\examples{ +\dontrun{ +# Run TWDTW analysis for raster time series +patt = MOD13Q1.MT.yearly.patterns +evi = brick(system.file("lucc_MT/data/evi.tif", package="dtwSat")) +ndvi = brick(system.file("lucc_MT/data/ndvi.tif", package="dtwSat")) +red = brick(system.file("lucc_MT/data/red.tif", package="dtwSat")) +blue = brick(system.file("lucc_MT/data/blue.tif", package="dtwSat")) +nir = brick(system.file("lucc_MT/data/nir.tif", package="dtwSat")) +mir = brick(system.file("lucc_MT/data/mir.tif", package="dtwSat")) +doy = brick(system.file("lucc_MT/data/doy.tif", package="dtwSat")) +timeline = scan(system.file("lucc_MT/data/timeline", package="dtwSat"), what="date") +rts = twdtwRaster(evi, ndvi, red, blue, nir, mir, timeline = timeline, doy = doy) + +time_interval = seq(from=as.Date("2007-09-01"), to=as.Date("2013-09-01"), + by="12 month") +log_fun = weight.fun=logisticWeight(-0.1,50) + +r_twdtw = twdtwApply(x=rts, y=patt, weight.fun=log_fun, breaks=time_interval, + filepath="~/test_twdtw", overwrite=TRUE, format="GTiff") + +r_lucc = twdtwClassify(r_twdtw, format="GTiff", overwrite=TRUE) + +plotChanges(r_lucc) + +} +} +\author{ +Victor Maus, \email{vwmaus1@gmail.com} +} +\seealso{ +\code{\link[dtwSat]{twdtwRaster-class}}, +\code{\link[dtwSat]{twdtwApply}}, +\code{\link[dtwSat]{plotArea}}, +\code{\link[dtwSat]{plotMaps}}, and +\code{\link[dtwSat]{plotDistance}}. +} + diff --git a/man/plotClassification.Rd b/man/plotClassification.Rd new file mode 100644 index 0000000..2e96699 --- /dev/null +++ b/man/plotClassification.Rd @@ -0,0 +1,59 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/plotClassification.R +\name{plotClassification} +\alias{plotClassification} +\title{Plotting subintervals classification} +\usage{ +plotClassification(x, timeseries.labels = NULL, patterns.labels = NULL, + attr, ...) +} +\arguments{ +\item{x}{An object of class \code{\link[dtwSat]{twdtwMatches}}.} + +\item{timeseries.labels}{the label or index of the time series. +Default is 1.} + +\item{patterns.labels}{a vector with labels of the patterns. If not +declared the function will plot one alignment for each pattern.} + +\item{attr}{An \link[base]{integer} vector or \link[base]{character} vector +indicating the attribute for plotting. If not declared the function will plot +all attributes.} + +\item{...}{additional arguments passed to \code{\link[dtwSat]{twdtwClassify}}.} +} +\value{ +A \link[ggplot2]{ggplot} object. +} +\description{ +Method for plotting the classification of each +subinterval of the time series based on TWDTW analysis. +} +\examples{ +log_fun = logisticWeight(-0.1, 100) +ts = twdtwTimeSeries(MOD13Q1.ts.list) +patt = twdtwTimeSeries(MOD13Q1.patterns.list) +mat1 = twdtwApply(x=ts, y=patt, weight.fun=log_fun) + +# Classify interval +from = as.Date("2007-09-01") +to = as.Date("2013-09-01") +by = "6 month" +gp = plotClassification(x=mat1, from=from, to=to, by=by, overlap=.5) +gp + + +} +\author{ +Victor Maus, \email{vwmaus1@gmail.com} +} +\seealso{ +\code{\link[dtwSat]{twdtwMatches-class}}, +\code{\link[dtwSat]{twdtwApply}}, +\code{\link[dtwSat]{twdtwClassify}}, +\code{\link[dtwSat]{plotAlignments}}, +\code{\link[dtwSat]{plotPaths}}, +\code{\link[dtwSat]{plotMatches}}, and +\code{\link[dtwSat]{plotCostMatrix}}. +} + diff --git a/man/plotCostMatrix.Rd b/man/plotCostMatrix.Rd new file mode 100644 index 0000000..db46c1a --- /dev/null +++ b/man/plotCostMatrix.Rd @@ -0,0 +1,54 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/plotCostMatrix.R +\name{plotCostMatrix} +\alias{plotCostMatrix} +\title{Plotting paths} +\usage{ +plotCostMatrix(x, timeseries.labels = NULL, patterns.labels = NULL, + matrix.name = "costMatrix") +} +\arguments{ +\item{x}{An object of class \code{\link[dtwSat]{twdtwMatches}}.} + +\item{timeseries.labels}{the label or index of the time series. +Default is 1.} + +\item{patterns.labels}{a vector with labels of the patterns. If not +declared the function will plot one alignment for each pattern.} + +\item{matrix.name}{A character. The name of the matrix to plot, +"costMatrix" for accumulated cost, "localMatrix" for local cost, +or "timeWeight" for time-weight. Default is "costMatrix".} +} +\value{ +A \link[ggplot2]{ggplot} object. +} +\description{ +Method for plotting low cost paths in the TWDTW +cost matrix. +} +\examples{ +log_fun = logisticWeight(-0.1, 100) +ts = twdtwTimeSeries(MOD13Q1.ts.list) +patt = twdtwTimeSeries(MOD13Q1.patterns.list) +mat1 = twdtwApply(x=ts, y=patt, weight.fun=log_fun, keep=TRUE) + +plotCostMatrix(mat1, matrix.name="costMatrix") + +plotCostMatrix(mat1, matrix.name="localMatrix") + +plotCostMatrix(mat1, matrix.name="timeWeight") + +} +\author{ +Victor Maus, \email{vwmaus1@gmail.com} +} +\seealso{ +\code{\link[dtwSat]{twdtwMatches-class}}, +\code{\link[dtwSat]{twdtwApply}}, +\code{\link[dtwSat]{plotAlignments}}, +\code{\link[dtwSat]{plotPaths}}, +\code{\link[dtwSat]{plotMatches}}, and +\code{\link[dtwSat]{plotClassification}}. +} + diff --git a/man/plotCrossValidation.Rd b/man/plotCrossValidation.Rd new file mode 100644 index 0000000..67815a0 --- /dev/null +++ b/man/plotCrossValidation.Rd @@ -0,0 +1,66 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/plotCrossValidation.R +\name{plotCrossValidation} +\alias{plotCrossValidation} +\title{Plotting cross-validation} +\usage{ +plotCrossValidation(x, conf.int = 0.95) +} +\arguments{ +\item{x}{An object of class \code{\link[dtwSat]{plotCrossValidation}}.} + +\item{conf.int}{confidence level (0-1) for interval estimation of the population mean. +for details see \code{\link[Hmisc]{smean.cl.normal}}.} +} +\value{ +A \link[ggplot2]{ggplot} object. +} +\description{ +Method for plotting cross-validation results. +} +\examples{ +\dontrun{ +# Data folder +data_folder = system.file("lucc_MT/data", package = "dtwSat") + +# Read dates +dates = scan(paste(data_folder,"timeline", sep = "/"), what = "dates") + +# Read raster time series +evi = brick(paste(data_folder,"evi.tif", sep = "/")) +raster_timeseries = twdtwRaster(evi, timeline = dates) + +# Read field samples +field_samples = read.csv(paste(data_folder,"samples.csv", sep = "/")) +table(field_samples[["label"]]) + +# Read field samples projection +proj_str = scan(paste(data_folder,"samples_projection", sep = "/"), + what = "character") + +# Get sample time series from raster time series +field_samples_ts = getTimeSeries(raster_timeseries, + y = field_samples, proj4string = proj_str) +field_samples_ts + +# Run cross validation +set.seed(1) +# Define TWDTW weight function +log_fun = logisticWeight(alpha=-0.1, beta=50) +cross_validation = twdtwCrossValidation(field_samples_ts, times=3, p=0.1, + freq = 8, formula = y ~ s(x, bs="cc"), weight.fun = log_fun) + +summary(cross_validation) + +plot(cross_validation, conf.int=.99) + +} + +} +\author{ +Victor Maus, \email{vwmaus1@gmail.com} +} +\seealso{ +\code{\link[dtwSat]{twdtwCrossValidation}} +} + diff --git a/man/plotDistance.Rd b/man/plotDistance.Rd new file mode 100644 index 0000000..8452998 --- /dev/null +++ b/man/plotDistance.Rd @@ -0,0 +1,64 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/plotDistance.R +\name{plotDistance} +\alias{plotDistance} +\title{Plotting distance maps} +\usage{ +plotDistance(x, time.levels = 1, time.labels = 1, layers = NULL) +} +\arguments{ +\item{x}{An object of class \code{\link[dtwSat]{twdtwRaster}}.} + +\item{time.levels}{A \link[base]{character} or \link[base]{numeric} +vector with the layers to plot. For plot type ''change'' the minimum length +is two.} + +\item{time.labels}{A \link[base]{character} or \link[base]{numeric} +vector with the labels of the layers. It must have the same +length as time.levels. Default is NULL.} + +\item{layers}{A \link[base]{character} or \link[base]{numeric} +vector with the layers/bands of the raster time series.} +} +\value{ +A \link[ggplot2]{ggplot} object. +} +\description{ +Method for plotting TWDTW distance maps. +} +\examples{ +\dontrun{ +# Run TWDTW analysis for raster time series +patt = MOD13Q1.MT.yearly.patterns +evi = brick(system.file("lucc_MT/data/evi.tif", package="dtwSat")) +ndvi = brick(system.file("lucc_MT/data/ndvi.tif", package="dtwSat")) +red = brick(system.file("lucc_MT/data/red.tif", package="dtwSat")) +blue = brick(system.file("lucc_MT/data/blue.tif", package="dtwSat")) +nir = brick(system.file("lucc_MT/data/nir.tif", package="dtwSat")) +mir = brick(system.file("lucc_MT/data/mir.tif", package="dtwSat")) +doy = brick(system.file("lucc_MT/data/doy.tif", package="dtwSat")) +timeline = scan(system.file("lucc_MT/data/timeline", package="dtwSat"), what="date") +rts = twdtwRaster(evi, ndvi, red, blue, nir, mir, timeline = timeline, doy = doy) + +time_interval = seq(from=as.Date("2007-09-01"), to=as.Date("2013-09-01"), + by="12 month") +log_fun = weight.fun=logisticWeight(-0.1,50) + +r_twdtw = twdtwApply(x=rts, y=patt, weight.fun=log_fun, breaks=time_interval, + filepath="~/test_twdtw", overwrite=TRUE, format="GTiff", mc.cores=3) + +plotDistance(r_twdtw) + +} +} +\author{ +Victor Maus, \email{vwmaus1@gmail.com} +} +\seealso{ +\code{\link[dtwSat]{twdtwRaster-class}}, +\code{\link[dtwSat]{twdtwApply}}, +\code{\link[dtwSat]{plotArea}}, +\code{\link[dtwSat]{plotChanges}}, and +\code{\link[dtwSat]{plotDistance}}. +} + diff --git a/man/plotMaps.Rd b/man/plotMaps.Rd new file mode 100644 index 0000000..e28a2ee --- /dev/null +++ b/man/plotMaps.Rd @@ -0,0 +1,75 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/plotMaps.R +\name{plotMaps} +\alias{plotMaps} +\title{Plotting maps} +\usage{ +plotMaps(x, time.levels = NULL, time.labels = NULL, class.levels = NULL, + class.labels = NULL, class.colors = NULL) +} +\arguments{ +\item{x}{An object of class \code{\link[dtwSat]{twdtwRaster}}.} + +\item{time.levels}{A \link[base]{character} or \link[base]{numeric} +vector with the layers to plot. For plot type ''change'' the minimum length +is two.} + +\item{time.labels}{A \link[base]{character} or \link[base]{numeric} +vector with the labels of the layers. It must have the same +length as time.levels. Default is NULL.} + +\item{class.levels}{A \link[base]{character} or \link[base]{numeric} +vector with the levels of the raster values. Default is NULL.} + +\item{class.labels}{A \link[base]{character} or \link[base]{numeric} +vector with the labels of the raster values. It must have the same +length as class.levels. Default is NULL.} + +\item{class.colors}{a set of aesthetic values. It must have the same +length as class.levels. Default is NULL. See +\link[ggplot2]{scale_fill_manual} for details.} +} +\value{ +A \link[ggplot2]{ggplot} object. +} +\description{ +Method for plotting time series of maps. +} +\examples{ +\dontrun{ +# Run TWDTW analysis for raster time series +patt = MOD13Q1.MT.yearly.patterns +evi = brick(system.file("lucc_MT/data/evi.tif", package="dtwSat")) +ndvi = brick(system.file("lucc_MT/data/ndvi.tif", package="dtwSat")) +red = brick(system.file("lucc_MT/data/red.tif", package="dtwSat")) +blue = brick(system.file("lucc_MT/data/blue.tif", package="dtwSat")) +nir = brick(system.file("lucc_MT/data/nir.tif", package="dtwSat")) +mir = brick(system.file("lucc_MT/data/mir.tif", package="dtwSat")) +doy = brick(system.file("lucc_MT/data/doy.tif", package="dtwSat")) +timeline = scan(system.file("lucc_MT/data/timeline", package="dtwSat"), what="date") +rts = twdtwRaster(evi, ndvi, red, blue, nir, mir, timeline = timeline, doy = doy) + +time_interval = seq(from=as.Date("2007-09-01"), to=as.Date("2013-09-01"), + by="12 month") +log_fun = weight.fun=logisticWeight(-0.1,50) + +r_twdtw = twdtwApply(x=rts, y=patt, weight.fun=log_fun, breaks=time_interval, + filepath="~/test_twdtw", overwrite=TRUE, format="GTiff", mc.cores=3) + +r_lucc = twdtwClassify(r_twdtw, format="GTiff", overwrite=TRUE) + +plotMaps(r_lucc) + +} +} +\author{ +Victor Maus, \email{vwmaus1@gmail.com} +} +\seealso{ +\code{\link[dtwSat]{twdtwRaster-class}}, +\code{\link[dtwSat]{twdtwApply}}, +\code{\link[dtwSat]{plotArea}}, +\code{\link[dtwSat]{plotChanges}}, and +\code{\link[dtwSat]{plotDistance}}. +} + diff --git a/man/plotMatches.Rd b/man/plotMatches.Rd new file mode 100644 index 0000000..a916014 --- /dev/null +++ b/man/plotMatches.Rd @@ -0,0 +1,65 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/plotMatches.R +\docType{methods} +\name{plotMatches} +\alias{plotMatches} +\title{Plotting matching points} +\usage{ +plotMatches(x, timeseries.labels = 1, patterns.labels = NULL, k = 1, + attr = 1, shift = 0.5, show.dist = FALSE) +} +\arguments{ +\item{x}{An object of class \code{\link[dtwSat]{twdtwMatches}}.} + +\item{timeseries.labels}{the label or index of the time series. +Default is 1.} + +\item{patterns.labels}{a vector with labels of the patterns. If not +declared the function will plot one alignment for each pattern.} + +\item{k}{A positive integer. The index of the last alignment to include in +the plot. If not declared the function will plot the best match for +each pattern.} + +\item{attr}{An \link[base]{integer} or \link[base]{character} vector +indicating the attribute for plotting. Default is 1.} + +\item{shift}{A number, it shifts the pattern position in the \code{x} +direction. Default is 0.5.} + +\item{show.dist}{show the distance for each alignment. Default is FALSE.} +} +\value{ +A \link[ggplot2]{ggplot} object. +} +\description{ +Method for plotting the matching points from +TWDTW analysis. +} +\examples{ +log_fun = logisticWeight(-0.1, 100) +ts = twdtwTimeSeries(MOD13Q1.ts.list) +patt = twdtwTimeSeries(MOD13Q1.patterns.list) +mat1 = twdtwApply(x=ts, y=patt, weight.fun=log_fun, keep=TRUE) + +plotMatches(mat1) + +plotMatches(mat1, patterns.labels="Soybean", k=4) + +plotMatches(mat1, patterns.labels=c("Soybean","Maize"), k=4) + +plotMatches(mat1, patterns.labels=c("Soybean","Cotton"), k=c(3,1)) + +} +\author{ +Victor Maus, \email{vwmaus1@gmail.com} +} +\seealso{ +\code{\link[dtwSat]{twdtwMatches-class}}, +\code{\link[dtwSat]{twdtwApply}}, +\code{\link[dtwSat]{plotPaths}}, +\code{\link[dtwSat]{plotCostMatrix}}, +\code{\link[dtwSat]{plotAlignments}}, and +\code{\link[dtwSat]{plotClassification}}. +} + diff --git a/man/plotPaths.Rd b/man/plotPaths.Rd new file mode 100644 index 0000000..469c648 --- /dev/null +++ b/man/plotPaths.Rd @@ -0,0 +1,52 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/plotPaths.R +\name{plotPaths} +\alias{plotPaths} +\title{Plotting paths} +\usage{ +plotPaths(x, timeseries.labels = NULL, patterns.labels = NULL, k = NULL) +} +\arguments{ +\item{x}{An object of class \code{\link[dtwSat]{twdtwMatches}}.} + +\item{timeseries.labels}{the label or index of the time series. +Default is 1.} + +\item{patterns.labels}{a vector with labels of the patterns. If not +declared the function will plot one alignment for each pattern.} + +\item{k}{A positive integer. The index of the last alignment to include in +the plot. If not declared the function will plot all low cost paths.} +} +\value{ +A \link[ggplot2]{ggplot} object. +} +\description{ +Method for plotting low cost paths in the TWDTW +cost matrix. +} +\examples{ +log_fun = logisticWeight(-0.1, 100) +ts = twdtwTimeSeries(MOD13Q1.ts.list) +patt = twdtwTimeSeries(MOD13Q1.patterns.list) +mat1 = twdtwApply(x=ts, y=patt, weight.fun=log_fun, keep=TRUE) + +plotPaths(mat1) + +plotPaths(mat1, patterns.labels="Soybean", k=1:2) + +plotPaths(mat1, patterns.labels=c("Maize","Cotton"), k=2) + +} +\author{ +Victor Maus, \email{vwmaus1@gmail.com} +} +\seealso{ +\code{\link[dtwSat]{twdtwMatches-class}}, +\code{\link[dtwSat]{twdtwApply}}, +\code{\link[dtwSat]{plotAlignments}}, +\code{\link[dtwSat]{plotCostMatrix}}, +\code{\link[dtwSat]{plotMatches}}, and +\code{\link[dtwSat]{plotClassification}}. +} + diff --git a/man/plotPatterns.Rd b/man/plotPatterns.Rd new file mode 100644 index 0000000..c285d45 --- /dev/null +++ b/man/plotPatterns.Rd @@ -0,0 +1,42 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/plotPatterns.R +\name{plotPatterns} +\alias{plotPatterns} +\title{Plotting temporal patterns} +\usage{ +plotPatterns(x, labels = NULL, attr, year = 2005) +} +\arguments{ +\item{x}{An object of class \code{\link[dtwSat]{twdtwTimeSeries}}, +\code{\link[zoo]{zoo}}, or list of \code{\link[zoo]{zoo}}.} + +\item{labels}{a vector with labels of the time series. If not declared +the function will plot all time series.} + +\item{attr}{An \link[base]{integer} vector or \link[base]{character} vector +indicating the attribute for plotting. If not declared the function will plot +all attributes.} + +\item{year}{An integer. The base year to shift the dates of the time series to. +If NULL then it does not shif the time series. Default is 2005.} +} +\value{ +A \link[ggplot2]{ggplot} object. +} +\description{ +Method for plotting the temporal patterns. +} +\examples{ +patt = twdtwTimeSeries(MOD13Q1.patterns.list) +plotPatterns(patt) +plotPatterns(patt, attr="evi") + +} +\author{ +Victor Maus, \email{vwmaus1@gmail.com} +} +\seealso{ +\code{\link[dtwSat]{twdtwTimeSeries-class}} and +\code{\link[dtwSat]{plotTimeSeries}} +} + diff --git a/man/plotTimeSeries.Rd b/man/plotTimeSeries.Rd new file mode 100644 index 0000000..c48ee23 --- /dev/null +++ b/man/plotTimeSeries.Rd @@ -0,0 +1,39 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/plotTimeSeries.R +\name{plotTimeSeries} +\alias{plotTimeSeries} +\title{Plotting time series} +\usage{ +plotTimeSeries(x, labels = NULL, attr) +} +\arguments{ +\item{x}{An object of class \code{\link[dtwSat]{twdtwTimeSeries}}, +\code{\link[zoo]{zoo}}, or list of \code{\link[zoo]{zoo}}.} + +\item{labels}{a vector with labels of the time series. If missing, all +elements in the list will be plotted (up to a maximum of 16).} + +\item{attr}{An \link[base]{integer} vector or \link[base]{character} vector +indicating the attribute for plotting. If not declared the function will plot +all attributes.} +} +\value{ +A \link[ggplot2]{ggplot} object. +} +\description{ +Method for plotting the temporal patterns. +} +\examples{ +ts = twdtwTimeSeries(MOD13Q1.ts.list) +plotTimeSeries(ts) +plotTimeSeries(ts, attr="evi") + +} +\author{ +Victor Maus, \email{vwmaus1@gmail.com} +} +\seealso{ +\code{\link[dtwSat]{twdtwTimeSeries-class}} and +\code{\link[dtwSat]{plotPatterns}} +} + diff --git a/man/reexports.Rd b/man/reexports.Rd new file mode 100644 index 0000000..b656e63 --- /dev/null +++ b/man/reexports.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/zzz.R +\docType{import} +\name{reexports} +\alias{asymmetric} +\alias{rabinerJuangStepPattern} +\alias{reexports} +\alias{symmetric1} +\alias{symmetric2} +\title{Objects exported from other packages} +\description{ +These objects are imported from other packages. Follow the links +below to see their documentation. + +\describe{ + \item{dtw}{\code{\link[dtw]{symmetric1}}, \code{\link[dtw]{symmetric2}}, \code{\link[dtw]{asymmetric}}, \code{\link[dtw]{rabinerJuangStepPattern}}} +}} +\keyword{internal} + diff --git a/man/resampleTimeSeries.Rd b/man/resampleTimeSeries.Rd new file mode 100644 index 0000000..4edac62 --- /dev/null +++ b/man/resampleTimeSeries.Rd @@ -0,0 +1,43 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/resampleTimeSeries.R +\docType{methods} +\name{resampleTimeSeries} +\alias{resampleTimeSeries} +\alias{resampleTimeSeries,twdtwTimeSeries-method} +\alias{resampleTimeSeries-twdtwMatches} +\title{Resample time series} +\usage{ +resampleTimeSeries(object, length = NULL) + +\S4method{resampleTimeSeries}{twdtwTimeSeries}(object, length = NULL) +} +\arguments{ +\item{object}{an object of class twdtwTimeSeries.} + +\item{length}{An integer. The number of samples to resample the time series. +If not declared the length is set to the length of the longest time series.} +} +\value{ +An object of class \code{\link[dtwSat]{twdtwTimeSeries}} whose +time series have the same number of samples (points). +} +\description{ +resample time series in the same object to have the same +the length. +} +\examples{ +# Resampling time series from objects of class twdtwTimeSeries +patt = twdtwTimeSeries(MOD13Q1.patterns.list) +npatt = resampleTimeSeries(patt, length=46) +nrow(patt) +nrow(npatt) + +} +\author{ +Victor Maus, \email{vwmaus1@gmail.com} +} +\seealso{ +\code{\link[dtwSat]{twdtwTimeSeries-class}}, and +\code{\link[dtwSat]{twdtwApply}} +} + diff --git a/man/shiftDates.Rd b/man/shiftDates.Rd new file mode 100644 index 0000000..76d33e0 --- /dev/null +++ b/man/shiftDates.Rd @@ -0,0 +1,48 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/miscellaneous.R +\docType{methods} +\name{shiftDates} +\alias{shiftDates} +\alias{shiftDates,list-method} +\alias{shiftDates,twdtwTimeSeries-method} +\alias{shiftDates,zoo-method} +\alias{shiftDates-list} +\alias{shiftDates-twdtwTimeSeries} +\alias{shiftDates-zoo} +\title{Shift dates} +\usage{ +shiftDates(object, year = NULL) + +\S4method{shiftDates}{twdtwTimeSeries}(object, year = NULL) + +\S4method{shiftDates}{list}(object, year = NULL) + +\S4method{shiftDates}{zoo}(object, year = NULL) +} +\arguments{ +\item{object}{\code{\link[dtwSat]{twdtwTimeSeries}} objects, +\code{\link[zoo]{zoo}} objects or a list of \code{\link[zoo]{zoo}} objects.} + +\item{year}{the base year to shit the time series.} +} +\value{ +An object of the same class as the input \code{object}. +} +\description{ +This function shifts the dates of the time series to a +given base year. +} +\examples{ +patt = twdtwTimeSeries(MOD13Q1.patterns.list) +npatt = shiftDates(patt, year=2005) +index(patt) +index(npatt) + +} +\author{ +Victor Maus, \email{vwmaus1@gmail.com} +} +\seealso{ +\code{\link[dtwSat]{twdtwTimeSeries-class}} +} + diff --git a/man/subset.Rd b/man/subset.Rd new file mode 100644 index 0000000..0b393f2 --- /dev/null +++ b/man/subset.Rd @@ -0,0 +1,84 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/subset.R +\docType{methods} +\name{subset} +\alias{subset} +\alias{subset,twdtwMatches-method} +\alias{subset,twdtwRaster-method} +\alias{subset,twdtwTimeSeries-method} +\alias{subset-twdtwMatches} +\alias{subset-twdtwRaster} +\alias{subset-twdtwTimeSeries} +\title{Subset time series} +\usage{ +\S4method{subset}{twdtwTimeSeries}(x, labels = NULL) + +\S4method{subset}{twdtwMatches}(x, timeseries.labels = NULL, + patterns.labels = NULL, k = NULL) + +\S4method{subset}{twdtwRaster}(x, e = NULL, layers = NULL) +} +\arguments{ +\item{x}{An objects of class twdtw*.} + +\item{labels}{character vector with time series labels.} + +\item{timeseries.labels}{a vector with labels of the time series.} + +\item{patterns.labels}{a vector with labels of the patterns.} + +\item{k}{A positive integer. The index of the last alignment to include in +the subset.} + +\item{e}{An extent object, or any object from which an Extent object can +be extracted. See \link[raster]{crop} for details.} + +\item{layers}{a vector with the names of the \code{twdtwRaster} object to include in +the subset.} +} +\value{ +an object of class twdtw*. +} +\description{ +Get subsets from objects of class twdtw*. +} +\examples{ +# Getting time series from objects of class twdtwTimeSeries +ts = twdtwTimeSeries(MOD13Q1.ts.list) +ts = subset(ts, 2) +ts +# Getting time series from objects of class twdtwTimeSeries +patt = twdtwTimeSeries(MOD13Q1.patterns.list) +mat = twdtwApply(x=ts, y=patt, weight.fun=logisticWeight(-0.1,100)) +mat = subset(mat, k=4) + +## This example creates a twdtwRaster object and extract time series from it. + +# Creating objects of class twdtwRaster with evi and ndvi time series +evi = brick(system.file("lucc_MT/data/evi.tif", package="dtwSat")) +ndvi = brick(system.file("lucc_MT/data/ndvi.tif", package="dtwSat")) +timeline = scan(system.file("lucc_MT/data/timeline", package="dtwSat"), what="date") +rts = twdtwRaster(evi, ndvi, timeline=timeline) + +rts_evi = subset(rts, layers="evi") + +field_samples = read.csv(system.file("lucc_MT/data/samples.csv", package="dtwSat")) +prj_string = scan(system.file("lucc_MT/data/samples_projection", package="dtwSat"), + what = "character") + +# Extract time series +ts_evi = getTimeSeries(rts_evi, y = field_samples, proj4string = prj_string) + +# subset all labels = "Forest" +ts_forest = subset(ts_evi, labels="Forest") + +} +\author{ +Victor Maus, \email{vwmaus1@gmail.com} +} +\seealso{ +\code{\link[dtwSat]{twdtwRaster-class}}, +\code{\link[dtwSat]{twdtwTimeSeries-class}}, and +\code{\link[dtwSat]{twdtwMatches-class}} +} + diff --git a/man/twdtwApply.Rd b/man/twdtwApply.Rd new file mode 100644 index 0000000..9d2ec01 --- /dev/null +++ b/man/twdtwApply.Rd @@ -0,0 +1,175 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/twdtwApply.R +\docType{methods} +\name{twdtwApply} +\alias{twdtwApply} +\alias{twdtwApply,twdtwRaster-method} +\alias{twdtwApply,twdtwTimeSeries-method} +\alias{twdtwApply-twdtwRaster} +\alias{twdtwApply-twdtwTimeSeries} +\title{Apply TWDTW analysis} +\usage{ +twdtwApply(x, y, resample = TRUE, length = NULL, weight.fun = NULL, + dist.method = "Euclidean", step.matrix = symmetric1, n = NULL, + span = NULL, min.length = 0.5, theta = 0.5, ...) + +\S4method{twdtwApply}{twdtwTimeSeries}(x, y, resample, length, weight.fun, + dist.method, step.matrix, n, span, min.length, theta, keep = FALSE, ...) + +\S4method{twdtwApply}{twdtwRaster}(x, y, resample, length, weight.fun, + dist.method, step.matrix, n, span, min.length, theta, breaks = NULL, + from = NULL, to = NULL, by = NULL, overlap = 0.5, chunk.size = 1000, + filepath = NULL, ...) +} +\arguments{ +\item{x}{an object of class twdtw*. This is the target time series. +Usually, it is a set of unclassified time series.} + +\item{y}{an object of class \link[dtwSat]{twdtwTimeSeries}. +The temporal patterns.} + +\item{resample}{resample the patterns to have the same length. Default is TRUE. +See \link[dtwSat]{resampleTimeSeries} for details.} + +\item{length}{An integer. Patterns length used with \code{patterns.length}. +If not declared the length of the output patterns will be the length of +the longest pattern.} + +\item{weight.fun}{A function. Any function that receive and performs a +computation on a matrix. The function receives a matrix of time differences +in days and returns a matrix of time-weights. If not declared the time-weight +is zero. In this case the function runs the standard version of the dynamic +time warping. See details.} + +\item{dist.method}{A character. Method to derive the local cost matrix. +Default is ''Euclidean'' see \code{\link[proxy]{dist}} in package +\pkg{proxy}.} + +\item{step.matrix}{see \code{\link[dtw]{stepPattern}} in package \pkg{dtw} [2].} + +\item{n}{An integer. The maximun number of matches to perform. +NULL will return all matches.} + +\item{span}{A number. Span between two matches, \emph{i.e.} the minimum +interval between two matches, for details see [3]. If not declared it removes +all overlapping matches of the same pattern. To include overlapping matches +of the same pattern use \code{span=0}.} + +\item{min.length}{A number between 0 an 1. This argument removes the over fittings. +Minimum length after warping. Percentage of the original pattern length. Default is 0.5, +meaning that the matching cannot be shorter than half of the pattern length.} + +\item{theta}{numeric between 0 and 1. The weight of the time +for the TWDTW computation. Use \code{theta=0} to cancel the time-weight, +\emph{i.e.} to run the original DTW algorithm. Default is 0.5, meaning that +the time has the same weight as the curve shape in the TWDTW analysis.} + +\item{...}{arguments to pass to \code{\link[raster]{writeRaster}}} + +\item{keep}{preserves the cost matrix, inputs, and other internal structures. +Default is FALSE. For plot methods use \code{keep=TRUE}.} + +\item{breaks}{A vector of class \code{\link[base]{Dates}}. This replaces the arguments \code{from}, +\code{to}, and \code{by}.} + +\item{from}{A character or \code{\link[base]{Dates}} object in the format "yyyy-mm-dd".} + +\item{to}{A \code{\link[base]{character}} or \code{\link[base]{Dates}} object in the format "yyyy-mm-dd".} + +\item{by}{A \code{\link[base]{character}} with the intevals size, \emph{e.g.} "6 month".} + +\item{overlap}{A number between 0 and 1. The minimum overlapping +between one match and the interval of classification. Default is 0.5, +\emph{i.e.} an overlap minimum of 50\%.} + +\item{chunk.size}{An integer. Set the number of cells for each block, +see \code{\link[raster]{blockSize}} for details.} + +\item{filepath}{A character. The path to save the raster with results. If not informed the +function saves in the current work directory.} +} +\value{ +An object of class twdtw*. +} +\description{ +This function performs a multidimensional Time-Weighted DTW +analysis and retrieves the matches between the temporal patterns and +a set of time series [1]. +} +\details{ +The linear \code{linearWeight} and \code{logisticWeight} weight functions +can be passed to \code{twdtwApply} through the argument \code{weight.fun}. This will +add a time-weight to the dynamic time warping analysis. The time weight +creates a global constraint useful to analyse time series with phenological cycles +of vegetation that are usually bound to seasons. In previous studies by [1] the +logistic weight had better results than the linear for land cover classification. +See [1] for details about the method. +} +\examples{ +# Applying TWDTW analysis to objects of class twdtwTimeSeries +log_fun = logisticWeight(-0.1, 100) +ts = twdtwTimeSeries(MOD13Q1.ts.list) +patt = twdtwTimeSeries(MOD13Q1.patterns.list) +mat1 = twdtwApply(x=ts, y=patt, weight.fun=log_fun) +mat1 + +\dontrun{ +# Parallel processin +require(parallel) +mat_list = mclapply(as.list(ts), mc.cores=2, FUN=twdtwApply, y=patt, weight.fun=log_fun) +mat2 = twdtwMatches(alignments=mat_list) +} +\dontrun{ +# Run TWDTW analysis for raster time series +patt = MOD13Q1.MT.yearly.patterns +evi = brick(system.file("lucc_MT/data/evi.tif", package="dtwSat")) +ndvi = brick(system.file("lucc_MT/data/ndvi.tif", package="dtwSat")) +red = brick(system.file("lucc_MT/data/red.tif", package="dtwSat")) +blue = brick(system.file("lucc_MT/data/blue.tif", package="dtwSat")) +nir = brick(system.file("lucc_MT/data/nir.tif", package="dtwSat")) +mir = brick(system.file("lucc_MT/data/mir.tif", package="dtwSat")) +doy = brick(system.file("lucc_MT/data/doy.tif", package="dtwSat")) +timeline = scan(system.file("lucc_MT/data/timeline", package="dtwSat"), what="date") +rts = twdtwRaster(evi, ndvi, red, blue, nir, mir, timeline = timeline, doy = doy) + +time_interval = seq(from=as.Date("2007-09-01"), to=as.Date("2013-09-01"), + by="12 month") +log_fun = weight.fun=logisticWeight(-0.1,50) + +r_twdtw = twdtwApply(x=rts, y=patt, weight.fun=log_fun, breaks=time_interval, + filepath="~/test_twdtw", overwrite=TRUE, format="GTiff", mc.cores=3, + chunk.size=1000) + +plot(r_twdtw, type="distance") + +r_lucc = twdtwClassify(r_twdtw, format="GTiff", overwrite=TRUE) + +plot(r_lucc) + +plot(r_lucc, type="distance") + +} +} +\author{ +Victor Maus, \email{vwmaus1@gmail.com} +} +\references{ +[1] Maus V, Camara G, Cartaxo R, Sanchez A, Ramos FM, de Queiroz, GR. +(2016). A Time-Weighted Dynamic Time Warping method for land use and land cover +mapping. Selected Topics in Applied Earth Observations and Remote Sensing, +IEEE Journal of, vol.PP, no.99, pp.1-11. + +[2] Giorgino, T. (2009). Computing and Visualizing Dynamic Time Warping Alignments in R: +The dtw Package. Journal of Statistical Software, 31, 1-24. + +[3] Muller, M. (2007). Dynamic Time Warping. In Information Retrieval for Music +and Motion (pp. 79-84). London: Springer London, Limited. +} +\seealso{ +\code{\link[dtwSat]{twdtwMatches-class}}, +\code{\link[dtwSat]{twdtwTimeSeries-class}}, +\code{\link[dtwSat]{twdtwRaster-class}}, +\code{\link[dtwSat]{getTimeSeries}}, and +\code{\link[dtwSat]{createPatterns}} +} + diff --git a/man/twdtwAssessment-class.Rd b/man/twdtwAssessment-class.Rd new file mode 100644 index 0000000..ddfac98 --- /dev/null +++ b/man/twdtwAssessment-class.Rd @@ -0,0 +1,140 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/class-twdtwAssessment.R, R/methods.R, R/twdtwAssess.R, R/xtable.R +\docType{methods} +\name{twdtwAssessment-class} +\alias{show,twdtwAssessment-method} +\alias{twdtwAssess} +\alias{twdtwAssess,twdtwRaster-method} +\alias{twdtwAssessment} +\alias{twdtwAssessment-class} +\alias{xtable} +\alias{xtable,twdtwAssessment-method} +\title{class "twdtwAssessment"} +\usage{ +\S4method{show}{twdtwAssessment}(object) + +\S4method{twdtwAssess}{twdtwRaster}(object, y, labels = NULL, + id.labels = NULL, proj4string = NULL, conf.int = 0.95) + +\S4method{xtable}{twdtwAssessment}(x, type = "accuracy", time.labels = NULL, + ...) +} +\arguments{ +\item{object}{an object of class \code{\link[dtwSat]{twdtwRaster}} resulting from +the classification, i.e. \code{\link[dtwSat]{twdtwClassify}}.} + +\item{y}{a \code{\link[base]{data.frame}} whose attributes are: longitude, +latitude, the start ''from'' and the end ''to'' of the time interval +for each sample. This can also be a \code{\link[sp]{SpatialPointsDataFrame}} +whose attributes are the start ''from'' and the end ''to'' of the time interval. +If missing ''from'' and/or ''to'', they are set to the time range of the +\code{object}.} + +\item{labels}{character vector with time series labels. For signature +\code{\link[dtwSat]{twdtwRaster}} this argument can be used to set the +labels for each sample in \code{y}, or it can be combined with \code{id.labels} +to select samples with a specific label.} + +\item{id.labels}{a numeric or character with an column name from \code{y} to +be used as samples labels. Optional.} + +\item{proj4string}{projection string, see \code{\link[sp]{CRS-class}}. Used +if \code{y} is a \code{\link[base]{data.frame}}.} + +\item{conf.int}{specifies the confidence level (0-1).} + +\item{x}{an object of class \code{\link[dtwSat]{twdtwAssessment}}.} + +\item{type}{table type, 'accuracy' for User's and Producer's Accuracy, +'matrix' for error matrix, and 'area' for area and uncertainty. +Default is 'accuracy'.} + +\item{time.labels}{a character or numeric for the time period or NULL to +include all classified periods. Default is NULL.} + +\item{...}{other arguments to pass to \code{\link[xtable]{xtable}}.} +} +\description{ +This class stores the map assessment. +} +\details{ +If the twdtwRaster is unprojected (longitude/latitude) the estimated area is sum of the approximate +surface area in km2 of each cell (pixel). If the twdtwRaster is projected the estimated area is calculated +using the the pixel resolution in the map unit. +} +\section{Methods (by generic)}{ +\itemize{ +\item \code{twdtwAssess}: This function performs an accuracy assessment +of the classified maps. The function returns Overall Accuracy, +User's Accuracy, Produce's Accuracy, error matrix (confusion matrix), +and estimated area according to [1]. The function returns the metrics +for each time interval and a summary considering all classified intervals. +}} +\section{Slots }{ + +\describe{ + \item{\code{accuracySummary}:}{Overall Accuracy, User's Accuracy, Produce's Accuracy, + Error Matrix (confusion matrix), and Estimated Area, considering all time periods.} + \item{\code{accuracyByPeriod}:}{Overall Accuracy, User's Accuracy, Produce's Accuracy, + Error Matrix (confusion matrix), and Estimated Area, for each time periods independently + from each other.} + \item{\code{data}:}{A \code{\link[base]{data.frame}} with period (from - to), reference labels, + predicted labels, and other TWDTW information.} +} +} +\examples{ +\dontrun{ + +} +\dontrun{ + +# Create raster time series +evi = brick(system.file("lucc_MT/data/evi.tif", package="dtwSat")) +ndvi = brick(system.file("lucc_MT/data/ndvi.tif", package="dtwSat")) +red = brick(system.file("lucc_MT/data/red.tif", package="dtwSat")) +blue = brick(system.file("lucc_MT/data/blue.tif", package="dtwSat")) +nir = brick(system.file("lucc_MT/data/nir.tif", package="dtwSat")) +mir = brick(system.file("lucc_MT/data/mir.tif", package="dtwSat")) +doy = brick(system.file("lucc_MT/data/doy.tif", package="dtwSat")) +timeline = scan(system.file("lucc_MT/data/timeline", package="dtwSat"), what="date") +rts = twdtwRaster(evi, ndvi, red, blue, nir, mir, timeline = timeline, doy = doy) + +# Read fiels samples +field_samples = read.csv(system.file("lucc_MT/data/samples.csv", package="dtwSat")) +proj_str = scan(system.file("lucc_MT/data/samples_projection", + package="dtwSat"), what = "character") + +# Split samples for training (10\%) and validation (90\%) using stratified sampling +library(caret) +set.seed(1) +I = unlist(createDataPartition(field_samples$label, p = 0.1)) +training_samples = field_samples[I,] +validation_samples = field_samples[-I,] + +# Create temporal patterns +training_ts = getTimeSeries(rts, y = training_samples, proj4string = proj_str) +temporal_patterns = createPatterns(training_ts, freq = 8, formula = y ~ s(x)) + +# Run TWDTW analysis for raster time series +log_fun = weight.fun=logisticWeight(-0.1,50) +r_twdtw = twdtwApply(x=rts, y=temporal_patterns, weight.fun=log_fun, format="GTiff", + overwrite=TRUE) + +# Classify raster based on the TWDTW analysis +r_lucc = twdtwClassify(r_twdtw, format="GTiff", overwrite=TRUE) +plot(r_lucc) + +# Assess classification +twdtw_assess = twdtwAssess(r_lucc, validation_samples, proj4string=proj_str) +twdtw_assess + +} +} +\author{ +Victor Maus, \email{vwmaus1@gmail.com} +} +\seealso{ +\code{\link[dtwSat]{twdtwRaster-class}}, and +\code{\link[dtwSat]{twdtwClassify}}. +} + diff --git a/man/twdtwClassify.Rd b/man/twdtwClassify.Rd new file mode 100644 index 0000000..a4968e3 --- /dev/null +++ b/man/twdtwClassify.Rd @@ -0,0 +1,111 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/twdtwClassify.R +\docType{methods} +\name{twdtwClassify} +\alias{twdtwClassify} +\alias{twdtwClassify,twdtwMatches-method} +\alias{twdtwClassify,twdtwRaster-method} +\alias{twdtwClassify-twdtwRaster} +\alias{twdtwClassify-twdtwTimeSeries} +\title{Classify time series} +\usage{ +twdtwClassify(x, ...) + +\S4method{twdtwClassify}{twdtwMatches}(x, patterns.labels = NULL, + from = NULL, to = NULL, by = NULL, breaks = NULL, overlap = 0.5, + thresholds = Inf, fill = "unclassified") + +\S4method{twdtwClassify}{twdtwRaster}(x, patterns.labels = NULL, + thresholds = Inf, fill = 255, filepath, ...) +} +\arguments{ +\item{x}{an object of class twdtw*. This is the target time series. +Usually, it is a set of unclassified time series.} + +\item{...}{arguments to pass to specifique methods for each twdtw* signature +and other arguments to pass to \code{\link[raster]{writeRaster}}.} + +\item{patterns.labels}{a vector with labels of the patterns.} + +\item{from}{A character or \code{\link[base]{Dates}} object in the format "yyyy-mm-dd".} + +\item{to}{A \code{\link[base]{character}} or \code{\link[base]{Dates}} object in the format "yyyy-mm-dd".} + +\item{by}{A \code{\link[base]{character}} with the intevals size, \emph{e.g.} "6 month".} + +\item{breaks}{A vector of class \code{\link[base]{Dates}}. This replaces the arguments \code{from}, +\code{to}, and \code{by}.} + +\item{overlap}{A number between 0 and 1. The minimum overlapping +between one match and the interval of classification. Default is 0.5, +\emph{i.e.} an overlap minimum of 50\%.} + +\item{thresholds}{A numeric vector the same length as \code{patterns.labels}. +The TWDTW dissimilarity thresholds, i.e. the maximum TWDTW cost for consideration +in the classification. Default is \code{Inf} for all \code{patterns.labels}.} + +\item{fill}{a character or value to fill the classification gaps. +For signature \code{twdtwTimeSeries} the default is \code{fill="unclassified"}, and +for signature \code{twdtwRaster} the default is \code{fill="unclassified"}.} + +\item{filepath}{A character. The path to save the raster with results. If not informed the +function saves in the same directory as the input time series raster.} +} +\value{ +An object of class twdtw*. +} +\description{ +This function classifies the intervals of a time series +based on the TWDTW results. +} +\examples{ +# Classifying time series based on TWDTW results +ts = twdtwTimeSeries(MOD13Q1.ts.list) +patt = twdtwTimeSeries(MOD13Q1.patterns.list) +log_fun = logisticWeight(-0.1, 100) +time_intervals = seq(from=as.Date("2007-09-01"), to=as.Date("2013-09-01"), by="6 month") +mat = twdtwApply(x=ts, y=patt, weight.fun=log_fun, keep=TRUE) +best_mat = twdtwClassify(x=mat, breaks=time_intervals, overlap=0.5) +plot(x=best_mat, type="classification") + +\dontrun{ +require(parallel) +best_mat = mclapply(as.list(mat), mc.cores=2, FUN=twdtwClassify, breaks=time_intervals, overlap=0.5) +best_mat = twdtwMatches(alignments=best_mat) +} +\dontrun{ +# Run TWDTW analysis for raster time series +patt = MOD13Q1.MT.yearly.patterns +evi = brick(system.file("lucc_MT/data/evi.tif", package="dtwSat")) +ndvi = brick(system.file("lucc_MT/data/ndvi.tif", package="dtwSat")) +red = brick(system.file("lucc_MT/data/red.tif", package="dtwSat")) +blue = brick(system.file("lucc_MT/data/blue.tif", package="dtwSat")) +nir = brick(system.file("lucc_MT/data/nir.tif", package="dtwSat")) +mir = brick(system.file("lucc_MT/data/mir.tif", package="dtwSat")) +doy = brick(system.file("lucc_MT/data/doy.tif", package="dtwSat")) +timeline = scan(system.file("lucc_MT/data/timeline", package="dtwSat"), what="date") +rts = twdtwRaster(evi, ndvi, red, blue, nir, mir, timeline = timeline, doy = doy) + +time_interval = seq(from=as.Date("2007-09-01"), to=as.Date("2013-09-01"), + by="12 month") +log_fun = weight.fun=logisticWeight(-0.1,50) + +r_twdtw = twdtwApply(x=rts, y=patt, weight.fun=log_fun, breaks=time_interval, + filepath="~/test_twdtw", overwrite=TRUE, format="GTiff", mc.cores=3) + +r_lucc = twdtwClassify(r_twdtw, format="GTiff") + +plotMaps(r_lucc) + +} +} +\author{ +Victor Maus, \email{vwmaus1@gmail.com} +} +\seealso{ +\code{\link[dtwSat]{twdtwApply}}, +\code{\link[dtwSat]{twdtwMatches-class}}, +\code{\link[dtwSat]{twdtwTimeSeries-class}}, and +\code{\link[dtwSat]{twdtwRaster-class}}, +} + diff --git a/man/twdtwCrossValidation-class.Rd b/man/twdtwCrossValidation-class.Rd new file mode 100644 index 0000000..fcbb76b --- /dev/null +++ b/man/twdtwCrossValidation-class.Rd @@ -0,0 +1,103 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/class-crossValidation.R, R/methods.R, R/twdtwCrossValidation.R +\docType{methods} +\name{twdtwCrossValidation-class} +\alias{show,twdtwCrossValidation-method} +\alias{summary,twdtwCrossValidation-method} +\alias{twdtwCrossValidation} +\alias{twdtwCrossValidation,ANY-method} +\alias{twdtwCrossValidation-class} +\title{class "twdtwCrossValidation"} +\usage{ +\S4method{show}{twdtwCrossValidation}(object) + +\S4method{summary}{twdtwCrossValidation}(object, conf.int = 0.95, ...) + +\S4method{twdtwCrossValidation}{ANY}(object, times, p, ...) +} +\arguments{ +\item{object}{an object of class \code{\link[dtwSat]{twdtwTimeSeries}}.} + +\item{conf.int}{specifies the confidence level (0-1) for interval estimation of the +population mean. For more details see \code{\link[ggplot2]{mean_cl_boot}}.} + +\item{...}{Other arguments to be passed to \code{\link[dtwSat]{createPatterns}} and +to \code{\link[dtwSat]{twdtwApply}}.} + +\item{times}{Number of partitions to create.} + +\item{p}{the percentage of data that goes to training. +See \code{\link[caret]{createDataPartition}} for details.} +} +\description{ +This class stores the results of the cross-validation. +} +\section{Methods (by generic)}{ +\itemize{ +\item \code{twdtwCrossValidation}: Splits the set of time series into training and validation. +The function uses stratified sampling and a simple random sampling for +each stratum. For each data partition this function performs a TWDTW +analysis and returns the Overall Accuracy, User's Accuracy, Produce's Accuracy, +error matrix (confusion matrix), and a \code{\link[base]{data.frame}} with +the classification (Predicted), the reference classes (Reference), +and the results of the TWDTW analysis. +}} +\section{Slots }{ + +\describe{ + \item{\code{partitions}:}{A list with the indices of time series used for training.} + \item{\code{accuracy}:}{A list with the accuracy and other TWDTW information for each + data partitions.} +} +} +\examples{ +\dontrun{ + +} +\dontrun{ +# Data folder +data_folder = system.file("lucc_MT/data", package = "dtwSat") + +# Read dates +dates = scan(paste(data_folder,"timeline", sep = "/"), what = "dates") + +# Read raster time series +evi = brick(paste(data_folder,"evi.tif", sep = "/")) +raster_timeseries = twdtwRaster(evi, timeline = dates) + +# Read field samples +field_samples = read.csv(paste(data_folder,"samples.csv", sep = "/")) +table(field_samples[["label"]]) + +# Read field samples projection +proj_str = scan(paste(data_folder,"samples_projection", sep = "/"), + what = "character") + +# Get sample time series from raster time series +field_samples_ts = getTimeSeries(raster_timeseries, + y = field_samples, proj4string = proj_str) +field_samples_ts + +# Run cross validation +set.seed(1) +# Define TWDTW weight function +log_fun = logisticWeight(alpha=-0.1, beta=50) +cross_validation = twdtwCrossValidation(field_samples_ts, times=3, p=0.1, + freq = 8, formula = y ~ s(x, bs="cc"), weight.fun = log_fun) +cross_validation + +summary(cross_validation) + +plot(cross_validation) + +} +} +\author{ +Victor Maus, \email{vwmaus1@gmail.com} +} +\seealso{ +\code{\link[dtwSat]{twdtwMatches-class}}, +\code{\link[dtwSat]{createPatterns}}, and +\code{\link[dtwSat]{twdtwApply}}. +} + diff --git a/man/twdtwMatches-class.Rd b/man/twdtwMatches-class.Rd new file mode 100644 index 0000000..ef30dd8 --- /dev/null +++ b/man/twdtwMatches-class.Rd @@ -0,0 +1,128 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/class-twdtwMatches.R, R/methods.R +\docType{methods} +\name{twdtwMatches-class} +\alias{[,twdtwMatches,ANY,ANY,ANY-method} +\alias{[[,twdtwMatches,numeric,ANY-method} +\alias{as.list,twdtwMatches-method} +\alias{as.list,twdtwRaster-method} +\alias{index,twdtwMatches-method} +\alias{is.twdtwMatches} +\alias{is.twdtwMatches,ANY-method} +\alias{labels,twdtwMatches-method} +\alias{length,twdtwMatches-method} +\alias{show,twdtwMatches-method} +\alias{twdtwMatches} +\alias{twdtwMatches,ANY-method} +\alias{twdtwMatches-class} +\alias{twdtwMatches-create} +\title{class "twdtwMatches"} +\usage{ +\S4method{twdtwMatches}{ANY}(timeseries = NULL, patterns = NULL, + alignments = NULL) + +\S4method{index}{twdtwMatches}(x) + +\S4method{length}{twdtwMatches}(x) + +\S4method{as.list}{twdtwMatches}(x) + +\S4method{as.list}{twdtwRaster}(x) + +\S4method{[}{twdtwMatches,ANY,ANY,ANY}(x, i, j, drop = TRUE) + +\S4method{[[}{twdtwMatches,numeric,ANY}(x, i, j, drop = TRUE) + +\S4method{labels}{twdtwMatches}(object) + +\S4method{show}{twdtwMatches}(object) + +\S4method{is.twdtwMatches}{ANY}(x) +} +\arguments{ +\item{timeseries}{a \code{\link[dtwSat]{twdtwTimeSeries}} object.} + +\item{patterns}{a \code{\link[dtwSat]{twdtwTimeSeries}} object.} + +\item{alignments}{an object of class list with the TWDTW results with +the same length as \code{timeseries} or a list of twdtwMatches.} + +\item{x}{an object of class twdtwMatches.} + +\item{i}{indices of the time series.} + +\item{j}{indices of the pattern.} + +\item{drop}{if TRUE returns a data.frame, if FALSE returns a list. +Default is TRUE.} + +\item{object}{an object of class twdtwMatches.} + +\item{labels}{a vector with labels of the time series.} + +\item{...}{objects of class twdtwMatches.} +} +\description{ +Class for Time-Weighted Dynamic Time Warping results. +} +\section{Methods (by generic)}{ +\itemize{ +\item \code{twdtwMatches}: Create object of class twdtwMatches. + +\item \code{is.twdtwMatches}: Check if the object belongs to the class twdtwMatches. +}} +\section{Slots }{ + +\describe{ + \item{\code{timeseries}:}{An object of class \code{\link[dtwSat]{twdtwTimeSeries-class}} with the satellite time series.} + \item{\code{pattern}:}{An object of class \code{\link[dtwSat]{twdtwTimeSeries-class}} with the temporal patterns.} + \item{\code{alignments}:}{A \code{\link[base]{list}} of TWDTW results with the same length as + the \code{timeseries}. Each element in this list has the following results for each temporal pattern + in \code{patterns}: + \cr\code{from}: a vector with the starting dates of each match in the format "YYYY-MM-DD", + \cr\code{to}: a vector with the ending dates of each match in the format "YYYY-MM-DD", + \cr\code{distance}: a vector with TWDTW dissimilarity measure, and + \cr\code{K}: the number of matches of the pattern. + } + \item{This list might have additional elements:}{ if \code{keep=TRUE} in the \code{twdtwApply} call + the list is extended to include internal structures used during the TWDTW computation: + \cr\code{costMatrix}: cumulative cost matrix, + \cr\code{directionMatrix}: directions of steps that would be taken from each element of matrix, + \cr\code{startingMatrix}: the starting points of each element of the matrix, + \cr\code{stepPattern}: \code{\link[dtw]{stepPattern}} used for the + computation, see package \code{\link[dtw]{dtw}}, + \cr\code{N}: the length of the \code{pattern}, + \cr\code{M}: the length of the time series \code{timeseries}, + \cr\code{timeWeight}: time weight matrix, + \cr\code{localMatrix}: local cost matrix, + \cr\code{matching}: A list whose elements have the matching points for + each match between pattern the time series, such that: + \cr--\code{index1}: a vector with matching points of the pattern, and + \cr--\code{index2}: a vector with matching points of the time series. + } +} +} +\examples{ +ts = twdtwTimeSeries(timeseries=MOD13Q1.ts.list) +patterns = twdtwTimeSeries(timeseries=MOD13Q1.patterns.list) +matches = twdtwApply(x = ts, y = patterns) +class(matches) +length(matches) +matches +# Creating objects of class twdtwMatches +ts = twdtwTimeSeries(MOD13Q1.ts.list) +patt = twdtwTimeSeries(MOD13Q1.patterns.list) +mat = twdtwApply(ts, patt, weight.fun = logisticWeight(-0.1, 100)) +mat = twdtwMatches(ts, patterns=patt, alignments=mat) +mat + +} +\author{ +Victor Maus, \email{vwmaus1@gmail.com} +} +\seealso{ +\code{\link[dtwSat]{twdtwApply}}, +\code{\link[dtwSat]{twdtwTimeSeries-class}}, and +\code{\link[dtwSat]{twdtwRaster-class}} +} + diff --git a/man/twdtwRaster-class.Rd b/man/twdtwRaster-class.Rd new file mode 100644 index 0000000..11d94fb --- /dev/null +++ b/man/twdtwRaster-class.Rd @@ -0,0 +1,186 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/class-twdtwRaster.R, R/methods.R +\docType{methods} +\name{twdtwRaster-class} +\alias{[,twdtwRaster,ANY,ANY,ANY-method} +\alias{[[,twdtwRaster,ANY,ANY-method} +\alias{bands} +\alias{bands,twdtwRaster-method} +\alias{coverages} +\alias{coverages,twdtwRaster-method} +\alias{crop,twdtwRaster-method} +\alias{dim,twdtwRaster-method} +\alias{extent,twdtwRaster-method} +\alias{index,twdtwRaster-method} +\alias{is.twdtwRaster} +\alias{is.twdtwRaster,ANY-method} +\alias{labels,twdtwRaster-method} +\alias{layers} +\alias{layers,twdtwRaster-method} +\alias{length,twdtwRaster-method} +\alias{levels,twdtwRaster-method} +\alias{names,twdtwRaster-method} +\alias{ncol,twdtwRaster-method} +\alias{nlayers,twdtwRaster-method} +\alias{nrow,twdtwRaster-method} +\alias{projection,twdtwRaster-method} +\alias{projecttwdtwRaster} +\alias{projecttwdtwRaster,twdtwRaster-method} +\alias{res,twdtwRaster-method} +\alias{show,twdtwRaster-method} +\alias{twdtwRaster} +\alias{twdtwRaster,ANY-method} +\alias{twdtwRaster-class} +\alias{twdtwRaster-create} +\title{class "twdtwRaster"} +\usage{ +\S4method{twdtwRaster}{ANY}(..., timeline, doy = NULL, layers = NULL, + labels = NULL, levels = NULL, filepath = NULL) + +\S4method{dim}{twdtwRaster}(x) + +\S4method{res}{twdtwRaster}(x) + +\S4method{extent}{twdtwRaster}(x, y, ...) + +\S4method{projection}{twdtwRaster}(x) + +\S4method{ncol}{twdtwRaster}(x) + +\S4method{nrow}{twdtwRaster}(x) + +\S4method{nlayers}{twdtwRaster}(x) + +\S4method{levels}{twdtwRaster}(x) + +\S4method{layers}{twdtwRaster}(x) + +\S4method{coverages}{twdtwRaster}(x) + +\S4method{bands}{twdtwRaster}(x) + +\S4method{names}{twdtwRaster}(x) + +\S4method{index}{twdtwRaster}(x) + +\S4method{length}{twdtwRaster}(x) + +\S4method{[}{twdtwRaster,ANY,ANY,ANY}(x, i) + +\S4method{[[}{twdtwRaster,ANY,ANY}(x, i) + +\S4method{labels}{twdtwRaster}(object) + +\S4method{crop}{twdtwRaster}(x, y, ...) + +\S4method{extent}{twdtwRaster}(x, y, ...) + +\S4method{show}{twdtwRaster}(object) + +\S4method{is.twdtwRaster}{ANY}(x) + +\S4method{projecttwdtwRaster}{twdtwRaster}(x, crs, ...) +} +\arguments{ +\item{...}{objects of class \code{\link[raster]{RasterBrick-class}} or +\code{\link[raster]{RasterStack-class}}.} + +\item{timeline}{a vector with the dates of the satellite images +in the format of "YYYY-MM-DD".} + +\item{doy}{A \code{\link[raster]{RasterBrick-class}} or +\code{\link[raster]{RasterStack-class}} with a sequence of days of the year for each pixel. +\code{doy} must have the same spatial and temporal extents as the Raster* objects passed to \code{...}. +If \code{doy} is not informed then at least one Raster* object must be passed through \code{...}.} + +\item{layers}{a vector with the names of the \code{Raster*} objects +passed to "\code{...}". If not informed the layers are set to the +names of objects in "\code{...}".} + +\item{labels}{a vector of class \code{\link[base]{character}} with +labels of the values in the Raster* objects. This is +useful for categorical Raster* values of land use classes.} + +\item{levels}{a vector of class \code{\link[base]{numeric}} with +levels of the values in the Raster* objects. This is +useful for categorical Raster* values of land use classes.} + +\item{filepath}{A character. The path to save the raster time series. If informed the +function saves a raster file for each Raster* object in the list, \emph{i.e} one file +for each time series. This way the function retrieves an list of +\code{\link[raster]{RasterBrick-class}}. It is useful when the time series are +originally stores in separated files. See details.} + +\item{x}{an object of class twdtwRaster.} + +\item{y}{Extent object, or any object from which an Extent object can be extracted.} + +\item{i}{indices of the time series.} + +\item{object}{an object of class twdtwRaster.} + +\item{crs}{character or object of class 'CRS'. PROJ.4 description of +the coordinate reference system. For other arguments and more details see +\code{\link[raster]{projectRaster}}.} +} +\description{ +Class for set of satellite time series. +} +\details{ +The performance the functions \code{\link[dtwSat]{twdtwApply}} and +\code{\link[dtwSat]{getTimeSeries}} is improved if the Raster* objects are connected +to files with the whole time series for each attribute. +} +\section{Methods (by generic)}{ +\itemize{ +\item \code{twdtwRaster}: Create object of class twdtwRaster. + +\item \code{is.twdtwRaster}: Check if the object belongs to the class twdtwRaster. + +\item \code{projecttwdtwRaster}: project twdtwRaster object. +}} +\section{Slots }{ + +\describe{ + \item{\code{timeseries}:}{A list of multi-layers Raster* objects + with the satellite image time series.} + \item{\code{timeline}:}{A vector of class \code{\link[base]{date}} + with dates of the satellite images in \code{timeseries}.} + \item{\code{layers}:}{A vector of class \code{\link[base]{character}} + with the names of the Raster* objects.} + \item{\code{labels}:}{A vector of class \code{\link[base]{factor}} + with levels and labels of the values in the Raster* objects. This + is useful for categorical Raster* values of land use classes.} +} +} +\examples{ +# Creating new object of class twdtwTimeSeries +evi = brick(system.file("lucc_MT/data/evi.tif", package="dtwSat")) +timeline = scan(system.file("lucc_MT/data/timeline", package="dtwSat"), what="date") +rts = new("twdtwRaster", timeseries = evi, timeline = timeline) + +\dontrun{ +# Creating objects of class twdtwRaster +evi = brick(system.file("lucc_MT/data/evi.tif", package="dtwSat")) +timeline = scan(system.file("lucc_MT/data/timeline", package="dtwSat"), what="date") +ts_evi = twdtwRaster(evi, timeline=timeline) + +ndvi = brick(system.file("lucc_MT/data/ndvi.tif", package="dtwSat")) +blue = brick(system.file("lucc_MT/data/blue.tif", package="dtwSat")) +red = brick(system.file("lucc_MT/data/red.tif", package="dtwSat")) +nir = brick(system.file("lucc_MT/data/nir.tif", package="dtwSat")) +mir = brick(system.file("lucc_MT/data/mir.tif", package="dtwSat")) +doy = brick(system.file("lucc_MT/data/doy.tif", package="dtwSat")) +rts = twdtwRaster(evi, ndvi, blue, red, nir, mir, timeline=timeline, doy=doy) +} +} +\author{ +Victor Maus, \email{vwmaus1@gmail.com} +} +\seealso{ +\code{\link[dtwSat]{twdtwApply}}, +\code{\link[dtwSat]{getTimeSeries}}, +\code{\link[dtwSat]{twdtwMatches-class}}, and +\code{\link[dtwSat]{twdtwTimeSeries-class}} +} + diff --git a/man/twdtwTimeSeries-class.Rd b/man/twdtwTimeSeries-class.Rd new file mode 100644 index 0000000..f881985 --- /dev/null +++ b/man/twdtwTimeSeries-class.Rd @@ -0,0 +1,113 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/class-twdtwTimeSeries.R, R/methods.R +\docType{methods} +\name{twdtwTimeSeries-class} +\alias{[,twdtwTimeSeries,ANY,ANY,ANY-method} +\alias{[[,twdtwTimeSeries,ANY,ANY-method} +\alias{as.list,twdtwTimeSeries-method} +\alias{dim,twdtwTimeSeries-method} +\alias{index,twdtwTimeSeries-method} +\alias{is.twdtwTimeSeries} +\alias{is.twdtwTimeSeries,ANY-method} +\alias{labels,twdtwTimeSeries-method} +\alias{length,twdtwTimeSeries-method} +\alias{levels,twdtwTimeSeries-method} +\alias{ncol,twdtwTimeSeries-method} +\alias{nrow,twdtwTimeSeries-method} +\alias{show,twdtwTimeSeries-method} +\alias{twdtwTimeSeries} +\alias{twdtwTimeSeries,ANY-method} +\alias{twdtwTimeSeries-class} +\alias{twdtwTimeSeries-create} +\title{class "twdtwTimeSeries"} +\usage{ +\S4method{twdtwTimeSeries}{ANY}(..., labels = NULL) + +\S4method{dim}{twdtwTimeSeries}(x) + +\S4method{index}{twdtwTimeSeries}(x) + +\S4method{nrow}{twdtwTimeSeries}(x) + +\S4method{ncol}{twdtwTimeSeries}(x) + +\S4method{length}{twdtwTimeSeries}(x) + +\S4method{as.list}{twdtwTimeSeries}(x) + +\S4method{[}{twdtwTimeSeries,ANY,ANY,ANY}(x, i) + +\S4method{[[}{twdtwTimeSeries,ANY,ANY}(x, i) + +\S4method{labels}{twdtwTimeSeries}(object) + +\S4method{levels}{twdtwTimeSeries}(x) + +\S4method{show}{twdtwTimeSeries}(object) + +\S4method{is.twdtwTimeSeries}{ANY}(x) +} +\arguments{ +\item{...}{\code{\link[dtwSat]{twdtwTimeSeries}} objects, +\code{\link[zoo]{zoo}} objects or a list of \code{\link[zoo]{zoo}} objects.} + +\item{labels}{a vector with labels of the time series.} + +\item{x}{an object of class twdtwTimeSeries.} + +\item{i}{indices of the time series.} + +\item{object}{an object of class twdtwTimeSeries.} +} +\description{ +Class for set of irregular time series. +} +\section{Methods (by generic)}{ +\itemize{ +\item \code{twdtwTimeSeries}: Create object of class twdtwTimeSeries. + +\item \code{is.twdtwTimeSeries}: Check if the object belongs to the class twdtwTimeSeries. +}} +\section{Slots }{ + +\describe{ + \item{\code{timeseries}:}{A list of \code{\link[zoo]{zoo}} objects.} + \item{\code{labels}:}{A vector of class \code{\link[base]{factor}} with time series labels.} +} +} +\examples{ +# Creating new object of class twdtwTimeSeries +ptt = new("twdtwTimeSeries", timeseries = MOD13Q1.patterns.list, + labels = names(MOD13Q1.patterns.list)) +class(ptt) +labels(ptt) +levels(ptt) +length(ptt) +nrow(ptt) +ncol(ptt) +dim(ptt) +# Creating objects of class twdtwTimeSeries from zoo objects +ts = twdtwTimeSeries(MOD13Q1.ts) +ts + +# Creating objects of class twdtwTimeSeries from list of zoo objects +patt = twdtwTimeSeries(MOD13Q1.patterns.list) +patt + +# Joining objects of class twdtwTimeSeries +tsA = twdtwTimeSeries(MOD13Q1.ts.list[[1]], labels = "A") +tsB = twdtwTimeSeries(B = MOD13Q1.ts.list[[2]]) +ts = twdtwTimeSeries(tsA, tsB, C=MOD13Q1.ts) +ts + +} +\author{ +Victor Maus, \email{vwmaus1@gmail.com} +} +\seealso{ +\code{\link[dtwSat]{twdtwMatches-class}}, +\code{\link[dtwSat]{twdtwRaster-class}}, +\code{\link[dtwSat]{getTimeSeries}}, and +\code{\link[dtwSat]{twdtwApply}} +} +