Resample trajectory positions using a constant time interval. If no timestamp that represents an exact multiple of this time interval is found, linear interpolation is performed using the two adjacent timestamps.
mt_resample( data, use = "trajectories", save_as = "rs_trajectories", dimensions = c("xpos", "ypos"), timestamps = "timestamps", step_size = 10, exact_last_timestamp = TRUE, constant_interpolation = NULL, verbose = FALSE )
a mousetrap data object created using one of the mt_import
functions (see mt_example for details). Alternatively, a trajectory
array can be provided directly (in this case
use will be ignored).
a character string specifying which trajectory data should be used.
a character string specifying where the resulting trajectory data should be stored.
a character vector specifying the dimensions in the
trajectory array that should be resampled. If
"all", all trajectory
dimensions except the timestamps will be resampled.
a character string specifying the trajectory dimension containing the timestamps.
an integer specifying the size of the constant time interval. The unit corresponds to the unit of the timestamps.
logical indicating if the last timestamp should
always be appended (which is the case by default). If
last timestamp is only appended if it is a multiple of the step_size.
an optional integer. If specified, constant
instead of linear interpolation will be performed for all adjacent
timestamps whose difference exceeds the number specified for
constant_interpolation. The unit corresponds to the unit of the
logical indicating whether function should report its progress.
A mousetrap data object (see mt_example) with an additional
array (by default called
rs_trajectories) containing the resampled
trajectories. If a trajectory array was provided directly as
only the resampled trajectories will be returned.
mt_resample can be used if the number of logged positions in a trial
should be reduced.
mt_resample achieves this by artificially
decreasing the resolution with which the positions were recorded. For
example, if mouse positions were recorded every 10 ms in an experiment, but
one was only interested in the exact mouse position every 50 ms,
step_size=50 could be used. In this case, only
every fifth sample would be kept.
mt_resample can be used to only retain values for
specific timestamps across trials (e.g., if for each trial the position of
the mouse exactly 250 ms and 500 ms after onset of the trial are of
interest). In case that a trial does not contain samples at the specified
timestamps, linear interpolation is performed using the two adjacent
If a number is specified for
constant_interpolation, constant instead
of linear interpolation will be performed for all adjacent timestamps whose
difference exceeds this number. Specifically, a period without mouse movement
will be assumed starting at the respective timestamp until the next timestamp
mt_resample does not average across time intervals. For
this, mt_average can be used.
mt_example <- mt_resample(mt_example, save_as="rs_trajectories", step_size=50)