diff --git a/DESCRIPTION b/DESCRIPTION
index 2633f64..84068e3 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -32,7 +32,6 @@ Imports:
RColorBrewer,
plyr,
stats,
- parallel,
sp,
lubridate,
caret,
diff --git a/NAMESPACE b/NAMESPACE
index 647e7f6..7797a07 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -85,7 +85,6 @@ importFrom(lubridate,month)
importFrom(lubridate,year)
importFrom(mgcv,gam)
importFrom(mgcv,predict.gam)
-importFrom(parallel,mclapply)
importFrom(plyr,alply)
importFrom(proxy,dist)
importFrom(reshape2,melt)
diff --git a/R/class-twdtwTimeSeries.R b/R/class-twdtwTimeSeries.R
index a9f1088..c7d2834 100644
--- a/R/class-twdtwTimeSeries.R
+++ b/R/class-twdtwTimeSeries.R
@@ -131,7 +131,7 @@ setMethod(f = "twdtwTimeSeries",
} else {}
if(check_class[2]){
list_obj = c(do.call("c", timeseries[which(timeseries_class=="list")]))
- if(is.null(names(list_obj))) names(list_obj) = paste0("ts",seq_along(list_obj))
+ if(is.null(names(list_obj))) names(list_obj) = paste0("ts", seq_along(list_obj))
joint_timeseries = c(joint_timeseries, list_obj)
} else {}
if(check_class[3]){
diff --git a/R/methods.R b/R/methods.R
index 8ddc6c5..4a3dabd 100644
--- a/R/methods.R
+++ b/R/methods.R
@@ -332,9 +332,12 @@ setMethod("[[", "twdtwRaster", function(x, i) {
setMethod("[", "twdtwMatches", function(x, i, j, drop=TRUE) {
if(length(x@alignments)<1) return(x@alignments)
if(missing(i)) i = 1:length(x@alignments)
+ # if(missing(j)) j = 2:length(x@patterns)
if(any(is.na(i))) stop("NA index not permitted")
+ if(class(i)=="character") i = match(i, names(x@timeseries@timeseries))
res = x@alignments[i]
if(missing(j)) j = 1:length(res[[1]])
+ if(class(j)=="character") j = match(j, names(x@patterns@timeseries))
if(any(is.na(j))) stop("NA index not permitted")
res = lapply(res, function(x) x[j])
res = res[sapply(res, length)>0]
@@ -360,13 +363,13 @@ setMethod("[[", c("twdtwMatches", "numeric"), function(x, i, j,drop=TRUE) {
#' @rdname twdtwTimeSeries-class
#' @export
setMethod("labels", signature = signature(object="twdtwTimeSeries"),
- definition = function(object) object@labels)
+ definition = function(object) as.character(object@labels))
#' @inheritParams twdtwTimeSeries-class
#' @rdname twdtwTimeSeries-class
#' @export
setMethod("levels", "twdtwTimeSeries",
- definition = function(x) levels(labels(x)))
+ definition = function(x) levels(factor(labels(x))))
#' @inheritParams twdtwRaster-class
#' @rdname twdtwRaster-class
diff --git a/R/plotTimeSeries.R b/R/plotTimeSeries.R
index 64024a8..ca2d43b 100644
--- a/R/plotTimeSeries.R
+++ b/R/plotTimeSeries.R
@@ -42,8 +42,8 @@ plotTimeSeries = function(x, labels=NULL, attr){
if(is(x, "twdtwMatches")) x = subset(x@timeseries, labels)
if(is(x, "twdtwTimeSeries")) x = subset(x, labels)
- if(is.null(labels)) labels = labels(x)
- new_labels = as.character(labels(x))
+ if(is.null(labels)) labels = labels(x)
+ new_labels = labels(x)
labels_tabel = table(new_labels)
if(any(labels_tabel>1))
for(p in names(labels_tabel)){
diff --git a/R/twdtwApply.R b/R/twdtwApply.R
index 1e11a6e..4d202c6 100644
--- a/R/twdtwApply.R
+++ b/R/twdtwApply.R
@@ -29,8 +29,7 @@
#' @param y an object of class \link[dtwSat]{twdtwTimeSeries}.
#' The temporal patterns.
#'
-#' @param ... arguments to pass to \code{\link[raster]{writeRaster}} and for parallel
-#' processing to pass to \code{\link[parallel]{mclapply}}.
+#' @param ... arguments to pass to \code{\link[raster]{writeRaster}}
#'
#' @param resample resample the patterns to have the same length. Default is TRUE.
#' See \link[dtwSat]{resampleTimeSeries} for details.
@@ -265,8 +264,7 @@ twdtwApply.twdtwRaster = function(x, y, weight.fun, dist.method, step.matrix, n,
if(!mc.silent) print(paste0("Procesing chunk ",i,"/",threads[length(threads)]))
# Get time series from raster
- #ts_list = lapply(as.list(x), FUN=getValuesBlock, row=blocks$row[i], nrows=blocks$nrows[i])
- ts_list = mclapply(as.list(x), FUN=getValuesBlock, row=blocks$row[i], nrows=blocks$nrows[i], mc.preschedule = mc.preschedule, mc.set.seed = mc.set.seed, mc.silent = mc.silent, mc.cores = mc.cores, mc.cleanup = mc.cleanup)
+ ts_list = lapply(as.list(x), FUN=getValuesBlock, row=blocks$row[i], nrows=blocks$nrows[i])
# Create a dummy array
nts = seq(1, nrow(ts_list[[1]]))
@@ -274,8 +272,7 @@ twdtwApply.twdtwRaster = function(x, y, weight.fun, dist.method, step.matrix, n,
n = length(breaks)-1
# Create zoo time series
- #ts_zoo = lapply(nts, FUN=.bulidZoo, x=ts_list, timeline=timeline)
- ts_zoo = mclapply(nts, FUN=.bulidZoo, x=ts_list, timeline=timeline, mc.preschedule = mc.preschedule, mc.set.seed = mc.set.seed, mc.silent = mc.silent, mc.cores = mc.cores, mc.cleanup = mc.cleanup)
+ ts_zoo = lapply(nts, FUN=.bulidZoo, x=ts_list, timeline=timeline)
# Create twdtwTimeSeries object
ts = try(twdtwTimeSeries(ts_zoo), silent = TRUE)
@@ -283,12 +280,10 @@ twdtwApply.twdtwRaster = function(x, y, weight.fun, dist.method, step.matrix, n,
return(lapply(levels, function(l) writeValues(b_files[[l]], matrix(9999, nrow=length(nts), ncol=n), blocks$row[i])))
# Apply TWDTW analysis
- #twdtw_results = lapply(as.list(ts), FUN=get_aligs)
- twdtw_results = mclapply(as.list(ts), FUN=get_aligs, mc.preschedule = mc.preschedule, mc.set.seed = mc.set.seed, mc.silent = mc.silent, mc.cores = mc.cores, mc.cleanup = mc.cleanup)
+ twdtw_results = lapply(as.list(ts), FUN=get_aligs)
# Get best mathces for each point, period, and pattern
- #A = lapply(twdtw_results, FUN=.lowestDistances, m=m, n=n, levels=levels, breaks=breaks, overlap=overlap, fill=9999)
- A = mclapply(twdtw_results, FUN=.lowestDistances, m=m, n=n, levels=levels, breaks=breaks, overlap=overlap, fill=9999, mc.preschedule = mc.preschedule, mc.set.seed = mc.set.seed, mc.silent = mc.silent, mc.cores = mc.cores, mc.cleanup = mc.cleanup)
+ A = lapply(twdtw_results, FUN=.lowestDistances, m=m, n=n, levels=levels, breaks=breaks, overlap=overlap, fill=9999)
# Reshape list to array
A = sapply(A, matrix, nrow=n, ncol=m, simplify = 'array')
diff --git a/R/twdtwClassify.R b/R/twdtwClassify.R
index 2d4a76b..3e0e9e7 100644
--- a/R/twdtwClassify.R
+++ b/R/twdtwClassify.R
@@ -79,7 +79,7 @@ setGeneric(name = "twdtwClassify",
#'
#' \dontrun{
#' require(parallel)
-#' best_mat = mclapply(as.list(mat), mc.cores=4, FUN=twdtwClassify, breaks=time_intervals, overlap=0.5)
+#' best_mat = mclapply(as.list(mat), mc.cores=2, FUN=twdtwClassify, breaks=time_intervals, overlap=0.5)
#' best_mat = twdtwMatches(alignments=best_mat)
#' }
#' @export
@@ -110,8 +110,8 @@ setMethod("twdtwClassify", "twdtwMatches",
breaks = seq(from, to, paste(by,"month"))
}
breaks = as.Date(breaks)
- twdtwClassify.twdtwMatches(x, patterns.labels=patterns.labels, breaks=breaks,
- overlap=overlap, thresholds=thresholds, fill=fill)
+ twdtwClassify.twdtwMatches(x, patterns.labels=patterns.labels, breaks=breaks,
+ overlap=overlap, thresholds=thresholds, fill=fill)
})
#' @rdname twdtwClassify
@@ -181,7 +181,6 @@ twdtwClassify.twdtwMatches = function(x, patterns.labels, breaks, overlap, thres
m = length(levels)
n = length(breaks)-1
aligs = lapply(as.list(x), FUN=.bestIntervals, m=m, n=n, levels=levels, breaks=breaks, overlap=overlap)
- # res = lapply(as.list(x), FUN = classifyIntervals, patterns.labels, breaks, overlap, thresholds, fill)
twdtwMatches(x@timeseries, patterns=x@patterns, alignments=aligs)
}
diff --git a/R/zzz.R b/R/zzz.R
index 8ba14bc..da6f44b 100644
--- a/R/zzz.R
+++ b/R/zzz.R
@@ -29,7 +29,6 @@
#' @importFrom scales pretty_breaks date_format percent
#' @importFrom grDevices terrain.colors gray.colors
#' @importFrom plyr alply
-#' @importFrom parallel mclapply
#' @importFrom sp Polygon Polygons SpatialPoints SpatialPolygons SpatialPointsDataFrame over CRS spTransform coordinates bbox
#' @importFrom mgcv gam predict.gam
#' @importFrom RColorBrewer brewer.pal
diff --git a/README.Rmd b/README.Rmd
index 8e4bc82..16dae6d 100644
--- a/README.Rmd
+++ b/README.Rmd
@@ -13,7 +13,7 @@ knitr::opts_chunk$set(
warning = FALSE,
message = FALSE,
error = FALSE,
- cache = TRUE,
+ cache = FALSE,
results = "hide"
)
```
diff --git a/README.md b/README.md
index b5c1ab5..50a281d 100644
--- a/README.md
+++ b/README.md
@@ -31,7 +31,7 @@ plot(ts, type="timeseries")
-Fig. 1. example\_ts time series. +Fig. 1. MOD13Q1.ts time series.
We know that in the region where the time series was observed we have *soybean*, *cotton*, and *maize*, whose typical temporal pattern are: diff --git a/figure/plot-MOD13Q1.ts-ts-1.png b/figure/plot-MOD13Q1.ts-ts-1.png new file mode 100644 index 0000000..496e0fe Binary files /dev/null and b/figure/plot-MOD13Q1.ts-ts-1.png differ diff --git a/figure/plot-patterns-1.png b/figure/plot-patterns-1.png index cb08159..7d761b5 100644 Binary files a/figure/plot-patterns-1.png and b/figure/plot-patterns-1.png differ diff --git a/man/twdtwApply.Rd b/man/twdtwApply.Rd index 582f914..9d2ec01 100644 --- a/man/twdtwApply.Rd +++ b/man/twdtwApply.Rd @@ -64,8 +64,7 @@ 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}} and for parallel -processing to pass to \code{\link[parallel]{mclapply}}.} +\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}.} diff --git a/man/twdtwClassify.Rd b/man/twdtwClassify.Rd index 46ecec1..a4968e3 100644 --- a/man/twdtwClassify.Rd +++ b/man/twdtwClassify.Rd @@ -70,7 +70,7 @@ plot(x=best_mat, type="classification") \dontrun{ require(parallel) -best_mat = mclapply(as.list(mat), mc.cores=4, FUN=twdtwClassify, breaks=time_intervals, overlap=0.5) +best_mat = mclapply(as.list(mat), mc.cores=2, FUN=twdtwClassify, breaks=time_intervals, overlap=0.5) best_mat = twdtwMatches(alignments=best_mat) } \dontrun{