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
# About time in R | |
# M. Johnston | |
# Thu Aug 10 13:06:35 2023 America/Los_Angeles ------------------------------ | |
#---------------------------------------------------------# | |
# Takeaway: For date-times in R (POSIXt objects), there are differences between what | |
# your R session references, stores, and displays. It's very important to be aware | |
# of these differences to avoid date time gotchas. | |
#---------------------------------------------------------# |
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
install.packages(c('rmarkdown', | |
'knitr', | |
'lubridate', | |
'ggplot2', | |
'data.table', | |
'readxl', | |
'RSQLite', | |
'dplyr' | |
) | |
) |
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
library(tidyverse) | |
# Previous version of SBM used 120 mm cutoff for rearing | |
# Exploring idea of using hypothetical continuous relationship between rearing probability and fork length | |
## Four-parameter logistic model gives nice control over the curve | |
# a = max value | |
# b = steepness of the curve | |
# c = inflection point | |
# d = min value |
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
#--------------------------------------------# | |
# ARTEMIS Demo | |
# Stantec presentation, 2020-03-03 | |
# M. Johnston, Cramer Fish Sciences | |
# This script presents an introduction to data simulation in {artemis}. | |
#--------------------------------------------# | |
# Goal: Simlulate data and visualize relationships | |
#-------------------------------------------------------# |
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
# separates the vemco column formatting of freq-codespace-tagid, then returns the original dataframe with the codespace and tagids as separate columns | |
parse_tag_info <- function(df, tagcol = "TagID") { | |
names(df)[names(df) == tagcol] <- "SepTagID" # rename the old combined tagid col | |
out <- as.data.frame(do.call(rbind, strsplit(as.character(df$SepTagID),'-')), | |
stringsAsFactors = FALSE) | |
colnames(out) <- c("freq", "CodeSpace", "TagID") | |
final <- cbind(df, out) | |
drops <- c("freq", "SepTagID") |
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
If the original vrl files are unavailable, a drift-correction needs to be performed on the .csv file for each receiver in a deployment. You will need at least a .vdb with the receiver log of interest to be able to do this. | |
To do this, access the events tab in VUE for a receiver download. Export it to a csv. | |
Open it in Excel. Make sure the PC Time (very last cell in the Description column) is in an acceptable date/time format. Do this by copying and pasting it to the cell below it, and using the custom m/d/yyyy hh:mm:ss.00 format. | |
Events Tab: | |
In a new column, calculate the time between initialization and end time (days). Do this by subtracting A1 from the final cell in the A column. This is done in J2 in the example | |
Covert J2 to seconds (multiply by 84600). This is done in K2. |
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
#Goal: identify fieldwork periods by finding high tide on for each of the next 2 weeks. | |
# There are two high tides per day. A high high tide and a lower high tide. Adding ~25.3 hours to each one, respectively, gives you the # date/times of the next ones. | |
# So for the two high tides on 1/1/19: | |
tides <- structure(c(1546341300, 1546384500), class = c("POSIXct", "POSIXt" | |
), tzone = "Pacific/Pitcairn") | |
# adding 25.3 hours to this vector gives us the date/times of the next two high tides: | |
tides + as.difftime(25.3, units = "hours"). |
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
# Depends on the `beepr` package by @rasmusab: https://cran.r-project.org/web/packages/beepr/README.html | |
# Code greatly improved by flodel on Stack Exchange Code Review (thanks flodel) | |
# Planned improvements/expansions: new end-of-timer sounds, add functionality for starting a separate R session so that it doesn't bogart the current one. | |
timer <- function(interval, units = c("secs", "mins", "hours", "days", "weeks")) { | |
units <- match.arg(units) | |
num_sec <- interval * switch(units, secs = 1, mins = 60, hours = 3600, | |
days = 86400, weeks = 604800) | |
Sys.sleep(num_sec) | |
if (require(beepr)) beep(2) else message("TIMER DONE YO!") |
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
tt %>% | |
mutate( | |
laststation = as.character(laststation), | |
TagID = as.character(TagID) | |
) %>% | |
group_by(laststation) %>% | |
ggplot(aes(TagID, kmday)) + | |
geom_segment(aes(xend=TagID, yend=0)) + | |
geom_point(shape="—", size=5) + | |
facet_wrap(~laststation, nrow=1, scales="free_x") + |
NewerOlder