library(here)
library(swfscDAS)
library(tidyverse)
localwd <- here("_R_code","task_1_segment_das_data")
das_file <- file.path(localwd, "CenPac_Toolbox_1997-2023.das")
strata_file <- file.path(localwd, "CenPac2.csv")
# randPics <- readRDS(file.path(localwd, "output","seg_sight_out.rds"))[["randpicks"]] # Run this to maintain segments from previous processing of same das file, and load using argument below
sp.code <- "033" # false killer whale species codeSegmenting DAS Survey Data
The first step in our workflow is to process raw DAS data collected during NOAA Fisheries ship-based line-transect surveys . DAS data are collected using WinCruz, the data collection software developed by Southwest Fisheries Science Center, and record animal encounter data as well as in-situ visual sighting conditions. After processing, we break effort into discrete segments for variance estimation. Here, we use swfscdas package tools to load, process, and segment these DAS files, but this functionality exists in other packages such as LTabundR.
Load packages and define working directory
Process raw DAS data into segments for DSM analysis
y.proc <- swfscDAS::das_process(das_file)
y.eff <- swfscDAS::das_effort(
y.proc,
method = "equallength",
seg.km = 10,
dist.method = "greatcircle",
num.cores = 1,
strata_files = strata_file
# , randpicks.load = randPics
)
y.eff.sight <- swfscDAS::das_effort_sight(y.eff, sp.codes = sp.code, sp.events = "S") # Arguments define which sightings to summarize
y.eff.sight.strata <- swfscDAS::das_intersects_strata(y.eff.sight, list(InPoly = strata_file)) # Provides logical column to filter for strata
#Filter for study area
y.eff.sight.strata$segdata <- y.eff.sight.strata$segdata %>% filter(InPoly == 1)
y.eff.sight.strata$sightinfo <- y.eff.sight.strata$sightinfo %>% filter(InPoly == 1)
#filter sighting info for S,G events
y.eff.sight.strata$sightinfo <- y.eff.sight.strata$sightinfo%>%filter(Event %in% c("S","G"))Data editing, filtering for errors
#Filter for segment lengths > 0 that do not have an associated sighting (threshold distance = 0.1)
zero_dist_segs <- y.eff.sight.strata$segdata$segnum[y.eff.sight.strata$segdata$dist<0.1] #define which segments are less than threshold
for(k in 1:length(zero_dist_segs)){ # For those segments less than threshold,
segnum_k <- zero_dist_segs[k]
y.eff.sight.strata$segdata$dist[y.eff.sight.strata$segdata$segnum==segnum_k] <- ifelse(y.eff.sight.strata$segdata$nSI_033[y.eff.sight.strata$segdata$segnum==segnum_k] > 0, 0.11,0) # If there is a sighting, increase distance to 0.11 to avoid filtering out
}
y.eff.sight.strata$segdata <- y.eff.sight.strata$segdata %>% filter(dist > 0.1)
# Error in data entry resulted in NA values in avgBft -- fix with Bft values provided from das file
if(any(is.na(y.eff.sight.strata$segdata$avgBft))){
fix_bft<-data.frame(NA_bft = which(is.na(y.eff.sight.strata$segdata$avgBft)), fixed = c(5,6,6,5,5,4,4))
y.eff.sight.strata$segdata[fix_bft$NA_bft,"avgBft"] <- fix_bft$fixed
}Save processed segment data
if (!dir.exists(file.path(localwd,"output"))) {
dir.create(file.path(localwd,"output"))
}
saveRDS(y.eff.sight.strata, file.path(localwd,"output", "seg_sight_out.rds"))