s2ts: Class 's2ts'

View source: R/s2ts-class.R

s2tsR Documentation

Class s2ts

Description

Class used for {sen2rts} time series.

Usage

s2ts(value, date, id = NA, qa, orbit, sensor, rawval, ...)

as.s2ts(x, ...)

Arguments

value

(mandatory) Vector with the values ("y") of the time series.

date

(mandatory) Vector (of the same length of value) with the dates of each value.

id

(optional) Vector (of the same length of value or of length 1, in which case the passed value is replicated for each element of value) with the feature IDs of each value. If missing, all the values are considered as extracted from the same feature.

qa

(optional) Vector (of the same length of value) with the quality assessment values (range 0-1) associated to each value. If missing, all the values are considered as equally weighted.

orbit

(optional) Vector (of the same length of valueor of length 1, in which case the passed value is replicated for each element of value) with the Sentinel-2 orbits of each value.

sensor

(optional) Vector (of the same length of value or of length 1, in which case the passed value is replicated for each element of value) with the Sentinel-2 sensors ("2A" or "2B") of each value.

rawval

(optional) Vector (of the same length of value) with the non-smoothed values (this is generally created by outputs of smooth_s2ts()).

...

Additional vectors to be passed. Each additional argument is threated as an additional element of the output list in case it is of the same length of value, otherwise it is threated as an output attribute.

x

Input element to be converted to s2ts.

Details

Some specific methods for this class are defined.

  • ⁠<s2ts_obj>$value⁠ returns a data.table with the values for each date, in wide format.

  • ⁠<s2ts_obj>$date⁠ returns a vector with the dates.

  • ⁠<s2ts_obj>$id⁠ returns a vector with the unique ID values.

  • ⁠<s2ts_obj>$qa⁠ returns a data.table with the quality assessment values for each date, in wide format.

  • ⁠<s2ts_obj>$rawval⁠ returns a data.table with the rawval values for each date, in wide format.

  • ⁠<s2ts_obj>[[<idname>]]⁠ returns a subsampled s2ts containing only the values of the provided ID.

Notice that since $ and [[ methods are defined, the syntaxes ⁠<s2ts_obj>$<fieldname>⁠ and ⁠<s2ts_obj>[["<fieldname>"]]⁠ can not be used (use instead ⁠<s2ts_obj>[,<fieldname>]⁠).

Value

The output time series in s2ts format.

This is a format derived from data.table, containing the mandatory columns id, date, value, and additional ones among which qa, orbit, sensor and rawval (see the arguments in this help for their meanings).

The optional attribute gen_by provides information about the function which generated the object (if provided).

Author(s)

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

Examples

## Create a s2ts object from raw
library(sen2r)
sample_dt <- sen2r::s2_dop(
  timewindow = c("2020-01-01", "2020-01-31"), 
  s2_orbit = 22
)
sample_dt$ndvi <- runif(nrow(sample_dt), 0, 1)
sample_dt$qa <- sqrt(sample_dt$ndvi)

# Minimum example (including dates and values)
s2ts(value = sample_dt$ndvi, date = sample_dt$date, id = "1")

# Example with additional information (including quality flags)
sample_ts <- s2ts(
  value = sample_dt$ndvi, 
  date = sample_dt$date, 
  id = "1",
  qa = sample_dt$qa, 
  sensor = sample_dt$mission
)
sample_ts

# Extract s2ts content
as.list(sample_dt) # convert in list (unclass)
sample_ts$date # extract dates
sample_ts$id # extract IDs
sample_ts$value # extract values
sample_ts$qa # extract quality values
sample_ts$rawval # extract raw values (for smooth_s2ts() and fill_s2ts() outputs)

# Load sample data generated by sen2rts functions
data(ts_raw)      # generated by extract_s2ts()
data(ts_smoothed) # generated by smooth_s2ts()
data(ts_filled)   # generated by fill_s2ts()

# Visualise data
print(ts_raw, topn = 5)
print(ts_smoothed, topn = 5)
print(ts_raw, topn = 5)

# See which function generated a s2ts object
attr(ts_raw, "gen_by")
attr(ts_smoothed, "gen_by")
attr(ts_filled, "gen_by")

# Convert in data frames or data tables
df_raw <- as.data.frame(ts_raw)
head(df_raw)
df_smoothed <- as.data.frame(ts_smoothed)
head(df_smoothed)
df_filled <- as.data.frame(ts_filled)
head(df_filled)

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