knitr::opts_chunk$set(echo = TRUE)
#knitr::opts_knit$set(root.dir = 'relative_path_to_root_from_Rmd' )
library(devtools)
library(ggplot2)
library(pander)
library(magick)
library(StereoCamDataUtils)

To install the package

library(devtools)
devtools::install_github("rooperc4/StereoCamDataUtils")
library("StereoCamDataUtils")

Purpose

The functions contained in this package are used to deal with the data from image analyses conducted using SEBASTES stereo camera software. Currently there are two functions, but more will be added in the future.

p<-image_read("Sebastes.png")
plot(p)

Existing Functions

Data replace

This function replaces the *.db data files with new versions by matching the deployment ID's and replacing the appropriate data files

SEB_data_replace("D:/Longline Survey Gear Comparisons/TrigCamData/Raja/Raja data/Raja data","D:/Longline Survey Gear Comparisons/TrigCamData/Raja")
SEB_data_replace("D:/Longline Survey Gear Comparisons/TrigCamData/Gadus/Gadus data","D:/Longline Survey Gear Comparisons/TrigCamData/Gadus")
SEB_data_replace("D:/Longline Survey Gear Comparisons/TrigCamData/Alutus/Alutus data/Alutus data","D:/Longline Survey Gear Comparisons/TrigCamData/Alutus")
SEB_data_replace("D:/Longline Survey Gear Comparisons/TrigCamData/Clupea/Clupea data","D:/Longline Survey Gear Comparisons/TrigCamData/Clupea")

Data concatenate

This function concatenates the *.db data files from multiple deployments into a single frame table (which includes accessory data) and a target table.

SEB_data_concatenate("D:/Longline Survey Gear Comparisons/TrigCamData/Raja")
SEB_data_concatenate("D:/Longline Survey Gear Comparisons/TrigCamData/Gadus")
SEB_data_concatenate("D:/Longline Survey Gear Comparisons/TrigCamData/Alutus")
SEB_data_concatenate("D:/Longline Survey Gear Comparisons/TrigCamData/Clupea")

Merge SEBASTES data with GPS and other data

There are typically two types of GPS data to merge with the image analysis data. The first are point data, where each camera deployment is at a single position (e.g. TrigCam deployments). In this case a simple function to merge the position data with the deployment data is used; SEB_GPS_point. It inputs the frame data outpub from the data concatenate function and a table of GPS points identified by a Deployment_ID column. Accessory data, such as depth or temperature can also be added in. The code below outlines an example.

all_frame_data<-rbind(SEB_data_concatenate("D:/Longline Survey Gear Comparisons/TrigCamData/Raja")$frame.data,SEB_data_concatenate("D:/Longline Survey Gear Comparisons/TrigCamData/Clupea")$frame.data,SEB_data_concatenate("D:/Longline Survey Gear Comparisons/TrigCamData/Gadus")$frame.data)

GPS_data<-read.csv("D:/LonglineTrigCamPositions.csv",header=TRUE)

all_frame_data<-SEB_GPS_point(all_frame_data,Deployment_ID=GPS_data$Deployment_ID,Longitude=GPS_data$Longitude,Latitude=GPS_data$Latitude,Accessory_data=data.frame(GPS_data$Camera.Name,GPS_data$Depth,GPS_data$Deployment.event))

The second type of GPS data are transect-type data (e.g. drop camera deployments). Here we have GPS data with a time stamp and a location. These data are merged with the frame data using the time stamp of the image and the time stamp of the GPS feed. It is important that the time zone be consistent between the two feeds, but the function allows the user to input an offset (such as -7 hours from GMT to PST). Accessory data can also be added here as well. The below code outlines an example.

#Example to come
SEB_GPS_transect()

Often we have deployed a Seabird CTD on the drop camera systems. The following function will match the SBE data to the frame data using the time stamp and merge the depth and temperature data to the frames. It can be used for multiple files or a single file of SBE data and works with concatenated frame data. It is important that the time zone be consistent between the two data sources, but the function allows the user to input an offset (such as -7 hours from GMT to PST). The below code outlines an example.

frame_data<-SEB_data_concatenate("D:/Longline Survey Gear Comparisons/TrigCamData/Raja")
files<-list.files("D:/Longline Survey Gear Comparisons/TrigCamData/Raja",pattern=".asc",full.names=TRUE)
frame_data<-SEB_SeaBird_append(frame_data, files,offset=0)

Example output

Finally, here's an example of pulling the target data using the SEB_data_concatenate function and produce length frequency histograms in ggplot.

library(ggplot2)
library(gridExtra)

target_data<-rbind(SEB_data_concatenate("D:/Longline Survey Gear Comparisons/TrigCamData/Raja")$target.data,SEB_data_concatenate("D:/Longline Survey Gear Comparisons/TrigCamData/Clupea")$target.data,SEB_data_concatenate("D:/Longline Survey Gear Comparisons/TrigCamData/Gadus")$target.data)

p1<-ggplot()+geom_histogram(data=target_data,aes(x=LENGTH,color=SPECIES_GROUP))+theme(legend.position="none")
p1+facet_wrap(~SPECIES_GROUP)

d1<-aggregate(RANGE~DEPLOYMENT_ID+SPECIES_GROUP,data=target_data,FUN="length")
p1<-ggplot(d1)+geom_bar(aes(x=DEPLOYMENT_ID,y=RANGE,color=SPECIES_GROUP,fill=SPECIES_GROUP),stat="identity",position="fill")
p1


rooperc4/StereoCamDataUtils documentation built on Nov. 20, 2024, 9:58 p.m.