diff --git a/content/NWFSC-petrale.qmd b/content/NWFSC-petrale.qmd index c0ac3cd..e1c5810 100644 --- a/content/NWFSC-petrale.qmd +++ b/content/NWFSC-petrale.qmd @@ -77,8 +77,8 @@ source("R/get_ss3_data.R") # by assigning to fleet -1, these get filtered by get_ss3_data() # only include age comps with fleet = -4 or 1: -ss3dat$agecomp <- ss3dat$agecomp |> dplyr::filter(FltSvy %in% c(-4, 1)) -ss3dat$agecomp$FltSvy <- abs(ss3dat$agecomp$FltSvy) +ss3dat$agecomp <- ss3dat$agecomp |> dplyr::filter(fleet %in% c(-4, 1)) +ss3dat$agecomp$fleet <- abs(ss3dat$agecomp$fleet) # convert SS3 data into FIMS format using function defined in the R directory mydat <- get_ss3_data(ss3dat, fleets = c(1,4), ages = ages) diff --git a/content/PIFS-opakapaka.qmd b/content/PIFS-opakapaka.qmd index 0023b6c..0a74a79 100644 --- a/content/PIFS-opakapaka.qmd +++ b/content/PIFS-opakapaka.qmd @@ -53,8 +53,13 @@ load(file.path(getwd(), "data_files", "opaka_model.RDS")) ## Should now have ss3dat, ss3ctl, and ss3rep in environment ## RDS file can also be found at #githubURL <- "https://github.com/MOshima-PIFSC/Opaka-FIMS-Case-Study/blob/main/Model/FIMS-em/1/em/opaka_model.RDS" +# replace ss3dat and ss3ctl loaded from RDS file with new versions +# using current r4ss to read ss_new files from github +opaka_input <- r4ss::SS_read("https://raw.githubusercontent.com/MOshima-PIFSC/Opaka-FIMS-Case-Study/refs/heads/main/Model/FIMS-em/1/em/", ss_new = TRUE) +ss3dat <- opaka_input$dat +ss3ctl <- opaka_input$ctl -## Function written by Ian Taylor to get SS3 data into FIMSFrame format +## Function written by Ian Taylor and Meg Oshima to get SS3 data into FIMSFrame format source("./R/get_ss3_data.R") # Define the dimensions ---- diff --git a/content/R/get_ss3_data.R b/content/R/get_ss3_data.R index e0520ff..3ceb396 100644 --- a/content/R/get_ss3_data.R +++ b/content/R/get_ss3_data.R @@ -102,22 +102,22 @@ get_ss3_data <- function(dat, fleets, ages) { # further processing age_info <- dat$agecomp |> - dplyr::filter(FltSvy %in% fleets) |> # filter by requested fleets - dplyr::mutate(FltSvy = abs(FltSvy)) |> # convert any negative fleet to positive - dplyr::select(!dplyr::starts_with("m", ignore.case = FALSE)) |> # exclude male comps + dplyr::filter(fleet %in% fleets) |> # filter by requested fleets + dplyr::mutate(fleet = abs(fleet)) |> # convert any negative fleet to positive + dplyr::select(!dplyr::matches("^m[0-9]")) |> # exclude male comps tidyr::pivot_longer( # convert columns f1...f17 to values in a new "age" colum of a longer table - cols = dplyr::starts_with(c("f", "a"), ignore.case = FALSE), + cols = dplyr::matches("^f[0-9]") | dplyr::matches("^a[0-9]"), # 2-sex model uses f1, f2, ...; 1-sex model uses a1, a2, ... names_to = "age", values_to = "value" ) |> dplyr::mutate(age = as.numeric(substring(age, first = 2))) |> # convert "f17" to 17 - dplyr::select(Yr, FltSvy, Nsamp, age, value) + dplyr::select(year, fleet, Nsamp, age, value) # add -999 for missing years # create empty data frame for all combinations of year, fleet, and age age_info_empty <- tidyr::expand_grid( - Yr = years, - FltSvy = fleets, + year = years, + fleet = fleets, age = ages ) |> dplyr::mutate(Nsamp = 1, value = -999 - 0.001) # combine the two data frames and remove redundant rows @@ -125,16 +125,16 @@ get_ss3_data <- function(dat, fleets, ages) { # were years with multiple observations from the same fleet # due to multiple ageing error matrices age_info <- rbind(age_info, age_info_empty) |> - dplyr::distinct(Yr, FltSvy, age, .keep_all = TRUE) |> - dplyr::arrange(FltSvy, Yr, age) + dplyr::distinct(year, fleet, age, .keep_all = TRUE) |> + dplyr::arrange(fleet, year, age) # finish converting age comps to FIMSFrame format agecomps <- data.frame( type = "age", - name = paste0("fleet", abs(age_info$FltSvy)), # abs to include fleet == -4 + name = paste0("fleet", abs(age_info$fleet)), # abs to include fleet == -4 age = age_info$age, - datestart = paste0(age_info$Yr, "-01-01"), - dateend = paste0(age_info$Yr, "-12-31"), + datestart = paste0(age_info$year, "-01-01"), + dateend = paste0(age_info$year, "-12-31"), value = age_info$value + 0.001, # add constant to avoid 0 values unit = "", # Q: should uncertainty here be the total sample size across bins, or the samples within the bin? diff --git a/content/SWFSC-sardine.qmd b/content/SWFSC-sardine.qmd index a2a0b83..5b08681 100644 --- a/content/SWFSC-sardine.qmd +++ b/content/SWFSC-sardine.qmd @@ -330,7 +330,7 @@ ewaa_growth <- methods::new(EWAAgrowth) ewaa_growth$ages <- ages # NOTE: getting weight-at-age vector from # petrale_output$wtatage |> -# dplyr::filter(Sex == 1 & Fleet == -1 & Yr == 1876) |> +# dplyr::filter(sex == 1 & fleet == -1 & year == 1876) |> # dplyr::select(paste(0:40)) |> # round(4) # ewaa_growth$weights <- c(0.019490,0.077760,0.108865, @@ -338,7 +338,7 @@ ewaa_growth$ages <- ages # 0.196460,0.214155) -ewaa_growth$weights <- wtatage %>% filter(Fleet == 1, Yr == 2010) %>% select(as.character(0:10)) %>% t %>% +ewaa_growth$weights <- wtatage %>% filter(fleet == 1, year == 2010) %>% select(as.character(0:10)) %>% t %>% as.vector # maturity