smooth_s2ts: Filter and smooth time series from sen2r archives

View source: R/smooth_s2ts.R

smooth_s2tsR Documentation

Filter and smooth time series from sen2r archives

Description

Smooth time series extracted with function extract_s2ts() using a Savitzky-Golay filter. Quality flags associated to the time series are used to obtain better results. Argument values should be manually set to obtain a correct smoothing.

Usage

smooth_s2ts(
  ts,
  min_qa = 0.2,
  noise_dir = "low",
  spike = 0.25,
  spike_window = 5,
  sg_daywindow = 15,
  sg_polynom = 2,
  sg_n = 3,
  max_extrapolation = 0.1
)

Arguments

ts

Time series in s2ts format (generated using extract_s2ts()).

min_qa

(optional) minimum 0-1 quality value (points with qa < min_qa are not used, while qa values in the range min_qa to 1 are reshaped into the range 0 to 1). Default is 0.5.

noise_dir

Direction of points generally containing noise. If "low", higher values are generally maintained (this is the case of most vegetation indices like NDVI); if "high", lower values are generally maintained; if "undefined" (default), no assumptions are done.

spike

Relative "y" difference for spike determination (default is 0.25). Set to NA to skip spike removal.

spike_window

Maximum number of values for spike identification (it must be an odd number). Default is 3.

sg_daywindow

Half-size of the time window to be used to interpolate

sg_polynom

Argument polynom of function w_savgol().

sg_n

(optional) Positive integer: number of applications of the Savitzky-Golay filter. The minimum value is 1 (a single application using the weights included in ts). Within each additional application, the weights included in ts are multiplicated for the relative ranks of the difference between original and smoothed values (if noise_dir = "low") or between smoothed and original values (if noise_dir = "high"). If noise_dir = "undefined", this argument is coerced to 1.

max_extrapolation

(optional) Numeric: maximum allowed extrapolation out of original range (relative value). Default is 0.1 (+10%). Set to Inf in order not to set any constraint.

Value

The output time series in s2ts format.

Author(s)

Luigi Ranghetti, PhD (2020) luigi@ranghetti.info

Examples

# Load input data
data("ts_raw")

# Smoothing time series using default parameters
ts_smoothed <- smooth_s2ts(ts_raw)
print(ts_smoothed, topn = 5) # standard print
head(as.data.frame(ts_smoothed)) # see content
plot(ts_smoothed)

# Apply a more pronounced smoothing
ts_smoothed_2 <- smooth_s2ts(
  ts_raw,
  min_qa = 0.5, # exclude values with qa < 0.5
  sg_daywindow = 30, # larger moving window
  sg_polynom = 3, # cubic interpolation
  sg_n = 5 # apply the SG filter 5 times
)
plot(ts_smoothed_2)

ranghetti/sen2rts documentation built on March 31, 2024, 1:18 a.m.