Learn R Programming

dtwSat (version 0.2.8)

twdtwReduceTime: Faster version of TWDTW apply

Description

This function is a faster implementation of twdtwApply that is in average 4x faster. The time weight function is coded in Fortran. It does not keep any intermediate data. It performs a multidimensional TWDTW analysis Maus:2019dtwSat and retrieves only the best matches between the unclassified time series and the patterns for each defined time interval.

Usage

twdtwReduceTime(
  x,
  y,
  alpha = -0.1,
  beta = 50,
  time.window = FALSE,
  dist.method = "Euclidean",
  step.matrix = symmetric1,
  from = NULL,
  to = NULL,
  by = NULL,
  breaks = NULL,
  overlap = 0.5,
  fill = length(y) + 1,
  keep = FALSE,
  ...
)

Arguments

x

a data.frame with the target time series. Usually, it is an unclassified time series. It must contain two or more columns, one column called date with dates in the format "YYYY-MM-DD". The other columns can have any names (e.g., red, blue, nir, evi, ndvi) as long as they match the column names in the temporal patterns y.

y

a list of data.frame objects similar to x. The temporal patterns used to classify the time series in x.

alpha

Numeric. The steepness of TWDTW logistic weight.

beta

Numeric. The midpoint of TWDTW logistic weight.

time.window

logical. TRUE will constrain the TWDTW computation to the value of the parameter beta defined in the logistic weight function. Default is FALSE.

dist.method

A character. Method to derive the local cost matrix. Default is ''Euclidean'' see dist in package proxy.

step.matrix

See stepPattern in package dtw Giorgino:2009dtwSat.

from

A character or Dates object in the format "yyyy-mm-dd".

to

A character or Dates object in the format "yyyy-mm-dd".

by

A character with the interval size, e.g. "6 month".

breaks

A vector of class Dates. This replaces the arguments from, to, and by.

overlap

A number between 0 and 1. The minimum overlapping between one match and the interval of classification. Default is 0.5, i.e. an overlap minimum of 50%.

fill

An integer to fill the classification gaps.

keep

Preserves the cost matrix, inputs, and other internal structures. Default is FALSE. For plot methods use keep=TRUE.

...

Arguments to pass to writeRaster and pbCreate

Author

Victor Maus, vwmaus1@gmail.com

Examples

Run this code
if (FALSE) {

library(dtwSat)
from = "2009-09-01"
to = "2017-09-01"
by = "12 month"

# S4 objects for original implementation 
tw_patt = readRDS(system.file("lucc_MT/patterns/patt.rds", package = "dtwSat"))
tw_ts = twdtwTimeSeries(MOD13Q1.ts) 

# Table from csv for faster version 
mn_patt <- lapply(dir(system.file("lucc_MT/patterns", package = "dtwSat"), 
  pattern = ".csv$", full.names = TRUE), read.csv, stringsAsFactors = FALSE)
mn_ts <- read.csv(system.file("reduce_time/ts_MODIS13Q1.csv", package = "dtwSat"), 
  stringsAsFactors = FALSE)

# Benchtmark 
rbenchmark::benchmark(
  legacy_twdtw = twdtwClassify(twdtwApply(x = tw_ts, y = tw_patt, weight.fun = log_fun), 
                                      from = from, to = to, by = by)[[1]],
  fast_twdtw = twdtwReduceTime(x = mn_ts, y = mn_patt, rom = from, to = to, by = by)  
 )
}

Run the code above in your browser using DataLab