Skip to content

Commit

Permalink
Merge pull request #860 from ichimomo/release2024
Browse files Browse the repository at this point in the history
update
  • Loading branch information
ichimomo authored Jul 3, 2024
2 parents 3c0d437 + 5073b7b commit 27b5718
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 18 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: frasyr
Title: Fisheries Research Agency (FRA) provides the method for calculating sustainable yield (SY) with R
Version: 2.3.0.0
Version: 2.4.0.0
Authors@R: c(person(given="Momoko", family="Ichinokawa", email = "ichinokawa_momoko09@fra.go.jp", role = c("aut", "cre")),
person(given="Mitsuyo", family="Miyagawa", email = "miyagawa_mitsuyo88@fra.go.jp", role = c("aut")),
person(given="Kohei", family="Hamabe", email = "hamabe_kohei20@fra.go.jp", role = c("aut")),
Expand All @@ -10,7 +10,7 @@ Depends: R (>= 4.0.0)
License: GPL (>=3)
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Imports:
ggplot2,
purrr,
Expand Down
11 changes: 6 additions & 5 deletions R/utilities.r
Original file line number Diff line number Diff line change
Expand Up @@ -3195,13 +3195,14 @@ calculate_all_pm <- function(res_future, SBtarget=-1, SBlimit=-1, SBban=-1, SBmi
ABC_year <- res_future$mat_year$year[res_future$mat_year$is_manage] %>% min()
}
period_range <- list(0:9, 0:4, 5:9, 1:10, 1:4, 6:10)
ss <- rep(TRUE,length(period_extra))
if(!is.null(period_extra)){
for(i in 1:length(period_extra)){
if(sum(purrr::map_lgl(period_range, function(x) all(x==period_extra[[i]])))==0){
period_range <- c(period_range, period_extra[i])
}
}
}
for(j in 1:length(period_range)){
if(length(period_extra[[i]])==length(period_range[[j]]) && all(period_extra[[i]]==period_range[[j]]))
ss[[i]] <- FALSE
}}}
period_range <- c(period_range, period_extra[ss])
period_list <- purrr::map(period_range, function(x) ABC_year + x)
names(period_list) <- purrr::map_chr(period_list, function(x) str_c(range(x),collapse="."))

Expand Down
2 changes: 2 additions & 0 deletions man/compare_SRfit.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/future_vpa.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 13 additions & 7 deletions tests/testthat/test-future-part.R
Original file line number Diff line number Diff line change
Expand Up @@ -414,22 +414,29 @@ test_that("check MSE feature",{ # ----

test_that("future_vpa function (carry over TAC) (level 2)",{

# 0.1まで繰越
data_future_test <- redo_future(data_future_test,
list(nsim=10,nyear=10,
HCR_TAC_reserve_rate=0.1,
HCR_TAC_carry_rate=0.1,
fix_recruit=NULL,fix_wcatch=NULL),
only_data=TRUE)
# 0.1まで繰越
data_future_no_reserve <- list_modify(data_future_test$input,HCR_TAC_reserve_rate=0) %>%
safe_call(make_future_data,.)

res_future_noMSE <- test_sd0_future(data_future_test)$res1
expect_equal(all(round(res_future_noMSE$HCR_realized[as.character(2019:2023),,"wcatch"]/
res_future_noMSE$HCR_realized[as.character(2019:2023),,"original_ABC_plus"],3)
==0.9),TRUE)
==0.9),TRUE)

# 繰入する場合
data_future_borrow <- list_modify(data_future_test$input,HCR_TAC_reserve_rate=-0.1, HCR_TAC_carry_rate=1) %>%
safe_call(make_future_data,.)
res_future_borrow <- test_sd0_future(data_future_borrow)$res1
expect_equal(all(round(res_future_borrow$HCR_realized[as.character(2019:2023),,"wcatch"]/
res_future_borrow$HCR_realized[as.character(2019:2023),,"original_ABC_plus"],3)
==1.1),TRUE)

# 余るけど繰越をしない場合
data_future_no_reserve <- list_modify(data_future_test$input,HCR_TAC_reserve_rate=0) %>%
safe_call(make_future_data,.)
res_future_noreserve <- test_sd0_future(data_future_no_reserve)$res1
expect_equal(all(round(res_future_noreserve$HCR_realized[as.character(2019:2023),,"wcatch"]/
res_future_noreserve$HCR_realized[as.character(2019:2023),,"original_ABC_plus"],3)
Expand Down Expand Up @@ -489,8 +496,7 @@ test_that("future_vpa function (carry over TAC) (level 2)",{
res_future_reserve_CC1$HCR_realized[as.character(2019:2025),1,"original_ABC_plus"]%>%
round() %>% unlist() %>% as.numeric() %>% expect_equal(c(100,rep(110,6)))

expect_error(data_future_no_reserve <- list_modify(data_future_test$input,HCR_TAC_reserve_rate=-1) %>%
safe_call(make_future_data,.))


})

Expand Down
5 changes: 3 additions & 2 deletions tests/testthat/test-utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -430,16 +430,17 @@ test_that("calculate_all_pm", {
all_pm <- calculate_all_pm(res_future)
expect_equal(is_tibble(all_pm),TRUE)

# 暫定テスト(1:10までの出力が一致するか)
# 暫定テスト(1:10までの出力が一致するか) => 出力範囲を過去にさかのぼって変えたため、参照範囲を修正
c(`2017` = 710.22, `2018` = 447.9, `2019` = 470.5, `2020` = 1000,
`2021` = 2000, `2022` = 941.73, `2023` = 954.37, `2024` = 918.09,
`2025` = 897.95, `2026` = 895.95) %>%
expect_equal(round(all_pm$value[1:10],2))
expect_equal(round(all_pm$value[30:39],2))

# 引数extra_periodの確認
all_pm1 <- calculate_all_pm(res_future, period_extra=list(2:6, 0:4))
all_pm2 <- calculate_all_pm(res_future, period_extra=list(2:6))

expect_equal(all_pm1, all_pm2)
expect_equal(nrow(all_pm)<nrow(all_pm1), TRUE)

})

0 comments on commit 27b5718

Please sign in to comment.