Learn R Programming

dtwSat (version 0.2.8)

createPatterns: Create patterns

Description

Create temporal patterns from objects of class twdtwTimeSeries.

Usage

createPatterns(
  x,
  from = NULL,
  to = NULL,
  freq = 1,
  attr = NULL,
  split = TRUE,
  formula,
  ...
)

# S4 method for twdtwTimeSeries createPatterns( x, from = NULL, to = NULL, freq = 1, attr = NULL, split = TRUE, formula, ... )

Value

an object of class twdtwTimeSeries

Arguments

x

an object of class twdtwTimeSeries.

from

A character or Dates object in the format "yyyy-mm-dd". If not provided it is equal to the smallest date of the first element in x. See details.

to

A character or Dates object in the format "yyyy-mm-dd". If not provided it is equal to the greatest date of the first element in x. See details.

freq

An integer. The sampling frequency of the output patterns.

attr

A vector character or numeric. The attributes in x to be used. If not declared the function uses all attributes.

split

A logical. If TRUE the samples are split by label. If FALSE all samples are set to the same label.

formula

A formula. Argument to pass to gam.

...

other arguments to pass to the function gam in the package mgcv.

Author

Victor Maus, vwmaus1@gmail.com

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 x are aligned with 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.

References

Maus:2019dtwSat

Maus:2016dtwSat

See Also

twdtwMatches-class, twdtwTimeSeries-class, getTimeSeries, and twdtwApply

Examples

Run this code
# 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 
if (FALSE) {
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")

}

Run the code above in your browser using DataLab