Commit 29994e3b authored by Chris Holbrook's avatar Chris Holbrook

fix #74; add arg show_progress to make_frames & interpolate_path

parent 66014038
......@@ -16,6 +16,14 @@
### Minor changes
- make_frames
- add argument show_progress (default = TRUE) to optionally supress progress bars
- issue #74
- interpolate_path
- add argument show_progress (default = TRUE) to optionally supress progres bars
- issue #74
- calc_collision_probs
- in help examples, make separate plots for detection and collision probs
- issue #77
......
......@@ -28,6 +28,9 @@
#'
#' @param lnl_thresh A numeric threshold for determining if linear or
#' non-linear interpolation shortest path will be used.
#'
#' @param show_progress Logical. Progress bar and status messages will be
#' shown if TRUE (default) and not shown if FALSE.
#'
#' @details Non-linear interpolation uses the \code{gdistance} package
#' to find the shortest pathway between two locations (i.e.,
......@@ -180,7 +183,7 @@
interpolate_path <- function(det, trans = NULL, start_time = NULL,
int_time_stamp = 86400, lnl_thresh = 0.9,
out_class = NULL){
out_class = NULL, show_progress = TRUE){
# stop if out_class is not NULL, data.table, or tibble
if(!is.null(out_class)){
......@@ -331,9 +334,9 @@ interpolate_path <- function(det, trans = NULL, start_time = NULL,
grpn = data.table::uniqueN(dtc$i.start)
pb <- txtProgressBar(min = 0, max = grpn, style = 3)
if(show_progress) pb <- txtProgressBar(min = 0, max = grpn, style = 3)
dtc[, lcd := {setTxtProgressBar(pb, value = .GRP);
dtc[, lcd := {if(show_progress) setTxtProgressBar(pb, value = .GRP);
gdistance::costDistance(trans, fromCoords = as.matrix(
.SD[1, c("deploy_long", "deploy_lat")]),
toCoords = as.matrix(.SD[.N, c("deploy_long", "deploy_lat")]))},
......@@ -382,10 +385,10 @@ interpolate_path <- function(det, trans = NULL, start_time = NULL,
message("Starting linear interpolation... (step 2 of 3)")
# linear interpolation
grpn = uniqueN(ln$i.start)
pb <- txtProgressBar(min = 0, max = grpn, style = 3)
if(show_progress) pb <- txtProgressBar(min = 0, max = grpn, style = 3)
ln[, bin_stamp := detection_timestamp_utc][is.na(detection_timestamp_utc),
bin_stamp := bin]
ln[, i_lat := {setTxtProgressBar(pb, .GRP);
ln[, i_lat := {if(show_progress) setTxtProgressBar(pb, .GRP);
tmp = .SD[c(1, .N),
c("detection_timestamp_utc", "deploy_lat")];
approx(c(tmp$detection_timestamp_utc),
......@@ -417,9 +420,9 @@ interpolate_path <- function(det, trans = NULL, start_time = NULL,
message("\nStarting non-linear interpolation... (step 3 of 3)")
grpn <- nrow(lookup)
pb <- txtProgressBar(min = 0, max = grpn, style = 3)
if(show_progress) pb <- txtProgressBar(min = 0, max = grpn, style = 3)
# calculate non-linear interpolation for all unique movements in lookup
lookup[, coord := { setTxtProgressBar(pb, value = .GRP);
lookup[, coord := { if(show_progress) setTxtProgressBar(pb, value = .GRP);
sp::coordinates(
gdistance::shortestPath(trans, as.matrix(
.SD[1, c("deploy_long", "deploy_lat")]), as.matrix(
......
......@@ -57,6 +57,9 @@
#' processing large number of frames. Default \code{preview = FALSE}
#'
#' @param bg_map A spatial points, lines, or polygons object.
#'
#' @param show_progress Logical. Progress bar and status messages will be
#' shown if TRUE (default) and not shown if FALSE.
#'
#' @param ... Optional graphing parameters for customizing elments of
#' fish location points, receiver location points, timeline, and
......@@ -205,7 +208,7 @@ make_frames <- function(proc_obj, recs = NULL, out_dir = getwd(),
show_interpolated = TRUE, tail_dur = 0, animate = TRUE,
ani_name = "animation.mp4", frame_delete = FALSE,
overwrite = FALSE, ffmpeg = NA, preview = FALSE,
bg_map = NULL, ...){
bg_map = NULL, show_progress = TRUE, ...){
# test ffmpeg and get path
if(animate) ffmpeg <- get_ffmpeg_path(ffmpeg)
......@@ -489,12 +492,12 @@ make_frames <- function(proc_obj, recs = NULL, out_dir = getwd(),
if(preview){ grpn <- 1 } else {
# start progress bar
grpn <- data.table::uniqueN(work_proc_obj$grp)
pb <- txtProgressBar(min = 0, max = grpn, style = 3)
if(show_progress) pb <- txtProgressBar(min = 0, max = grpn, style = 3)
}
# call cust_plot witin data.table
work_proc_obj[grp_num <= grpn,
{if(!preview) setTxtProgressBar(pb, .GRP)
{if(!preview & show_progress) setTxtProgressBar(pb, .GRP)
cust_plot(x = .SD,
.time_period = time_period,
.recs = recs,
......@@ -508,7 +511,7 @@ make_frames <- function(proc_obj, recs = NULL, out_dir = getwd(),
"record_type", "f_name", "grp", "row_in")]
if(preview) { return(paste("preview frames are in \n", out_dir)) } else {
close(pb) }
if(show_progress) close(pb) }
if(animate == FALSE & frame_delete == TRUE) message("are you sure?")
if(animate == FALSE) message(paste("frames are in\n", out_dir))
......@@ -522,6 +525,6 @@ make_frames <- function(proc_obj, recs = NULL, out_dir = getwd(),
if(animate & !frame_delete){
make_video(dir = out_dir, pattern = paste0(char, ".png"), output = ani_name,
output_dir = out_dir, overwrite = overwrite, ffmpeg = ffmpeg)
message(paste("video and frames in \n", out_dir))}
if(show_progress) message(paste("video and frames in \n", out_dir))}
}
......@@ -5,7 +5,8 @@
\title{Interpolate new positions within a spatiotemporal path data}
\usage{
interpolate_path(det, trans = NULL, start_time = NULL,
int_time_stamp = 86400, lnl_thresh = 0.9, out_class = NULL)
int_time_stamp = 86400, lnl_thresh = 0.9, out_class = NULL,
show_progress = TRUE)
}
\arguments{
\item{det}{An object of class \code{glatos_detections} or data frame
......@@ -32,6 +33,9 @@ non-linear interpolation shortest path will be used.}
\item{out_class}{Return results as a data.table or tibble. Default
returns results as data.frame. Accepts `data.table` or `tibble`.}
\item{show_progress}{Logical. Progress bar and status messages will be
shown if TRUE (default) and not shown if FALSE.}
}
\value{
A dataframe with animal_id, bin_timestamp,
......
......@@ -9,7 +9,7 @@ make_frames(proc_obj, recs = NULL, out_dir = getwd(),
show_interpolated = TRUE, tail_dur = 0, animate = TRUE,
ani_name = "animation.mp4", frame_delete = FALSE,
overwrite = FALSE, ffmpeg = NA, preview = FALSE, bg_map = NULL,
...)
show_progress = TRUE, ...)
}
\arguments{
\item{proc_obj}{A data frame created by
......@@ -64,6 +64,9 @@ processing large number of frames. Default \code{preview = FALSE}}
\item{bg_map}{A spatial points, lines, or polygons object.}
\item{show_progress}{Logical. Progress bar and status messages will be
shown if TRUE (default) and not shown if FALSE.}
\item{...}{Optional graphing parameters for customizing elments of
fish location points, receiver location points, timeline, and
slider (moves along the timeline). See also \strong{Note} section.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment