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
2 changes: 1 addition & 1 deletion R/calculate-consumed-biomass.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
#' select_groups = groups_rest, select_variable = "Grazing",
#' prm_run = prm_run, bboxes = bboxes)
#' df_dm <- load_dietcheck(dietcheck = file.path(d, "outputSETASDietCheck.txt"),
#' fgs = fgs, prm_run = prm_run, version_flag = 2, convert_names = TRUE)
#' fgs = fgs, prm_run = prm_run, convert_names = TRUE)
#' vol <- load_nc_physics(nc = nc_gen, select_physics = "volume",
#' prm_run = prm_run, bboxes = bboxes, aggregate_layers = FALSE)
#'
Expand Down
16 changes: 5 additions & 11 deletions R/change-prm.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ change_prm <- function(
roc,
parameter,
relative = TRUE,
save_to_disc = TRUE,
version_flag = 2
save_to_disc = TRUE
) {
if (length(parameter) != 1) {
stop("Please suply only one parameter per function call.")
Expand Down Expand Up @@ -64,15 +63,10 @@ change_prm <- function(
new_value <- roc
}

# Update value. Some pesky expectations have to be added here.
if (
is.element(parameter, c("mum", "C", "mQ", "mL", "jmL", "jmQ")) &
version_flag == 1
) {
prm_biol[pos] <- paste(paste0(flag, "_T15"), new_value, sep = "\t")
} else {
prm_biol[pos] <- paste(flag, new_value, sep = "\t")
}
# Update value.

prm_biol[pos] <- paste(flag, new_value, sep = "\t")

return(prm_biol)
}

Expand Down
33 changes: 14 additions & 19 deletions R/load-dietcheck.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@
#' diet <- load_dietcheck(dietcheck, fgs, prm_run)
#' head(diet, n = 10)

#BJS 7/6/16 change to be compatible with trunk version; added version_flag
load_dietcheck <- function(
dietcheck,
fgs,
prm_run,
convert_names = FALSE,
report = FALSE,
version_flag = 2
report = FALSE
) {
# read in diet information
diet <- utils::read.table(
Expand All @@ -41,20 +39,19 @@ load_dietcheck <- function(
)

#Check if multiple stocks are available per functional group for trunk branch!
if (version_flag == 2) {
if (all(diet$Stock) == 0) {
diet$Stock <- NULL
} else {
stop(
"Multiple stocks present. Dietcheck only works with 1 stock per funtional group."
)
}

diet$Cohort <- diet$Cohort + 1 # Cohorts start with 0 in DietCheck.txt!
if (all(diet$Stock) == 0) {
diet$Stock <- NULL
} else {
stop(
"Multiple stocks present. Dietcheck only works with 1 stock per funtional group."
)
}

diet$Cohort <- diet$Cohort + 1 # Cohorts start with 0 in DietCheck.txt!

# Column Updated was added to trunk code.
if (version_flag == 2 & "Updated" %in% names(diet)) {
if ("Updated" %in% names(diet)) {
prey_col_start <- 5 #bjs remove magic number below
} else {
prey_col_start <- 4 #bjs remove magic number below
Expand Down Expand Up @@ -112,12 +109,10 @@ load_dietcheck <- function(

names(diet_long)[names(diet_long) == "Predator"] <- "pred" #bjs predator -> colnames(diet)[2]

if (version_flag == 2) {
names(diet_long)[names(diet_long) == "Cohort"] <- "agecl" #bjs cohort -> colnames(diet)[3]
# Column Updated was added to trunk code.
if ("Updated" %in% names(diet_long)) {
diet_long <- diet_long[, names(diet_long) != "Updated"]
}
names(diet_long)[names(diet_long) == "Cohort"] <- "agecl" #bjs cohort -> colnames(diet)[3]
# Column Updated was added to trunk code.
if ("Updated" %in% names(diet_long)) {
diet_long <- diet_long[, names(diet_long) != "Updated"]
}

names(diet_long) <- tolower(names(diet_long))
Expand Down
19 changes: 3 additions & 16 deletions R/load-dietmatrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#' diet matrix entries.
#' @param convert_names Logical indicating if group codes are transformed to LongNames (\code{TRUE})
#' or not (default = \code{FALSE}).
#' @param version_flag The version of ATLANTIS model. 1 for bec_dev, 2 for trunk. \code{default is 2.}.
#' @return dataframe of the availability matrix in long format with columns
#' pred, pred_stanza (1 = juvenile, 2 = adult), prey_stanza, prey, avail, code.
#' @param dietmatrix Dataframe of the ATLANTIS dietmatrix generated with \code{load_dietmatrix}
Expand Down Expand Up @@ -41,8 +40,7 @@ load_dietmatrix <- function(
prm_biol,
fgs,
transform = TRUE,
convert_names = FALSE,
version_flag = 2
convert_names = FALSE
) {
fgs_data <- load_fgs(fgs = fgs)
acr <- fgs_data$Code[
Expand All @@ -63,10 +61,8 @@ load_dietmatrix <- function(
coh2 <- acr[agecl == 2]
coh1 <- acr[agecl == 1]

if (version_flag == 2) {
coh10 <- c(coh10, coh2)
coh2 <- NULL
}
coh10 <- c(coh10, coh2)
coh2 <- NULL

if (length(c(coh10, coh2, coh1)) != length(acr)) {
stop("Incomplete functional groups file.")
Expand Down Expand Up @@ -237,12 +233,3 @@ write_diet <- function(dietmatrix, prm_biol, save_to_disc = TRUE) {
}
}
}

# sicily debugging
# dir <- "z:/my_data_alex/Matteo/"
# prm_biol <- list.files(dir)[2]
# fgs <- list.files(dir)[1]
# transform <- FALSE
# convert_names <- FALSE
# version_flag <- 1
# dietmatrix <- load_dietmatrix(dir, prm_biol, fgs, transform, convert_names, version_flag)
1 change: 0 additions & 1 deletion R/load-mort.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#' df <- load_mort(mortFile, prm_run, fgs)
#' head(df)

#BJS 7/15/16 add version_flag and make compatible with trunk output
load_mort <- function(mortFile, prm_run, fgs, convert_names = F) {
mort <- load_txt(file = mortFile, id_col = c("Time"))

Expand Down
1 change: 0 additions & 1 deletion R/load-spec-mort.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#' df <- load_spec_mort(specmort, prm_run, fgs)
#' head(df)

#BJS 7/15/16 add version_flag and make compatible with trunk output
load_spec_mort <- function(
mortFile,
prm_run,
Expand Down
43 changes: 11 additions & 32 deletions R/load-spec-pred-mort.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,45 +20,24 @@
#' df <- load_spec_pred_mort(specmort, prm_run, fgs)
#' head(df)

#BJS 7/15/16 add version_flag and make compatible with trunk output
load_spec_pred_mort <- function(
specmort,
prm_run,
fgs,
convert_names = FALSE,
version_flag = 2
convert_names = FALSE
) {
if (version_flag == 1) {
mort <- load_txt(file = specmort)
mort <- mort |>
tidyr::separate(
col = "code",
into = c("prey", "agecl", "stock", "pred", "mort"),
convert = TRUE
)
# check uniqueness of column notsure and mort
if (
any(
sapply(mort[, c("stock", "mort")], function(x) length(unique(x))) != 1
)
) {
stop(
"Multiple stocks present. This is not covered by the current version of atlantistools. Please contact the package development team."
)
}
} else if (version_flag == 2) {
mort <- load_txt(
file = specmort,
id_col = c("Time", "Group", "Cohort", "Stock")
mort <- load_txt(
file = specmort,
id_col = c("Time", "Group", "Cohort", "Stock")
)
mort <- mort |>
dplyr::rename(pred = group, agecl = cohort, prey = code)
if (any(sapply(mort[, "stock"], function(x) length(unique(x))) != 1)) {
stop(
"Multiple stocks present. This is not covered by the current version of atlantistools. Please contact the package development team."
)
mort <- mort |>
dplyr::rename(pred = group, agecl = cohort, prey = code)
if (any(sapply(mort[, "stock"], function(x) length(unique(x))) != 1)) {
stop(
"Multiple stocks present. This is not covered by the current version of atlantistools. Please contact the package development team."
)
}
}

mort$agecl <- mort$agecl + 1

# Remove unnecessary columns
Expand Down
6 changes: 2 additions & 4 deletions R/sc-init.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ sc_init <- function(
fgs,
bboxes,
pred = NULL,
set_avail = NULL,
version_flag = 2
set_avail = NULL
) {
fgs_data <- load_fgs(fgs = fgs)

Expand Down Expand Up @@ -259,8 +258,7 @@ sc_init <- function(
dm <- load_dietmatrix(
prm_biol = prm_biol,
fgs = fgs,
convert_names = TRUE,
version_flag = version_flag
convert_names = TRUE
) |>
dplyr::filter(avail != 0) |>
dplyr::left_join(ass_type, by = "prey")
Expand Down
34 changes: 0 additions & 34 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,37 +64,3 @@ release_questions <- function() {
"Have you run devtools::build_win(args = '--compact-vignettes=both') to check with win-builder?"
)
}

# dir <- "C:/Users/alexanderke/Dropbox/Atlantis_SoS_Files_Alex"
# setwd(dir)
# nomeNc <- "output/out_newfleet9"
#
# nc_gen <- paste(nomeNc,".nc",sep="")
# nc_prod <- paste(nomeNc,"PROD.nc",sep="")
# dietcheck <- paste(nomeNc,"DietCheck.txt",sep="")
# yoy <- paste(nomeNc,"YOY.txt",sep="")
# ssb <- paste(nomeNc,"SSB.txt",sep="")
# specmort <- paste(nomeNc,"SpecificMort.txt",sep="")
# predspecmort <-paste(nomeNc,"SpecificPredMort.txt",sep="")
# version_flag <- 1
#
# prm_run <- "Sic_run_fishing_F_gape100_65yr.prm"
# prm_biol <- "Sic_biol_newfleet21.prm"
# fgs <- "newFGHorMigr.csv"
# bgm <- "geometry.bgm"
# init <- "inSic26042017.nc"
#
# bboxes <- get_boundary(boxinfo = load_box(bgm))
# bps <- load_bps(fgs, init)
# bio_conv <- get_conv_mgnbiot(prm_biol)
#
# groups <- get_groups(fgs)
# groups_age <- get_age_groups(fgs)
#
# load_nc(nc = nc_gen, bps = bps, select_groups = groups_age[1:5], select_variable = "ResN", fgs = fgs, prm_run = prm_run, bboxes = bboxes)
#
# nc = nc_gen
# select_groups = groups_age[1:5]
# select_variable = "ResN"
#
# agemat <- prm_to_df(prm_biol, fgs, group = get_age_acronyms(fgs), "age_mat")
1 change: 0 additions & 1 deletion data-raw/data-create-reference-dfs.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ ref_dm <- atlantistools::load_dietcheck(
dietcheck = dietcheck,
fgs = fgs,
prm_run = prm_run,
version_flag = 2,
convert_names = TRUE
)

Expand Down
2 changes: 1 addition & 1 deletion man/calculate_consumed_biomass.Rd

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

5 changes: 1 addition & 4 deletions man/change_prm.Rd

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

11 changes: 1 addition & 10 deletions man/load_dietcheck.Rd

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

10 changes: 1 addition & 9 deletions man/load_dietmatrix.Rd

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

10 changes: 1 addition & 9 deletions man/load_spec_pred_mort.Rd

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

Loading
Loading