Skip to content

Commit

Permalink
update for widow rockfish
Browse files Browse the repository at this point in the history
  • Loading branch information
chantelwetzel-noaa committed Jan 15, 2025
1 parent 1d05a26 commit 4fe162b
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 87 deletions.
2 changes: 1 addition & 1 deletion data-raw/configuration.csv
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"sharpchin rockfish","nwfscSurvey::pull_catch(common_name = species,survey=source)","NWFSC.Combo","sdmTMB::delta_lognormal()","catch_weight ~ 0 + fyear + pass_scaled",-55,-475,33,Inf,-Inf,Inf,TRUE,200,"iid","off",FALSE
"splitnose rockfish","nwfscSurvey::pull_catch(common_name = species,survey=source)","NWFSC.Combo","sdmTMB::delta_gamma()","catch_weight ~ 0 + fyear + pass_scaled",-55,-700,-Inf,Inf,-Inf,Inf,TRUE,500,"iid","off",FALSE
"stripetail rockfish","nwfscSurvey::pull_catch(common_name = species,survey=source)","NWFSC.Combo","sdmTMB::delta_gamma()","catch_weight ~ 0 + fyear",-55,-500,-Inf,Inf,-Inf,Inf,TRUE,500,"off","iid",FALSE
"widow rockfish","nwfscSurvey::pull_catch(common_name = species,survey=source)","NWFSC.Combo","sdmTMB::delta_gamma()","catch_weight ~ 0 + fyear + pass_scaled",-55,-675,33.5,Inf,-Inf,Inf,TRUE,200,"iid","off",TRUE
"widow rockfish","nwfscSurvey::pull_catch(common_name = species,survey=source)","NWFSC.Combo","sdmTMB::delta_lognormal()","catch_weight ~ 0 + fyear + pass_scaled",-55,-500,33.5,Inf,-Inf,Inf,TRUE,200,"iid","off",TRUE
"yelloweye rockfish","nwfscSurvey::pull_catch(common_name = species,survey=source)","NWFSC.Combo","sdmTMB::delta_gamma()","catch_weight ~ 0 + fyear + pass_scaled",-55,-325,34.5,Inf,-Inf,Inf,TRUE,200,"off","off",TRUE
"yellowtail rockfish","nwfscSurvey::pull_catch(common_name = species,survey=source)","NWFSC.Combo","sdmTMB::delta_gamma()","catch_weight ~ 0 + fyear*split_mendocino + pass_scaled",-55,-425,33.5,Inf,-Inf,Inf,TRUE,400,"iid","off",TRUE
"yellowtail rockfish","nwfscSurvey::pull_catch(common_name = species,survey=source)","Triennial","sdmTMB::delta_gamma()","catch_weight ~ 0 + fyear*split_mendocino",-55,-425,33.5,Inf,1980,Inf,TRUE,400,"iid","off",TRUE
Expand Down
Binary file modified data/configuration.rda
Binary file not shown.
211 changes: 125 additions & 86 deletions examples/2025_assessments.R
Original file line number Diff line number Diff line change
@@ -1,36 +1,31 @@
# Run with configuration file associated with
# commit 1d05a26e09f99e003120a18d0171b7249ea00654
library(dplyr)
library(indexwc)

savedir <- here::here("2025")

configuration_all <- tibble::as_tibble(read.csv(
file.path("data-raw", "configuration.csv")
))


# Tweaking stuff for wcgbt widow index
configuration_all[which(configuration_all$species == "widow rockfish" &
configuration_all$source == "NWFSC.Combo"), "knots"] <- 50

configuration_all[which(configuration_all$species == "widow rockfish" &
configuration_all$source == "NWFSC.Combo"), "spatiotemporal2"] <- "iid"


#===============================================================================
# NWFSC Combo All default setting species
#===============================================================================

wcgbt_species_list <- c(
"sablefish",
"chilipepper",
"rougheye rockfish",
"sablefish",
"widow rockfish",
"yelloweye rockfish",
"rougheye rockfish",
"rougheye and blackpotted rockfish"
"yellowtail rockfish"
)

