diff --git a/R/Biomass.fn.R b/R/Biomass.fn.R index bb733e1..12083db 100644 --- a/R/Biomass.fn.R +++ b/R/Biomass.fn.R @@ -35,7 +35,7 @@ Biomass.fn <- function(dir = NULL, dat, strat.vars = c("Depth_m", "Latitude_dd") if (is.null(dat$cpue_kg_km2)) stop("There must be a column called cpue_kg_km2 in the dataframe") # Calculate the CPUE in terms of nubmer - dat$cpue_km2_count <- (dat$total_catch_numbers / (0.01 * dat$Area_Swept_ha)) + dat$cpue_km2_count <- (dat$total_catch_numbers / (0.01 * dat$Area_swept_ha)) row.names(strat.df) <- strat.df[, 1] # put in rownmaes to make easier to index later numStrata <- nrow(strat.df) @@ -81,10 +81,10 @@ Biomass.fn <- function(dir = NULL, dat, strat.vars = c("Depth_m", "Latitude_dd") })) stratStats <- data.frame( - name = namesStrat, - area = strat.df[namesStrat, 2], + name = namesStrat, + area = strat.df[namesStrat, 2], ntows = nobs, - meanCatchRate = meanCatchRateInStrata, + meanCatchRate = meanCatchRateInStrata, varCatchRate = varCatchRateInStrata ) @@ -125,10 +125,10 @@ Biomass.fn <- function(dir = NULL, dat, strat.vars = c("Depth_m", "Latitude_dd") })) stratStats <- data.frame( - name = namesYear, - area = strat.df[ind, 2], + name = namesYear, + area = strat.df[ind, 2], ntows = nobs, - meanCatchRate = meanCatchRateInStrata, + meanCatchRate = meanCatchRateInStrata, varCatchRate = varCatchRateInStrata ) @@ -149,8 +149,8 @@ Biomass.fn <- function(dir = NULL, dat, strat.vars = c("Depth_m", "Latitude_dd") yrTotal.fn <- function(x) { data.frame( - Bhat = sum(x$Bhat), - seBhat = sqrt(sum(x$varBhat)), + Bhat = sum(x$Bhat), + seBhat = sqrt(sum(x$varBhat)), cv = sqrt(sum(x$varBhat)) / sum(x$Bhat)) } diff --git a/R/Format.AKSlope.fn.R b/R/Format.AKSlope.fn.R index ae56ac7..c80b243 100644 --- a/R/Format.AKSlope.fn.R +++ b/R/Format.AKSlope.fn.R @@ -1,44 +1,44 @@ #' Rename columns in the AFSC slope survey data file -#' received prior to the creation of the NWFSC data -#' warehouse. This function converts the older data files -#' to create the needed column names to work within survey +#' received prior to the creation of the NWFSC data +#' warehouse. This function converts the older data files +#' to create the needed column names to work within survey #' package functions. Output from this function will be list #' of containing catch, length, and age data. #' -#' @template dir -#' @param datTows A data frame of catch data for the +#' @template dir +#' @param datTows A data frame of catch data for the #' AKFSC slope survey with incorrect column names. #' prior to the creation of the data warehouse. -#' @param datL A list of biological data (lengths and ages) -#' for the AKFSC slope survey with incorrect column +#' @param datL A list of biological data (lengths and ages) +#' for the AKFSC slope survey with incorrect column #' names prior to the creation of the data warehouse. -#' @param start.year The first year of data to retain within +#' @param start.year The first year of data to retain within #' the data frame. The first year typically used from this -#' survey is 1997. +#' survey is 1997. #' @template verbose #' #' @author Chantel Wetzel #' @export -#' +#' #' @examples #' \dontrun{ #' # load data files for catch and biological data #' load("Tri.Shelf.and.AFSC.Slope.canary.Catch.24.May.11.dmp") -#' catch = Tri.Shelf.and.AFSC.Slope.canary.Catch.24.May.11 +#' catch = Tri.Shelf.and.AFSC.Slope.canary.Catch.24.May.11 #' load("AFSC.Slope.Shelf.sable.bio.5.24.11.dmp") #' bio = AK.Surveys.Bio.sablefish.24.May.11 #' # call function and reformat the data #' filter.dat = Format.AKSlope.fn( -#' datTows = catch, -#' datL = bio, -#' start.year = 1997) +#' datTows = catch, +#' datL = bio, +#' start.year = 1997) #' catch = filter.dat$datTows #' len = filter.dat$length #' age = filter.dat$age #' ) #' } #' -Format.AKSlope.fn <- function(dir = NULL, datTows, datL = NA, +Format.AKSlope.fn <- function(dir = NULL, datTows, datL = NA, start.year = 1997, verbose = TRUE) { check_dir(dir = dir, verbose) @@ -66,12 +66,12 @@ Format.AKSlope.fn <- function(dir = NULL, datTows, datL = NA, datTows$Longitude_dd <- (datTows$START_LONGITUDE + datTows$END_LONGITUDE) / 2 datTows$total_catch_numbers <- datTows$Subsample_count datTows$total_catch_wt_kg <- datTows$Subsample_wt_kg - datTows$Area_Swept_ha <- (datTows$DISTANCE_FISHED * datTows$NET_WIDTH) / 10 # area swept for each tow in hectare - datTows$cpue_kg_km2 <- datTows$Subsample_wt_kg / (0.01 * datTows$Area_Swept_ha) + datTows$Area_swept_ha <- (datTows$DISTANCE_FISHED * datTows$NET_WIDTH) / 10 # area swept for each tow in hectare + datTows$cpue_kg_km2 <- datTows$Subsample_wt_kg / (0.01 * datTows$Area_swept_ha) datTows <- datTows[, c( "Project", "Trawl_id", "Year", "Pass", "Vessel", "Tow", "Date", "Depth_m", "Longitude_dd", "Latitude_dd", - "Area_Swept_ha", "cpue_kg_km2", "Subsample_count", "Subsample_wt_kg", + "Area_swept_ha", "cpue_kg_km2", "Subsample_count", "Subsample_wt_kg", "total_catch_numbers", "total_catch_wt_kg" )] diff --git a/R/SurveyAgeAtLen.fn.R b/R/SurveyAgeAtLen.fn.R index 6a6bd18..b4b3698 100644 --- a/R/SurveyAgeAtLen.fn.R +++ b/R/SurveyAgeAtLen.fn.R @@ -65,7 +65,7 @@ SurveyAgeAtLen.fn <- function(dir = NULL, datAL, datTows, strat.vars = c("Depth_ Area_Swept_km2 <- Total_fish_number <- Sub_fish_number <- numeric(dim(datB)[1]) for (i in 1:length(tows)) { find <- which(tows[i] == datTows$Trawl_id) - area <- datTows$Area_Swept_ha[find] * 0.01 # km2 + area <- datTows$Area_swept_ha[find] * 0.01 # km2 tot.num <- datTows$total_catch_numbers[find] sub.num <- datTows$Subsample_count[find] @@ -140,7 +140,7 @@ SurveyAgeAtLen.fn <- function(dir = NULL, datAL, datTows, strat.vars = c("Depth_ datB[is.na(datB$numF), "numF"] <- 0 } - if ("M" %in% sexes_present){ + if ("M" %in% sexes_present){ temp <- TdatL.al[["M"]][, c("Trawl_id", "allLs", "allAs", "num")] names(temp) <- c("Trawl_id", "allLs", "allAs", "numM") datB <- merge(datB, temp, by = c("Trawl_id", "allLs", "allAs"), all = T) @@ -282,7 +282,7 @@ SurveyAgeAtLen.fn <- function(dir = NULL, datAL, datTows, strat.vars = c("Depth_ sum(x$numAll) })) x <- data.frame(x[rep(1, length(AjhAll)), xcols], area = A.h, AGE = as.numeric(names(AjhAll)), AjhAll = AjhAll, TotalAjhAll = AjhAll) - + if ("U" %in% sexes_present){ AjhU <- unlist(lapply(ages, function(x) { sum(x$numU) @@ -302,7 +302,7 @@ SurveyAgeAtLen.fn <- function(dir = NULL, datAL, datTows, strat.vars = c("Depth_ sum(x$numM) })) x <- data.frame(x, AjhM = AjhM, TotalAjhM = AjhM) - } + } } else { AjhAll <- unlist(lapply(ages, function(x) { @@ -314,12 +314,12 @@ SurveyAgeAtLen.fn <- function(dir = NULL, datAL, datTows, strat.vars = c("Depth_ sum(x$expU / x$areaFished) })) x <- data.frame(x, AjhU = AjhU / ntows, TotalAjhU = A.h * AjhU / ntows) - + AjhF <- unlist(lapply(ages, function(x) { sum(x$expF / x$areaFished) })) x <- data.frame(x, AjhF = AjhF / ntows, TotalAjhF = A.h * AjhF / ntows) - + AjhM <- unlist(lapply(ages, function(x) { sum(x$expM / x$areaFished) })) diff --git a/R/SurveyLFs.fn.R b/R/SurveyLFs.fn.R index 85f463d..ef21685 100644 --- a/R/SurveyLFs.fn.R +++ b/R/SurveyLFs.fn.R @@ -73,7 +73,7 @@ SurveyLFs.fn <- function(dir = NULL, datL, datTows, strat.vars = c("Depth_m", "L missing <- sum(postows[find, "total_catch_numbers"]) percent <- 100 * round(missing / sum(datTows[, "total_catch_numbers"]), 3) if (verbose) { - cat("\nThere are", x, "tows where fish were observed but no lengths/ages taken. + cat("\nThere are", x, "tows where fish were observed but no lengths/ages taken. These tows contain", missing, "lengths/ages that comprise", percent, "percent of total sampled fish.\n") } @@ -92,7 +92,7 @@ SurveyLFs.fn <- function(dir = NULL, datL, datTows, strat.vars = c("Depth_m", "L Area_Swept <- Total_fish_number <- Sub_fish_number <- Sexed_fish <- numeric(dim(datB)[1]) for (i in 1:length(tows)) { find <- which(tows[i] == datTows$Trawl_id) - area <- datTows$Area_Swept_ha[find] * 0.01 #km2 + area <- datTows$Area_swept_ha[find] * 0.01 #km2 #Alternative: * 10000 square meter tot.num <- datTows$total_catch_numbers[find] sub.num <- datTows$Subsample_count[find] @@ -154,13 +154,13 @@ SurveyLFs.fn <- function(dir = NULL, datL, datTows, strat.vars = c("Depth_m", "L TdatL.tows <- TdatL.tows[TdatL.tows$Var2 == "TRUE", ] if(dim(TdatL.tows)[1] > 0) { datB <- data.frame( - datB[match(as.character(TdatL.tows$Var1), - as.character(datB$Trawl_id)), ], + datB[match(as.character(TdatL.tows$Var1), + as.character(datB$Trawl_id)), ], TowExpFactorMF = TdatL.tows$Freq) # Find the numerator looking where the number of fish = sexed fish when all fish are sampled (e.g., sexed and unsexed in a fully sampled tow) # The previous approach expanded sexed fish relative to the full sample size resulting in expansions when there should not have been - datB <- data.frame(datB[match(as.character(TdatL.tows$Var1), - as.character(datB$Trawl_id)), ], + datB <- data.frame(datB[match(as.character(TdatL.tows$Var1), + as.character(datB$Trawl_id)), ], true_sub_MFfish = TdatL.tows$Freq) } if (is.null(datB$true_sub_MFfish)) { @@ -584,7 +584,7 @@ SurveyLFs.fn <- function(dir = NULL, datL, datTows, strat.vars = c("Depth_m", "L if (verbose && !is.null(dir)) { cat("\nNOTE: Files have been saved the the printfolder directory. - The first file has the 999 column showing fish smaller or younger than the initial bin. + The first file has the 999 column showing fish smaller or younger than the initial bin. Check to make sure there is not a large number of fish smaller or younger than the initial bin. The second file has combined the 999 with the first bin and is ready for use in SS.\n") }