Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix render issues caused by r4ss changes #48

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions content/NWFSC-petrale.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion content/PIFS-opakapaka.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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 ----
Expand Down
24 changes: 12 additions & 12 deletions content/R/get_ss3_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -102,39 +102,39 @@ 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
# NOTE: this removes some age comp data because there
# 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?
Expand Down
4 changes: 2 additions & 2 deletions content/SWFSC-sardine.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -330,15 +330,15 @@ 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,
# 0.133855,0.154360,0.174905,0.184200,
# 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
Expand Down
Loading