configuration_sub <- configuration_all |>
dplyr::filter(source == "NWFSC.Combo", species %in% wcgbt_species_list)
dplyr::filter(source == "NWFSC.Combo",
species %in% wcgbt_species_list,
formula == "catch_weight ~ 0 + fyear + pass_scaled")

for(sp in wcgbt_species_list){
configuration <- configuration_sub |>
Expand All @@ -48,12 +43,7 @@ for(sp in wcgbt_species_list){
depth <= min_depth, depth >= max_depth,
latitude >= min_latitude, latitude <= max_latitude,
year >= min_year, year <= max_year
) |>
dplyr::mutate(
split_mendocino = 1,
split_conception = 1,
split_monterey = 1,
split_state = 1))
))
) |>
dplyr::ungroup()

Expand All @@ -79,80 +69,129 @@ for(sp in wcgbt_species_list){
}
}


#===============================================================================
# Yellowtail rockfish north - WCGBT
#===============================================================================

savedir <- "yellowtail_interaction"
configuration <- configuration_all |>
dplyr::filter(species == "yellowtail rockfish")
# Change the covariates to include a split at cape mendocino
configuration$formula <- "catch_weight ~ 0 + fyear*split_mendocino + pass_scaled"

data <- configuration |>
# Row by row ... do stuff then ungroup
dplyr::rowwise() |>
# Pull the data based on the function found in fxn column
dplyr::mutate(
data_raw = list(format_data(eval(parse(text = fxn)))),
data_filtered = list(data_raw |>
dplyr::filter(
depth <= min_depth, depth >= max_depth,
latitude >= min_latitude, latitude <= max_latitude,
year >= min_year, year <= max_year
) |>
dplyr::mutate(split_mendocino = ifelse(latitude > 40.1666667, "N", "S")))
) |>
dplyr::ungroup()

# Confirm no data in the south in 2007:
dplyr::filter(data$data_filtered[[1]], catch_weight > 0) |>
dplyr::group_by(split_mendocino, year) |>
dplyr::summarise(n = dplyr::n())

# Find variables that aren't identifiable for presence-absence model
lm <- lm(formula = as.formula(configuration$formula),
data = data$data_filtered[[1]])
#not_identifiable <- names(which(is.na(coef(lm))))
# Find variables that aren't identifiable for positive model
lm_pos <- lm(formula = as.formula(configuration$formula),
data = dplyr::filter(data$data_filtered[[1]], catch_weight>0))
pos_not_identifiable <- names(which(is.na(coef(lm_pos))))

# Create variables to be not estimated/ mapped off
coef_names <- names(coef(lm))
.map_pos <- coef_names
.map_pos[coef_names %in% pos_not_identifiable] <- NA
.map_pos <- factor(.map_pos)
.start_pos <- rep(0, length(coef_names))
.start_pos[coef_names %in% pos_not_identifiable] <- -20

