Gapfill_ssa: Gap-fill using SSA

View source: R/Gapf_SSA.R

Gapfill_ssaR Documentation

Gap-fill using SSA

Description

This function automatically gap-fills the missing data points (marked as "NA") in the flux dataset using sigular spectrum analysis (SSA). The SSA is based on the algorithms in the package 'spectral.methods' and 'Rssa'.

Usage

Gapfill_ssa(
  data,
  Flux = "Flux",
  Date = "Date",
  Date_form = "ymd_hms",
  borders.wl = list(a = c(0, 10, Inf)),
  win = 5,
  L = NULL,
  interval = 10,
  fail = "ave",
  ...
)

Arguments

data

a data frame that includes the flux (with NA indicating the missing data)

Flux

a string indicates the column name for the flux variable to be gap-filled

Date

a string indicates the column name for the date, which HAS to include the time information

Date_form

a string indicates the format of the date, either "ymd_hms" (default), "mdy_hms" or "dmy_hms"

borders.wl

list of numeric vectors indicate orders of the different periodicity bands to extract. Units are the sampling frequency of the series (needs one vector per step; default: list(a = c(0,10, Inf)) (see details in the package 'spectral.methods')).

win

a number indicates the required sampling window length around each gap (total number in two sides), unit: days (default: 5)

L

an integer indicates the window length for time series decomposition, see ?ssa. If not provided, one third of the length of the selected time series is used.

interval

a number indicates the temporal resolution of the measurements in the dataset, unit: minutes (default: 10)

fail

a string or a number indicates what to do when model fails to converge: 1. use the mean value in the sampling window to fill the gap ("ave", default), or 2. use any value assigned here to fill the gap (e.g., 9999, NA, etc.)

...

other arguments pass to 'gapfillSSA'

Value

A data frame that includes the original data, gap-filled data ("filled") and a "mark" column that indicates the value in each row of the "filled" is either: 0. original, 1. gap-filled, or 2. failed to converge

Examples

# read example data
df <- read.csv(file = system.file("extdata", "Soil_resp_example.csv", package = "FluxGapsR"),header = T)
df_filled <- Gapfill_ssa(data = df)
# visualize the gapfilled results
plot(df_filled$filled,col="red")
points(df_filled$Flux)

junbinzhao/FluxGapsR documentation built on Nov. 19, 2022, 9:17 p.m.