Skip to content
Merged
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: 3 additions & 1 deletion R/load-nc-physics.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
#' nc <- file.path(d, "outputSETAS.nc")
#' prm_run <- file.path(d, "VMPA_setas_run_fishing_F_Trunk.prm")
#' bboxes <- get_boundary(boxinfo = load_box(file.path(d, bgm = "VMPA_setas.bgm")))
#' select_physics = c("salt", "NO3", "NH3", "Temp", "Chl_a", "Denitrifiction")
#'
#' test <- load_nc_physics(nc, select_physics, prm_run, bboxes)
#' str(test)
#' head(test)
#'
#' test <- load_nc_physics(nc, select_physics = "nominal_dz", prm_run, bboxes)
#' head(test)

load_nc_physics <- function(
nc,
Expand Down
2 changes: 1 addition & 1 deletion R/load-txt.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ load_txt <- function(file, id_col = "Time") {
names_to = "code",
values_to = "atoutput"
) |>
dplyr::arrange(id_col, code)
dplyr::arrange(dplyr::across(all_of(id_col)), code)

data$code <- as.character(data$code)
names(data) <- tolower(names(data))
Expand Down
34 changes: 20 additions & 14 deletions data-raw/data-create-reference-dfs.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ ssb <- file.path(d, "outputSETASSSB.txt")
prm_biol <- file.path(d, "VMPA_setas_biol_fishing_Trunk.prm")
prm_run <- file.path(d, "VMPA_setas_run_fishing_F_Trunk.prm")

boundary_boxes <- get_boundary(boxinfo = load_box(bgm = bgm))
epibenthic_groups <- load_bps(fgs = fgs, init = init)
boundary_boxes <- atlantistools::get_boundary(
boxinfo = atlantistools::load_box(bgm = bgm)
)
epibenthic_groups <- atlantistools::load_bps(fgs = fgs, init = init)
groups <- c(
"Planktiv_S_Fish",
"Pisciv_S_Fish",
Expand All @@ -25,7 +27,7 @@ groups <- c(
)
groups_age <- groups[1:2]
groups_rest <- groups[3:length(groups)]
bio_conv <- get_conv_mgnbiot(prm_biol = prm_biol)
bio_conv <- atlantistools::get_conv_mgnbiot(prm_biol = prm_biol)

# Create reference dataframes ---------------------------------------------------------------------
vars <- list("Nums", "StructN", "ResN", "Growth", "Eat", "Grazing", "N")
Expand All @@ -40,7 +42,7 @@ grps <- list(
groups_rest
)
dfs <- Map(
load_nc,
atlantistools::load_nc,
nc = ncs,
select_variable = vars,
select_groups = grps,
Expand All @@ -60,39 +62,39 @@ ref_eat <- dfs[[5]]
ref_grazing <- dfs[[6]]
ref_n <- dfs[[7]]

ref_vol_dz <- load_nc_physics(
ref_vol_dz <- atlantistools::load_nc_physics(
nc = nc_gen,
select_physics = c("volume", "dz"),
prm_run = prm_run,
bboxes = boundary_boxes,
aggregate_layers = F
)

ref_vol <- load_nc_physics(
ref_vol <- atlantistools::load_nc_physics(
nc = nc_gen,
select_physics = "volume",
prm_run = prm_run,
bboxes = boundary_boxes,
aggregate_layers = F
)

ref_physics <- load_nc_physics(
ref_physics <- atlantistools::load_nc_physics(
nc = nc_gen,
select_physics = c("salt", "NO3", "NH3", "Temp", "Chl_a", "Denitrifiction"),
prm_run = prm_run,
bboxes = boundary_boxes,
aggregate_layers = F
)

ref_dm <- load_dietcheck(
ref_dm <- atlantistools::load_dietcheck(
dietcheck = dietcheck,
fgs = fgs,
prm_run = prm_run,
version_flag = 2,
convert_names = TRUE
)

ref_bio_sp <- calculate_biomass_spatial(
ref_bio_sp <- atlantistools::calculate_biomass_spatial(
nums = ref_nums,
sn = ref_structn,
rn = ref_resn,
Expand All @@ -102,25 +104,29 @@ ref_bio_sp <- calculate_biomass_spatial(
bps = epibenthic_groups
)

ref_bio_cons <- calculate_consumed_biomass(
ref_bio_cons <- atlantistools::calculate_consumed_biomass(
eat = ref_eat,
grazing = ref_grazing,
dm = ref_dm,
vol = ref_vol,
bio_conv = bio_conv
)

ref_dietmatrix <- load_dietmatrix(prm_biol, fgs, convert_names = TRUE)
ref_dietmatrix <- atlantistools::load_dietmatrix(
prm_biol,
fgs,
convert_names = TRUE
)

ref_agemat <- prm_to_df(
ref_agemat <- atlantistools::prm_to_df(
prm_biol = prm_biol,
fgs = fgs,
group = get_age_acronyms(fgs = fgs),
group = atlantistools::get_age_acronyms(fgs = fgs),
parameter = "age_mat"
)

# Save to HDD and cleanup -------------------------------------------------------------------------
devtools::use_data(
usethis::use_data(
ref_eat,
ref_grazing,
ref_n,
Expand Down
4 changes: 3 additions & 1 deletion man/load_nc_physics.Rd

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

38 changes: 18 additions & 20 deletions tests/testthat/test-load-dietcheck.R
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
context("load_dietcheck test datastructure")

diet <- ref_dm

d <- system.file("extdata", "setas-model-new-trunk", package = "atlantistools")
test_that("test output numbers trunk", {
diet <- ref_dm

diet2 <- load_dietcheck(
dietcheck = file.path(d, "outputSETASDietCheck.txt"),
fgs = file.path(d, "SETasGroupsDem_NoCep.csv"),
prm_run = file.path(d, "VMPA_setas_run_fishing_F_Trunk.prm"),
report = FALSE,
version_flag = 2
)
d <- system.file(
"extdata",
"setas-model-new-trunk",
package = "atlantistools"
)

# This is only used for code-coverage purposes.
diet3 <- suppressWarnings(load_dietcheck(
dietcheck = file.path(d, "outputSETASDietCheck.txt"),
fgs = file.path(d, "SETasGroupsDem_NoCep.csv"),
prm_run = file.path(d, "VMPA_setas_run_fishing_F_Trunk.prm"),
report = TRUE,
version_flag = 2
))
diet2 <- load_dietcheck(
dietcheck = file.path(d, "outputSETASDietCheck.txt"),
fgs = file.path(d, "SETasGroupsDem_NoCep.csv"),
prm_run = file.path(d, "VMPA_setas_run_fishing_F_Trunk.prm"),
report = FALSE,
version_flag = 2
)

test_that("test output numbers trunk", {
# expect_true(all(abs(test1$check - 1) < 0.001))
expect_equal(dim(diet), c(241, 5))
expect_is(diet$pred, "character")
Expand Down Expand Up @@ -55,7 +51,8 @@ test_that("test output numbers trunk", {
diet2$agecl == 2 &
diet2$prey == "PL"
],
2.680623e-001
2.680623e-001,
tolerance = 1e-3
)
expect_equal(
diet2$atoutput[
Expand All @@ -64,6 +61,7 @@ test_that("test output numbers trunk", {
diet2$agecl == 1 &
diet2$prey == "CEP"
],
6.483338e-001
6.483338e-001,
tolerance = 1e-3
)
})
Loading
Loading