Skip to content

Commit

Permalink
add length-age conversion matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristineStawitz-NOAA committed Sep 24, 2024
1 parent b26c118 commit edbdc25
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
6 changes: 5 additions & 1 deletion tests/testthat/fixtures/simulate-length-test-data.r
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,15 @@ for(i in seq_along(ages)){
colnames(length_age_conversion) <- len_bins
rownames(length_age_conversion) <- ages


#add code to simulate length data
length_data <- 0L

on.exit(unlink(maindir, recursive = TRUE), add = TRUE)

setwd(working_dir)
on.exit(setwd(working_dir), add = TRUE)

save(om_input_list, length_age_conversion,
save(om_input_list, length_age_conversion, length_data,
file = test_path("fixtures", "length_test_data.RData")
)
26 changes: 26 additions & 0 deletions tests/testthat/test-rcpp-fleet-interface.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,30 @@ fleet module", {
clear()
})

test_that("Fleet: length composition can be added to the
fleet module", {

# set fishing fleet age comp data, need to set dimensions of age comps
fishing_fleet_length_comp <- new(LengthComp, om_input$nyr, om_input$nages)
fishing_fleet_length_comp$length_comp_data <- c(t(length_data)) * length(om_input_list$len_bins)

# Add selectivity to fleet
fleet1 <- new(Fleet)

fleet1$nages <- om_input$nages
fleet1$nyears <- om_input$nyr
fleet1$nlengths <- length(om_input_list$len_bins)
fleet1$age_length_conversion_matrix <- length_age_conversion #this should be a matrix of dim nages * nlengths
fleet1$log_Fmort <- methods::new(ParameterVector, log(om_output$f), om_input$nyr)
fleet1$log_Fmort$set_all_estimable(TRUE)
fleet1$log_q <- log(1.0)
fleet1$estimate_q <- FALSE
fleet1$random_q <- FALSE

# Set up fishery age composition data using the multinomial
fishing_fleet_lengthcomp_distribution <- methods::new(TMBDmultinomDistribution)
fishing_fleet_lengthcomp_distribution$set_observed_data(fishing_fleet_length_comp$get_id())
fishing_fleet_lengthcomp_distribution$set_distribution_links("data", fishing_fleet$proportion_catch_numbers_at_length$get_id())

clear()
})

0 comments on commit edbdc25

Please sign in to comment.