Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
befa2c6
commit 4dec20a
Showing
14 changed files
with
389 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
Package: RchivalTag | ||
Type: Package | ||
Title: Analyzing Archival Tagging Data | ||
Version: 0.1.1 | ||
Date: 2020-03-23 | ||
Version: 0.1.2 | ||
Date: 2020-06-17 | ||
Author: Robert Bauer | ||
Maintainer: Robert Bauer <marine.biologging@gmail.com> | ||
Description: A set of functions to generate, access and analyze standard data products from archival tagging data. | ||
Depends: R (>= 3.5.0) | ||
Imports: plyr, maptools, graphics, stats, raster, readr, rgeos, ncdf4, | ||
pracma, maps, mapdata, grDevices, oceanmap, sp, methods, | ||
PBSmapping | ||
pracma, dygraphs, xts, maps, mapdata, grDevices, oceanmap, sp, | ||
methods, PBSmapping | ||
License: GPL (>= 3) | ||
LazyLoad: yes | ||
Packaged: 2020-03-24 18:42:37 UTC; work | ||
Packaged: 2020-06-23 22:48:04 UTC; work | ||
Repository: CRAN | ||
Date/Publication: 2020-03-25 14:00:02 UTC | ||
Date/Publication: 2020-06-24 04:30:03 UTC | ||
NeedsCompilation: no |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
dy_DepthTS <- dy_TS <- function(ts_df, y="Depth", xlim, ylim, | ||
ylab=y, xlab="Time (UTC)", main, | ||
ID, ID_label="Serial", | ||
plot_DayTimePeriods=TRUE, twilight.set="ast", | ||
color="darkblue", | ||
doRangeSelector=TRUE, labelsUTC=TRUE, drawPoints=FALSE,pointSize=2, | ||
...){ | ||
|
||
if(missing(ID) & is.null(ts_df[[ID_label]])) { | ||
k <- c("DeployID","Ptt") %in% names(ts_df) | ||
if(any(k)) { | ||
ID_label <- c("DeployID","Ptt")[which(k)[1]] | ||
warning(paste0("ID_label 'Serial' not found! Resetting ID_label to '",ID_label,"'!")) | ||
} | ||
if(!all(k)) warning(paste0("no column corresponding to ID_label '",ID_label,"' found!")) | ||
} | ||
if(missing(ID)) ID <- unique(ts_df[[ID_label]]) | ||
if(length(ID) > 1) { | ||
warning("multiple tags in data set: ", paste(ID, collapse=', ')) | ||
main <- '' | ||
} | ||
if(missing(main)) main <- paste("Tag ID", ID) | ||
|
||
if(missing(ylim)){ | ||
if(y == "Depth") {ylim <- c(max(ts_df$Depth,na.rm = T),-1) | ||
}else{ | ||
ylim <- range(ts_df$y) | ||
} | ||
} | ||
if(!missing(xlim)) { | ||
if(class(xlim)[1] == 'Date' | nchar(as.character(xlim[1])) == 10){ | ||
xlim <- as.Date(xlim) | ||
if(length(xlim) == 1) xlim <- c(xlim, xlim) | ||
xlim[2] <- xlim[2]+1 | ||
xlim <- paste(xlim, '00:00:00') | ||
} | ||
xlim <- .fact2datetime(xlim,tz = "UTC") | ||
if(length(xlim) > 2) xlim <- range(xlim) | ||
if(length(xlim) == 1) xlim <- c(xlim, xlim[1]+24*60*60) | ||
|
||
ts_df <- ts_df[which(ts_df$datetime >= xlim[1] & ts_df$datetime <= xlim[2]),] | ||
} | ||
|
||
if(!labelsUTC) xlab <- gsub("(UTC)","",xlab) | ||
|
||
dat <- ts_df[,c("datetime",y)] | ||
dat$datetime <- as.POSIXct(dat$datetime,tz = "UTC") | ||
ds <- data.frame(dat[,y]); names(ds) <- y | ||
dat_xts <- xts::xts(ds,order.by=dat$datetime) | ||
|
||
# create dygraph | ||
dg <- dygraph(dat_xts, xlab=xlab, ylab=ylab, main=main, ...) | ||
|
||
|
||
|
||
# add shades | ||
if(plot_DayTimePeriods){ | ||
dawn <- paste0("dawn.",twilight.set) | ||
dusk <- paste0("dusk.",twilight.set) | ||
shade_periods <- c("sunrise","sunset",dawn,dusk) | ||
if(!all(shade_periods %in% names(ts_df))) { | ||
if(all(c("Lon", "Lat", "datetime") %in% names(ts_df))){ | ||
ts_df <- get_DayTimeLimits(ts_df) | ||
}else{ | ||
plot_DayTimePeriods <- F | ||
warning("no geolocation data or datetime vector provided (Lon, Lat, datetime)! plot_DayTimePeriods omitted in current call. Please revise.") | ||
} | ||
} | ||
} | ||
if(plot_DayTimePeriods){ | ||
shades <- unique(ts_df[,shade_periods]) | ||
|
||
shades_list <- list() | ||
j <- 1 | ||
|
||
for(i in 1:nrow(shades)){ | ||
add <- list(from=as.POSIXct(shades$sunrise[i],tz = "UTC"), to=as.POSIXct(shades$sunset[i],tz = "UTC"),color="white") | ||
shades_list[[j]] <- add | ||
j <- j+1 | ||
add <- list(from=as.POSIXct(shades$dawn.ast[i],tz = "UTC"), to=as.POSIXct(shades$sunrise[i],tz = "UTC"),color="lightgrey") | ||
shades_list[[j]] <- add | ||
j <- j+1 | ||
add <- list(from=as.POSIXct(shades$dusk.ast[i],tz = "UTC"), to=as.POSIXct(shades$sunset[i],tz = "UTC"),color="lightgrey") | ||
shades_list[[j]] <- add | ||
j <- j+1 | ||
} | ||
shades_list | ||
|
||
dg <- dyShading(dg, from = ts_df$datetime[1] , to = tail(ts_df$datetime,1),color = "darkgrey" ) | ||
for( period in shades_list ) { | ||
dg <- dyShading(dg, from = period$from , to = period$to,color = period$color) | ||
dg <- dyAnnotation(dg, x = mean(c(period$from,period$to)), text = period$label, attachAtBottom=T) | ||
} | ||
} | ||
label <- y | ||
if(y == "Depth") label <- paste(y,"(m)") | ||
dg <- dg %>% dyOptions(colors=color,drawPoints = drawPoints, pointSize = pointSize,labelsUTC = labelsUTC, strokeWidth = 1) %>% dyAxis("y", label = label, valueRange = ylim) | ||
if(doRangeSelector) dg <- dg %>% dyRangeSelector() | ||
return(dg) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.