knitr::opts_chunk$set(warning = FALSE, message = FALSE)
Wildlife Computers (Redmond, Washington, USA) provides an API for their data
portal that allows us to download the latest telemetry data for any deployment.
To facilitate connection and use of this API within R, the wcUtils
package
has been developed.
The data portal is not a public repository. Data access is controlled by the data owner. Thus, only those users who are either owners of the deployment data or users who have been granted access by the owner can access the API.
The wcUtils
package is available for install from GitHub:
if (!require('devtools')) install.packages('devtools') if (!require('wcUtils')) { devtools::install_github('jmlondon/wcUtils') } if (!require('tidyverse')) install.packages('tidyverse')
All of the deployments have been labeled within the data portal as ProjectID = AleutPV. We will use that information to only download the relevant data.
# first thing, get deployment data from WCDP r <- wcUtils::wcPOST() # get KotzEB09 ids and download the data aleut_ids <- wcUtils::wcGetProjectIDs(r,project = 'AleutPV') for (i in 1:length(aleut_ids)) { zipfile <- wcUtils::wcGetZip(id = aleut_ids[i]) file.copy(zipfile,'.',overwrite = TRUE) file.rename(file.path(basename(zipfile)), file.path(paste(aleut_ids[i],"zip",sep = '.')) ) }
The zip files downloaded from the data portal are named based on the
unique id assigned within the data portal. For our deployments, we have
assigned each a unique DeployID
. It would be more informative if we could
rename all of these zip files to the assigned DeployID
. Eventually, this
functionality could be implemented within the wcUtils
package and the API,
but for now, we'll just open each zip file and examine the data files to
extract the assigned DeployID
.
df <- tibble::as_tibble() for (zipfile in list.files(pattern = ".zip",full.names = TRUE)) { summary_name <- grep('*-Summary.csv', unzip(file.path( basename(zipfile)), list = TRUE)$Name, value = TRUE) deployid <- read.csv(unzip(zipfile, files = summary_name))$DeployID deployid <- as.character(deployid) instr <- read.csv(unzip(zipfile, files = summary_name))$Instr instr <- as.character(instr) first_tx <- read.csv(unzip(zipfile, files = summary_name))$LatestXmitTime first_tx <- as.character(first_tx) last_tx <- read.csv(unzip(zipfile, files = summary_name))$LatestXmitTime last_tx <- as.character(last_tx) ndays_tx <- read.csv(unzip(zipfile, files = summary_name))$XmitDays ndays_tx <- as.character(ndays_tx) file.remove(summary_name) file.rename(file.path(zipfile), file.path(paste(deployid,"zip",sep = '.')) ) df <- df %>% dplyr::bind_rows(list(filename = paste(deployid,"zip",sep = '.'), instrument = instr, "first transmission" = first_tx, "last transmission" = last_tx, "no. days" = ndays_tx )) }
df %>% knitr::kable(booktabs = TRUE, caption = 'Files and Associated Key Deployment Statistics')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.