timeDir | R Documentation |
Analysis of environmental change in time for a set of coordinate pairs.
timeDir(x, x.dates, y, y.dates, temporal.buffer, fun = NULL, min.count = 2)
x |
Object of class SpatRaster. |
x.dates |
Object of class Date with observation dates of y. |
y |
Object of class SpatVector. |
y.dates |
Object of class Date with observation dates of y. |
temporal.buffer |
two element vector with temporal window size (expressed in days). |
fun |
List of statistical function to apply to the data. |
min.count |
Minimum number of samples required by stat.fun. Default is 2. |
This function quantifies environmental changes in time for each GPS entry along a movement track. First, for each point in y, the function compares its observation date (y.dates) against the dates with environmental data (x.dates), and preserves those entries in x that fall within the temporal.buffer. The user can adjust this window to determine which images are the most important. For example, if one wishes to know how the landscape evolved up to the observation date of the target sample, temporal.buffer can be define as, e.g., c(30,0) forcing the function to only consider pixels recorded within the previous 30 days. After selecting adequate temporal information for each data point, a list of user-defined statistical metrics are calculated (i.e., fun).
A data.frame with statistics at each GPS observation. In addition the user defined statistics, the table will contain several entries describing the data used to calculate those statistics:
distance_traveled - Total distance traveled between all observations
elapsed_time - Time between the first and last observation
nr_observations - nr_observations
pixel_value - Pixel value at the main observation
spaceDir
{
require(terra)
# read raster data
file <- list.files(system.file('extdata', '', package="rsMove"), 'ndvi.tif', full.names=TRUE)
r.stk <- rast(file)
r.stk <- c(r.stk, r.stk, r.stk) # dummy files for the example
# read movement data
shortMove <- read.csv(system.file('extdata', 'shortMove.csv', package="rsMove"))
# convert observations to vector
shortMove = vect(shortMove, geom=c("x","y"), crs="EPSG:32632")
# raster dates
r.dates <- seq.Date(as.Date("2013-08-01"), as.Date("2013-08-09"), 1)
# sample dates
obs.dates <- as.Date(shortMove$date)
# perform directional sampling
functions <- list(
slope=function(x,y) lm(y~x)$coefficients[2][[1]],
mean=function(x,y) mean(y, na.rm=T),
sd=function(x,y) sd(y, na.rm=T)
)
time.env <- timeDir(r.stk, r.dates, shortMove, obs.dates, 3, fun=functions)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.