Is it something that I am doing or something funky with the function? Thanks! Tagging in @sowasser for awareness.
sql_channel <- gapindex::get_connected()
## Pull data. Note the format of the `spp_codes` argument with the GROUP column
library(gapindex)
production_data <- get_data(
year_set = c(1982:2023),
survey_set = c("EBS", "NBS"),
spp_codes = rbind(data.frame(GROUP = "all flatfishes", SPECIES_CODE = c(10000:10399)),
data.frame(GROUP = "neptune welks", SPECIES_CODE = c(71884, 71882))),
pull_lengths = TRUE,
haul_type = 3,
abundance_haul = "Y",
sql_channel = channel)
## Zero-fill and calculate CPUE
production_cpue <- calc_cpue(racebase_tables = production_data)
## Calculate Biomass, abundance, mean CPUE, and associated variances by stratum
production_biomass_stratum <-
gapindex::calc_biomass_stratum(racebase_tables = production_data,
cpue = production_cpue)
## Aggregate Biomass to subareas and region
production_biomass_subarea <-
calc_biomass_subarea(racebase_tables = production_data,
biomass_strata = production_biomass_stratum)
## Calculate size composition by stratum. Note fill_NA_method == "BS" because
## our region is EBS, NBS, or BSS. If the survey region of interest is AI or
## GOA, use "AIGOA". See ?gapindex::gapindex::calc_sizecomp_stratum for more
## details.
production_sizecomp_stratum <-
gapindex::calc_sizecomp_stratum(
racebase_tables = production_data,
racebase_cpue = production_cpue,
racebase_stratum_popn = production_biomass_stratum,
spatial_level = "stratum",
fill_NA_method = "BS")
## Aggregate size composition to subareas/region
production_sizecomp_subarea <- gapindex::calc_sizecomp_subarea(
racebase_tables = production_data,
size_comps = production_sizecomp_stratum)
## rbind stratum and subarea/region biomass estimates into one dataframe
names(x = production_biomass_stratum)[
names(x = production_biomass_stratum) == "STRATUM"
] <- "AREA_ID"
production_biomass <- rbind(production_biomass_stratum,
production_biomass_subarea)
## rbind stratum and subarea/region biomass estimates into one dataframe
names(x = production_sizecomp_stratum)[
names(x = production_sizecomp_stratum) == "STRATUM"] <- "AREA_ID"
production_sizecomp <-
rbind(production_sizecomp_subarea,
production_sizecomp_stratum[, names(production_sizecomp_subarea)])
library(dplyr)
production_biomass %>%
dplyr::select(SURVEY_DEFINITION_ID, AREA_ID, SPECIES_CODE) %>%
table() %>%
data.frame() %>%
dplyr::filter(Freq != 0) %>%
dplyr::arrange(desc(AREA_ID)) %>%
head()
production_biomass %>%
unique() %>% # to address point 2
dplyr::select(SURVEY_DEFINITION_ID, AREA_ID, SPECIES_CODE) %>%
table() %>%
data.frame() %>%
dplyr::filter(Freq != 0) %>%
dplyr::arrange(desc(AREA_ID)) %>%
head()
production_sizecomp %>%
dplyr::select(SURVEY_DEFINITION_ID, AREA_ID, SPECIES_CODE) %>%
table() %>%
data.frame() %>%
dplyr::arrange(desc(AREA_ID)) %>%
head(10)