TrajsBuild | R Documentation |
Reads multiple trajectories from files, performs some basic sanity checks on them, and optionally smooths and scales them. Attempts to collect and report errors for multiple trajectories in a single call.
TrajsBuild(
fileNames,
fps = NULL,
scale = NULL,
spatialUnits = NULL,
timeUnits = NULL,
csvStruct = list(x = 1, y = 2, time = NULL),
smoothP = 3,
smoothN = 41,
translateToOrigin = FALSE,
rootDir = NULL,
csvReadFn = function(filename, ...) utils::read.csv(filename, stringsAsFactors = FALSE,
...),
...
)
fileNames |
Vector of the names of CSV files containing trajectory
coordinates. All of the files must have the same columns. All file names
must be unique. If |
fps |
Vector of frames-per-second values corresponding to the
trajectories in |
scale |
Vector of scale values corresponding to the trajectories in
|
spatialUnits |
Abbreviated name of spatial coordinate units after scaling, e.g. "m". |
timeUnits |
Abbreviated name of temporal units, e.g. "s". |
csvStruct |
A list which identifies the columns in each CSV file which contain x-, y-, and optionally time-values. |
smoothP |
Filter order to be used for Savitzky-Golay smoothing (see
|
smoothN |
Filter length to be used for Savitzky-Golay smoothing (must be
odd, see |
translateToOrigin |
If TRUE, each trajectory is translated so that its starting point is at (0, 0). |
rootDir |
Optional name of a top level directory which contains the CSV
files. If |
csvReadFn |
Function used to read the CSV files. Required to accept
arguments |
... |
Additional arguments passed to |
If rootDir
is not null, it should be the name of a directory which is
searched for the files in fileNames
. The found files are then used as
the list of files to be read in. This may be useful when the names of the
files are known, but their exact location within a directory structure is not
known.
For each file name in fileNames
, reads the file by calling
csvReadFn
to obtain a set of coordinates and optionally times. A
Trajectory is then constructed by passing the coordinates to
TrajFromCoords
, passing in the appropriate fps
value,
and x, y and time column names/indices from csvStruct
. If scale
is not NULL
, the trajectory is scaled by calling
TrajScale
. If smoothP
and smoothN
are not
NULL
, the trajectory is smoothed by calling
TrajSmoothSG
.
A list of trajectories.
read.csv
, TrajFromCoords
,
TrajScale
, TrajSmoothSG
,
TrajTranslate
## Not run:
# Names of CSV files containing trajectory coordinates
fileNames <- c('xy001.csv', 'xy003.csv', 'xy004.csv')
# The files are all located somewhere under this directory
rootDir <- '.'
# Scale for these files is 1 / pixels per metre
scale <- c('1/1200', '1/1350', '1/1300')
# Files have columns y, x
csvStruct <- list(x = 2, y = 1)
# Apply default smoothing, and the files are formatted as conventional CSV,
# so there's no need to specify csvReadFn
trjs <- TrajsBuild(fileNames, fps = 50, scale = scale, units = "m",
csvStruct = csvStruct, rootDir = rootDir)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.