best <- data |>
dplyr::mutate(
# Evaluate the call in family
family = purrr::map(family, .f = ~ eval(parse(text = .x))),
# Run the model on each row in data
results = purrr::pmap(
.l = list(
data = data_filtered,
formula = formula,
family = family,
anisotropy = anisotropy,
n_knots = knots,
share_range = share_range,
spatiotemporal = purrr::map2(spatiotemporal1, spatiotemporal2, list),
sdmtmb_control = list(
sdmTMB::sdmTMBcontrol(
map = list(b_j = .map_pos, b_j2 = .map_pos),
start = list(b_j = .start_pos, b_j2 = .start_pos),
newton_loops = 3
dplyr::filter(source == "NWFSC.Combo",
species == "yellowtail rockfish",
formula != "catch_weight ~ 0 + fyear + pass_scaled")

for (run in 1:nrow(configuration)){
data <- configuration[run, ] |>
# Row by row ... do stuff then ungroup
dplyr::rowwise() |>
# Pull the data based on the function found in fxn column
dplyr::mutate(
data_raw = list(format_data(eval(parse(text = fxn)))),
data_filtered = list(data_raw |>
dplyr::filter(
depth <= min_depth, depth >= max_depth,
latitude >= min_latitude, latitude <= max_latitude,
year >= min_year, year <= max_year
) |>
dplyr::mutate(split_mendocino = ifelse(latitude > 40.1666667, "N", "S")))
) |>
dplyr::ungroup()

# Confirm no data in the south in 2007:
dplyr::filter(data$data_filtered[[1]], catch_weight > 0) |>
dplyr::group_by(split_mendocino, year) |>
dplyr::summarise(n = dplyr::n())

# Find variables that aren't identifiable for presence-absence model
lm <- lm(formula = as.formula(configuration$formula),
data = data$data_filtered[[1]])
#not_identifiable <- names(which(is.na(coef(lm))))
# Find variables that aren't identifiable for positive model
lm_pos <- lm(formula = as.formula(configuration$formula),
data = dplyr::filter(data$data_filtered[[1]], catch_weight>0))
pos_not_identifiable <- names(which(is.na(coef(lm_pos))))

# Create variables to be not estimated/ mapped off
coef_names <- names(coef(lm))
.map_pos <- coef_names
.map_pos[coef_names %in% pos_not_identifiable] <- NA
.map_pos <- factor(.map_pos)
.start_pos <- rep(0, length(coef_names))
.start_pos[coef_names %in% pos_not_identifiable] <- -20

best <- data |>
dplyr::mutate(
# Evaluate the call in family
family = purrr::map(family, .f = ~ eval(parse(text = .x))),
# Run the model on each row in data
results = purrr::pmap(
.l = list(
dir_main = savedir,
data = data_filtered,
formula = formula,
family = family,
anisotropy = anisotropy,
n_knots = knots,
share_range = share_range,
spatiotemporal = purrr::map2(spatiotemporal1, spatiotemporal2, list),
sdmtmb_control = list(
sdmTMB::sdmTMBcontrol(
map = list(b_j = .map_pos, b_j2 = .map_pos),
start = list(b_j = .start_pos, b_j2 = .start_pos),
newton_loops = 3
)
)
)
),
.f = indexwc::run_sdmtmb
),
.f = indexwc::run_sdmtmb
)
)
)
}

#===============================================================================
# Widow rockfish - WCGBT
#===============================================================================
savedir <- "2025"
configuration <- configuration_all |>
dplyr::filter(source == "NWFSC.Combo",
species == "widow rockfish")

for (run in 1:nrow(configuration)){
data <- configuration[run, ] |>
# Row by row ... do stuff then ungroup
dplyr::rowwise() |>
# Pull the data based on the function found in fxn column
dplyr::mutate(
data_raw = list(format_data(eval(parse(text = fxn)))),
data_filtered = list(data_raw |>
dplyr::filter(
depth <= min_depth, depth >= max_depth,
latitude >= min_latitude, latitude <= max_latitude,
year >= min_year, year <= max_year
))
) |>
dplyr::ungroup()

best <- data |>
dplyr::mutate(
# Evaluate the call in family
family = purrr::map(family, .f = ~ eval(parse(text = .x))),
# Run the model on each row in data
results = purrr::pmap(
.l = list(
dir_main = savedir,
data = data_filtered,
formula = formula,
family = family,
anisotropy = anisotropy,
n_knots = knots,
share_range = share_range,
spatiotemporal = purrr::map2(spatiotemporal1, spatiotemporal2, list)#,
#priors = list(sdmTMB::sdmTMBpriors(
# matern_s = sdmTMB::pc_matern(range_gt = 10, sigma_lt = 5)
#))
),
.f = indexwc::run_sdmtmb
)
)
}

#===============================================================================
# NWFSC Slope
Expand Down

0 comments on commit 4fe162b

Please sign in to comment.